Search in sources :

Example 11 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 12 with Function

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

the class ExpressionAnalyzerTest method testInSelfJoinCaseFunctionsThatLookTheSameMustNotReuseFunctionAllocation.

@Test
public void testInSelfJoinCaseFunctionsThatLookTheSameMustNotReuseFunctionAllocation() throws Exception {
    TableInfo tableInfo = mock(TableInfo.class);
    when(tableInfo.getReference(new ColumnIdent("id"))).thenReturn(new Reference(new ReferenceIdent(new TableIdent("doc", "t"), "id"), RowGranularity.DOC, DataTypes.INTEGER));
    when(tableInfo.ident()).thenReturn(new TableIdent("doc", "t"));
    TableRelation tr1 = new TableRelation(tableInfo);
    TableRelation tr2 = new TableRelation(tableInfo);
    Map<QualifiedName, AnalyzedRelation> sources = ImmutableMap.of(new QualifiedName("t1"), tr1, new QualifiedName("t2"), tr2);
    ExpressionAnalyzer expressionAnalyzer = new ExpressionAnalyzer(functions, SessionContext.SYSTEM_SESSION, paramTypeHints, new FullQualifedNameFieldProvider(sources), null);
    Function andFunction = (Function) expressionAnalyzer.convert(SqlParser.createExpression("not t1.id = 1 and not t2.id = 1"), context);
    Field t1Id = ((Field) ((Function) ((Function) andFunction.arguments().get(0)).arguments().get(0)).arguments().get(0));
    Field t2Id = ((Field) ((Function) ((Function) andFunction.arguments().get(1)).arguments().get(0)).arguments().get(0));
    assertTrue(t1Id.relation() != t2Id.relation());
}
Also used : AnalyzedRelation(io.crate.analyze.relations.AnalyzedRelation) TableRelation(io.crate.analyze.relations.TableRelation) Function(io.crate.analyze.symbol.Function) SymbolMatchers.isField(io.crate.testing.SymbolMatchers.isField) Field(io.crate.analyze.symbol.Field) TableInfo(io.crate.metadata.table.TableInfo) FullQualifedNameFieldProvider(io.crate.analyze.relations.FullQualifedNameFieldProvider) Test(org.junit.Test) CrateUnitTest(io.crate.test.integration.CrateUnitTest)

Example 13 with Function

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

the class SymbolFormatterTest method testFormat.

@Test
public void testFormat() throws Exception {
    Function f = new Function(new FunctionInfo(new FunctionIdent("foo", Arrays.<DataType>asList(DataTypes.STRING, DataTypes.UNDEFINED)), DataTypes.DOUBLE), Arrays.<Symbol>asList(Literal.of("bar"), Literal.of(3.4)));
    assertThat(SymbolFormatter.format("This Symbol is formatted %s", f), is("This Symbol is formatted foo('bar', 3.4)"));
}
Also used : Function(io.crate.analyze.symbol.Function) FunctionIdent(io.crate.metadata.FunctionIdent) FunctionInfo(io.crate.metadata.FunctionInfo) Test(org.junit.Test) CrateUnitTest(io.crate.test.integration.CrateUnitTest)

Example 14 with Function

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

the class AggregationTest method normalize.

protected Symbol normalize(String functionName, Symbol... args) {
    DataType[] argTypes = new DataType[args.length];
    for (int i = 0; i < args.length; i++) {
        argTypes[i] = args[i].valueType();
    }
    AggregationFunction function = (AggregationFunction) functions.get(new FunctionIdent(functionName, Arrays.asList(argTypes)));
    return function.normalizeSymbol(new Function(function.info(), Arrays.asList(args)), new TransactionContext(SessionContext.SYSTEM_SESSION));
}
Also used : Function(io.crate.analyze.symbol.Function) FunctionIdent(io.crate.metadata.FunctionIdent) TransactionContext(io.crate.metadata.TransactionContext) DataType(io.crate.types.DataType)

Example 15 with Function

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

the class WithinFunctionTest method testNormalizeWithStringLiteralAndReference.

@Test
public void testNormalizeWithStringLiteralAndReference() throws Exception {
    Symbol normalized = normalize(FNAME, createReference("point", DataTypes.GEO_POINT), Literal.of("POLYGON ((5 5, 20 5, 30 30, 5 30, 5 5))"));
    assertThat(normalized, instanceOf(Function.class));
    Function function = (Function) normalized;
    Symbol symbol = function.arguments().get(1);
    assertThat(symbol.valueType(), equalTo(DataTypes.GEO_SHAPE));
}
Also used : Function(io.crate.analyze.symbol.Function) SymbolMatchers.isFunction(io.crate.testing.SymbolMatchers.isFunction) Symbol(io.crate.analyze.symbol.Symbol) AbstractScalarFunctionsTest(io.crate.operation.scalar.AbstractScalarFunctionsTest) Test(org.junit.Test)

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