Search in sources :

Example 66 with SQLTable

use of com.yahoo.elide.datastores.aggregation.queryengines.sql.metadata.SQLTable in project elide by yahoo.

the class TableArgumentValidator method verifyRequiredTableArgsForJoinTables.

private void verifyRequiredTableArgsForJoinTables() {
    table.getJoins().forEach((joinName, sqlJoin) -> {
        SQLTable joinTable = metaDataStore.getTable(sqlJoin.getJoinTableType());
        joinTable.getArgumentDefinitions().forEach(joinArgDef -> {
            String joinArgName = joinArgDef.getName();
            if (table.hasArgumentDefinition(joinArgName)) {
                if (joinArgDef.getType() != table.getArgumentDefinition(joinArgName).getType()) {
                    throw new IllegalStateException(String.format(errorMsgPrefix + "Argument type mismatch. Join table: '%s' has same Argument: '%s'" + " with type '%s'.", joinTable.getName(), joinArgName, joinArgDef.getType()));
                }
            } else if (StringUtils.isBlank(joinArgDef.getDefaultValue().toString())) {
                throw new IllegalStateException(String.format(errorMsgPrefix + "Argument '%s' with type '%s' is not defined but is required by join table: %s.", joinArgName, joinArgDef.getType(), joinTable.getName()));
            }
        });
    });
}
Also used : SQLTable(com.yahoo.elide.datastores.aggregation.queryengines.sql.metadata.SQLTable)

Example 67 with SQLTable

use of com.yahoo.elide.datastores.aggregation.queryengines.sql.metadata.SQLTable in project elide by yahoo.

the class AggregationDataStoreTransactionTest method testRequiredColumnFilterArguments.

@Test
public void testRequiredColumnFilterArguments() throws Exception {
    Type<PlayerStatsWithRequiredFilter> tableType = ClassType.of(PlayerStatsWithRequiredFilter.class);
    EntityDictionary dictionary = EntityDictionary.builder().build();
    dictionary.bindEntity(PlayerStatsWithRequiredFilter.class);
    SQLTable table = new SQLTable(new Namespace(DEFAULT_NAMESPACE), tableType, dictionary);
    RSQLFilterDialect filterDialect = RSQLFilterDialect.builder().dictionary(dictionary).build();
    FilterExpression where = filterDialect.parse(tableType, new HashSet<>(), "recordedDate>2019-07-12T00:00Z", NO_VERSION);
    Query query = Query.builder().column(SQLMetricProjection.builder().name("highScore").alias("highScore").build()).whereFilter(where).source(table).build();
    AggregationDataStoreTransaction tx = new AggregationDataStoreTransaction(queryEngine, cache, queryLogger);
    Query modifiedQuery = tx.addColumnFilterArguments(table, query, dictionary);
    Map<String, Argument> columnArguments = modifiedQuery.getColumnProjection("highScore").getArguments();
    assertTrue(columnArguments.containsKey("recordedDate"));
    assertEquals(1, columnArguments.size());
}
Also used : NativeQuery(com.yahoo.elide.datastores.aggregation.queryengines.sql.query.NativeQuery) Query(com.yahoo.elide.datastores.aggregation.query.Query) Argument(com.yahoo.elide.core.request.Argument) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) Namespace(com.yahoo.elide.datastores.aggregation.metadata.models.Namespace) PlayerStatsWithRequiredFilter(example.PlayerStatsWithRequiredFilter) SQLTable(com.yahoo.elide.datastores.aggregation.queryengines.sql.metadata.SQLTable) FilterExpression(com.yahoo.elide.core.filter.expression.FilterExpression) EntityDictionary(com.yahoo.elide.core.dictionary.EntityDictionary) RSQLFilterDialect(com.yahoo.elide.core.filter.dialect.RSQLFilterDialect) SQLUnitTest(com.yahoo.elide.datastores.aggregation.framework.SQLUnitTest) Test(org.junit.jupiter.api.Test)

Example 68 with SQLTable

use of com.yahoo.elide.datastores.aggregation.queryengines.sql.metadata.SQLTable in project elide by yahoo.

the class AggregationDataStoreTransactionTest method testRequiredTableFilterArguments.

