Search in sources :

Example 1 with TransactionContext

use of io.crate.metadata.TransactionContext in project crate by crate.

the class RegexpMatchOperatortest method normalizeSymbol.

private static Symbol normalizeSymbol(String source, String pattern) {
    RegexpMatchOperator op = new RegexpMatchOperator();
    Function function = new Function(op.info(), Arrays.<Symbol>asList(Literal.of(source), Literal.of(pattern)));
    return op.normalizeSymbol(function, new TransactionContext(SessionContext.SYSTEM_SESSION));
}
Also used : Function(io.crate.analyze.symbol.Function) TransactionContext(io.crate.metadata.TransactionContext)

Example 2 with TransactionContext

use of io.crate.metadata.TransactionContext 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 3 with TransactionContext

use of io.crate.metadata.TransactionContext 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)

Example 4 with TransactionContext

use of io.crate.metadata.TransactionContext in project crate by crate.

the class AnyNotLikeOperatorTest method normalizeSymbol.

private static Symbol normalizeSymbol(String pattern, String... expressions) {
    Literal patternLiteral = Literal.of(pattern);
    Object[] value = new Object[expressions.length];
    for (int i = 0; i < expressions.length; i++) {
        value[i] = expressions[i] == null ? null : new BytesRef(expressions[i]);
    }
    Literal valuesLiteral = Literal.of(new ArrayType(DataTypes.STRING), value);
    AnyNotLikeOperator impl = (AnyNotLikeOperator) new AnyNotLikeOperator.AnyNotLikeResolver().getForTypes(Arrays.asList(patternLiteral.valueType(), valuesLiteral.valueType()));
    Function function = new Function(impl.info(), Arrays.<Symbol>asList(patternLiteral, valuesLiteral));
    return impl.normalizeSymbol(function, new TransactionContext(SessionContext.SYSTEM_SESSION));
}
Also used : ArrayType(io.crate.types.ArrayType) Function(io.crate.analyze.symbol.Function) TransactionContext(io.crate.metadata.TransactionContext) Literal(io.crate.analyze.symbol.Literal) BytesRef(org.apache.lucene.util.BytesRef)

Example 5 with TransactionContext

use of io.crate.metadata.TransactionContext in project crate by crate.

the class RoutedCollectPhaseTest method testNormalizeDoesNotRemoveOrderBy.

@Test
public void testNormalizeDoesNotRemoveOrderBy() throws Exception {
    Symbol toInt10 = CastFunctionResolver.generateCastFunction(Literal.of(10L), DataTypes.INTEGER, false);
    RoutedCollectPhase collect = new RoutedCollectPhase(UUID.randomUUID(), 1, "collect", new Routing(Collections.emptyMap()), RowGranularity.DOC, Collections.singletonList(toInt10), Collections.emptyList(), WhereClause.MATCH_ALL, DistributionInfo.DEFAULT_SAME_NODE);
    collect.orderBy(new OrderBy(Collections.singletonList(toInt10), new boolean[] { false }, new Boolean[] { null }));
    EvaluatingNormalizer normalizer = EvaluatingNormalizer.functionOnlyNormalizer(getFunctions(), ReplaceMode.COPY);
    RoutedCollectPhase normalizedCollect = collect.normalize(normalizer, new TransactionContext(SessionContext.SYSTEM_SESSION));
    assertThat(normalizedCollect.orderBy(), notNullValue());
}
Also used : OrderBy(io.crate.analyze.OrderBy) EvaluatingNormalizer(io.crate.analyze.EvaluatingNormalizer) Symbol(io.crate.analyze.symbol.Symbol) TransactionContext(io.crate.metadata.TransactionContext) Routing(io.crate.metadata.Routing) RoutedCollectPhase(io.crate.planner.node.dql.RoutedCollectPhase) Test(org.junit.Test) CrateUnitTest(io.crate.test.integration.CrateUnitTest)

Aggregations

TransactionContext (io.crate.metadata.TransactionContext)10 Function (io.crate.analyze.symbol.Function)8 Literal (io.crate.analyze.symbol.Literal)4 ArrayType (io.crate.types.ArrayType)4 BytesRef (org.apache.lucene.util.BytesRef)4 Test (org.junit.Test)4 CrateUnitTest (io.crate.test.integration.CrateUnitTest)3 Symbol (io.crate.analyze.symbol.Symbol)2 Input (io.crate.data.Input)2 FunctionImplementation (io.crate.metadata.FunctionImplementation)2 NotPredicate (io.crate.operation.predicate.NotPredicate)2 EvaluatingNormalizer (io.crate.analyze.EvaluatingNormalizer)1 OrderBy (io.crate.analyze.OrderBy)1 ExpressionAnalysisContext (io.crate.analyze.expressions.ExpressionAnalysisContext)1 ExpressionAnalyzer (io.crate.analyze.expressions.ExpressionAnalyzer)1 WhereClauseAnalyzer (io.crate.analyze.where.WhereClauseAnalyzer)1 FunctionIdent (io.crate.metadata.FunctionIdent)1 Routing (io.crate.metadata.Routing)1 AbstractScalarFunctionsTest (io.crate.operation.scalar.AbstractScalarFunctionsTest)1 RoutedCollectPhase (io.crate.planner.node.dql.RoutedCollectPhase)1