diff --git a/elide-core/src/main/java/com/yahoo/elide/core/EntityDictionary.java b/elide-core/src/main/java/com/yahoo/elide/core/EntityDictionary.java index 2a7e2361d8..1e1785c94d 100644 --- a/elide-core/src/main/java/com/yahoo/elide/core/EntityDictionary.java +++ b/elide-core/src/main/java/com/yahoo/elide/core/EntityDictionary.java @@ -1429,7 +1429,7 @@ public void addArgumentsToAttributes(Class cls, String attributeName, Set cls, String attributeName, ArgumentType argument) { + public void addArgumentToAttribute(Class cls, String attributeName, ArgumentType argument) { this.addArgumentsToAttributes(cls, attributeName, Sets.newHashSet(argument)); } diff --git a/elide-datastore/elide-datastore-aggregation/pom.xml.releaseBackup b/elide-datastore/elide-datastore-aggregation/pom.xml.releaseBackup deleted file mode 100644 index ccf7c1fbd9..0000000000 --- a/elide-datastore/elide-datastore-aggregation/pom.xml.releaseBackup +++ /dev/null @@ -1,198 +0,0 @@ - - - - 4.0.0 - elide-datastore-aggregation - jar - Elide Data Store: Aggregation Data Store - Elide Data Store for Aggregation - https://github.com/yahoo/elide/tree/master/elide-datastore/elide-datastore-aggregation - - com.yahoo.elide - elide-datastore-parent-pom - 5.0.0-pr2-SNAPSHOT - - - - - The Apache Software License, Version 2.0 - http://www.apache.org/licenses/LICENSE-2.0.txt - repo - - - - - - Yahoo Inc. - https://github.com/yahoo - - - - - scm:git:ssh://git@github.com/yahoo/elide.git - https://github.com/yahoo/elide.git - HEAD - - - - 5.4.1 - - - - - com.yahoo.elide - elide-core - 5.0.0-pr2-SNAPSHOT - - - - com.yahoo.elide - elide-datastore-hibernate - 5.0.0-pr2-SNAPSHOT - - - - com.yahoo.elide - elide-graphql - 5.0.0-pr2-SNAPSHOT - - - - org.projectlombok - lombok - - - - - org.hibernate.javax.persistence - hibernate-jpa-2.1-api - 1.0.0.Final - - - - - org.hibernate - hibernate-entitymanager - ${hibernate5.version} - - - - - - org.junit.jupiter - junit-jupiter-api - ${junit.version} - test - - - - org.junit.jupiter - junit-jupiter-params - ${junit.version} - test - - - - org.junit.jupiter - junit-jupiter-engine - ${junit.version} - test - - - - - com.h2database - h2 - 1.4.197 - test - - - - - org.mockito - mockito-core - test - - - - - com.yahoo.elide - elide-integration-tests - 5.0.0-pr2-SNAPSHOT - test - test-jar - - - - - org.eclipse.jetty - jetty-servlet - test - - - - org.eclipse.jetty - jetty-webapp - test - - - - - org.glassfish.jersey.containers - jersey-container-servlet-core - 2.29.1 - test - - - - org.glassfish.jersey.inject - jersey-hk2 - test - - - - org.glassfish.jersey.containers - jersey-container-servlet - test - - - - io.rest-assured - rest-assured - 4.0.0 - test - - - - org.glassfish.hk2 - hk2-api - 2.5.0 - test - - - - - - - org.codehaus.mojo - build-helper-maven-plugin - - - org.apache.maven.plugins - maven-dependency-plugin - - - org.apache.maven.plugins - maven-surefire-plugin - - - org.apache.maven.plugins - maven-checkstyle-plugin - - - - diff --git a/elide-datastore/elide-datastore-aggregation/src/main/java/com/yahoo/elide/datastores/aggregation/AggregationDataStore.java b/elide-datastore/elide-datastore-aggregation/src/main/java/com/yahoo/elide/datastores/aggregation/AggregationDataStore.java index 163b448beb..18f15155d6 100644 --- a/elide-datastore/elide-datastore-aggregation/src/main/java/com/yahoo/elide/datastores/aggregation/AggregationDataStore.java +++ b/elide-datastore/elide-datastore-aggregation/src/main/java/com/yahoo/elide/datastores/aggregation/AggregationDataStore.java @@ -35,7 +35,7 @@ public void populateEntityDictionary(EntityDictionary dictionary) { /* Add 'grain' argument to each TimeDimensionColumn */ for (Schema schema: queryEngine.getSchemas()) { for (TimeDimensionColumn timeDim : schema.getTimeDimensions()) { - dictionary.addArgumentToAttributes(schema.getEntityClass(), timeDim.getName(), + dictionary.addArgumentToAttribute(schema.getEntityClass(), timeDim.getName(), new ArgumentType("grain", String.class)); } } diff --git a/elide-datastore/elide-datastore-aggregation/src/main/java/com/yahoo/elide/datastores/aggregation/AggregationDataStoreHelper.java b/elide-datastore/elide-datastore-aggregation/src/main/java/com/yahoo/elide/datastores/aggregation/AggregationDataStoreHelper.java index ba4172c604..d9bab6f9f8 100644 --- a/elide-datastore/elide-datastore-aggregation/src/main/java/com/yahoo/elide/datastores/aggregation/AggregationDataStoreHelper.java +++ b/elide-datastore/elide-datastore-aggregation/src/main/java/com/yahoo/elide/datastores/aggregation/AggregationDataStoreHelper.java @@ -102,7 +102,6 @@ private void splitFilters() { } } - //TODO - Add tests in the next PR. /** * Gets time dimensions based on relationships and attributes from {@link EntityProjection}. * @@ -110,47 +109,46 @@ private void splitFilters() { * @throws InvalidOperationException Thrown if a requested time grain is not supported. */ private Set resolveTimeDimensions() { + return entityProjection.getAttributes().stream() + .filter(attribute -> schema.getTimeDimension(attribute.getName()) != null) + .map(attribute -> { + TimeDimensionColumn timeDim = schema.getTimeDimension(attribute.getName()); - Set timeDims = new LinkedHashSet<>(); - //Only attributes can be time dimensions - entityProjection.getAttributes().stream().forEach((attribute -> { - TimeDimensionColumn timeDim = schema.getTimeDimension(attribute.getName()); - if (timeDim == null) { - return; - } - - Argument timeGrainArgument = attribute.getArguments().stream() - .filter(attr -> attr.getName().equals("grain")) - .findAny() - .orElse(null); - - TimeGrainDefinition requestedGrainDefinition; - if (timeGrainArgument == null) { + Argument timeGrainArgument = attribute.getArguments().stream() + .filter(attr -> attr.getName().equals("grain")) + .findAny() + .orElse(null); - //The first grain is the default. - requestedGrainDefinition = timeDim.getSupportedGrains().iterator().next(); - } else { - String requestedGrainName = timeGrainArgument.getValue().toString().toUpperCase(Locale.ENGLISH); + TimeGrainDefinition requestedGrainDefinition; + if (timeGrainArgument == null) { - TimeGrain requestedGrain; - try { - requestedGrain = TimeGrain.valueOf(requestedGrainName); - } catch (IllegalArgumentException e) { - throw new InvalidOperationException(String.format("Invalid grain %s", requestedGrainName)); - } + //The first grain is the default. + requestedGrainDefinition = timeDim.getSupportedGrains().stream() + .findFirst() + .orElseThrow(() -> new IllegalStateException( + String.format("Requested default grain, no grain defined on %s", + attribute.getName()))); + } else { + String requestedGrainName = timeGrainArgument.getValue().toString().toUpperCase(Locale.ENGLISH); - requestedGrainDefinition = timeDim.getSupportedGrains().stream() - .filter(supportedGrainDef -> supportedGrainDef.grain().equals(requestedGrain)) - .findAny() - .orElseThrow(() -> new InvalidOperationException( - String.format("Requested grain %s, not supported on %s", - requestedGrainName, attribute.getName()))); - } + TimeGrain requestedGrain; + try { + requestedGrain = TimeGrain.valueOf(requestedGrainName); + } catch (IllegalArgumentException e) { + throw new InvalidOperationException(String.format("Invalid grain %s", requestedGrainName)); + } - timeDims.add(timeDim.toProjectedDimension(requestedGrainDefinition)); - })); + requestedGrainDefinition = timeDim.getSupportedGrains().stream() + .filter(supportedGrainDef -> supportedGrainDef.grain().equals(requestedGrain)) + .findAny() + .orElseThrow(() -> new InvalidOperationException( + String.format("Requested grain %s, not supported on %s", + requestedGrainName, attribute.getName()))); + } - return timeDims; + return timeDim.toProjectedDimension(requestedGrainDefinition); + }) + .collect(Collectors.toCollection(LinkedHashSet::new)); } /** diff --git a/elide-datastore/elide-datastore-aggregation/src/main/java/com/yahoo/elide/datastores/aggregation/queryengines/sql/schema/SQLSchema.java b/elide-datastore/elide-datastore-aggregation/src/main/java/com/yahoo/elide/datastores/aggregation/queryengines/sql/schema/SQLSchema.java index d413c655b3..b1aa5270ad 100644 --- a/elide-datastore/elide-datastore-aggregation/src/main/java/com/yahoo/elide/datastores/aggregation/queryengines/sql/schema/SQLSchema.java +++ b/elide-datastore/elide-datastore-aggregation/src/main/java/com/yahoo/elide/datastores/aggregation/queryengines/sql/schema/SQLSchema.java @@ -75,7 +75,7 @@ protected DimensionColumn constructDimension(String dimensionField, String columnName = getColumnName(entityClass, dimensionField); if (dim instanceof TimeDimensionColumn) { - return new SQLTimeDimensionColumn((TimeDimensionColumn) dim, columnName, getAlias()); + return new SQLTimeDimensionColumn((TimeDimensionColumn) dim, columnName, getAlias()); } return new SQLDimensionColumn(dim, columnName, getAlias()); } diff --git a/elide-datastore/elide-datastore-aggregation/src/main/java/com/yahoo/elide/datastores/aggregation/queryengines/sql/schema/SQLTimeDimensionColumn.java b/elide-datastore/elide-datastore-aggregation/src/main/java/com/yahoo/elide/datastores/aggregation/queryengines/sql/schema/SQLTimeDimensionColumn.java index bff2db3a0a..438ff9a7ad 100644 --- a/elide-datastore/elide-datastore-aggregation/src/main/java/com/yahoo/elide/datastores/aggregation/queryengines/sql/schema/SQLTimeDimensionColumn.java +++ b/elide-datastore/elide-datastore-aggregation/src/main/java/com/yahoo/elide/datastores/aggregation/queryengines/sql/schema/SQLTimeDimensionColumn.java @@ -11,8 +11,6 @@ import com.yahoo.elide.datastores.aggregation.schema.dimension.TimeDimensionColumn; import com.yahoo.elide.datastores.aggregation.time.TimeGrain; -import com.google.common.base.Preconditions; - import java.util.Set; import java.util.TimeZone; @@ -63,11 +61,9 @@ public Set getSupportedGrains() { * @return Something like "table_alias.column_name" */ public String getColumnReference(TimeGrain requestedGrain) { - Preconditions.checkArgument(getSupportedGrains().stream() - .anyMatch((grainDef -> grainDef.grain().equals(requestedGrain)))); - TimeGrainDefinition definition = getSupportedGrains().stream() - .filter(grainDef -> grainDef.grain().equals(requestedGrain)).findFirst().get(); + .filter(grainDef -> grainDef.grain().equals(requestedGrain)).findFirst() + .orElseThrow(() -> new IllegalStateException("Requested time grain not supported.")); //TODO - We will likely migrate to a templating language when we support parameterized metrics. return String.format(definition.expression(), getColumnReference()); diff --git a/elide-datastore/elide-datastore-aggregation/src/main/java/com/yahoo/elide/datastores/aggregation/schema/Schema.java b/elide-datastore/elide-datastore-aggregation/src/main/java/com/yahoo/elide/datastores/aggregation/schema/Schema.java index 3717c77985..d1641bffa0 100644 --- a/elide-datastore/elide-datastore-aggregation/src/main/java/com/yahoo/elide/datastores/aggregation/schema/Schema.java +++ b/elide-datastore/elide-datastore-aggregation/src/main/java/com/yahoo/elide/datastores/aggregation/schema/Schema.java @@ -53,7 +53,7 @@ public class Schema { @Getter - public final Class entityClass; + protected final Class entityClass; @Getter protected final Set metrics; protected final Map dimensions; diff --git a/elide-datastore/elide-datastore-aggregation/src/test/java/com/yahoo/elide/datastores/aggregation/example/SubCountry.java b/elide-datastore/elide-datastore-aggregation/src/test/java/com/yahoo/elide/datastores/aggregation/example/SubCountry.java index a009fd3911..f6c14c611e 100644 --- a/elide-datastore/elide-datastore-aggregation/src/test/java/com/yahoo/elide/datastores/aggregation/example/SubCountry.java +++ b/elide-datastore/elide-datastore-aggregation/src/test/java/com/yahoo/elide/datastores/aggregation/example/SubCountry.java @@ -18,7 +18,7 @@ import javax.persistence.Id; /** - * A root level entity for testing AggregationDataStore with @Subselect annotation + * A root level entity for testing AggregationDataStore with @Subselect annotation. */ @Data @Entity