Search in sources :

Example 1 with BooleanOperator

use of org.apache.drill.common.expression.BooleanOperator in project drill by apache.

the class DruidFilterBuilderTest method visitBooleanOperatorWithAndOperator.

@Test
public void visitBooleanOperatorWithAndOperator() {
    LogicalExpression logicalExpression2 = mock(LogicalExpression.class);
    try {
        when(logicalExpression.accept(any(), any())).thenReturn(druidScanSpecLeft);
        when(logicalExpression2.accept(any(), any())).thenReturn(druidScanSpecRight);
    } catch (Exception ignored) {
    }
    BooleanOperator booleanOperator = new BooleanOperator(FunctionNames.AND, Stream.of(logicalExpression, logicalExpression2).collect(Collectors.toList()), null);
    DruidScanSpec druidScanSpec = druidFilterBuilder.visitBooleanOperator(booleanOperator, null);
    String expectedFilterJson = "{\"type\":\"and\",\"fields\":[{\"type\":\"selector\",\"dimension\":\"some dimension\",\"value\":\"some value\"},{\"type\":\"selector\",\"dimension\":\"some other dimension\",\"value\":\"some other value\"}]}";
    String actual = druidScanSpec.getFilter().toJson();
    assertThat(actual).isEqualTo(expectedFilterJson);
}
Also used : LogicalExpression(org.apache.drill.common.expression.LogicalExpression) BooleanOperator(org.apache.drill.common.expression.BooleanOperator) Test(org.junit.Test)

Example 2 with BooleanOperator

use of org.apache.drill.common.expression.BooleanOperator in project drill by apache.

the class DruidFilterBuilderTest method visitBooleanOperatorWithOrOperator.

@Test
public void visitBooleanOperatorWithOrOperator() {
    LogicalExpression logicalExpression2 = mock(LogicalExpression.class);
    try {
        when(logicalExpression.accept(any(), any())).thenReturn(druidScanSpecLeft);
        when(logicalExpression2.accept(any(), any())).thenReturn(druidScanSpecRight);
    } catch (Exception ignored) {
    }
    BooleanOperator booleanOperator = new BooleanOperator(FunctionNames.OR, Stream.of(logicalExpression, logicalExpression2).collect(Collectors.toList()), null);
    DruidScanSpec druidScanSpec = druidFilterBuilder.visitBooleanOperator(booleanOperator, null);
    String expectedFilterJson = "{\"type\":\"or\",\"fields\":[{\"type\":\"selector\",\"dimension\":\"some dimension\",\"value\":\"some value\"},{\"type\":\"selector\",\"dimension\":\"some other dimension\",\"value\":\"some other value\"}]}";
    String actual = druidScanSpec.getFilter().toJson();
    assertThat(actual).isEqualTo(expectedFilterJson);
}
Also used : LogicalExpression(org.apache.drill.common.expression.LogicalExpression) BooleanOperator(org.apache.drill.common.expression.BooleanOperator) Test(org.junit.Test)

Aggregations

BooleanOperator (org.apache.drill.common.expression.BooleanOperator)2 LogicalExpression (org.apache.drill.common.expression.LogicalExpression)2 Test (org.junit.Test)2