Search in sources :

Example 36 with Argument

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

the class DefaultQueryPlanMergerTest method testCannotMergeMismatchedDimension.

@Test
public void testCannotMergeMismatchedDimension() {
    MetaDataStore metaDataStore = mock(MetaDataStore.class);
    DefaultQueryPlanMerger merger = new DefaultQueryPlanMerger(metaDataStore);
    QueryPlan a = mock(QueryPlan.class);
    QueryPlan b = mock(QueryPlan.class);
    when(a.canNest(any())).thenReturn(false);
    when(b.canNest(any())).thenReturn(false);
    when(a.nestDepth()).thenReturn(1);
    when(b.nestDepth()).thenReturn(1);
    DimensionProjection p1 = mock(DimensionProjection.class);
    Map<String, Argument> args1 = new HashMap<>();
    when(p1.getName()).thenReturn("name");
    when(p1.getArguments()).thenReturn(args1);
    DimensionProjection p2 = mock(DimensionProjection.class);
    Map<String, Argument> args2 = new HashMap<>();
    args2.put("foo", Argument.builder().name("a").value(100).build());
    when(p2.getName()).thenReturn("name");
    when(p2.getArguments()).thenReturn(args2);
    when(a.getDimensionProjections()).thenReturn(List.of(p1));
    when(b.getDimensionProjections()).thenReturn(List.of(p2));
    when(b.getDimensionProjection(eq("name"))).thenReturn(p2);
    when(a.getDimensionProjection(eq("name"))).thenReturn(p1);
    assertFalse(merger.canMerge(a, b));
    assertFalse(merger.canMerge(b, a));
}
Also used : Argument(com.yahoo.elide.core.request.Argument) HashMap(java.util.HashMap) MetaDataStore(com.yahoo.elide.datastores.aggregation.metadata.MetaDataStore) Test(org.junit.jupiter.api.Test)

Example 37 with Argument

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

the class MetricRatio method make.

@Override
public MetricProjection make(Metric metric, String alias, Map<String, Argument> arguments) {
    Argument numerator = arguments.get("numerator");
    Argument denominator = arguments.get("denominator");
    if (numerator == null || denominator == null) {
        throw new BadRequestException("'numerator' and 'denominator' arguments are required for " + metric.getName());
    }
    return SQLMetricProjection.builder().alias(alias).arguments(arguments).name(metric.getName()).expression("{{" + numerator.getValue() + "}} / {{" + denominator.getValue() + "}}").valueType(metric.getValueType()).columnType(metric.getColumnType()).build();
}
Also used : Argument(com.yahoo.elide.core.request.Argument) BadRequestException(com.yahoo.elide.core.exceptions.BadRequestException)

Example 38 with Argument

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

the class RSQLFilterDialectTest method testFilterArgumentParsingEncodeValues.

@Test
public void testFilterArgumentParsingEncodeValues() throws Exception {
    FilterExpression expr;
    Type<Book> bookType = ClassType.of(Book.class);
    String argValue1 = "with space";
    String argValue2 = ": \" ' ( ) ; , = ! ~ < > ] [";
    Set<Argument> inputArgs = new HashSet<>();
    inputArgs.add(Argument.builder().name("arg1").value(argValue1).build());
    inputArgs.add(Argument.builder().name("arg2").value(argValue2).build());
    String encodeArgValue1 = URLEncoder.encode(argValue1, "UTF-8");
    String encodeArgValue2 = URLEncoder.encode(argValue2, "UTF-8");
    expr = assertDoesNotThrow(() -> dialect.parse(bookType, Collections.emptySet(), "genre=in=(sci-fi,action),title[arg1:" + encodeArgValue1 + "][arg2:" + encodeArgValue2 + "]==Hemingway", NO_VERSION));
    assertEquals("(book.genre IN [sci-fi, action] OR book.title IN [Hemingway])", expr.toString());
    FilterPredicate left = (FilterPredicate) ((OrFilterExpression) expr).getLeft();
    Set<Argument> leftArgs = left.getPath().getPathElements().get(0).getArguments();
    assertTrue(leftArgs.isEmpty());
    FilterPredicate right = (FilterPredicate) ((OrFilterExpression) expr).getRight();
    Set<Argument> rightArgs = right.getPath().getPathElements().get(0).getArguments();
    assertTrue(rightArgs.equals(inputArgs));
}
Also used : Argument(com.yahoo.elide.core.request.Argument) Book(example.Book) FilterPredicate(com.yahoo.elide.core.filter.predicates.FilterPredicate) OrFilterExpression(com.yahoo.elide.core.filter.expression.OrFilterExpression) FilterExpression(com.yahoo.elide.core.filter.expression.FilterExpression) HashSet(java.util.HashSet) Test(org.junit.jupiter.api.Test)

Example 39 with Argument

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

the class JoinJoinTable method testArgumentsInJoinExprCase2a.

