Search in sources :

Example 61 with Argument

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

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

the class MatchesTemplateVisitorTest method complexExpressionTest.

@Test
public void complexExpressionTest() throws Exception {
    String complexExpression = "(lowScore>100;((player.name==Bob*,lowScore>100);(highScore==123)))";
    FilterExpression clientExpression = dialect.parseFilterExpression(complexExpression, playerStatsType, true);
    FilterExpression templateExpression = dialect.parseFilterExpression("highScore=={{variable}}", playerStatsType, false, true);
    Map<String, Argument> extractedArgs = new HashMap<>();
    Argument expected = Argument.builder().name("variable").value(123L).build();
    assertTrue(MatchesTemplateVisitor.isValid(templateExpression, clientExpression, extractedArgs));
    assertEquals(1, extractedArgs.size());
    assertEquals(extractedArgs.get("variable"), expected);
}
Also used : Argument(com.yahoo.elide.core.request.Argument) HashMap(java.util.HashMap) FilterExpression(com.yahoo.elide.core.filter.expression.FilterExpression) Test(org.junit.jupiter.api.Test)

Example 63 with Argument

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

the class MatchesTemplateVisitorTest method predicateMismatchWithoutTemplateTest.

@Test
public void predicateMismatchWithoutTemplateTest() throws Exception {
    FilterExpression clientExpression = dialect.parseFilterExpression("highScore==123", playerStatsType, true);
    FilterExpression templateExpression = dialect.parseFilterExpression("highScore==456", playerStatsType, false, true);
    Map<String, Argument> extractedArgs = new HashMap<>();
    assertFalse(MatchesTemplateVisitor.isValid(templateExpression, clientExpression, extractedArgs));
    assertEquals(0, extractedArgs.size());
}
Also used : Argument(com.yahoo.elide.core.request.Argument) HashMap(java.util.HashMap) FilterExpression(com.yahoo.elide.core.filter.expression.FilterExpression) Test(org.junit.jupiter.api.Test)

Example 64 with Argument

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

the class MatchesTemplateVisitorTest method disjunctionMatchesTest.

@Test
public void disjunctionMatchesTest() throws Exception {
    FilterExpression clientExpression = dialect.parseFilterExpression("lowScore>100,highScore==123", playerStatsType, true);
    FilterExpression templateExpression = dialect.parseFilterExpression("lowScore>100,highScore=={{variable}}", playerStatsType, false, true);
    Map<String, Argument> extractedArgs = new HashMap<>();
    Argument expected = Argument.builder().name("variable").value(123L).build();
    assertTrue(MatchesTemplateVisitor.isValid(templateExpression, clientExpression, extractedArgs));
    assertEquals(1, extractedArgs.size());
    assertEquals(extractedArgs.get("variable"), expected);
}
Also used : Argument(com.yahoo.elide.core.request.Argument) HashMap(java.util.HashMap) FilterExpression(com.yahoo.elide.core.filter.expression.FilterExpression) Test(org.junit.jupiter.api.Test)

Example 65 with Argument

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

the class MatchesTemplateVisitorTest method parameterizedFilterMatches.

@Test
public void parameterizedFilterMatches() throws Exception {
    FilterExpression clientExpression = dialect.parseFilterExpression("recordedDate[grain:day]=='2020-01-01'", playerStatsType, true);
    FilterExpression templateExpression = dialect.parseFilterExpression("recordedDate[grain:day]=={{day}}", playerStatsType, false, true);
    Map<String, Argument> extractedArgs = new HashMap<>();
    assertTrue(MatchesTemplateVisitor.isValid(templateExpression, clientExpression, extractedArgs));
    assertEquals(1, extractedArgs.size());
}
Also used : Argument(com.yahoo.elide.core.request.Argument) HashMap(java.util.HashMap) FilterExpression(com.yahoo.elide.core.filter.expression.FilterExpression) 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