Skip to content

Commit

Permalink
Rename base model to base object (#382)
Browse files Browse the repository at this point in the history
  • Loading branch information
brandboat committed Nov 2, 2023
1 parent f1b26cf commit 9f33916
Show file tree
Hide file tree
Showing 14 changed files with 61 additions and 61 deletions.
20 changes: 10 additions & 10 deletions accio-base/src/main/java/io/accio/base/dto/CumulativeMetric.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -43,15 +43,15 @@ 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,
@JsonProperty("refreshTime") Duration refreshTime,
@JsonProperty("description") String description)
{
this.name = name;
this.baseModel = baseModel;
this.baseObject = baseObject;
this.measure = measure;
this.window = window;
this.preAggregated = preAggregated;
Expand All @@ -66,9 +66,9 @@ public String getName()
}

@JsonProperty
public String getBaseModel()
public String getBaseObject()
{
return baseModel;
return baseObject;
}

@JsonProperty
Expand Down Expand Up @@ -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
Expand All @@ -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) &&
Expand All @@ -133,7 +133,7 @@ public String toString()
{
return "CumulativeMetric{" +
"name='" + name + '\'' +
", baseModel='" + baseModel + '\'' +
", baseObject='" + baseObject + '\'' +
", measure=" + measure +
", window=" + window +
", preAggregated=" + preAggregated +
Expand Down
28 changes: 14 additions & 14 deletions accio-base/src/main/java/io/accio/base/dto/Metric.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,33 +29,33 @@ public class Metric
implements PreAggregationInfo
{
private final String name;
private final String baseModel;
private final String baseObject;
private final List<Column> dimension;
private final List<Column> measure;
private final List<TimeGrain> timeGrain;
private final boolean preAggregated;
private final Duration refreshTime;
private final String description;

public static Metric metric(String name, String baseModel, List<Column> dimension, List<Column> measure, List<TimeGrain> timeGrain)
public static Metric metric(String name, String baseObject, List<Column> dimension, List<Column> measure, List<TimeGrain> 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<Column> dimension, List<Column> measure, List<TimeGrain> timeGrain, boolean preAggregated)
public static Metric metric(String name, String baseObject, List<Column> dimension, List<Column> measure, List<TimeGrain> 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<Column> dimension, List<Column> measure, List<TimeGrain> timeGrain, boolean preAggregated, String description)
public static Metric metric(String name, String baseObject, List<Column> dimension, List<Column> measure, List<TimeGrain> 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<Column> dimension,
@JsonProperty("measure") List<Column> measure,
@JsonProperty("timeGrain") List<TimeGrain> timeGrain,
Expand All @@ -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;
Expand All @@ -82,9 +82,9 @@ public String getName()
}

@JsonProperty
public String getBaseModel()
public String getBaseObject()
{
return baseModel;
return baseObject;
}

@JsonProperty
Expand Down Expand Up @@ -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)
Expand All @@ -157,7 +157,7 @@ public int hashCode()
{
return Objects.hash(
name,
baseModel,
baseObject,
dimension,
measure,
timeGrain,
Expand All @@ -171,7 +171,7 @@ public String toString()
{
return "Metric{" +
"name='" + name + '\'' +
", baseModel='" + baseModel + '\'' +
", baseObject='" + baseObject + '\'' +
", dimension=" + dimension +
", measure=" + measure +
", timeGrain=" + timeGrain +
Expand Down
24 changes: 12 additions & 12 deletions accio-base/src/main/java/io/accio/base/dto/Model.java
Original file line number Diff line number Diff line change
Expand Up @@ -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<Column> columns;
private final String primaryKey;
private final boolean preAggregated;
Expand All @@ -57,27 +57,27 @@ public static Model model(String name, String refSql, List<Column> columns, Stri
return new Model(name, refSql, null, columns, primaryKey, false, null, description);
}

public static Model onModel(String name, String baseModel, List<Column> columns, String primaryKey)
public static Model onModel(String name, String baseObject, List<Column> 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<Column> columns,
@JsonProperty("primaryKey") String primaryKey,
@JsonProperty("preAggregated") boolean preAggregated,
@JsonProperty("refreshTime") Duration refreshTime,
@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;
Expand All @@ -98,9 +98,9 @@ public String getRefSql()
}

@JsonProperty
public String getBaseModel()
public String getBaseObject()
{
return baseModel;
return baseObject;
}

@JsonProperty
Expand Down Expand Up @@ -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)
Expand All @@ -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
Expand All @@ -167,7 +167,7 @@ public String toString()
return "Model{" +
"name='" + name + '\'' +
", refSql='" + refSql + '\'' +
", baseModel='" + baseModel + '\'' +
", baseObject='" + baseObject + '\'' +
", columns=" + columns +
", primaryKey='" + primaryKey + '\'' +
", preAggregated=" + preAggregated +
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}
}

Expand Down
12 changes: 6 additions & 6 deletions accio-sqlrewrite/src/main/java/io/accio/sqlrewrite/Utils.java
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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" +
Expand Down Expand Up @@ -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(),
Expand Down Expand Up @@ -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);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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()));
Expand All @@ -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()));
Expand Down
4 changes: 2 additions & 2 deletions accio-sqlrewrite/src/test/resources/tpch_mdl.json
Original file line number Diff line number Diff line change
Expand Up @@ -265,7 +265,7 @@
"metrics": [
{
"name": "Revenue",
"baseModel": "Orders",
"baseObject": "Orders",
"dimension": [
{
"name": "custkey",
Expand Down Expand Up @@ -294,7 +294,7 @@
"cumulativeMetrics": [
{
"name": "WeeklyRevenue",
"baseModel": "Orders",
"baseObject": "Orders",
"measure": {
"name": "totalprice",
"type": "int4",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@
{
"preAggregated": "true",
"name": "PrintBigQueryType",
"baseModel": "BigQueryType",
"baseObject": "BigQueryType",
"dimension": [
{
"name": "c_string",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@
{
"preAggregated": "true",
"name": "RefreshFrequently",
"baseModel": "Orders",
"baseObject": "Orders",
"dimension": [
{
"name": "custkey",
Expand Down
Loading

0 comments on commit 9f33916

Please sign in to comment.