Search in sources :

Example 31 with Function

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))));
}
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) CrateDummyClusterServiceUnitTest(io.crate.test.integration.CrateDummyClusterServiceUnitTest) Test(org.junit.Test)

Example 32 with Function

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"));
    }
}
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) BitString(io.crate.sql.tree.BitString) CrateDummyClusterServiceUnitTest(io.crate.test.integration.CrateDummyClusterServiceUnitTest) Test(org.junit.Test)

Example 33 with Function

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));
}
Also used : Function(io.crate.expression.symbol.Function) EvaluatingNormalizer(io.crate.expression.eval.EvaluatingNormalizer) Symbol(io.crate.expression.symbol.Symbol) Test(org.junit.Test)

Example 34 with Function

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));
}
Also used : Function(io.crate.expression.symbol.Function) EvaluatingNormalizer(io.crate.expression.eval.EvaluatingNormalizer) Symbol(io.crate.expression.symbol.Symbol) Test(org.junit.Test)

Example 35 with Function

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"));
}
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)

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