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));
}
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));
}
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));
}
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));
}
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());
}
Aggregations