diff --git a/accio-base/src/main/java/io/accio/base/dto/CumulativeMetric.java b/accio-base/src/main/java/io/accio/base/dto/CumulativeMetric.java index 675b4c7de..060958c8b 100644 --- a/accio-base/src/main/java/io/accio/base/dto/CumulativeMetric.java +++ b/accio-base/src/main/java/io/accio/base/dto/CumulativeMetric.java @@ -25,15 +25,15 @@ public class CumulativeMetric { public static CumulativeMetric cumulativeMetric( String name, - String baseModel, + String baseObject, Measure measure, Window window) { - return new CumulativeMetric(name, baseModel, measure, window, false, null, null); + return new CumulativeMetric(name, baseObject, measure, window, false, null, null); } private final String name; - private final String baseModel; + private final String baseObject; private final Measure measure; private final Window window; private final boolean preAggregated; @@ -43,7 +43,7 @@ public static CumulativeMetric cumulativeMetric( @JsonCreator public CumulativeMetric( @JsonProperty("name") String name, - @JsonProperty("baseModel") String baseModel, + @JsonProperty("baseObject") String baseObject, @JsonProperty("measure") Measure measure, @JsonProperty("window") Window window, @JsonProperty("preAggregated") boolean preAggregated, @@ -51,7 +51,7 @@ public CumulativeMetric( @JsonProperty("description") String description) { this.name = name; - this.baseModel = baseModel; + this.baseObject = baseObject; this.measure = measure; this.window = window; this.preAggregated = preAggregated; @@ -66,9 +66,9 @@ public String getName() } @JsonProperty - public String getBaseModel() + public String getBaseObject() { - return baseModel; + return baseObject; } @JsonProperty @@ -104,7 +104,7 @@ public String getDescription() @Override public int hashCode() { - return Objects.hash(name, baseModel, measure, window, preAggregated, refreshTime, description); + return Objects.hash(name, baseObject, measure, window, preAggregated, refreshTime, description); } @Override @@ -121,7 +121,7 @@ public boolean equals(Object o) CumulativeMetric that = (CumulativeMetric) o; return preAggregated == that.preAggregated && Objects.equals(name, that.name) && - Objects.equals(baseModel, that.baseModel) && + Objects.equals(baseObject, that.baseObject) && Objects.equals(measure, that.measure) && Objects.equals(window, that.window) && Objects.equals(refreshTime, that.refreshTime) && @@ -133,7 +133,7 @@ public String toString() { return "CumulativeMetric{" + "name='" + name + '\'' + - ", baseModel='" + baseModel + '\'' + + ", baseObject='" + baseObject + '\'' + ", measure=" + measure + ", window=" + window + ", preAggregated=" + preAggregated + diff --git a/accio-base/src/main/java/io/accio/base/dto/Metric.java b/accio-base/src/main/java/io/accio/base/dto/Metric.java index 51ff7beae..fbc14d3f2 100644 --- a/accio-base/src/main/java/io/accio/base/dto/Metric.java +++ b/accio-base/src/main/java/io/accio/base/dto/Metric.java @@ -29,7 +29,7 @@ public class Metric implements PreAggregationInfo { private final String name; - private final String baseModel; + private final String baseObject; private final List dimension; private final List measure; private final List timeGrain; @@ -37,25 +37,25 @@ public class Metric private final Duration refreshTime; private final String description; - public static Metric metric(String name, String baseModel, List dimension, List measure, List timeGrain) + public static Metric metric(String name, String baseObject, List dimension, List measure, List timeGrain) { - return metric(name, baseModel, dimension, measure, timeGrain, false); + return metric(name, baseObject, dimension, measure, timeGrain, false); } - public static Metric metric(String name, String baseModel, List dimension, List measure, List timeGrain, boolean preAggregated) + public static Metric metric(String name, String baseObject, List dimension, List measure, List timeGrain, boolean preAggregated) { - return metric(name, baseModel, dimension, measure, timeGrain, preAggregated, null); + return metric(name, baseObject, dimension, measure, timeGrain, preAggregated, null); } - public static Metric metric(String name, String baseModel, List dimension, List measure, List timeGrain, boolean preAggregated, String description) + public static Metric metric(String name, String baseObject, List dimension, List measure, List timeGrain, boolean preAggregated, String description) { - return new Metric(name, baseModel, dimension, measure, timeGrain, preAggregated, null, description); + return new Metric(name, baseObject, dimension, measure, timeGrain, preAggregated, null, description); } @JsonCreator public Metric( @JsonProperty("name") String name, - @JsonProperty("baseModel") String baseModel, + @JsonProperty("baseObject") String baseObject, @JsonProperty("dimension") List dimension, @JsonProperty("measure") List measure, @JsonProperty("timeGrain") List timeGrain, @@ -64,7 +64,7 @@ public Metric( @JsonProperty("description") String description) { this.name = requireNonNull(name, "name is null"); - this.baseModel = requireNonNull(baseModel, "baseModel is null"); + this.baseObject = requireNonNull(baseObject, "baseObject is null"); this.dimension = requireNonNull(dimension, "dimension is null"); this.measure = requireNonNull(measure, "measure is null"); this.preAggregated = preAggregated; @@ -82,9 +82,9 @@ public String getName() } @JsonProperty - public String getBaseModel() + public String getBaseObject() { - return baseModel; + return baseObject; } @JsonProperty @@ -144,7 +144,7 @@ public boolean equals(Object obj) Metric that = (Metric) obj; return preAggregated == that.preAggregated && Objects.equals(name, that.name) - && Objects.equals(baseModel, that.baseModel) + && Objects.equals(baseObject, that.baseObject) && Objects.equals(dimension, that.dimension) && Objects.equals(measure, that.measure) && Objects.equals(timeGrain, that.timeGrain) @@ -157,7 +157,7 @@ public int hashCode() { return Objects.hash( name, - baseModel, + baseObject, dimension, measure, timeGrain, @@ -171,7 +171,7 @@ public String toString() { return "Metric{" + "name='" + name + '\'' + - ", baseModel='" + baseModel + '\'' + + ", baseObject='" + baseObject + '\'' + ", dimension=" + dimension + ", measure=" + measure + ", timeGrain=" + timeGrain + diff --git a/accio-base/src/main/java/io/accio/base/dto/Model.java b/accio-base/src/main/java/io/accio/base/dto/Model.java index f10360953..13810758f 100644 --- a/accio-base/src/main/java/io/accio/base/dto/Model.java +++ b/accio-base/src/main/java/io/accio/base/dto/Model.java @@ -30,7 +30,7 @@ public class Model { private final String name; private final String refSql; - private final String baseModel; + private final String baseObject; private final List columns; private final String primaryKey; private final boolean preAggregated; @@ -57,16 +57,16 @@ public static Model model(String name, String refSql, List columns, Stri return new Model(name, refSql, null, columns, primaryKey, false, null, description); } - public static Model onModel(String name, String baseModel, List columns, String primaryKey) + public static Model onModel(String name, String baseObject, List columns, String primaryKey) { - return new Model(name, null, baseModel, columns, primaryKey, false, null, null); + return new Model(name, null, baseObject, columns, primaryKey, false, null, null); } @JsonCreator public Model( @JsonProperty("name") String name, @JsonProperty("refSql") String refSql, - @JsonProperty("baseModel") String baseModel, + @JsonProperty("baseObject") String baseObject, @JsonProperty("columns") List columns, @JsonProperty("primaryKey") String primaryKey, @JsonProperty("preAggregated") boolean preAggregated, @@ -74,10 +74,10 @@ public Model( @JsonProperty("description") String description) { this.name = requireNonNull(name, "name is null"); - checkArgument(Stream.of(refSql, baseModel).filter(Objects::nonNull).count() == 1, - "either none or more than one of (refSql, baseModel) are set"); + checkArgument(Stream.of(refSql, baseObject).filter(Objects::nonNull).count() == 1, + "either none or more than one of (refSql, baseObject) are set"); this.refSql = refSql; - this.baseModel = baseModel; + this.baseObject = baseObject; this.columns = columns == null ? List.of() : columns; this.primaryKey = primaryKey; this.preAggregated = preAggregated; @@ -98,9 +98,9 @@ public String getRefSql() } @JsonProperty - public String getBaseModel() + public String getBaseObject() { - return baseModel; + return baseObject; } @JsonProperty @@ -148,7 +148,7 @@ public boolean equals(Object obj) return preAggregated == that.preAggregated && Objects.equals(name, that.name) && Objects.equals(refSql, that.refSql) - && Objects.equals(baseModel, that.baseModel) + && Objects.equals(baseObject, that.baseObject) && Objects.equals(columns, that.columns) && Objects.equals(primaryKey, that.primaryKey) && Objects.equals(refreshTime, that.refreshTime) @@ -158,7 +158,7 @@ public boolean equals(Object obj) @Override public int hashCode() { - return Objects.hash(name, refSql, baseModel, columns, primaryKey, description); + return Objects.hash(name, refSql, baseObject, columns, primaryKey, description); } @Override @@ -167,7 +167,7 @@ public String toString() return "Model{" + "name='" + name + '\'' + ", refSql='" + refSql + '\'' + - ", baseModel='" + baseModel + '\'' + + ", baseObject='" + baseObject + '\'' + ", columns=" + columns + ", primaryKey='" + primaryKey + '\'' + ", preAggregated=" + preAggregated + diff --git a/accio-sqlrewrite/src/main/java/io/accio/sqlrewrite/ModelInfo.java b/accio-sqlrewrite/src/main/java/io/accio/sqlrewrite/ModelInfo.java index c0de40b4d..6abc549f4 100644 --- a/accio-sqlrewrite/src/main/java/io/accio/sqlrewrite/ModelInfo.java +++ b/accio-sqlrewrite/src/main/java/io/accio/sqlrewrite/ModelInfo.java @@ -113,16 +113,16 @@ public Analyzer(Model model, AccioMDL mdl) if (model.getRefSql() != null) { this.refSql = model.getRefSql(); } - else if (model.getBaseModel() != null) { - this.refSql = "SELECT * FROM " + model.getBaseModel(); + else if (model.getBaseObject() != null) { + this.refSql = "SELECT * FROM " + model.getBaseObject(); } else { throw new IllegalArgumentException("cannot get reference sql from model"); } this.requiredModels = new HashSet<>(); - if (model.getBaseModel() != null) { - requiredModels.add(model.getBaseModel()); + if (model.getBaseObject() != null) { + requiredModels.add(model.getBaseObject()); } } diff --git a/accio-sqlrewrite/src/main/java/io/accio/sqlrewrite/Utils.java b/accio-sqlrewrite/src/main/java/io/accio/sqlrewrite/Utils.java index e914ebbd4..d3bbd7a99 100644 --- a/accio-sqlrewrite/src/main/java/io/accio/sqlrewrite/Utils.java +++ b/accio-sqlrewrite/src/main/java/io/accio/sqlrewrite/Utils.java @@ -124,7 +124,7 @@ private static String getMetricSql(Metric metric) String selectItems = Stream.concat(metric.getDimension().stream(), metric.getMeasure().stream()) .map(Column::getSqlExpression).collect(joining(",")); String groupByItems = IntStream.rangeClosed(1, metric.getDimension().size()).mapToObj(String::valueOf).collect(joining(",")); - return format("SELECT %s FROM %s GROUP BY %s", selectItems, metric.getBaseModel(), groupByItems); + return format("SELECT %s FROM %s GROUP BY %s", selectItems, metric.getBaseObject(), groupByItems); } public static Query parseCumulativeMetricSql(CumulativeMetric cumulativeMetric, AccioMDL accioMDL) @@ -141,11 +141,11 @@ public static String getCumulativeMetricSql(CumulativeMetric cumulativeMetric, A { requireNonNull(cumulativeMetric, "cumulativeMetric is null"); - String windowType = accioMDL.getModel(cumulativeMetric.getBaseModel()) + String windowType = accioMDL.getModel(cumulativeMetric.getBaseObject()) .map(model -> model.getColumns().stream() .filter(column -> column.getName().equals(cumulativeMetric.getWindow().getRefColumn())) - .map(Column::getType).findAny().orElseThrow(() -> new NoSuchElementException(format("Column %s not found in model %s", cumulativeMetric.getWindow().getRefColumn(), cumulativeMetric.getBaseModel())))) - .orElseThrow(() -> new NoSuchElementException(format("Model %s not found", cumulativeMetric.getBaseModel()))); + .map(Column::getType).findAny().orElseThrow(() -> new NoSuchElementException(format("Column %s not found in model %s", cumulativeMetric.getWindow().getRefColumn(), cumulativeMetric.getBaseObject())))) + .orElseThrow(() -> new NoSuchElementException(format("Model %s not found", cumulativeMetric.getBaseObject()))); String pattern = "select \n" + @@ -182,7 +182,7 @@ public static String getCumulativeMetricSql(CumulativeMetric cumulativeMetric, A String selectFromModel = format("select %s as measure_field, %s as metric_time from %s", cumulativeMetric.getMeasure().getRefColumn(), cumulativeMetric.getWindow().getRefColumn(), - cumulativeMetric.getBaseModel()); + cumulativeMetric.getBaseObject()); return format(pattern, cumulativeMetric.getWindow().getName(), @@ -228,7 +228,7 @@ private static String getMetricRollupSql(MetricRollupInfo metricRollupInfo) return format("SELECT %s FROM %s GROUP BY %s", String.join(",", selectItems), - metric.getBaseModel(), + metric.getBaseObject(), groupByColumnOrdinals); } diff --git a/accio-sqlrewrite/src/main/java/io/accio/sqlrewrite/analyzer/StatementAnalyzer.java b/accio-sqlrewrite/src/main/java/io/accio/sqlrewrite/analyzer/StatementAnalyzer.java index 565e007ed..a6d274ce7 100644 --- a/accio-sqlrewrite/src/main/java/io/accio/sqlrewrite/analyzer/StatementAnalyzer.java +++ b/accio-sqlrewrite/src/main/java/io/accio/sqlrewrite/analyzer/StatementAnalyzer.java @@ -106,7 +106,7 @@ public static Analysis analyze(Statement statement, SessionContext sessionContex analysis.addModels( Stream.of(metrics, metricInMetricRollups) .flatMap(Collection::stream) - .map(Metric::getBaseModel) + .map(Metric::getBaseObject) .distinct() .map(model -> accioMDL.getModel(model).orElseThrow(() -> new IllegalArgumentException(format("metric model %s not exists", model)))) .collect(toUnmodifiableSet())); @@ -121,7 +121,7 @@ public static Analysis analyze(Statement statement, SessionContext sessionContex analysis.addModels( cumulativeMetrics.stream() - .map(CumulativeMetric::getBaseModel) + .map(CumulativeMetric::getBaseObject) .distinct() .map(model -> accioMDL.getModel(model).orElseThrow(() -> new IllegalArgumentException(format("cumulative metric model %s not exists", model)))) .collect(toUnmodifiableSet())); diff --git a/accio-sqlrewrite/src/test/resources/tpch_mdl.json b/accio-sqlrewrite/src/test/resources/tpch_mdl.json index d07e90820..568a6f11a 100644 --- a/accio-sqlrewrite/src/test/resources/tpch_mdl.json +++ b/accio-sqlrewrite/src/test/resources/tpch_mdl.json @@ -265,7 +265,7 @@ "metrics": [ { "name": "Revenue", - "baseModel": "Orders", + "baseObject": "Orders", "dimension": [ { "name": "custkey", @@ -294,7 +294,7 @@ "cumulativeMetrics": [ { "name": "WeeklyRevenue", - "baseModel": "Orders", + "baseObject": "Orders", "measure": { "name": "totalprice", "type": "int4", diff --git a/accio-tests/src/test/resources/pre_agg/pre_agg_bigquery_mdl.json b/accio-tests/src/test/resources/pre_agg/pre_agg_bigquery_mdl.json index 7d1736792..56b5ec2b8 100644 --- a/accio-tests/src/test/resources/pre_agg/pre_agg_bigquery_mdl.json +++ b/accio-tests/src/test/resources/pre_agg/pre_agg_bigquery_mdl.json @@ -66,7 +66,7 @@ { "preAggregated": "true", "name": "PrintBigQueryType", - "baseModel": "BigQueryType", + "baseObject": "BigQueryType", "dimension": [ { "name": "c_string", diff --git a/accio-tests/src/test/resources/pre_agg/pre_agg_frequently_mdl.json b/accio-tests/src/test/resources/pre_agg/pre_agg_frequently_mdl.json index 1259620c7..5930ee3e3 100644 --- a/accio-tests/src/test/resources/pre_agg/pre_agg_frequently_mdl.json +++ b/accio-tests/src/test/resources/pre_agg/pre_agg_frequently_mdl.json @@ -77,7 +77,7 @@ { "preAggregated": "true", "name": "RefreshFrequently", - "baseModel": "Orders", + "baseObject": "Orders", "dimension": [ { "name": "custkey", diff --git a/accio-tests/src/test/resources/pre_agg/pre_agg_mdl.json b/accio-tests/src/test/resources/pre_agg/pre_agg_mdl.json index a99ab556a..9daa31000 100644 --- a/accio-tests/src/test/resources/pre_agg/pre_agg_mdl.json +++ b/accio-tests/src/test/resources/pre_agg/pre_agg_mdl.json @@ -78,7 +78,7 @@ { "preAggregated": "true", "name": "Revenue", - "baseModel": "Orders", + "baseObject": "Orders", "dimension": [ { "name": "custkey", @@ -107,7 +107,7 @@ { "preAggregated": "true", "name": "unqualified", - "baseModel": "Orders", + "baseObject": "Orders", "dimension": [ { "name": "custkey", @@ -138,7 +138,7 @@ }, { "name": "AvgRevenue", - "baseModel": "Orders", + "baseObject": "Orders", "dimension": [ { "name": "custkey", @@ -166,7 +166,7 @@ { "preAggregated": "true", "name": "ForDropTable", - "baseModel": "Orders", + "baseObject": "Orders", "dimension": [ { "name": "custkey", diff --git a/accio-tests/src/test/resources/pre_agg/pre_agg_reload_1_mdl.json b/accio-tests/src/test/resources/pre_agg/pre_agg_reload_1_mdl.json index f7c719c52..dcd28b2e8 100644 --- a/accio-tests/src/test/resources/pre_agg/pre_agg_reload_1_mdl.json +++ b/accio-tests/src/test/resources/pre_agg/pre_agg_reload_1_mdl.json @@ -39,7 +39,7 @@ { "preAggregated": "true", "name": "Revenue", - "baseModel": "Orders", + "baseObject": "Orders", "dimension": [ { "name": "custkey", diff --git a/accio-tests/src/test/resources/pre_agg/pre_agg_reload_2_mdl.json b/accio-tests/src/test/resources/pre_agg/pre_agg_reload_2_mdl.json index a4885c823..832b76c79 100644 --- a/accio-tests/src/test/resources/pre_agg/pre_agg_reload_2_mdl.json +++ b/accio-tests/src/test/resources/pre_agg/pre_agg_reload_2_mdl.json @@ -39,7 +39,7 @@ { "preAggregated": "true", "name": "Revenue_After", - "baseModel": "Orders", + "baseObject": "Orders", "dimension": [ { "name": "custkey", diff --git a/accio-tests/src/test/resources/pre_agg/pre_agg_reload_3_mdl.json b/accio-tests/src/test/resources/pre_agg/pre_agg_reload_3_mdl.json index e6dfa667e..417400cb5 100644 --- a/accio-tests/src/test/resources/pre_agg/pre_agg_reload_3_mdl.json +++ b/accio-tests/src/test/resources/pre_agg/pre_agg_reload_3_mdl.json @@ -39,7 +39,7 @@ { "preAggregated": "true", "name": "Revenue_Fake", - "baseModel": "Orders", + "baseObject": "Orders", "dimension": [ { "name": "custkey_f", diff --git a/accio-tests/src/test/resources/tpch_mdl.json b/accio-tests/src/test/resources/tpch_mdl.json index 2a0c749ca..24af1eb9b 100644 --- a/accio-tests/src/test/resources/tpch_mdl.json +++ b/accio-tests/src/test/resources/tpch_mdl.json @@ -234,7 +234,7 @@ "metrics": [ { "name": "Revenue", - "baseModel": "Orders", + "baseObject": "Orders", "dimension": [ { "name": "custkey", @@ -263,7 +263,7 @@ "cumulativeMetrics": [ { "name": "WeeklyRevenue", - "baseModel": "Orders", + "baseObject": "Orders", "measure": { "name": "totalprice", "type": "int4",