Search in sources :

Example 36 with Function

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%"));
}
Also used : SymbolMatchers.isFunction(io.crate.testing.SymbolMatchers.isFunction) Function(io.crate.expression.symbol.Function) CrateDummyClusterServiceUnitTest(io.crate.test.integration.CrateDummyClusterServiceUnitTest) Test(org.junit.Test)

Example 37 with Function

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));
}
Also used : ArrayType(io.crate.types.ArrayType) DistanceFunction(io.crate.expression.scalar.geo.DistanceFunction) SymbolMatchers.isFunction(io.crate.testing.SymbolMatchers.isFunction) TryCastFunction(io.crate.expression.scalar.cast.TryCastFunction) ExplicitCastFunction(io.crate.expression.scalar.cast.ExplicitCastFunction) Function(io.crate.expression.symbol.Function) SubscriptFunction(io.crate.expression.scalar.SubscriptFunction) CrateDummyClusterServiceUnitTest(io.crate.test.integration.CrateDummyClusterServiceUnitTest) Test(org.junit.Test)

Example 38 with Function

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));
}
Also used : DistanceFunction(io.crate.expression.scalar.geo.DistanceFunction) SymbolMatchers.isFunction(io.crate.testing.SymbolMatchers.isFunction) TryCastFunction(io.crate.expression.scalar.cast.TryCastFunction) ExplicitCastFunction(io.crate.expression.scalar.cast.ExplicitCastFunction) Function(io.crate.expression.symbol.Function) SubscriptFunction(io.crate.expression.scalar.SubscriptFunction) ParameterSymbol(io.crate.expression.symbol.ParameterSymbol) SelectSymbol(io.crate.expression.symbol.SelectSymbol) Symbol(io.crate.expression.symbol.Symbol) AliasSymbol(io.crate.expression.symbol.AliasSymbol) AnalyzedRelation(io.crate.analyze.relations.AnalyzedRelation) CrateDummyClusterServiceUnitTest(io.crate.test.integration.CrateDummyClusterServiceUnitTest) Test(org.junit.Test)

Example 39 with Function

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));
}
Also used : DistanceFunction(io.crate.expression.scalar.geo.DistanceFunction) SymbolMatchers.isFunction(io.crate.testing.SymbolMatchers.isFunction) TryCastFunction(io.crate.expression.scalar.cast.TryCastFunction) ExplicitCastFunction(io.crate.expression.scalar.cast.ExplicitCastFunction) Function(io.crate.expression.symbol.Function) SubscriptFunction(io.crate.expression.scalar.SubscriptFunction) DocTableInfo(io.crate.metadata.doc.DocTableInfo) EvaluatingNormalizer(io.crate.expression.eval.EvaluatingNormalizer) ParameterSymbol(io.crate.expression.symbol.ParameterSymbol) SelectSymbol(io.crate.expression.symbol.SelectSymbol) Symbol(io.crate.expression.symbol.Symbol) AliasSymbol(io.crate.expression.symbol.AliasSymbol) StreamInput(org.elasticsearch.common.io.stream.StreamInput) DocTableRelation(io.crate.analyze.relations.DocTableRelation) BitString(io.crate.sql.tree.BitString) MatchPredicate(io.crate.expression.symbol.MatchPredicate) BytesStreamOutput(org.elasticsearch.common.io.stream.BytesStreamOutput) CrateDummyClusterServiceUnitTest(io.crate.test.integration.CrateDummyClusterServiceUnitTest) Test(org.junit.Test)

Example 40 with Function

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));
}
Also used : DistanceFunction(io.crate.expression.scalar.geo.DistanceFunction) SymbolMatchers.isFunction(io.crate.testing.SymbolMatchers.isFunction) TryCastFunction(io.crate.expression.scalar.cast.TryCastFunction) ExplicitCastFunction(io.crate.expression.scalar.cast.ExplicitCastFunction) Function(io.crate.expression.symbol.Function) SubscriptFunction(io.crate.expression.scalar.SubscriptFunction) ParameterSymbol(io.crate.expression.symbol.ParameterSymbol) SelectSymbol(io.crate.expression.symbol.SelectSymbol) Symbol(io.crate.expression.symbol.Symbol) AliasSymbol(io.crate.expression.symbol.AliasSymbol) CrateDummyClusterServiceUnitTest(io.crate.test.integration.CrateDummyClusterServiceUnitTest) Test(org.junit.Test)

Aggregations

Function (io.crate.expression.symbol.Function)80 Test (org.junit.Test)56 Symbol (io.crate.expression.symbol.Symbol)43 CrateDummyClusterServiceUnitTest (io.crate.test.integration.CrateDummyClusterServiceUnitTest)43 SymbolMatchers.isFunction (io.crate.testing.SymbolMatchers.isFunction)35 SubscriptFunction (io.crate.expression.scalar.SubscriptFunction)25 TryCastFunction (io.crate.expression.scalar.cast.TryCastFunction)24 ExplicitCastFunction (io.crate.expression.scalar.cast.ExplicitCastFunction)23 DistanceFunction (io.crate.expression.scalar.geo.DistanceFunction)23 AliasSymbol (io.crate.expression.symbol.AliasSymbol)13 ParameterSymbol (io.crate.expression.symbol.ParameterSymbol)13 SelectSymbol (io.crate.expression.symbol.SelectSymbol)13 InputColumn (io.crate.expression.symbol.InputColumn)10 ArrayList (java.util.ArrayList)10 Literal (io.crate.expression.symbol.Literal)9 ArraySliceFunction (io.crate.expression.scalar.ArraySliceFunction)8 FunctionImplementation (io.crate.metadata.FunctionImplementation)8 AnalyzedRelation (io.crate.analyze.relations.AnalyzedRelation)7 ScopedSymbol (io.crate.expression.symbol.ScopedSymbol)6 Reference (io.crate.metadata.Reference)6