Search in sources :

Example 71 with SQLTable

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

the class DefaultQueryValidatorTest method testHavingFilterMatchesProjection.

@Test
public void testHavingFilterMatchesProjection() throws ParseException {
    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> arguments = new HashMap<>();
    arguments.put("format", Argument.builder().name("format").value("lower").build());
    FilterExpression havingFilter = filterParser.parseFilterExpression("countryName[format:lower]==usa", playerStatsViewType, false);
    Query query = Query.builder().source(source).arguments(tableArguments).dimensionProjection(source.getDimensionProjection("countryName", arguments)).havingFilter(havingFilter).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) FilterExpression(com.yahoo.elide.core.filter.expression.FilterExpression) SQLUnitTest(com.yahoo.elide.datastores.aggregation.framework.SQLUnitTest) Test(org.junit.jupiter.api.Test)

Example 72 with SQLTable

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

the class DefaultQueryValidatorTest method testHavingFilterMismatchedWithProjection.

@Test
public void testHavingFilterMismatchedWithProjection() throws ParseException {
    SQLTable source = (SQLTable) metaDataStore.getTable("playerStatsView", NO_VERSION);
    FilterExpression havingFilter = filterParser.parseFilterExpression("countryName[format:upper]==USA", playerStatsViewType, false);
    Query query = Query.builder().source(source).dimensionProjection(source.getDimensionProjection("countryName")).havingFilter(havingFilter).build();
    validateQuery(query, "Invalid operation: Post aggregation filtering on 'countryName' requires the field to be projected in the response with matching arguments");
}
Also used : Query(com.yahoo.elide.datastores.aggregation.query.Query) SQLTable(com.yahoo.elide.datastores.aggregation.queryengines.sql.metadata.SQLTable) FilterExpression(com.yahoo.elide.core.filter.expression.FilterExpression) SQLUnitTest(com.yahoo.elide.datastores.aggregation.framework.SQLUnitTest) Test(org.junit.jupiter.api.Test)

Example 73 with SQLTable

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

the class DefaultQueryValidatorTest method testMissingRequiredParameterInFilter.

@Test
public void testMissingRequiredParameterInFilter() throws ParseException {
    SQLTable source = (SQLTable) metaDataStore.getTable("playerStatsView", NO_VERSION);
    FilterExpression havingFilter = filterParser.parseFilterExpression("countryName==usa", playerStatsViewType, false);
    Query query = Query.builder().source(source).dimensionProjection(source.getDimensionProjection("countryName")).havingFilter(havingFilter).build();
    validateQuery(query, "Invalid operation: Argument 'format' for column 'countryName' is required");
}
Also used : Query(com.yahoo.elide.datastores.aggregation.query.Query) SQLTable(com.yahoo.elide.datastores.aggregation.queryengines.sql.metadata.SQLTable) FilterExpression(com.yahoo.elide.core.filter.expression.FilterExpression) SQLUnitTest(com.yahoo.elide.datastores.aggregation.framework.SQLUnitTest) Test(org.junit.jupiter.api.Test)

Example 74 with SQLTable

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

the class SplitFilterExpressionVisitorTest method setupEntityDictionary.

@BeforeAll
public static void setupEntityDictionary() {
    EntityDictionary entityDictionary = EntityDictionary.builder().build();
    entityDictionary.bindEntity(PlayerStats.class);
    entityDictionary.bindEntity(Country.class);
    entityDictionary.bindEntity(SubCountry.class);
    entityDictionary.bindEntity(Player.class);
    Namespace namespace = new Namespace(DEFAULT_NAMESPACE);
    Table table = new SQLTable(namespace, ClassType.of(PlayerStats.class), entityDictionary);
    splitFilterExpressionVisitor = new SplitFilterExpressionVisitor(table);
}
Also used : SQLTable(com.yahoo.elide.datastores.aggregation.queryengines.sql.metadata.SQLTable) Table(com.yahoo.elide.datastores.aggregation.metadata.models.Table) SQLTable(com.yahoo.elide.datastores.aggregation.queryengines.sql.metadata.SQLTable) PlayerStats(example.PlayerStats) EntityDictionary(com.yahoo.elide.core.dictionary.EntityDictionary) Namespace(com.yahoo.elide.datastores.aggregation.metadata.models.Namespace) BeforeAll(org.junit.jupiter.api.BeforeAll)

Example 75 with SQLTable

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

the class ReferenceExtractor method visitJoinReference.

@Override
public Set<T> visitJoinReference(JoinReference reference) {
    if (referenceType.equals(JoinReference.class)) {
        references.add((T) reference);
    }
    JoinPath path = reference.getPath();
    int pathLimit = (mode == Mode.SAME_QUERY) ? 1 : path.getPathElements().size() - 1;
    for (int idx = 0; idx < pathLimit; idx++) {
        Path.PathElement pathElement = path.getPathElements().get(idx);
        String fieldName = pathElement.getFieldName();
        Type<?> parentClass = pathElement.getType();
        SQLTable table = metaDataStore.getTable(parentClass);
        SQLJoin join = table.getJoin(fieldName);
        if (visitedJoins.contains(join)) {
            continue;
        }
        visitedJoins.add(join);
        parser.parse(table, join.getJoinExpression()).stream().forEach(ref -> ref.accept(this));
    }
    if (mode != Mode.SAME_QUERY) {
        return reference.getReference().accept(this);
    }
    return references;
}
Also used : Path(com.yahoo.elide.core.Path) JoinPath(com.yahoo.elide.datastores.aggregation.core.JoinPath) JoinPath(com.yahoo.elide.datastores.aggregation.core.JoinPath) SQLTable(com.yahoo.elide.datastores.aggregation.queryengines.sql.metadata.SQLTable) SQLJoin(com.yahoo.elide.datastores.aggregation.queryengines.sql.metadata.SQLJoin)

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