@Test
public void testRequiredTableFilterArguments() throws Exception {
    Type<PlayerStatsWithRequiredFilter> tableType = ClassType.of(PlayerStatsWithRequiredFilter.class);
    EntityDictionary dictionary = EntityDictionary.builder().build();
    dictionary.bindEntity(PlayerStatsWithRequiredFilter.class);
    SQLTable table = new SQLTable(new Namespace(DEFAULT_NAMESPACE), tableType, dictionary);
    RSQLFilterDialect filterDialect = RSQLFilterDialect.builder().dictionary(dictionary).build();
    FilterExpression where = filterDialect.parse(tableType, new HashSet<>(), "recordedDate>=2019-07-12T00:00Z;recordedDate<2030-07-12T00:00Z", NO_VERSION);
    Query query = Query.builder().source(table).whereFilter(where).build();
    AggregationDataStoreTransaction tx = new AggregationDataStoreTransaction(queryEngine, cache, queryLogger);
    Query modifiedQuery = tx.addTableFilterArguments(table, query, dictionary);
    Map<String, Argument> tableArguments = modifiedQuery.getArguments();
    assertTrue(tableArguments.containsKey("start"));
    assertTrue(tableArguments.containsKey("end"));
    assertEquals(2, tableArguments.size());
}
Also used : NativeQuery(com.yahoo.elide.datastores.aggregation.queryengines.sql.query.NativeQuery) Query(com.yahoo.elide.datastores.aggregation.query.Query) Argument(com.yahoo.elide.core.request.Argument) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) Namespace(com.yahoo.elide.datastores.aggregation.metadata.models.Namespace) PlayerStatsWithRequiredFilter(example.PlayerStatsWithRequiredFilter) SQLTable(com.yahoo.elide.datastores.aggregation.queryengines.sql.metadata.SQLTable) FilterExpression(com.yahoo.elide.core.filter.expression.FilterExpression) EntityDictionary(com.yahoo.elide.core.dictionary.EntityDictionary) RSQLFilterDialect(com.yahoo.elide.core.filter.dialect.RSQLFilterDialect) SQLUnitTest(com.yahoo.elide.datastores.aggregation.framework.SQLUnitTest) Test(org.junit.jupiter.api.Test)

Example 69 with SQLTable

use of com.yahoo.elide.datastores.aggregation.queryengines.sql.metadata.SQLTable in project elide by yahoo.

the class DefaultQueryValidatorTest method testValidTableArgument.

@Test
public void testValidTableArgument() {
    SQLTable source = (SQLTable) metaDataStore.getTable("playerStatsView", NO_VERSION);
    Map<String, Argument> tableArguments = new HashMap<>();
    tableArguments.put("rating", Argument.builder().name("rating").value("Terrible").build());
    Map<String, Argument> columnArguments = new HashMap<>();
    columnArguments.put("format", Argument.builder().name("format").value("lower").build());
    Query query = Query.builder().source(source).arguments(tableArguments).metricProjection(source.getMetricProjection("highScore")).dimensionProjection(source.getDimensionProjection("countryName", columnArguments)).build();
    validateQueryDoesNotThrow(query);
}
Also used : Argument(com.yahoo.elide.core.request.Argument) Query(com.yahoo.elide.datastores.aggregation.query.Query) HashMap(java.util.HashMap) SQLTable(com.yahoo.elide.datastores.aggregation.queryengines.sql.metadata.SQLTable) SQLUnitTest(com.yahoo.elide.datastores.aggregation.framework.SQLUnitTest) Test(org.junit.jupiter.api.Test)

Example 70 with SQLTable

use of com.yahoo.elide.datastores.aggregation.queryengines.sql.metadata.SQLTable in project elide by yahoo.

the class DefaultQueryValidatorTest method testValidColumnArgument.

@Test
public void testValidColumnArgument() {
    SQLTable source = (SQLTable) metaDataStore.getTable("playerStatsView", NO_VERSION);
    Map<String, Argument> tableArguments = new HashMap<>();
    tableArguments.put("rating", Argument.builder().name("rating").value("Terrible").build());
    Map<String, Argument> argumentMap = new HashMap<>();
    argumentMap.put("format", Argument.builder().name("format").value("lower").build());
    Query query = Query.builder().source(source).arguments(tableArguments).metricProjection(source.getMetricProjection("highScore")).dimensionProjection(source.getDimensionProjection("countryName", "countryName", argumentMap)).build();
    validateQueryDoesNotThrow(query);
}
Also used : Argument(com.yahoo.elide.core.request.Argument) Query(com.yahoo.elide.datastores.aggregation.query.Query) HashMap(java.util.HashMap) SQLTable(com.yahoo.elide.datastores.aggregation.queryengines.sql.metadata.SQLTable) SQLUnitTest(com.yahoo.elide.datastores.aggregation.framework.SQLUnitTest) Test(org.junit.jupiter.api.Test)

Aggregations

SQLTable (com.yahoo.elide.datastores.aggregation.queryengines.sql.metadata.SQLTable)76 Test (org.junit.jupiter.api.Test)59 Query (com.yahoo.elide.datastores.aggregation.query.Query)50 SQLUnitTest (com.yahoo.elide.datastores.aggregation.framework.SQLUnitTest)49 FilterExpression (com.yahoo.elide.core.filter.expression.FilterExpression)34 Path (com.yahoo.elide.core.Path)31 FilterPredicate (com.yahoo.elide.core.filter.predicates.FilterPredicate)31 AndFilterExpression (com.yahoo.elide.core.filter.expression.AndFilterExpression)29 OrFilterExpression (com.yahoo.elide.core.filter.expression.OrFilterExpression)29 Argument (com.yahoo.elide.core.request.Argument)24 Day (com.yahoo.elide.datastores.aggregation.timegrains.Day)20 Date (java.util.Date)19 GameRevenue (example.GameRevenue)15 ColumnProjection (com.yahoo.elide.datastores.aggregation.query.ColumnProjection)12 HashSet (java.util.HashSet)12 SortingImpl (com.yahoo.elide.core.sort.SortingImpl)8 Namespace (com.yahoo.elide.datastores.aggregation.metadata.models.Namespace)8 HashMap (java.util.HashMap)8 TreeMap (java.util.TreeMap)8 EntityDictionary (com.yahoo.elide.core.dictionary.EntityDictionary)7