Search in sources :

Example 31 with SQLTable

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

the class DefaultQueryValidatorTest method testInvalidTableArgument.

@Test
public void testInvalidTableArgument() {
    SQLTable source = (SQLTable) metaDataStore.getTable("playerStatsView", NO_VERSION);
    Map<String, Argument> tableArguments = new HashMap<>();
    tableArguments.put("rating", Argument.builder().name("rating").value("SELECT * FROM FOO;").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();
    validateQuery(query, "Invalid operation: Argument 'rating' for table 'playerStatsView' has an invalid value: SELECT * FROM FOO;");
}
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 32 with SQLTable

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

the class QueryKeyExtractorTest method testDuplicateFullQuery.

@Test
public void testDuplicateFullQuery() throws Exception {
    // Build 1st Table
    NamespaceConfig testNamespace = NamespaceConfig.builder().name("namespace1").build();
    NamespacePackage testNamespacePackage = new NamespacePackage(testNamespace);
    Table testTable = Table.builder().cardinality("medium").description("A test table").friendlyName("foo").table("table1").name("Table").schema("db1").category("category1").readAccess("Admin").dbConnectionName("dbConn").isFact(true).filterTemplate("a==b").namespace("namespace1").dimension(Dimension.builder().name("dim1").definition("{{dim1}}").type(Type.BOOLEAN).values(Collections.EMPTY_SET).tags(Collections.EMPTY_SET).build()).build();
    TableType testType = new TableType(testTable, testNamespacePackage);
    dictionary.bindEntity(testType);
    SQLTable testSqlTable = new SQLTable(new Namespace(testNamespacePackage), testType, dictionary);
    // Build 2nd Table
    NamespaceConfig anotherTestNamespace = NamespaceConfig.builder().name("namespace2").build();
    NamespacePackage anotherTestNamespacePackage = new NamespacePackage(anotherTestNamespace);
    Table anotherTestTable = // Exactly same as testTable but different namespace
    Table.builder().cardinality("medium").description("A test table").friendlyName("foo").table("table1").name("Table").schema("db1").category("category1").readAccess("Admin").dbConnectionName("dbConn").isFact(true).filterTemplate("a==b").namespace("namespace2").dimension(Dimension.builder().name("dim1").definition("{{dim1}}").type(Type.BOOLEAN).values(Collections.EMPTY_SET).tags(Collections.EMPTY_SET).build()).build();
    TableType anotherTestType = new TableType(anotherTestTable, anotherTestNamespacePackage);
    dictionary.bindEntity(anotherTestType);
    SQLTable anotherTestSqlTable = new SQLTable(new Namespace(anotherTestNamespacePackage), anotherTestType, dictionary);
    // Build Query and Test
    Query query = Query.builder().source(testSqlTable).dimensionProjection(testSqlTable.getDimensionProjection("dim1")).pagination(new ImmutablePagination(0, 2, false, true)).build();
    assertEquals(// table name
    "namespace1_Table;" + // metrics
    "{}" + // Group by
    "{dim1;{}}" + // time dimensions
    "{}" + // where
    ";" + // having
    ";" + // sort
    ";" + // pagination
    "{0;2;1;}", QueryKeyExtractor.extractKey(query));
    Query anotherQuery = Query.builder().source(anotherTestSqlTable).dimensionProjection(anotherTestSqlTable.getDimensionProjection("dim1")).pagination(new ImmutablePagination(0, 2, false, true)).build();
    assertEquals(// table name
    "namespace2_Table;" + // metrics
    "{}" + // Group by
    "{dim1;{}}" + // time dimensions
    "{}" + // where
    ";" + // having
    ";" + // sort
    ";" + // pagination
    "{0;2;1;}", QueryKeyExtractor.extractKey(anotherQuery));
    assertNotEquals(QueryKeyExtractor.extractKey(anotherQuery), QueryKeyExtractor.extractKey(query));
}
Also used : NamespaceConfig(com.yahoo.elide.modelconfig.model.NamespaceConfig) Table(com.yahoo.elide.modelconfig.model.Table) SQLTable(com.yahoo.elide.datastores.aggregation.queryengines.sql.metadata.SQLTable) TableType(com.yahoo.elide.datastores.aggregation.dynamic.TableType) Query(com.yahoo.elide.datastores.aggregation.query.Query) SQLTable(com.yahoo.elide.datastores.aggregation.queryengines.sql.metadata.SQLTable) ImmutablePagination(com.yahoo.elide.datastores.aggregation.query.ImmutablePagination) NamespacePackage(com.yahoo.elide.datastores.aggregation.dynamic.NamespacePackage) Namespace(com.yahoo.elide.datastores.aggregation.metadata.models.Namespace) SQLUnitTest(com.yahoo.elide.datastores.aggregation.framework.SQLUnitTest) Test(org.junit.jupiter.api.Test)

Example 33 with SQLTable

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

the class ColumnArgumentValidator method verifyLogicalReference.

private void verifyLogicalReference(LogicalReference reference) {
    SQLTable sqlTable = (SQLTable) reference.getSource();
    ColumnProjection columnProj = reference.getColumn();
    // This will have dependent column's defined arguments merged with pinned arguments used to invoke this column.
    Map<String, Argument> mergedArguments = columnProj.getArguments();
    Column refColumn = sqlTable.getColumn(Column.class, columnProj.getName());
    verifyPinnedArguments(mergedArguments, refColumn, String.format(errorMsgPrefix + "Type mismatch of Fixed value provided for Dependent Column: '%s' in table: '%s'. ", refColumn.getName(), sqlTable.getName()));
    refColumn.getArgumentDefinitions().forEach(argDef -> {
        String argName = argDef.getName();
        if (column.hasArgumentDefinition(argName)) {
            if (argDef.getType() != column.getArgumentDefinition(argName).getType()) {
                throw new IllegalStateException(String.format(errorMsgPrefix + "Argument type mismatch. Dependent Column: '%s' in table: '%s' has same" + " Argument: '%s' with type '%s'.", refColumn.getName(), sqlTable.getName(), argName, argDef.getType()));
            }
        } else if (StringUtils.isBlank(argDef.getDefaultValue().toString()) && StringUtils.isBlank(mergedArguments.get(argName).getValue().toString())) {
            throw new IllegalStateException(String.format(errorMsgPrefix + "Argument '%s' with type '%s' is not defined but is required for" + " Dependent Column: '%s' in table: '%s'.", argName, argDef.getType(), refColumn.getName(), sqlTable.getName()));
        }
    });
}
Also used : Argument(com.yahoo.elide.core.request.Argument) Column(com.yahoo.elide.datastores.aggregation.metadata.models.Column) SQLTable(com.yahoo.elide.datastores.aggregation.queryengines.sql.metadata.SQLTable) ColumnProjection(com.yahoo.elide.datastores.aggregation.query.ColumnProjection)

Example 34 with SQLTable

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

the class TemplateConfigValidator method validate.

@Override
public void validate(Map<String, ConfigFile> resourceMap) {
    MetaDataStore metaDataStore = rebuildMetaDataStore(resourceMap);
    metaDataStore.getTables().forEach(table -> {
        SQLTable sqlTable = (SQLTable) table;
        checkForCycles(sqlTable, metaDataStore);
        TableArgumentValidator tableArgValidator = new TableArgumentValidator(metaDataStore, sqlTable);
        tableArgValidator.validate();
        sqlTable.getAllColumns().forEach(column -> {
            ColumnArgumentValidator colArgValidator = new ColumnArgumentValidator(metaDataStore, sqlTable, column);
            colArgValidator.validate();
        });
    });
}
Also used : MetaDataStore(com.yahoo.elide.datastores.aggregation.metadata.MetaDataStore) SQLTable(com.yahoo.elide.datastores.aggregation.queryengines.sql.metadata.SQLTable)

Example 35 with SQLTable

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

the class AggregationDataStoreTransactionTest method testMissingRequiredTableFilter.

@Test
public void testMissingRequiredTableFilter() {
    EntityDictionary dictionary = EntityDictionary.builder().build();
    dictionary.bindEntity(PlayerStatsWithRequiredFilter.class);
    Table table = new SQLTable(new Namespace(DEFAULT_NAMESPACE), ClassType.of(PlayerStatsWithRequiredFilter.class), dictionary);
    AggregationDataStoreTransaction tx = new AggregationDataStoreTransaction(queryEngine, cache, queryLogger);
    assertThrows(BadRequestException.class, () -> tx.addTableFilterArguments(table, query, dictionary));
}
Also used : PlayerStatsWithRequiredFilter(example.PlayerStatsWithRequiredFilter) Table(com.yahoo.elide.datastores.aggregation.metadata.models.Table) SQLTable(com.yahoo.elide.datastores.aggregation.queryengines.sql.metadata.SQLTable) SQLTable(com.yahoo.elide.datastores.aggregation.queryengines.sql.metadata.SQLTable) EntityDictionary(com.yahoo.elide.core.dictionary.EntityDictionary) Namespace(com.yahoo.elide.datastores.aggregation.metadata.models.Namespace) 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