EvaluatorFactory { Evaluator<?> newInstance(PredicateLeaf predicateLeaf) { TypeInfo typeInfo = structTypeInfo.getStructFieldTypeInfo(predicateLeaf.getColumnName()); if (typeInfo.getCategory() != Category.PRIMITIVE) { throw new IllegalArgumentException("Unsupported column type: " + typeInfo.getCategory()); } PrimitiveCategory category = ((PrimitiveTypeInfo) typeInfo).getPrimitiveCategory(); if (category == PrimitiveCategory.BINARY) { throw new IllegalArgumentException("Unsupported column type: " + category); } switch (predicateLeaf.getOperator()) { case EQUALS: case NULL_SAFE_EQUALS: return equalsEvaluator(predicateLeaf, category); case LESS_THAN: case LESS_THAN_EQUALS: return lessThanEvaluator(predicateLeaf, category); case IN: return inEvaluator(predicateLeaf, category); case BETWEEN: return betweenEvaluator(predicateLeaf, category); case IS_NULL: return isNullEvaluator(predicateLeaf); default: throw new IllegalArgumentException("Unsupported operator: " + predicateLeaf.getOperator()); } } EvaluatorFactory(StructTypeInfo structTypeInfo);   }
@Test(expected = IllegalArgumentException.class) public void notPrimitiveThrowsException() { when(predicateLeaf.getColumnName()).thenReturn(COL0); StructTypeInfo structTypeInfo = new StructTypeInfoBuilder().add(COL0, TypeInfoFactory.getListTypeInfo(TypeInfoFactory.stringTypeInfo)).build(); EvaluatorFactory factory = new EvaluatorFactory(structTypeInfo); factory.newInstance(predicateLeaf); }
@Test(expected = IllegalArgumentException.class) public void binaryThrowsException() { when(predicateLeaf.getColumnName()).thenReturn(COL0); StructTypeInfo structTypeInfo = new StructTypeInfoBuilder().add(COL0, TypeInfoFactory.binaryTypeInfo).build(); EvaluatorFactory factory = new EvaluatorFactory(structTypeInfo); factory.newInstance(predicateLeaf); }
@Test public void stringEquals() { when(predicateLeaf.getColumnName()).thenReturn(COL0); when(predicateLeaf.getOperator()).thenReturn(Operator.EQUALS); when(predicateLeaf.getLiteral()).thenReturn("foo"); StructTypeInfo structTypeInfo = new StructTypeInfoBuilder().add(COL0, TypeInfoFactory.stringTypeInfo).build(); EvaluatorFactory factory = new EvaluatorFactory(structTypeInfo); Evaluator<?> evaluator = factory.newInstance(predicateLeaf); assertThat(evaluator, instanceOf(EqualsEvaluator.class)); }
@Test public void stringNullSafeEquals() { when(predicateLeaf.getColumnName()).thenReturn(COL0); when(predicateLeaf.getOperator()).thenReturn(Operator.NULL_SAFE_EQUALS); when(predicateLeaf.getLiteral()).thenReturn("foo"); StructTypeInfo structTypeInfo = new StructTypeInfoBuilder().add(COL0, TypeInfoFactory.stringTypeInfo).build(); EvaluatorFactory factory = new EvaluatorFactory(structTypeInfo); Evaluator<?> evaluator = factory.newInstance(predicateLeaf); assertThat(evaluator, instanceOf(EqualsEvaluator.class)); }
@Test public void stringLessThan() { when(predicateLeaf.getColumnName()).thenReturn(COL0); when(predicateLeaf.getOperator()).thenReturn(Operator.LESS_THAN); when(predicateLeaf.getLiteral()).thenReturn("foo"); StructTypeInfo structTypeInfo = new StructTypeInfoBuilder().add(COL0, TypeInfoFactory.stringTypeInfo).build(); EvaluatorFactory factory = new EvaluatorFactory(structTypeInfo); Evaluator<?> evaluator = factory.newInstance(predicateLeaf); assertThat(evaluator, instanceOf(LessThanEvaluator.class)); }
@Test public void stringLessThanEquals() { when(predicateLeaf.getColumnName()).thenReturn(COL0); when(predicateLeaf.getOperator()).thenReturn(Operator.LESS_THAN_EQUALS); when(predicateLeaf.getLiteral()).thenReturn("foo"); StructTypeInfo structTypeInfo = new StructTypeInfoBuilder().add(COL0, TypeInfoFactory.stringTypeInfo).build(); EvaluatorFactory factory = new EvaluatorFactory(structTypeInfo); Evaluator<?> evaluator = factory.newInstance(predicateLeaf); assertThat(evaluator, instanceOf(LessThanEvaluator.class)); }
@Test public void stringIn() { when(predicateLeaf.getColumnName()).thenReturn(COL0); when(predicateLeaf.getOperator()).thenReturn(Operator.IN); when(predicateLeaf.getLiteralList()).thenReturn(Arrays.asList((Object) "foo")); StructTypeInfo structTypeInfo = new StructTypeInfoBuilder().add(COL0, TypeInfoFactory.stringTypeInfo).build(); EvaluatorFactory factory = new EvaluatorFactory(structTypeInfo); Evaluator<?> evaluator = factory.newInstance(predicateLeaf); assertThat(evaluator, instanceOf(InEvaluator.class)); }
@Test public void stringBetween() { when(predicateLeaf.getColumnName()).thenReturn(COL0); when(predicateLeaf.getOperator()).thenReturn(Operator.BETWEEN); when(predicateLeaf.getLiteralList()).thenReturn(Arrays.asList((Object) "foo", "bar")); StructTypeInfo structTypeInfo = new StructTypeInfoBuilder().add(COL0, TypeInfoFactory.stringTypeInfo).build(); EvaluatorFactory factory = new EvaluatorFactory(structTypeInfo); Evaluator<?> evaluator = factory.newInstance(predicateLeaf); assertThat(evaluator, instanceOf(BetweenEvaluator.class)); }
@Test public void stringIsNull() { when(predicateLeaf.getColumnName()).thenReturn(COL0); when(predicateLeaf.getOperator()).thenReturn(Operator.IS_NULL); StructTypeInfo structTypeInfo = new StructTypeInfoBuilder().add(COL0, TypeInfoFactory.stringTypeInfo).build(); EvaluatorFactory factory = new EvaluatorFactory(structTypeInfo); Evaluator<?> evaluator = factory.newInstance(predicateLeaf); assertThat(evaluator, instanceOf(IsNullEvaluator.class)); }