// dim4 and dim5 passes different value for join expression's argument 'exprArg'
// 2 Join expressions are generated.
@Test
void testArgumentsInJoinExprCase2a() {
    Map<String, Argument> dim4Arg = new HashMap<>();
    dim4Arg.put("exprArg", Argument.builder().name("exprArg").value("value4").build());
    SQLDimensionProjection dim4 = (SQLDimensionProjection) table.getDimensionProjection("dim4", "dim4", dim4Arg);
    Map<String, Argument> dim5Arg = new HashMap<>();
    dim5Arg.put("exprArg", Argument.builder().name("exprArg").value("value5").build());
    SQLDimensionProjection dim5 = (SQLDimensionProjection) table.getDimensionProjection("dim5", "dim5", dim5Arg);
    Query query = Query.builder().source(table).dimensionProjection(dim4).dimensionProjection(dim5).arguments(emptyMap()).build();
    String generatedSql = engine.explain(query).get(0);
    String expectedSQL = "SELECT " + NL + "  DISTINCT `MainTable_join2_63993339`.`dim1` AS `dim4`," + NL + "           `MainTable_join2_86115708`.`dim1` AS `dim5` " + NL + "FROM " + NL + "  `main_table` AS `MainTable` " + NL + "LEFT OUTER JOIN " + NL + "  `join_table` AS `MainTable_join2_63993339` " + NL + "ON " + NL + "  value = 'value4' AND `MainTable`.`dim6` - 'bar' = `MainTable_join2_63993339`.`dim4` - 'foo' " + "LEFT OUTER JOIN " + NL + "  `join_table` AS `MainTable_join2_86115708` " + NL + "ON " + NL + "  value = 'value5' AND `MainTable`.`dim6` - 'bar' = `MainTable_join2_86115708`.`dim4` - 'foo' ";
    assertEquals(formatExpected(expectedSQL), formatGenerated(generatedSql));
}
Also used : Argument(com.yahoo.elide.core.request.Argument) Query(com.yahoo.elide.datastores.aggregation.query.Query) HashMap(java.util.HashMap) SQLDimensionProjection(com.yahoo.elide.datastores.aggregation.queryengines.sql.query.SQLDimensionProjection) ToString(lombok.ToString) Test(org.junit.jupiter.api.Test)

Example 40 with Argument

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

the class JoinJoinTable method testArgumentsInJoinExprCase5b.

// dim4a and dim5a passes different value for join expression's argument 'exprArg'
// dim4a and dim5a passes different value for join table's column argument 'joinArg'
// 2 Join expressions are generated as 'exprArg' is different but fixed value of 'joinArg' is used.
@Test
void testArgumentsInJoinExprCase5b() {
    Map<String, Argument> dim4Arg = new HashMap<>();
    dim4Arg.put("exprArg", Argument.builder().name("exprArg").value("value4").build());
    dim4Arg.put("joinArg", Argument.builder().name("joinArg").value("foo4").build());
    SQLDimensionProjection dim4a = (SQLDimensionProjection) table.getDimensionProjection("dim4a", "dim4a", dim4Arg);
    Map<String, Argument> dim5Arg = new HashMap<>();
    dim5Arg.put("exprArg", Argument.builder().name("exprArg").value("value5").build());
    dim5Arg.put("joinArg", Argument.builder().name("joinArg").value("foo5").build());
    SQLDimensionProjection dim5a = (SQLDimensionProjection) table.getDimensionProjection("dim5a", "dim5a", dim5Arg);
    Query query = Query.builder().source(table).dimensionProjection(dim4a).dimensionProjection(dim5a).arguments(emptyMap()).build();
    String generatedSql = engine.explain(query).get(0);
    String expectedSQL = "SELECT " + NL + "  DISTINCT `MainTable_join2a_16142728`.`dim1` AS `dim4a`," + NL + "           `MainTable_join2a_29675529`.`dim1` AS `dim5a` " + NL + "FROM " + NL + "  `main_table` AS `MainTable` " + NL + "LEFT OUTER JOIN " + NL + "  `join_table` AS `MainTable_join2a_16142728` " + NL + "ON " + NL + "  value = 'value4' AND `MainTable`.`dim6` - 'bar' = `MainTable_join2a_16142728`.`dim4` - 'fixedFoo' " + NL + "LEFT OUTER JOIN " + NL + "  `join_table` AS `MainTable_join2a_29675529` " + NL + "ON " + NL + "  value = 'value5' AND `MainTable`.`dim6` - 'bar' = `MainTable_join2a_29675529`.`dim4` - 'fixedFoo' ";
    assertEquals(formatExpected(expectedSQL), formatGenerated(generatedSql));
}
Also used : Argument(com.yahoo.elide.core.request.Argument) Query(com.yahoo.elide.datastores.aggregation.query.Query) HashMap(java.util.HashMap) SQLDimensionProjection(com.yahoo.elide.datastores.aggregation.queryengines.sql.query.SQLDimensionProjection) ToString(lombok.ToString) Test(org.junit.jupiter.api.Test)

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