Skip to content

Commit

Permalink
Enhancemnents to Aggregation Store (#1300)
Browse files Browse the repository at this point in the history
Co-authored-by: moiz arafat <[email protected]>
  • Loading branch information
moizarafat and moiz arafat authored May 4, 2020
1 parent e362c10 commit 977271f
Show file tree
Hide file tree
Showing 15 changed files with 31 additions and 27 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,5 @@
@Retention(RetentionPolicy.RUNTIME)
public @interface Meta {

String longName() default "";

String description() default "";
}
Original file line number Diff line number Diff line change
@@ -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;
}
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,6 @@ public abstract class Column {

private final String name;

private final String longName;

private final String description;

@ToOne
Expand All @@ -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;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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<>());
Expand Down Expand Up @@ -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());
}

Expand All @@ -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<FunctionArgument> arguments) {
return new MetricFunction(id, longName, description, expression, arguments);
return new MetricFunction(id, description, expression, arguments);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,6 @@ public class MetricFunction {
@Id
private String name;

private String longName;

private String description;

private String expression;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<FunctionArgument> arguments) {
return new SQLMetricFunction(id, longName, description, expression, arguments);
return new SQLMetricFunction(id, description, expression, arguments);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<FunctionArgument> arguments) {
super(name, longName, description, expression, arguments);
super(name, description, expression, arguments);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down

0 comments on commit 977271f

Please sign in to comment.