Search in sources :

Example 1 with TimeDimension

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));
}
Also used : Table(com.yahoo.elide.datastores.aggregation.metadata.models.Table) Metric(com.yahoo.elide.datastores.aggregation.metadata.models.Metric) PlayerStats(example.PlayerStats) Dimension(com.yahoo.elide.datastores.aggregation.metadata.models.Dimension) TimeDimension(com.yahoo.elide.datastores.aggregation.metadata.models.TimeDimension) TimeDimension(com.yahoo.elide.datastores.aggregation.metadata.models.TimeDimension) Test(org.junit.jupiter.api.Test)

Example 2 with TimeDimension

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;
}
Also used : SQLMetricProjection(com.yahoo.elide.datastores.aggregation.queryengines.sql.query.SQLMetricProjection) MetricProjection(com.yahoo.elide.datastores.aggregation.query.MetricProjection) Argument(com.yahoo.elide.core.request.Argument) HashMap(java.util.HashMap) SQLTimeDimensionProjection(com.yahoo.elide.datastores.aggregation.queryengines.sql.query.SQLTimeDimensionProjection) SQLTable(com.yahoo.elide.datastores.aggregation.queryengines.sql.metadata.SQLTable) TimeDimension(com.yahoo.elide.datastores.aggregation.metadata.models.TimeDimension) QueryPlan(com.yahoo.elide.datastores.aggregation.query.QueryPlan)

Example 3 with TimeDimension

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()));
        }
    }
}
Also used : ColumnMeta(com.yahoo.elide.datastores.aggregation.annotation.ColumnMeta) Arrays(java.util.Arrays) ArgumentType(com.yahoo.elide.core.dictionary.ArgumentType) Join(com.yahoo.elide.datastores.aggregation.annotation.Join) AccessibleObject(com.yahoo.elide.core.type.AccessibleObject) TableMeta(com.yahoo.elide.datastores.aggregation.annotation.TableMeta) UserCheck(com.yahoo.elide.core.security.checks.UserCheck) PermissionExecutor(com.yahoo.elide.core.security.PermissionExecutor) Function(java.util.function.Function) ClassType(com.yahoo.elide.core.type.ClassType) Column(com.yahoo.elide.datastores.aggregation.metadata.models.Column) ToString(lombok.ToString) ParseTree(org.antlr.v4.runtime.tree.ParseTree) FilterExpressionCheck(com.yahoo.elide.core.security.checks.FilterExpressionCheck) RequestScope(com.yahoo.elide.core.RequestScope) DataStoreTransaction(com.yahoo.elide.core.datastore.DataStoreTransaction) Check(com.yahoo.elide.core.security.checks.Check) Cache(com.yahoo.elide.datastores.aggregation.cache.Cache) FromSubquery(com.yahoo.elide.datastores.aggregation.queryengines.sql.annotation.FromSubquery) PermissionExpressionVisitor(com.yahoo.elide.modelconfig.validator.PermissionExpressionVisitor) NonNull(lombok.NonNull) Predicate(java.util.function.Predicate) ValueType(com.yahoo.elide.datastores.aggregation.metadata.enums.ValueType) ArgumentDefinition(com.yahoo.elide.datastores.aggregation.metadata.models.ArgumentDefinition) Set(java.util.Set) FromTable(com.yahoo.elide.datastores.aggregation.queryengines.sql.annotation.FromTable) AggregationStorePermissionExecutor(com.yahoo.elide.core.security.executors.AggregationStorePermissionExecutor) EntityDictionary(com.yahoo.elide.core.dictionary.EntityDictionary) Objects(java.util.Objects) List(java.util.List) ReadPermission(com.yahoo.elide.annotation.ReadPermission) Builder(lombok.Builder) DataStore(com.yahoo.elide.core.datastore.DataStore) Type(com.yahoo.elide.core.type.Type) TimeDimension(com.yahoo.elide.datastores.aggregation.metadata.models.TimeDimension) Annotation(java.lang.annotation.Annotation) Table(com.yahoo.elide.datastores.aggregation.metadata.models.Table) QueryLogger(com.yahoo.elide.datastores.aggregation.core.QueryLogger) FromTable(com.yahoo.elide.datastores.aggregation.queryengines.sql.annotation.FromTable) Table(com.yahoo.elide.datastores.aggregation.metadata.models.Table) Column(com.yahoo.elide.datastores.aggregation.metadata.models.Column) ArgumentDefinition(com.yahoo.elide.datastores.aggregation.metadata.models.ArgumentDefinition) TimeDimension(com.yahoo.elide.datastores.aggregation.metadata.models.TimeDimension) ArgumentType(com.yahoo.elide.core.dictionary.ArgumentType)

Example 4 with TimeDimension

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));
}
Also used : TimeDimensionGrain(com.yahoo.elide.datastores.aggregation.metadata.models.TimeDimensionGrain) TimeDimension(com.yahoo.elide.datastores.aggregation.metadata.models.TimeDimension)

Aggregations

TimeDimension (com.yahoo.elide.datastores.aggregation.metadata.models.TimeDimension)4 Table (com.yahoo.elide.datastores.aggregation.metadata.models.Table)2 ReadPermission (com.yahoo.elide.annotation.ReadPermission)1 RequestScope (com.yahoo.elide.core.RequestScope)1 DataStore (com.yahoo.elide.core.datastore.DataStore)1 DataStoreTransaction (com.yahoo.elide.core.datastore.DataStoreTransaction)1 ArgumentType (com.yahoo.elide.core.dictionary.ArgumentType)1 EntityDictionary (com.yahoo.elide.core.dictionary.EntityDictionary)1 Argument (com.yahoo.elide.core.request.Argument)1 PermissionExecutor (com.yahoo.elide.core.security.PermissionExecutor)1 Check (com.yahoo.elide.core.security.checks.Check)1 FilterExpressionCheck (com.yahoo.elide.core.security.checks.FilterExpressionCheck)1 UserCheck (com.yahoo.elide.core.security.checks.UserCheck)1 AggregationStorePermissionExecutor (com.yahoo.elide.core.security.executors.AggregationStorePermissionExecutor)1 AccessibleObject (com.yahoo.elide.core.type.AccessibleObject)1 ClassType (com.yahoo.elide.core.type.ClassType)1 Type (com.yahoo.elide.core.type.Type)1 ColumnMeta (com.yahoo.elide.datastores.aggregation.annotation.ColumnMeta)1 Join (com.yahoo.elide.datastores.aggregation.annotation.Join)1 TableMeta (com.yahoo.elide.datastores.aggregation.annotation.TableMeta)1