Skip to content

Commit

Permalink
Fix bug querying a dynamic analytic model by ID in GraphQL (#2120)
Browse files Browse the repository at this point in the history
Co-authored-by: Aaron Klish <klish@verizonmedia.com>
  • Loading branch information
aklish and Aaron Klish committed May 21, 2021
1 parent 8b713e1 commit a691913
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import com.yahoo.elide.core.type.Type;
import com.yahoo.elide.core.utils.coerce.CoerceUtil;
import com.yahoo.elide.datastores.aggregation.QueryEngine;
import com.yahoo.elide.datastores.aggregation.metadata.enums.ValueType;
import com.yahoo.elide.datastores.aggregation.metadata.models.Table;
import com.yahoo.elide.datastores.aggregation.query.ColumnProjection;
import com.yahoo.elide.datastores.aggregation.query.MetricProjection;
Expand Down Expand Up @@ -65,6 +66,7 @@ public EntityHydrator(ResultSet rs, Query query, EntityDictionary entityDictiona
Map<String, String> projections = this.query.getMetricProjections().stream()
.map(SQLMetricProjection.class::cast)
.filter(SQLColumnProjection::isProjected)
.filter(projection -> ! projection.getValueType().equals(ValueType.ID))
.collect(Collectors.toMap(MetricProjection::getAlias, MetricProjection::getSafeAlias));

projections.putAll(this.query.getAllDimensionProjections().stream()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import com.yahoo.elide.datastores.aggregation.metadata.ColumnContext;
import com.yahoo.elide.datastores.aggregation.metadata.MetaDataStore;
import com.yahoo.elide.datastores.aggregation.metadata.TableContext;
import com.yahoo.elide.datastores.aggregation.metadata.enums.ValueType;
import com.yahoo.elide.datastores.aggregation.query.ColumnProjection;
import com.yahoo.elide.datastores.aggregation.query.Query;
import com.yahoo.elide.datastores.aggregation.query.QueryVisitor;
Expand Down Expand Up @@ -181,6 +182,7 @@ private String constructProjectionWithReference(Query query) {
List<String> metricProjections = query.getMetricProjections().stream()
.map(SQLMetricProjection.class::cast)
.filter(SQLColumnProjection::isProjected)
.filter(projection -> ! projection.getValueType().equals(ValueType.ID))
.map(invocation -> invocation.toSQL(query, metaDataStore) + " AS "
+ applyQuotes(invocation.getSafeAlias()))
.collect(Collectors.toList());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -908,6 +908,35 @@ public void multiTimeDimensionTest() throws IOException {
runQueryWithExpectedResult(graphQLRequest, expected);
}

@Test
public void testGraphqlQueryDynamicModelById() throws IOException {
String graphQLRequest = document(
selection(
field(
"SalesNamespace_orderDetails",
selections(
field("id"),
field("orderTotal")
)
)
)
).toQuery();

String expected = document(
selections(
field(
"SalesNamespace_orderDetails",
selections(
field("id", "0"),
field("orderTotal", 434.84)
)
)
)
).toResponse();

runQueryWithExpectedResult(graphQLRequest, expected);
}

@Test
public void jsonApiAggregationTest() {
given()
Expand Down

0 comments on commit a691913

Please sign in to comment.