Search in sources :

Example 91 with FilterExpression

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

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

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

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

the class DefaultQueryPlanMergerTest method testCannotMergeMismatchedNestedWhere.

@Test
public void testCannotMergeMismatchedNestedWhere() {
    Queryable source = mock(Queryable.class);
    // A root source.
    when(source.getSource()).thenReturn(source);
    MetricProjection m1 = mock(MetricProjection.class);
    MetricProjection m2 = mock(MetricProjection.class);
    when(m1.getName()).thenReturn("m1");
    when(m2.getName()).thenReturn("m2");
    when(m1.canNest(any(), any())).thenReturn(true);
    when(m1.nest(any(), any(), anyBoolean())).thenReturn(Pair.of(m1, Set.of(m1)));
    when(m2.canNest(any(), any())).thenReturn(true);
    when(m2.nest(any(), any(), anyBoolean())).thenReturn(Pair.of(m2, Set.of(m2)));
    FilterExpression filterA = mock(FilterExpression.class);
    FilterExpression filterB = mock(FilterExpression.class);
    QueryPlan a = QueryPlan.builder().source(source).whereFilter(filterA).metricProjection(m1).build();
    QueryPlan nested = QueryPlan.builder().source(source).whereFilter(filterB).metricProjection(m2).build();
    QueryPlan b = QueryPlan.builder().source(nested).metricProjection(m2).build();
    MetaDataStore metaDataStore = mock(MetaDataStore.class);
    DefaultQueryPlanMerger merger = new DefaultQueryPlanMerger(metaDataStore);
    assertFalse(merger.canMerge(a, b));
    assertFalse(merger.canMerge(b, a));
}
Also used : MetaDataStore(com.yahoo.elide.datastores.aggregation.metadata.MetaDataStore) FilterExpression(com.yahoo.elide.core.filter.expression.FilterExpression) Test(org.junit.jupiter.api.Test)

Example 95 with FilterExpression

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

the class JpaDataStoreTransactionTest method getTestArguments.

private Stream<Arguments> getTestArguments() throws Exception {
    RSQLFilterDialect parser = RSQLFilterDialect.builder().dictionary(dictionary).build();
    FilterExpression expression = parser.parse(ClassType.of(Book.class), Collections.emptySet(), "title=='foo'", NO_VERSION);
    return Stream.of(arguments(true, 1, null, true), arguments(true, 2, null, true), arguments(false, 1, null, true), arguments(false, 2, null, true), arguments(true, 1, expression, false), arguments(true, 2, expression, true), arguments(false, 1, expression, false), arguments(false, 2, expression, false));
}
Also used : Book(example.Book) FilterExpression(com.yahoo.elide.core.filter.expression.FilterExpression) RSQLFilterDialect(com.yahoo.elide.core.filter.dialect.RSQLFilterDialect)

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