use of io.crate.analyze.symbol.Function in project crate by crate.
the class InsertFromValuesAnalyzerTest method testInsertFromValuesWithOnDuplicateKey.
@Test
public void testInsertFromValuesWithOnDuplicateKey() throws Exception {
InsertFromValuesAnalyzedStatement statement = e.analyze("insert into users (id, name, other_id) values (1, 'Arthur', 10) " + "on duplicate key update name = substr(values (name), 1, 2), " + "other_id = other_id + 100");
assertThat(statement.onDuplicateKeyAssignments().size(), is(1));
Symbol[] assignments = statement.onDuplicateKeyAssignments().get(0);
assertThat(assignments.length, is(2));
assertThat(assignments[0], isLiteral("Ar"));
assertThat(assignments[1], isFunction(AddFunction.NAME));
Function function = (Function) assignments[1];
assertThat(function.arguments().get(0), isReference("other_id"));
}
use of io.crate.analyze.symbol.Function 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.analyze.symbol.Function 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.analyze.symbol.Function 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.analyze.symbol.Function 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));
}
Aggregations