use of io.crate.expression.symbol.Function in project crate by crate.
the class GroupByAnalyzerTest method testGroupByHaving.
@Test
public void testGroupByHaving() throws Exception {
QueriedSelectRelation relation = analyze("select sum(floats) from users group by name having name like 'Slartibart%'");
assertThat(relation.having(), isFunction(LikeOperators.OP_LIKE));
Function havingFunction = (Function) relation.having();
assertThat(havingFunction.arguments().size(), is(2));
assertThat(havingFunction.arguments().get(0), isReference("name"));
assertThat(havingFunction.arguments().get(1), isLiteral("Slartibart%"));
}
use of io.crate.expression.symbol.Function in project crate by crate.
the class SelectStatementAnalyzerTest method testAnyOnObjectArrayField.
@Test
public void testAnyOnObjectArrayField() throws Exception {
var executor = SQLExecutor.builder(clusterService).addTable(TableDefinitions.USER_TABLE_DEFINITION).build();
QueriedSelectRelation relation = executor.analyze("select * from users where 5 = ANY (friends['id'])");
Function anyFunction = (Function) relation.where();
assertThat(anyFunction.name(), is(AnyEqOperator.NAME));
assertThat(anyFunction.arguments().get(1), isReference("friends['id']", new ArrayType<>(DataTypes.LONG)));
assertThat(anyFunction.arguments().get(0), isLiteral(5L));
}
use of io.crate.expression.symbol.Function in project crate by crate.
the class SelectStatementAnalyzerTest method testRewriteCountStringLiteral.
@Test
public void testRewriteCountStringLiteral() {
var executor = SQLExecutor.builder(clusterService).build();
AnalyzedRelation relation = executor.analyze("select count('id') from sys.nodes");
List<Symbol> outputSymbols = relation.outputs();
assertThat(outputSymbols.size(), is(1));
assertThat(outputSymbols.get(0), instanceOf(Function.class));
assertThat(((Function) outputSymbols.get(0)).arguments().size(), is(0));
}
use of io.crate.expression.symbol.Function in project crate by crate.
the class SelectStatementAnalyzerTest method test_match_with_geo_shape_is_streamed_as_text_type_to_4_1_8_nodes.
@Test
public void test_match_with_geo_shape_is_streamed_as_text_type_to_4_1_8_nodes() throws Exception {
var executor = SQLExecutor.builder(clusterService).addTable("create table test (shape GEO_SHAPE)").build();
String stmt = "SELECT * FROM test WHERE MATCH (shape, 'POINT(1.2 1.3)')";
QueriedSelectRelation rel = executor.analyze(stmt);
Symbol where = rel.where();
assertThat(where, instanceOf(MatchPredicate.class));
DocTableInfo table = executor.resolveTableInfo("test");
EvaluatingNormalizer normalizer = new EvaluatingNormalizer(executor.nodeCtx, RowGranularity.DOC, null, new DocTableRelation(table));
Symbol normalized = normalizer.normalize(where, CoordinatorTxnCtx.systemTransactionContext());
assertThat(normalized, isFunction("match"));
Function match = (Function) normalized;
assertThat(match.arguments().get(1).valueType(), is(DataTypes.GEO_SHAPE));
assertThat(match.info().ident().argumentTypes().get(1), is(DataTypes.GEO_SHAPE));
BytesStreamOutput out = new BytesStreamOutput();
out.setVersion(Version.V_4_1_8);
match.writeTo(out);
StreamInput in = out.bytes().streamInput();
in.setVersion(Version.V_4_1_8);
Function serializedTo41 = new Function(in);
assertThat(serializedTo41.info().ident().argumentTypes().get(1), is(DataTypes.STRING));
}
use of io.crate.expression.symbol.Function in project crate by crate.
the class SelectStatementAnalyzerTest method testNegativeLiteral.
@Test
public void testNegativeLiteral() throws Exception {
var executor = SQLExecutor.builder(clusterService).build();
QueriedSelectRelation relation = executor.analyze("select * from sys.nodes where port['http'] = -400");
Function whereClause = (Function) relation.where();
Symbol symbol = whereClause.arguments().get(1);
assertThat(((Literal<?>) symbol).value(), is(-400));
}
Aggregations