Search in sources :

Example 1 with NotPredicate

use of io.crate.operation.predicate.NotPredicate in project crate by crate.

the class AnyLikeOperatorTest method testNegateLike.

@Test
public void testNegateLike() throws Exception {
    Literal patternLiteral = Literal.of("A");
    Literal valuesLiteral = Literal.of(new ArrayType(DataTypes.STRING), new Object[] { new BytesRef("A"), new BytesRef("B") });
    FunctionImplementation impl = new AnyLikeOperator.AnyLikeResolver().getForTypes(Arrays.asList(DataTypes.STRING, valuesLiteral.valueType()));
    Function anyLikeFunction = new Function(impl.info(), Arrays.<Symbol>asList(patternLiteral, valuesLiteral));
    Input<Boolean> normalized = (Input<Boolean>) impl.normalizeSymbol(anyLikeFunction, new TransactionContext(SessionContext.SYSTEM_SESSION));
    assertThat(normalized.value(), is(true));
    assertThat(new NotPredicate().evaluate(normalized), is(false));
}
Also used : ArrayType(io.crate.types.ArrayType) Function(io.crate.analyze.symbol.Function) Input(io.crate.data.Input) TransactionContext(io.crate.metadata.TransactionContext) Literal(io.crate.analyze.symbol.Literal) FunctionImplementation(io.crate.metadata.FunctionImplementation) NotPredicate(io.crate.operation.predicate.NotPredicate) BytesRef(org.apache.lucene.util.BytesRef) Test(org.junit.Test) CrateUnitTest(io.crate.test.integration.CrateUnitTest)

Example 2 with NotPredicate

use of io.crate.operation.predicate.NotPredicate in project crate by crate.

the class AnyNotLikeOperatorTest method testNegateNotLike.

@Test
public void testNegateNotLike() throws Exception {
    Literal patternLiteral = Literal.of("A");
    Literal valuesLiteral = Literal.of(new ArrayType(DataTypes.STRING), new Object[] { new BytesRef("A"), new BytesRef("B") });
    FunctionImplementation impl = new AnyNotLikeOperator.AnyNotLikeResolver().getForTypes(Arrays.asList(DataTypes.STRING, valuesLiteral.valueType()));
    Function anyNotLikeFunction = new Function(impl.info(), Arrays.<Symbol>asList(patternLiteral, valuesLiteral));
    Input<Boolean> normalized = (Input<Boolean>) impl.normalizeSymbol(anyNotLikeFunction, new TransactionContext(SessionContext.SYSTEM_SESSION));
    assertThat(normalized.value(), is(true));
    assertThat(new NotPredicate().evaluate(normalized), is(false));
}
Also used : ArrayType(io.crate.types.ArrayType) Function(io.crate.analyze.symbol.Function) Input(io.crate.data.Input) TransactionContext(io.crate.metadata.TransactionContext) Literal(io.crate.analyze.symbol.Literal) FunctionImplementation(io.crate.metadata.FunctionImplementation) NotPredicate(io.crate.operation.predicate.NotPredicate) BytesRef(org.apache.lucene.util.BytesRef) Test(org.junit.Test) CrateUnitTest(io.crate.test.integration.CrateUnitTest)

Aggregations

Function (io.crate.analyze.symbol.Function)2 Literal (io.crate.analyze.symbol.Literal)2 Input (io.crate.data.Input)2 FunctionImplementation (io.crate.metadata.FunctionImplementation)2 TransactionContext (io.crate.metadata.TransactionContext)2 NotPredicate (io.crate.operation.predicate.NotPredicate)2 CrateUnitTest (io.crate.test.integration.CrateUnitTest)2 ArrayType (io.crate.types.ArrayType)2 BytesRef (org.apache.lucene.util.BytesRef)2 Test (org.junit.Test)2