Search in sources :

Example 21 with Argument

use of com.yahoo.elide.core.request.Argument in project elide by yahoo.

the class DefaultQueryValidatorTest method testInvalidColumnArgument.

@Test
public void testInvalidColumnArgument() {
    SQLTable source = (SQLTable) metaDataStore.getTable("playerStatsView", NO_VERSION);
    Map<String, Argument> argumentMap = new HashMap<>();
    argumentMap.put("format", Argument.builder().name("format").value(";").build());
    Query query = Query.builder().source(source).metricProjection(source.getMetricProjection("highScore")).dimensionProjection(source.getDimensionProjection("countryName", "countryName", argumentMap)).build();
    validateQuery(query, "Invalid operation: Argument 'format' for column 'countryName' must match one of these values: [lower, upper]");
}
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 22 with Argument

use of com.yahoo.elide.core.request.Argument 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 23 with Argument

use of com.yahoo.elide.core.request.Argument in project elide by yahoo.

the class EntityProjectionTranslatorTest method testQueryArguments.

@Test
public void testQueryArguments() {
    EntityProjectionTranslator translator = new EntityProjectionTranslator(engine, playerStatsTable, basicProjection, scope, true);
    Query query = translator.getQuery();
    Argument queryArg = query.getArguments().get("foo");
    assertEquals("bar", queryArg.getValue());
    Argument lowScoreArg = query.getColumnProjection("lowScore").getArguments().get("foo");
    assertEquals("bar", lowScoreArg.getValue());
}
Also used : Query(com.yahoo.elide.datastores.aggregation.query.Query) Argument(com.yahoo.elide.core.request.Argument) SQLUnitTest(com.yahoo.elide.datastores.aggregation.framework.SQLUnitTest) Test(org.junit.jupiter.api.Test)

Example 24 with Argument

use of com.yahoo.elide.core.request.Argument 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 25 with Argument

use of com.yahoo.elide.core.request.Argument in project elide by yahoo.

the class SQLTimeDimensionProjection method getGrainFromArguments.

private TimeDimensionGrain getGrainFromArguments(Map<String, Argument> arguments, TimeDimension column) {
    Argument grainArgument = arguments.get("grain");
    if (grainArgument == null) {
        return column.getDefaultGrain();
    }
    String grainName = grainArgument.getValue().toString().toLowerCase(Locale.ENGLISH);
    return column.getSupportedGrains().stream().filter(grain -> grain.getGrain().name().toLowerCase(Locale.ENGLISH).equals(grainName)).findFirst().orElseThrow(() -> new InvalidParameterizedAttributeException(name, grainArgument));
}
Also used : Argument(com.yahoo.elide.core.request.Argument) InvalidParameterizedAttributeException(com.yahoo.elide.core.exceptions.InvalidParameterizedAttributeException)

Aggregations

Argument (com.yahoo.elide.core.request.Argument)71 Test (org.junit.jupiter.api.Test)59 HashMap (java.util.HashMap)48 Query (com.yahoo.elide.datastores.aggregation.query.Query)38 FilterExpression (com.yahoo.elide.core.filter.expression.FilterExpression)35 SQLUnitTest (com.yahoo.elide.datastores.aggregation.framework.SQLUnitTest)25 SQLTable (com.yahoo.elide.datastores.aggregation.queryengines.sql.metadata.SQLTable)22 FilterPredicate (com.yahoo.elide.core.filter.predicates.FilterPredicate)15 Day (com.yahoo.elide.datastores.aggregation.timegrains.Day)14 HashSet (java.util.HashSet)14 Path (com.yahoo.elide.core.Path)12 ToString (lombok.ToString)12 OrFilterExpression (com.yahoo.elide.core.filter.expression.OrFilterExpression)11 AndFilterExpression (com.yahoo.elide.core.filter.expression.AndFilterExpression)10 Date (java.util.Date)10 SQLDimensionProjection (com.yahoo.elide.datastores.aggregation.queryengines.sql.query.SQLDimensionProjection)9 GameRevenue (example.GameRevenue)7 PlayerStats (example.PlayerStats)6 SQLMetricProjection (com.yahoo.elide.datastores.aggregation.queryengines.sql.query.SQLMetricProjection)5 Month (com.yahoo.elide.datastores.aggregation.timegrains.Month)5