From 977271f7953914ebd9c46d0e146b254fff5c9f72 Mon Sep 17 00:00:00 2001 From: Moiz Arafat Date: Mon, 4 May 2020 14:06:59 -0400 Subject: [PATCH] Enhancemnents to Aggregation Store (#1300) Co-authored-by: moiz arafat --- .../datastores/aggregation/annotation/Meta.java | 2 -- .../metadata/enums/FunctionArgumentType.java | 14 ++++++++++++++ .../aggregation/metadata/models/Column.java | 4 ---- .../metadata/models/FunctionArgument.java | 8 ++++++-- .../aggregation/metadata/models/Metric.java | 6 +----- .../metadata/models/MetricFunction.java | 2 -- .../queryengines/sql/metadata/SQLMetric.java | 3 +-- .../queryengines/sql/metric/SQLMetricFunction.java | 4 ++-- .../queryengines/sql/metric/functions/SqlAvg.java | 2 +- .../queryengines/sql/metric/functions/SqlMax.java | 2 +- .../queryengines/sql/metric/functions/SqlMin.java | 2 +- .../queryengines/sql/metric/functions/SqlSum.java | 2 +- .../aggregation/example/PlayerStats.java | 2 +- .../aggregation/example/PlayerStatsWithView.java | 2 +- .../AggregationDataStoreIntegrationTest.java | 3 +-- 15 files changed, 31 insertions(+), 27 deletions(-) create mode 100644 elide-datastore/elide-datastore-aggregation/src/main/java/com/yahoo/elide/datastores/aggregation/metadata/enums/FunctionArgumentType.java diff --git a/elide-datastore/elide-datastore-aggregation/src/main/java/com/yahoo/elide/datastores/aggregation/annotation/Meta.java b/elide-datastore/elide-datastore-aggregation/src/main/java/com/yahoo/elide/datastores/aggregation/annotation/Meta.java index 384eb4abd8..c3de42ab18 100644 --- a/elide-datastore/elide-datastore-aggregation/src/main/java/com/yahoo/elide/datastores/aggregation/annotation/Meta.java +++ b/elide-datastore/elide-datastore-aggregation/src/main/java/com/yahoo/elide/datastores/aggregation/annotation/Meta.java @@ -19,7 +19,5 @@ @Retention(RetentionPolicy.RUNTIME) public @interface Meta { - String longName() default ""; - String description() default ""; } diff --git a/elide-datastore/elide-datastore-aggregation/src/main/java/com/yahoo/elide/datastores/aggregation/metadata/enums/FunctionArgumentType.java b/elide-datastore/elide-datastore-aggregation/src/main/java/com/yahoo/elide/datastores/aggregation/metadata/enums/FunctionArgumentType.java new file mode 100644 index 0000000000..20a27addfb --- /dev/null +++ b/elide-datastore/elide-datastore-aggregation/src/main/java/com/yahoo/elide/datastores/aggregation/metadata/enums/FunctionArgumentType.java @@ -0,0 +1,14 @@ +/* + * Copyright 2019, Yahoo Inc. + * Licensed under the Apache License, Version 2.0 + * See LICENSE file in project root for terms. + */ +package com.yahoo.elide.datastores.aggregation.metadata.enums; + +/** + * Actual value type of a data type. + */ +public enum FunctionArgumentType { + REFERENCE, + PRIMITIVE; +} diff --git a/elide-datastore/elide-datastore-aggregation/src/main/java/com/yahoo/elide/datastores/aggregation/metadata/models/Column.java b/elide-datastore/elide-datastore-aggregation/src/main/java/com/yahoo/elide/datastores/aggregation/metadata/models/Column.java index 041b240ce7..c4fc0a7f7b 100644 --- a/elide-datastore/elide-datastore-aggregation/src/main/java/com/yahoo/elide/datastores/aggregation/metadata/models/Column.java +++ b/elide-datastore/elide-datastore-aggregation/src/main/java/com/yahoo/elide/datastores/aggregation/metadata/models/Column.java @@ -41,8 +41,6 @@ public abstract class Column { private final String name; - private final String longName; - private final String description; @ToOne @@ -69,10 +67,8 @@ protected Column(Table table, String fieldName, EntityDictionary dictionary) { Meta meta = dictionary.getAttributeOrRelationAnnotation(tableClass, Meta.class, fieldName); if (meta != null) { - this.longName = meta.longName(); this.description = meta.description(); } else { - this.longName = null; this.description = null; } diff --git a/elide-datastore/elide-datastore-aggregation/src/main/java/com/yahoo/elide/datastores/aggregation/metadata/models/FunctionArgument.java b/elide-datastore/elide-datastore-aggregation/src/main/java/com/yahoo/elide/datastores/aggregation/metadata/models/FunctionArgument.java index 8aae3517e5..f131fa54a8 100644 --- a/elide-datastore/elide-datastore-aggregation/src/main/java/com/yahoo/elide/datastores/aggregation/metadata/models/FunctionArgument.java +++ b/elide-datastore/elide-datastore-aggregation/src/main/java/com/yahoo/elide/datastores/aggregation/metadata/models/FunctionArgument.java @@ -6,6 +6,7 @@ package com.yahoo.elide.datastores.aggregation.metadata.models; import com.yahoo.elide.annotation.Include; +import com.yahoo.elide.datastores.aggregation.metadata.enums.FunctionArgumentType; import com.yahoo.elide.datastores.aggregation.metadata.enums.ValueType; import lombok.AllArgsConstructor; @@ -31,13 +32,16 @@ public class FunctionArgument { private ValueType type; - private String subType; + private FunctionArgumentType functionArgumentType; + + private String expression; public FunctionArgument(String functionName, FunctionArgument argument) { this.id = functionName + "." + argument.getName(); this.name = argument.getName(); this.description = argument.getDescription(); this.type = argument.getType(); - this.subType = argument.getSubType(); + this.functionArgumentType = argument.getFunctionArgumentType(); + this.expression = argument.getExpression(); } } diff --git a/elide-datastore/elide-datastore-aggregation/src/main/java/com/yahoo/elide/datastores/aggregation/metadata/models/Metric.java b/elide-datastore/elide-datastore-aggregation/src/main/java/com/yahoo/elide/datastores/aggregation/metadata/models/Metric.java index 4c38eb0856..cf7aadf087 100644 --- a/elide-datastore/elide-datastore-aggregation/src/main/java/com/yahoo/elide/datastores/aggregation/metadata/models/Metric.java +++ b/elide-datastore/elide-datastore-aggregation/src/main/java/com/yahoo/elide/datastores/aggregation/metadata/models/Metric.java @@ -56,7 +56,6 @@ public Metric(Table table, String fieldName, EntityDictionary dictionary) { if (formula != null) { this.metricFunction = constructMetricFunction( constructColumnName(tableClass, fieldName, dictionary) + "[" + fieldName + "]", - meta == null ? null : meta.longName(), meta == null ? null : meta.description(), formula.value(), new HashSet<>()); @@ -89,7 +88,6 @@ private static MetricFunction resolveAggregation(Class tableClass, metricFunction.setName(columnName + "[" + metricFunction.getName() + "]"); if (meta != null) { - metricFunction.setLongName(meta.longName()); metricFunction.setDescription(meta.description()); } @@ -103,17 +101,15 @@ private static MetricFunction resolveAggregation(Class tableClass, * Dynamically construct a metric function * * @param id metric function id - * @param longName meta long name * @param description meta description * @param expression expression string * @param arguments function arguments * @return a metric function instance */ protected MetricFunction constructMetricFunction(String id, - String longName, String description, String expression, Set arguments) { - return new MetricFunction(id, longName, description, expression, arguments); + return new MetricFunction(id, description, expression, arguments); } } diff --git a/elide-datastore/elide-datastore-aggregation/src/main/java/com/yahoo/elide/datastores/aggregation/metadata/models/MetricFunction.java b/elide-datastore/elide-datastore-aggregation/src/main/java/com/yahoo/elide/datastores/aggregation/metadata/models/MetricFunction.java index c790a71298..0b68d8b21a 100644 --- a/elide-datastore/elide-datastore-aggregation/src/main/java/com/yahoo/elide/datastores/aggregation/metadata/models/MetricFunction.java +++ b/elide-datastore/elide-datastore-aggregation/src/main/java/com/yahoo/elide/datastores/aggregation/metadata/models/MetricFunction.java @@ -28,8 +28,6 @@ public class MetricFunction { @Id private String name; - private String longName; - private String description; private String expression; diff --git a/elide-datastore/elide-datastore-aggregation/src/main/java/com/yahoo/elide/datastores/aggregation/queryengines/sql/metadata/SQLMetric.java b/elide-datastore/elide-datastore-aggregation/src/main/java/com/yahoo/elide/datastores/aggregation/queryengines/sql/metadata/SQLMetric.java index 1ef40099dd..be61cb4ecc 100644 --- a/elide-datastore/elide-datastore-aggregation/src/main/java/com/yahoo/elide/datastores/aggregation/queryengines/sql/metadata/SQLMetric.java +++ b/elide-datastore/elide-datastore-aggregation/src/main/java/com/yahoo/elide/datastores/aggregation/queryengines/sql/metadata/SQLMetric.java @@ -26,11 +26,10 @@ public SQLMetric(SQLTable table, String fieldName, EntityDictionary dictionary) @Override protected SQLMetricFunction constructMetricFunction(String id, - String longName, String description, String expression, Set arguments) { - return new SQLMetricFunction(id, longName, description, expression, arguments); + return new SQLMetricFunction(id, description, expression, arguments); } /** diff --git a/elide-datastore/elide-datastore-aggregation/src/main/java/com/yahoo/elide/datastores/aggregation/queryengines/sql/metric/SQLMetricFunction.java b/elide-datastore/elide-datastore-aggregation/src/main/java/com/yahoo/elide/datastores/aggregation/queryengines/sql/metric/SQLMetricFunction.java index 5cc0eb00d7..904a353d6f 100644 --- a/elide-datastore/elide-datastore-aggregation/src/main/java/com/yahoo/elide/datastores/aggregation/queryengines/sql/metric/SQLMetricFunction.java +++ b/elide-datastore/elide-datastore-aggregation/src/main/java/com/yahoo/elide/datastores/aggregation/queryengines/sql/metric/SQLMetricFunction.java @@ -14,8 +14,8 @@ * SQL extension of {@link MetricFunction} which would be invoked as sql and can construct sql templates. */ public class SQLMetricFunction extends MetricFunction { - public SQLMetricFunction(String name, String longName, String description, String expression, + public SQLMetricFunction(String name, String description, String expression, Set arguments) { - super(name, longName, description, expression, arguments); + super(name, description, expression, arguments); } } diff --git a/elide-datastore/elide-datastore-aggregation/src/main/java/com/yahoo/elide/datastores/aggregation/queryengines/sql/metric/functions/SqlAvg.java b/elide-datastore/elide-datastore-aggregation/src/main/java/com/yahoo/elide/datastores/aggregation/queryengines/sql/metric/functions/SqlAvg.java index 4ff7ddeb81..b6b22d08e5 100644 --- a/elide-datastore/elide-datastore-aggregation/src/main/java/com/yahoo/elide/datastores/aggregation/queryengines/sql/metric/functions/SqlAvg.java +++ b/elide-datastore/elide-datastore-aggregation/src/main/java/com/yahoo/elide/datastores/aggregation/queryengines/sql/metric/functions/SqlAvg.java @@ -14,6 +14,6 @@ */ public class SqlAvg extends SQLMetricFunction { public SqlAvg() { - super("avg", "average", "sql average function", "AVG(%s)", Collections.emptySet()); + super("avg", "sql average function", "AVG(%s)", Collections.emptySet()); } } diff --git a/elide-datastore/elide-datastore-aggregation/src/main/java/com/yahoo/elide/datastores/aggregation/queryengines/sql/metric/functions/SqlMax.java b/elide-datastore/elide-datastore-aggregation/src/main/java/com/yahoo/elide/datastores/aggregation/queryengines/sql/metric/functions/SqlMax.java index 7a0918e927..dac3cd18f5 100644 --- a/elide-datastore/elide-datastore-aggregation/src/main/java/com/yahoo/elide/datastores/aggregation/queryengines/sql/metric/functions/SqlMax.java +++ b/elide-datastore/elide-datastore-aggregation/src/main/java/com/yahoo/elide/datastores/aggregation/queryengines/sql/metric/functions/SqlMax.java @@ -14,6 +14,6 @@ */ public class SqlMax extends SQLMetricFunction { public SqlMax() { - super("max", "max", "sql max function", "MAX(%s)", Collections.emptySet()); + super("max", "sql max function", "MAX(%s)", Collections.emptySet()); } } diff --git a/elide-datastore/elide-datastore-aggregation/src/main/java/com/yahoo/elide/datastores/aggregation/queryengines/sql/metric/functions/SqlMin.java b/elide-datastore/elide-datastore-aggregation/src/main/java/com/yahoo/elide/datastores/aggregation/queryengines/sql/metric/functions/SqlMin.java index 221559e5fd..f6fe7a77dc 100644 --- a/elide-datastore/elide-datastore-aggregation/src/main/java/com/yahoo/elide/datastores/aggregation/queryengines/sql/metric/functions/SqlMin.java +++ b/elide-datastore/elide-datastore-aggregation/src/main/java/com/yahoo/elide/datastores/aggregation/queryengines/sql/metric/functions/SqlMin.java @@ -14,6 +14,6 @@ */ public class SqlMin extends SQLMetricFunction { public SqlMin() { - super("min", "min", "sql min function", "MIN(%s)", Collections.emptySet()); + super("min", "sql min function", "MIN(%s)", Collections.emptySet()); } } diff --git a/elide-datastore/elide-datastore-aggregation/src/main/java/com/yahoo/elide/datastores/aggregation/queryengines/sql/metric/functions/SqlSum.java b/elide-datastore/elide-datastore-aggregation/src/main/java/com/yahoo/elide/datastores/aggregation/queryengines/sql/metric/functions/SqlSum.java index 9319f817bb..83d7d36c3a 100644 --- a/elide-datastore/elide-datastore-aggregation/src/main/java/com/yahoo/elide/datastores/aggregation/queryengines/sql/metric/functions/SqlSum.java +++ b/elide-datastore/elide-datastore-aggregation/src/main/java/com/yahoo/elide/datastores/aggregation/queryengines/sql/metric/functions/SqlSum.java @@ -14,6 +14,6 @@ */ public class SqlSum extends SQLMetricFunction { public SqlSum() { - super("sum", "sum", "sql sum function", "SUM(%s)", Collections.emptySet()); + super("sum", "sql sum function", "SUM(%s)", Collections.emptySet()); } } diff --git a/elide-datastore/elide-datastore-aggregation/src/test/java/com/yahoo/elide/datastores/aggregation/example/PlayerStats.java b/elide-datastore/elide-datastore-aggregation/src/test/java/com/yahoo/elide/datastores/aggregation/example/PlayerStats.java index 14fed61222..aa52aefe0c 100644 --- a/elide-datastore/elide-datastore-aggregation/src/test/java/com/yahoo/elide/datastores/aggregation/example/PlayerStats.java +++ b/elide-datastore/elide-datastore-aggregation/src/test/java/com/yahoo/elide/datastores/aggregation/example/PlayerStats.java @@ -120,7 +120,7 @@ public void setId(final String id) { } @MetricAggregation(function = SqlMax.class) - @Meta(longName = "awesome score", description = "very awesome score") + @Meta(description = "very awesome score") public long getHighScore() { return highScore; } diff --git a/elide-datastore/elide-datastore-aggregation/src/test/java/com/yahoo/elide/datastores/aggregation/example/PlayerStatsWithView.java b/elide-datastore/elide-datastore-aggregation/src/test/java/com/yahoo/elide/datastores/aggregation/example/PlayerStatsWithView.java index 664ff02c7e..82906dbf0e 100644 --- a/elide-datastore/elide-datastore-aggregation/src/test/java/com/yahoo/elide/datastores/aggregation/example/PlayerStatsWithView.java +++ b/elide-datastore/elide-datastore-aggregation/src/test/java/com/yahoo/elide/datastores/aggregation/example/PlayerStatsWithView.java @@ -103,7 +103,7 @@ public void setId(final String id) { } @MetricAggregation(function = SqlMax.class) - @Meta(longName = "awesome score", description = "very awesome score") + @Meta(description = "very awesome score") public long getHighScore() { return highScore; } diff --git a/elide-datastore/elide-datastore-aggregation/src/test/java/com/yahoo/elide/datastores/aggregation/integration/AggregationDataStoreIntegrationTest.java b/elide-datastore/elide-datastore-aggregation/src/test/java/com/yahoo/elide/datastores/aggregation/integration/AggregationDataStoreIntegrationTest.java index ae1763681a..0772851a9b 100644 --- a/elide-datastore/elide-datastore-aggregation/src/test/java/com/yahoo/elide/datastores/aggregation/integration/AggregationDataStoreIntegrationTest.java +++ b/elide-datastore/elide-datastore-aggregation/src/test/java/com/yahoo/elide/datastores/aggregation/integration/AggregationDataStoreIntegrationTest.java @@ -754,8 +754,7 @@ public void metaDataTest() { .body("data.relationships.metricFunction.data.id", equalTo("playerStats.lowScore[min]")) .body("included.id", hasItem("playerStats.lowScore[min]")) .body("included.attributes.description", hasItem("sql min function")) - .body("included.attributes.expression", hasItem("MIN(%s)")) - .body("included.attributes.longName", hasItem("min")); + .body("included.attributes.expression", hasItem("MIN(%s)")); given() .accept("application/vnd.api+json")