use of io.crate.expression.symbol.Function in project crate by crate.
the class SelectStatementAnalyzerTest method testSelectWithObjectLiteral.
@Test
public void testSelectWithObjectLiteral() throws Exception {
var executor = SQLExecutor.builder(clusterService).build();
QueriedSelectRelation relation = executor.analyze("select id from sys.nodes where load={\"1\"=1.0}");
Function whereClause = (Function) relation.where();
assertThat(whereClause.arguments(), hasItem(isLiteral(Map.of("1", 1.0))));
}
use of io.crate.expression.symbol.Function in project crate by crate.
the class SelectStatementAnalyzerTest method testRewriteNotEquals.
@Test
public void testRewriteNotEquals() {
var executor = SQLExecutor.builder(clusterService).build();
// should rewrite to:
// not(eq(sys.noes.name, 'something'))
List<String> statements = List.of("select * from sys.nodes where sys.nodes.name <> 'something'", "select * from sys.nodes where sys.nodes.name != 'something'");
for (String statement : statements) {
QueriedSelectRelation relation = executor.analyze(statement);
Function notFunction = (Function) relation.where();
assertThat(notFunction.name(), is(NotPredicate.NAME));
assertThat(notFunction.arguments().size(), is(1));
Function eqFunction = (Function) notFunction.arguments().get(0);
assertThat(eqFunction.name(), is(EqOperator.NAME));
assertThat(eqFunction.arguments().size(), is(2));
List<Symbol> eqArguments = eqFunction.arguments();
assertThat(eqArguments.get(1), isLiteral("something"));
}
}
use of io.crate.expression.symbol.Function in project crate by crate.
the class EvaluatingNormalizerTest method testEvaluationClusterGranularity.
@Test
public void testEvaluationClusterGranularity() {
EvaluatingNormalizer visitor = new EvaluatingNormalizer(nodeCtx, RowGranularity.CLUSTER, referenceResolver, null);
Function op_or = prepareFunctionTree();
Symbol query = visitor.normalize(op_or, coordinatorTxnCtx);
assertThat(query, instanceOf(Function.class));
}
use of io.crate.expression.symbol.Function in project crate by crate.
the class EvaluatingNormalizerTest method testEvaluation.
@Test
public void testEvaluation() {
EvaluatingNormalizer visitor = new EvaluatingNormalizer(nodeCtx, RowGranularity.NODE, 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, coordinatorTxnCtx);
assertThat(query, isLiteral(true));
}
use of io.crate.expression.symbol.Function in project crate by crate.
the class GroupByAnalyzerTest method testGroupByHavingComplex.
@Test
public void testGroupByHavingComplex() throws Exception {
QueriedSelectRelation relation = analyze("select sum(floats), name from users " + "group by name having 1=0 or sum(bytes) in (42, 43, 44) and name not like 'Slartibart%'");
Function andFunction = (Function) relation.having();
assertThat(andFunction, is(notNullValue()));
assertThat(andFunction.signature().getName().name(), is("op_and"));
assertThat(andFunction.arguments().size(), is(2));
assertThat(andFunction.arguments().get(0), isFunction("any_="));
assertThat(andFunction.arguments().get(1), isFunction("op_not"));
}
Aggregations