use of com.yahoo.elide.datastores.aggregation.metadata.models.TimeDimension 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));
}
use of com.yahoo.elide.datastores.aggregation.metadata.models.TimeDimension in project elide by yahoo.
the class DailyAverageScorePerPeriod method resolve.
@Override
public QueryPlan resolve(Query query) {
SQLTable table = (SQLTable) query.getSource();
MetricProjection innerMetric = table.getMetricProjection("highScore");
TimeDimension innerTimeGrain = table.getTimeDimension("recordedDate");
Map<String, Argument> arguments = new HashMap<>();
arguments.put("grain", Argument.builder().name("grain").value(TimeGrain.DAY).build());
QueryPlan innerQuery = QueryPlan.builder().source(query.getSource()).metricProjection(innerMetric).timeDimensionProjection(new SQLTimeDimensionProjection(innerTimeGrain, innerTimeGrain.getTimezone(), "recordedDate_DAY", arguments, true)).build();
QueryPlan outerQuery = QueryPlan.builder().source(innerQuery).metricProjection(new DailyAverageScorePerPeriod(this, "AVG({{$highScore}})")).build();
return outerQuery;
}
use of com.yahoo.elide.datastores.aggregation.metadata.models.TimeDimension in project elide by yahoo.
the class AggregationDataStore method populateEntityDictionary.
/**
* Populate an {@link EntityDictionary} and use this dictionary to construct a {@link QueryEngine}.
* @param dictionary the dictionary
*/
@Override
public void populateEntityDictionary(EntityDictionary dictionary) {
if (dynamicCompiledClasses != null && dynamicCompiledClasses.size() != 0) {
dynamicCompiledClasses.stream().filter((type) -> !IS_TYPE_HIDDEN.test(type)).forEach(dynamicLoadedClass -> {
dictionary.bindEntity(dynamicLoadedClass, IS_FIELD_HIDDEN);
validateModelExpressionChecks(dictionary, dynamicLoadedClass);
dictionary.bindPermissionExecutor(dynamicLoadedClass, aggPermissionExecutor);
});
}
dictionary.getScanner().getAnnotatedClasses(AGGREGATION_STORE_CLASSES).stream().filter((type) -> !IS_TYPE_HIDDEN.test(ClassType.of(type))).forEach(cls -> {
dictionary.bindEntity(cls, IS_FIELD_HIDDEN);
validateModelExpressionChecks(dictionary, ClassType.of(cls));
dictionary.bindPermissionExecutor(cls, aggPermissionExecutor);
});
for (Table table : queryEngine.getMetaDataStore().getMetaData(ClassType.of(Table.class))) {
/* Add 'grain' argument to each TimeDimensionColumn */
for (TimeDimension timeDim : table.getAllTimeDimensions()) {
dictionary.addArgumentToAttribute(dictionary.getEntityClass(table.getName(), table.getVersion()), timeDim.getName(), new ArgumentType("grain", ClassType.STRING_TYPE, timeDim.getDefaultGrain().getGrain()));
}
/* Add argument to each Column */
for (Column col : table.getAllColumns()) {
for (ArgumentDefinition arg : col.getArgumentDefinitions()) {
dictionary.addArgumentToAttribute(dictionary.getEntityClass(table.getName(), table.getVersion()), col.getName(), new ArgumentType(arg.getName(), ValueType.getType(arg.getType()), arg.getDefaultValue()));
}
}
/* Add argument to each Table */
for (ArgumentDefinition arg : table.getArgumentDefinitions()) {
dictionary.addArgumentToEntity(dictionary.getEntityClass(table.getName(), table.getVersion()), new ArgumentType(arg.getName(), ValueType.getType(arg.getType()), arg.getDefaultValue()));
}
}
}
use of com.yahoo.elide.datastores.aggregation.metadata.models.TimeDimension in project elide by yahoo.
the class MetaDataStore method addColumn.
/**
* Add a column metadata object.
*
* @param column column metadata
*/
private void addColumn(Column column) {
String version = column.getVersion();
if (!column.isHidden()) {
addMetaData(column, version);
}
if (column instanceof TimeDimension) {
TimeDimension timeDimension = (TimeDimension) column;
for (TimeDimensionGrain grain : timeDimension.getSupportedGrains()) {
addTimeDimensionGrain(grain, version);
}
}
column.getArgumentDefinitions().forEach(arg -> addArgument(arg, version));
}
Aggregations