Search in sources :

Example 86 with FilterExpression

use of com.yahoo.elide.core.filter.expression.FilterExpression in project elide by yahoo.

the class MatchesTemplateVisitorTest method conjunctionMatchesTest.

@Test
public void conjunctionMatchesTest() 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 87 with FilterExpression

use of com.yahoo.elide.core.filter.expression.FilterExpression in project elide by yahoo.

the class MatchesTemplateVisitorTest method mulipleConjunctionOrderTest.

@Test
public void mulipleConjunctionOrderTest() throws Exception {
    FilterExpression clientExpression = dialect.parseFilterExpression("lowScore>100;(highScore>=100;highScore<999)", playerStatsType, true);
    FilterExpression templateExpression = dialect.parseFilterExpression("highScore>={{low}};highScore<{{high}}", playerStatsType, false, true);
    Argument expected1 = Argument.builder().name("low").value(100L).build();
    Argument expected2 = Argument.builder().name("high").value(999L).build();
    Map<String, Argument> extractedArgs = new HashMap<>();
    assertTrue(MatchesTemplateVisitor.isValid(templateExpression, clientExpression, extractedArgs));
    assertEquals(2, extractedArgs.size());
    assertEquals(extractedArgs.get("low"), expected1);
    assertEquals(extractedArgs.get("high"), expected2);
}
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 88 with FilterExpression

use of com.yahoo.elide.core.filter.expression.FilterExpression in project elide by yahoo.

the class MatchesTemplateVisitorTest method parameterizedFilterArgumentsDoNotMatch.

@Test
public void parameterizedFilterArgumentsDoNotMatch() throws Exception {
    FilterExpression clientExpression = dialect.parseFilterExpression("recordedDate[grain:day]=='2020-01-01'", playerStatsType, true);
    FilterExpression templateExpression = dialect.parseFilterExpression("recordedDate[grain:month]=={{day}}", 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 89 with FilterExpression

use of com.yahoo.elide.core.filter.expression.FilterExpression in project elide by yahoo.

the class MatchesTemplateVisitorTest method predicateWithAliasMatchesTest.

@Test
public void predicateWithAliasMatchesTest() throws Exception {
    FilterExpression clientExpression = dialect.parseFilterExpression("highScore==123", playerStatsType, true);
    Attribute attribute = Attribute.builder().type(ClassType.of(Long.class)).name("highScore").alias("myScore").build();
    FilterExpression templateExpression = dialect.parseFilterExpression("myScore=={{foo}}", playerStatsType, false, true, Set.of(attribute));
    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);
}
Also used : Argument(com.yahoo.elide.core.request.Argument) Attribute(com.yahoo.elide.core.request.Attribute) HashMap(java.util.HashMap) FilterExpression(com.yahoo.elide.core.filter.expression.FilterExpression) Test(org.junit.jupiter.api.Test)

Example 90 with FilterExpression

use of com.yahoo.elide.core.filter.expression.FilterExpression 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());
}
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

FilterExpression (com.yahoo.elide.core.filter.expression.FilterExpression)214 Test (org.junit.jupiter.api.Test)161 OrFilterExpression (com.yahoo.elide.core.filter.expression.OrFilterExpression)91 AndFilterExpression (com.yahoo.elide.core.filter.expression.AndFilterExpression)72 MultivaluedHashMap (javax.ws.rs.core.MultivaluedHashMap)49 FilterPredicate (com.yahoo.elide.core.filter.predicates.FilterPredicate)46 Path (com.yahoo.elide.core.Path)44 Query (com.yahoo.elide.datastores.aggregation.query.Query)42 Argument (com.yahoo.elide.core.request.Argument)39 SQLUnitTest (com.yahoo.elide.datastores.aggregation.framework.SQLUnitTest)39 DataStoreTransaction (com.yahoo.elide.core.datastore.DataStoreTransaction)34 SQLTable (com.yahoo.elide.datastores.aggregation.queryengines.sql.metadata.SQLTable)34 HashMap (java.util.HashMap)29 Book (example.Book)28 NotFilterExpression (com.yahoo.elide.core.filter.expression.NotFilterExpression)24 EntityProjection (com.yahoo.elide.core.request.EntityProjection)22 Date (java.util.Date)21 EntityDictionary (com.yahoo.elide.core.dictionary.EntityDictionary)20 Day (com.yahoo.elide.datastores.aggregation.timegrains.Day)19 HashSet (java.util.HashSet)18