Search in sources :

Example 1 with Function

use of io.crate.analyze.symbol.Function in project crate by crate.

the class CurrentSchemaFunctionTest method testEvaluateCurrentSchemaNotSupported.

public void testEvaluateCurrentSchemaNotSupported() throws Exception {
    expectedException.expect(UnsupportedOperationException.class);
    expectedException.expectMessage("Cannot evaluate CURRENT_SCHEMA function.");
    Function function = (Function) sqlExpressions.asSymbol("current_schema()");
    Scalar impl = (Scalar) functions.get(function.info().ident());
    impl.evaluate();
}
Also used : Function(io.crate.analyze.symbol.Function) Scalar(io.crate.metadata.Scalar)

Example 2 with Function

use of io.crate.analyze.symbol.Function in project crate by crate.

the class EvaluatingNormalizerTest method testEvaluationClusterGranularity.

@Test
public void testEvaluationClusterGranularity() {
    EvaluatingNormalizer visitor = new EvaluatingNormalizer(functions, RowGranularity.CLUSTER, ReplaceMode.COPY, referenceResolver, null);
    Function op_or = prepareFunctionTree();
    Symbol query = visitor.normalize(op_or, transactionContext);
    assertThat(query, instanceOf(Function.class));
}
Also used : Function(io.crate.analyze.symbol.Function) Symbol(io.crate.analyze.symbol.Symbol) Test(org.junit.Test) CrateUnitTest(io.crate.test.integration.CrateUnitTest)

Example 3 with Function

use of io.crate.analyze.symbol.Function in project crate by crate.

the class EvaluatingNormalizerTest method testEvaluation.

@Test
public void testEvaluation() {
    EvaluatingNormalizer visitor = new EvaluatingNormalizer(functions, RowGranularity.NODE, ReplaceMode.MUTATE, 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, transactionContext);
    assertThat(query, isLiteral(true));
}
Also used : Function(io.crate.analyze.symbol.Function) Symbol(io.crate.analyze.symbol.Symbol) Test(org.junit.Test) CrateUnitTest(io.crate.test.integration.CrateUnitTest)

Example 4 with Function

use of io.crate.analyze.symbol.Function in project crate by crate.

the class InsertFromSubQueryAnalyzerTest method testFromQueryWithOnDuplicateKeyValues.

@Test
public void testFromQueryWithOnDuplicateKeyValues() throws Exception {
    InsertFromSubQueryAnalyzedStatement statement = e.analyze("insert into users (id, name) (select id, name from users) " + "on duplicate key update name = substr(values (name), 1, 1)");
    Assert.assertThat(statement.onDuplicateKeyAssignments().size(), is(1));
    for (Map.Entry<Reference, Symbol> entry : statement.onDuplicateKeyAssignments().entrySet()) {
        assertThat(entry.getKey(), isReference("name"));
        assertThat(entry.getValue(), isFunction(SubstrFunction.NAME));
        Function function = (Function) entry.getValue();
        assertThat(function.arguments().get(0), instanceOf(InputColumn.class));
        InputColumn inputColumn = (InputColumn) function.arguments().get(0);
        assertThat(inputColumn.index(), is(1));
        assertThat(inputColumn.valueType(), instanceOf(StringType.class));
    }
}
Also used : Function(io.crate.analyze.symbol.Function) SubstrFunction(io.crate.operation.scalar.SubstrFunction) StringType(io.crate.types.StringType) Reference(io.crate.metadata.Reference) Symbol(io.crate.analyze.symbol.Symbol) InputColumn(io.crate.analyze.symbol.InputColumn) Map(java.util.Map) Test(org.junit.Test) CrateUnitTest(io.crate.test.integration.CrateUnitTest)

Example 5 with Function

use of io.crate.analyze.symbol.Function in project crate by crate.

the class UpdateAnalyzerTest method testTestUpdateOnTableWithAliasAndFQColumnNameInWhereClause.

@Test
public void testTestUpdateOnTableWithAliasAndFQColumnNameInWhereClause() throws Exception {
    UpdateAnalyzedStatement statement = analyze("update users  t set name = 'foo' where t.name != 'foo'");
    Function eqFunction = (Function) ((Function) statement.nestedStatements().get(0).whereClause().query()).arguments().get(0);
    assertThat(eqFunction.arguments().get(0), isReference("name"));
}
Also used : Function(io.crate.analyze.symbol.Function) Test(org.junit.Test) CrateUnitTest(io.crate.test.integration.CrateUnitTest)

Aggregations

Function (io.crate.analyze.symbol.Function)40 Test (org.junit.Test)25 Symbol (io.crate.analyze.symbol.Symbol)19 CrateUnitTest (io.crate.test.integration.CrateUnitTest)18 TransactionContext (io.crate.metadata.TransactionContext)8 Input (io.crate.data.Input)5 TableInfo (io.crate.metadata.table.TableInfo)5 Literal (io.crate.analyze.symbol.Literal)4 ArrayType (io.crate.types.ArrayType)4 QuerySpec (io.crate.analyze.QuerySpec)3 WhereClause (io.crate.analyze.WhereClause)3 Reference (io.crate.metadata.Reference)3 AbstractScalarFunctionsTest (io.crate.operation.scalar.AbstractScalarFunctionsTest)3 RoutedCollectPhase (io.crate.planner.node.dql.RoutedCollectPhase)3 BytesRef (org.apache.lucene.util.BytesRef)3 SessionContext (io.crate.action.sql.SessionContext)2 OrderBy (io.crate.analyze.OrderBy)2 FullQualifedNameFieldProvider (io.crate.analyze.relations.FullQualifedNameFieldProvider)2 QueriedDocTable (io.crate.analyze.relations.QueriedDocTable)2 Field (io.crate.analyze.symbol.Field)2