use of com.yahoo.elide.datastores.aggregation.metadata.models.Dimension in project elide by yahoo.
the class SQLQueryEngine method toPageTotalSQL.
/**
* Takes a SQLQuery and creates a new clone that instead returns the total number of records of the original
* query.
*
* @param query The client query
* @param sql The generated SQL query
* @param sqlDialect the SQL dialect
* @return A new query that returns the total number of records.
*/
private NativeQuery toPageTotalSQL(Query query, NativeQuery sql, SQLDialect sqlDialect) {
// TODO: refactor this method
String groupByDimensions = query.getAllDimensionProjections().stream().map(SQLColumnProjection.class::cast).filter(SQLColumnProjection::isProjected).map((column) -> column.toSQL(query, metaDataStore)).collect(Collectors.joining(", "));
if (groupByDimensions.isEmpty()) {
// Metric projection without group by dimension will return onely 1 record.
return null;
}
NativeQuery innerQuery = NativeQuery.builder().projectionClause(groupByDimensions).fromClause(sql.getFromClause()).joinClause(sql.getJoinClause()).whereClause(sql.getWhereClause()).groupByClause(String.format("GROUP BY %s", groupByDimensions)).havingClause(sql.getHavingClause()).build();
return NativeQuery.builder().projectionClause("COUNT(*)").fromClause(QueryTranslator.getFromClause("(" + innerQuery + ")", applyQuotes("pagination_subquery", sqlDialect), sqlDialect)).build();
}
use of com.yahoo.elide.datastores.aggregation.metadata.models.Dimension in project elide by yahoo.
the class EntityProjectionTranslator method resolveNonTimeDimensions.
/**
* Gets dimensions except time dimensions based on relationships and attributes from {@link EntityProjection}.
*/
private Set<DimensionProjection> resolveNonTimeDimensions() {
Set<DimensionProjection> attributes = entityProjection.getAttributes().stream().filter(attribute -> queriedTable.getTimeDimension(attribute.getName()) == null).map(dimAttr -> {
Dimension dimension = queriedTable.getDimension(dimAttr.getName());
return dimension == null ? null : engine.constructDimensionProjection(dimension, dimAttr.getAlias(), getArgumentMapFromArgumentSet(dimAttr.getArguments()));
}).filter(Objects::nonNull).collect(Collectors.toSet());
Set<DimensionProjection> relationships = entityProjection.getRelationships().stream().map(dimAttr -> {
Dimension dimension = queriedTable.getDimension(dimAttr.getName());
return dimension == null ? null : engine.constructDimensionProjection(dimension, dimAttr.getAlias(), Collections.emptyMap());
}).filter(Objects::nonNull).collect(Collectors.toSet());
return Sets.union(attributes, relationships);
}
use of com.yahoo.elide.datastores.aggregation.metadata.models.Dimension in project elide by yahoo.
the class MetaDataStoreTest method testHiddenFields.
@Test
public void testHiddenFields() {
Table playerStats = dataStore.getTable(ClassType.of(PlayerStats.class));
Dimension country = playerStats.getDimension("country");
Dimension playerRank = playerStats.getDimension("playerRank");
Metric highScore = playerStats.getMetric("highScore");
Metric hiddenHighScore = playerStats.getMetric("hiddenHighScore");
TimeDimension recordedDate = playerStats.getTimeDimension("recordedDate");
TimeDimension hiddenRecordedDate = playerStats.getTimeDimension("hiddenRecordedDate");
assertTrue(country.isHidden());
assertFalse(playerRank.isHidden());
assertTrue(hiddenHighScore.isHidden());
assertFalse(highScore.isHidden());
assertTrue(hiddenRecordedDate.isHidden());
assertFalse(recordedDate.isHidden());
assertTrue(playerStats.getColumns().contains(highScore));
assertTrue(playerStats.getColumns().contains(recordedDate));
assertTrue(playerStats.getColumns().contains(playerRank));
assertFalse(playerStats.getColumns().contains(country));
assertFalse(playerStats.getColumns().contains(hiddenHighScore));
assertFalse(playerStats.getColumns().contains(hiddenRecordedDate));
assertTrue(playerStats.getAllColumns().contains(highScore));
assertTrue(playerStats.getAllColumns().contains(recordedDate));
assertTrue(playerStats.getAllColumns().contains(playerRank));
assertTrue(playerStats.getAllColumns().contains(country));
assertTrue(playerStats.getAllColumns().contains(hiddenHighScore));
assertTrue(playerStats.getAllColumns().contains(hiddenRecordedDate));
assertFalse(playerStats.getDimensions().contains(country));
assertFalse(playerStats.getMetrics().contains(hiddenHighScore));
assertFalse(playerStats.getTimeDimensions().contains(hiddenRecordedDate));
assertTrue(playerStats.getMetrics().contains(highScore));
assertTrue(playerStats.getDimensions().contains(playerRank));
assertTrue(playerStats.getTimeDimensions().contains(recordedDate));
assertTrue(playerStats.getAllDimensions().contains(country));
assertTrue(playerStats.getAllMetrics().contains(hiddenHighScore));
assertTrue(playerStats.getAllTimeDimensions().contains(hiddenRecordedDate));
assertTrue(playerStats.getAllMetrics().contains(highScore));
assertTrue(playerStats.getAllDimensions().contains(playerRank));
assertTrue(playerStats.getAllTimeDimensions().contains(recordedDate));
}
Aggregations