use of com.yahoo.elide.core.request.Argument in project elide by yahoo.
the class MatchesTemplateVisitorTest method predicateMatchWithoutTemplateTest.
@Test
public void predicateMatchWithoutTemplateTest() throws Exception {
FilterExpression clientExpression = dialect.parseFilterExpression("highScore==123", playerStatsType, true);
FilterExpression templateExpression = dialect.parseFilterExpression("highScore==123", playerStatsType, false, true);
Map<String, Argument> extractedArgs = new HashMap<>();
assertTrue(MatchesTemplateVisitor.isValid(templateExpression, clientExpression, extractedArgs));
assertEquals(0, extractedArgs.size());
}
use of com.yahoo.elide.core.request.Argument in project elide by yahoo.
the class MatchesTemplateVisitorTest method conjunctionDoesNotContainTest.
@Test
public void conjunctionDoesNotContainTest() throws Exception {
FilterExpression clientExpression = dialect.parseFilterExpression("lowScore>100;player.name==Bob*", playerStatsType, true);
FilterExpression templateExpression = dialect.parseFilterExpression("highScore=={{variable}}", playerStatsType, false, true);
Map<String, Argument> extractedArgs = new HashMap<>();
assertFalse(MatchesTemplateVisitor.isValid(templateExpression, clientExpression, extractedArgs));
assertEquals(0, extractedArgs.size());
}
use of com.yahoo.elide.core.request.Argument in project elide by yahoo.
the class MatchesTemplateVisitorTest method predicateMatchTest.
@Test
public void predicateMatchTest() throws Exception {
FilterExpression clientExpression = dialect.parseFilterExpression("highScore==123", playerStatsType, true);
FilterExpression templateExpression = dialect.parseFilterExpression("highScore=={{foo}}", playerStatsType, false, true);
Map<String, Argument> extractedArgs = new HashMap<>();
Argument expected = Argument.builder().name("foo").value(123L).build();
assertTrue(MatchesTemplateVisitor.isValid(templateExpression, clientExpression, extractedArgs));
assertEquals(1, extractedArgs.size());
assertEquals(extractedArgs.get("foo"), expected);
}
use of com.yahoo.elide.core.request.Argument in project elide by yahoo.
the class MatchesTemplateVisitorTest method disjunctionContainsTest.
@Test
public void disjunctionContainsTest() throws Exception {
FilterExpression clientExpression = dialect.parseFilterExpression("lowScore>100,highScore==123", playerStatsType, true);
FilterExpression templateExpression = dialect.parseFilterExpression("highScore=={{variable}}", playerStatsType, false, true);
Map<String, Argument> extractedArgs = new HashMap<>();
assertFalse(MatchesTemplateVisitor.isValid(templateExpression, clientExpression, extractedArgs));
assertEquals(0, extractedArgs.size());
}
use of com.yahoo.elide.core.request.Argument in project elide by yahoo.
the class PhysicalRefColumnContextTest method testSqlHelper.
@Test
public void testSqlHelper() {
Map<String, Argument> revenueArg = new HashMap<>();
revenueArg.put("format", Argument.builder().name("format").value("11D00").build());
SQLMetricProjection revenueUsingSqlHelper = (SQLMetricProjection) revenueFactTable.getMetricProjection("revenueUsingSqlHelper", "revenueUsingSqlHelper", revenueArg);
SQLMetricProjection impressionsPerUSD = (SQLMetricProjection) revenueFactTable.getMetricProjection("impressionsPerUSD");
Map<String, Argument> impressionsPerUSDArg = new HashMap<>();
impressionsPerUSDArg.put("format", Argument.builder().name("format").value("11D00").build());
SQLMetricProjection impressionsPerUSDWithArg = (SQLMetricProjection) revenueFactTable.getMetricProjection("impressionsPerUSD", "impressionsPerUSDWithArg", impressionsPerUSDArg);
// impressionsPerUSD2 invokes 'revenueUsingSqlHelper' instead of 'revenue'.
SQLMetricProjection impressionsPerUSD2 = (SQLMetricProjection) revenueFactTable.getMetricProjection("impressionsPerUSD2");
Query query = Query.builder().source(revenueFactTable).metricProjection(revenueUsingSqlHelper).metricProjection(impressionsPerUSD).metricProjection(impressionsPerUSD2).arguments(queryArgs).build();
Query.QueryBuilder builder = Query.builder().source(query.getSource()).metricProjections(query.getMetricProjections()).arguments(query.getArguments());
Query expandedQuery = addHiddenProjections(metaDataStore, builder, query).build();
// definition: TO_CHAR(SUM({{$revenue}}) * {{sql from='rate' column='conversionRate[format:9999D0000]'}}, {{$$column.args.format}})
// -> value of 'format' argument is passed in the query for "revenueUsingSqlHelper" column and same is used for
// resolving this column.
// -> pinned value (9999D0000) of 'format' argument in SQL helper is used while resolving referenced column "rate.conversionRate".
assertEquals("TO_CHAR(SUM({{$revenue}}) * TO_CHAR({{rate.$conversion_rate}}, 9999D0000), 11D00)", revenueUsingSqlHelper.toPhysicalReferences(expandedQuery, metaDataStore));
// definition: TO_CHAR({{sql column='impressions[aggregation:SUM]'}} / {{sql column='revenue[format:99999D00000]'}}, {{$$table.args.format}})
// -> {{$$table.args.format}} is resolved using query argument 'format' (999999D000000).
// -> pinned value (SUM) of 'aggregation' argument in SQL helper is used while resolving invoked column "impressions".
// -> pinned value (99999D00000) of 'format' argument in SQL helper is used while resolving invoked column "revenue".
// -> revenue definition is : TO_CHAR(SUM({{$revenue}}) * {{rate.conversionRate}}, {{$$column.args.format}}),
// Available value of 'format' argument in "revenue" column is passed to joined table's "conversionRate" column.
assertEquals("TO_CHAR(SUM({{$impressions}}) / TO_CHAR(SUM({{$revenue}}) * TO_CHAR({{rate.$conversion_rate}}, 99999D00000), 99999D00000), 999999D000000)", impressionsPerUSD.toPhysicalReferences(expandedQuery, metaDataStore));
// -> Even 'format' is passed in query column args, pinned value (9999D0000) of 'format' argument in SQL helper is used while
// resolving "revenue" column and same is passed to joined table's "conversionRate" column.
assertEquals("TO_CHAR(SUM({{$impressions}}) / TO_CHAR(SUM({{$revenue}}) * TO_CHAR({{rate.$conversion_rate}}, 99999D00000), 99999D00000), 999999D000000)", impressionsPerUSDWithArg.toPhysicalReferences(expandedQuery, metaDataStore));
// definition: TO_CHAR({{sql column='impressions[aggregation:SUM]'}} / {{sql column='revenueUsingSqlHelper[format:99999D00000]'}}, {{$$table.args.format}})
// -> As "rate.conversionRate" is invoked using SQL helper from "revenue" column, this uses the fixed value(9999D0000) of
// 'format' argument provided in definition of "revenueUsingSqlHelper" column.
assertEquals("TO_CHAR(SUM({{$impressions}}) / TO_CHAR(SUM({{$revenue}}) * TO_CHAR({{rate.$conversion_rate}}, 9999D0000), 99999D00000), 999999D000000)", impressionsPerUSD2.toPhysicalReferences(expandedQuery, metaDataStore));
}
Aggregations