use of io.crate.expression.symbol.Function in project crate by crate.
the class ExpressionAnalyzerTest method testFunctionsCanBeCasted.
@Test
public void testFunctionsCanBeCasted() {
Function symbol2 = (Function) executor.asSymbol("doc.t5.w = doc.t2.i + 1::smallint");
assertThat(symbol2, isFunction(EqOperator.NAME));
assertThat(symbol2.arguments().get(0), isReference("w"));
assertThat(symbol2.arguments().get(1), isFunction(ImplicitCastFunction.NAME, List.of(DataTypes.INTEGER, DataTypes.STRING)));
}
use of io.crate.expression.symbol.Function in project crate by crate.
the class ExpressionAnalyzerTest method testInSelfJoinCaseFunctionsThatLookTheSameMustNotReuseFunctionAllocation.
@Test
public void testInSelfJoinCaseFunctionsThatLookTheSameMustNotReuseFunctionAllocation() throws Exception {
TableInfo t1 = executor.resolveTableInfo("t1");
TableRelation relation = new TableRelation(t1);
RelationName a1 = new RelationName(null, "a1");
RelationName a2 = new RelationName(null, "a2");
Map<RelationName, AnalyzedRelation> sources = Map.of(a1, new AliasedAnalyzedRelation(relation, a1), a2, new AliasedAnalyzedRelation(relation, a2));
SessionContext sessionContext = SessionContext.systemSessionContext();
CoordinatorTxnCtx coordinatorTxnCtx = new CoordinatorTxnCtx(sessionContext);
ExpressionAnalyzer expressionAnalyzer = new ExpressionAnalyzer(coordinatorTxnCtx, expressions.nodeCtx, paramTypeHints, new FullQualifiedNameFieldProvider(sources, ParentRelations.NO_PARENTS, sessionContext.searchPath().currentSchema()), null);
Function andFunction = (Function) expressionAnalyzer.convert(SqlParser.createExpression("not a1.x = 1 and not a2.x = 1"), context);
ScopedSymbol t1Id = ((ScopedSymbol) ((Function) ((Function) andFunction.arguments().get(0)).arguments().get(0)).arguments().get(0));
ScopedSymbol t2Id = ((ScopedSymbol) ((Function) ((Function) andFunction.arguments().get(1)).arguments().get(0)).arguments().get(0));
assertThat(t1Id.relation(), is(not(t2Id.relation())));
}
use of io.crate.expression.symbol.Function in project crate by crate.
the class SelectStatementAnalyzerTest method testAggregationDistinct.
@Test
public void testAggregationDistinct() {
var executor = SQLExecutor.builder(clusterService).build();
AnalyzedRelation relation = executor.analyze("select count(distinct load['1']) from sys.nodes");
Symbol output = relation.outputs().get(0);
assertThat(output, isFunction("collection_count"));
Function collectionCount = (Function) output;
assertThat(collectionCount.arguments().size(), is(1));
Symbol symbol = collectionCount.arguments().get(0);
assertThat(symbol, isFunction("collect_set"));
Function collectSet = (Function) symbol;
assertThat(collectSet.signature().getKind(), equalTo(FunctionType.AGGREGATE));
assertThat(collectSet.arguments().size(), is(1));
assertThat(collectSet.arguments().get(0), isReference("load['1']"));
}
use of io.crate.expression.symbol.Function in project crate by crate.
the class SelectStatementAnalyzerTest method testAnyNotLike.
@Test
public void testAnyNotLike() throws Exception {
var executor = SQLExecutor.builder(clusterService).addTable(TableDefinitions.USER_TABLE_DEFINITION).build();
QueriedSelectRelation relation = executor.analyze("select * from users where 'awesome' NOT LIKE ANY (tags)");
Function query = (Function) relation.where();
assertThat(query.name(), is("any_not_like"));
assertThat(query.arguments().size(), is(2));
assertThat(query.arguments().get(0), instanceOf(Literal.class));
assertThat(query.arguments().get(0), isLiteral("awesome", DataTypes.STRING));
assertThat(query.arguments().get(1), isReference("tags"));
}
use of io.crate.expression.symbol.Function in project crate by crate.
the class SelectStatementAnalyzerTest method testGlobalAggregateHaving.
@Test
public void testGlobalAggregateHaving() throws Exception {
var executor = SQLExecutor.builder(clusterService).addTable(TableDefinitions.USER_TABLE_DEFINITION).build();
QueriedSelectRelation relation = executor.analyze("select sum(floats) from users having sum(bytes) in (42, 43, 44)");
Function havingFunction = (Function) relation.having();
// assert that the in was converted to or
assertThat(havingFunction.name(), is(AnyEqOperator.NAME));
}
Aggregations