use of io.crate.analyze.symbol.Function in project crate by crate.
the class CurrentSchemaFunctionTest method testEvaluateCurrentSchemaNotSupported.
public void testEvaluateCurrentSchemaNotSupported() throws Exception {
expectedException.expect(UnsupportedOperationException.class);
expectedException.expectMessage("Cannot evaluate CURRENT_SCHEMA function.");
Function function = (Function) sqlExpressions.asSymbol("current_schema()");
Scalar impl = (Scalar) functions.get(function.info().ident());
impl.evaluate();
}
use of io.crate.analyze.symbol.Function in project crate by crate.
the class EvaluatingNormalizerTest method testEvaluationClusterGranularity.
@Test
public void testEvaluationClusterGranularity() {
EvaluatingNormalizer visitor = new EvaluatingNormalizer(functions, RowGranularity.CLUSTER, ReplaceMode.COPY, referenceResolver, null);
Function op_or = prepareFunctionTree();
Symbol query = visitor.normalize(op_or, transactionContext);
assertThat(query, instanceOf(Function.class));
}
use of io.crate.analyze.symbol.Function in project crate by crate.
the class EvaluatingNormalizerTest method testEvaluation.
@Test
public void testEvaluation() {
EvaluatingNormalizer visitor = new EvaluatingNormalizer(functions, RowGranularity.NODE, ReplaceMode.MUTATE, referenceResolver, null);
Function op_or = prepareFunctionTree();
// the dummy reference load == 0.08 evaluates to true,
// so the whole query can be normalized to a single boolean literal
Symbol query = visitor.normalize(op_or, transactionContext);
assertThat(query, isLiteral(true));
}
use of io.crate.analyze.symbol.Function in project crate by crate.
the class InsertFromSubQueryAnalyzerTest method testFromQueryWithOnDuplicateKeyValues.
@Test
public void testFromQueryWithOnDuplicateKeyValues() throws Exception {
InsertFromSubQueryAnalyzedStatement statement = e.analyze("insert into users (id, name) (select id, name from users) " + "on duplicate key update name = substr(values (name), 1, 1)");
Assert.assertThat(statement.onDuplicateKeyAssignments().size(), is(1));
for (Map.Entry<Reference, Symbol> entry : statement.onDuplicateKeyAssignments().entrySet()) {
assertThat(entry.getKey(), isReference("name"));
assertThat(entry.getValue(), isFunction(SubstrFunction.NAME));
Function function = (Function) entry.getValue();
assertThat(function.arguments().get(0), instanceOf(InputColumn.class));
InputColumn inputColumn = (InputColumn) function.arguments().get(0);
assertThat(inputColumn.index(), is(1));
assertThat(inputColumn.valueType(), instanceOf(StringType.class));
}
}
use of io.crate.analyze.symbol.Function in project crate by crate.
the class UpdateAnalyzerTest method testTestUpdateOnTableWithAliasAndFQColumnNameInWhereClause.
@Test
public void testTestUpdateOnTableWithAliasAndFQColumnNameInWhereClause() throws Exception {
UpdateAnalyzedStatement statement = analyze("update users t set name = 'foo' where t.name != 'foo'");
Function eqFunction = (Function) ((Function) statement.nestedStatements().get(0).whereClause().query()).arguments().get(0);
assertThat(eqFunction.arguments().get(0), isReference("name"));
}
Aggregations