Search in sources :

Example 16 with Function

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

the class UnnestFunctionTest method execute.

private Bucket execute(String expr) {
    Symbol functionSymbol = sqlExpressions.asSymbol(expr);
    functionSymbol = sqlExpressions.normalize(functionSymbol);
    Function function = (Function) functionSymbol;
    TableFunctionImplementation tableFunction = (TableFunctionImplementation) functions.getSafe(function.info().ident());
    return tableFunction.execute(function.arguments().stream().map(a -> (Input) a).collect(Collectors.toList()));
}
Also used : Function(io.crate.analyze.symbol.Function) TableFunctionImplementation(io.crate.metadata.tablefunctions.TableFunctionImplementation) Symbol(io.crate.analyze.symbol.Symbol)

Example 17 with Function

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

the class RandomFunctionTest method normalizeReference.

@Test
public void normalizeReference() {
    Function function = new Function(random.info(), Collections.<Symbol>emptyList());
    Function normalized = (Function) random.normalizeSymbol(function, new TransactionContext(SessionContext.SYSTEM_SESSION));
    assertThat(normalized, sameInstance(function));
}
Also used : Function(io.crate.analyze.symbol.Function) TransactionContext(io.crate.metadata.TransactionContext) AbstractScalarFunctionsTest(io.crate.operation.scalar.AbstractScalarFunctionsTest) Test(org.junit.Test)

Example 18 with Function

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

the class DistanceFunction method normalizeSymbol.

@Override
public Symbol normalizeSymbol(Function symbol, TransactionContext transactionContext) {
    Symbol arg1 = symbol.arguments().get(0);
    Symbol arg2 = symbol.arguments().get(1);
    DataType arg1Type = arg1.valueType();
    DataType arg2Type = arg2.valueType();
    boolean arg1IsReference = true;
    boolean literalConverted = false;
    short numLiterals = 0;
    if (arg1.symbolType().isValueSymbol()) {
        numLiterals++;
        arg1IsReference = false;
        if (!arg1Type.equals(DataTypes.GEO_POINT)) {
            literalConverted = true;
            arg1 = Literal.convert(arg1, DataTypes.GEO_POINT);
        }
    } else {
        validateType(arg1, arg1Type);
    }
    if (arg2.symbolType().isValueSymbol()) {
        numLiterals++;
        if (!arg2Type.equals(DataTypes.GEO_POINT)) {
            literalConverted = true;
            arg2 = Literal.convert(arg2, DataTypes.GEO_POINT);
        }
    } else {
        validateType(arg2, arg2Type);
    }
    if (numLiterals == 2) {
        return Literal.of(evaluate((Input) arg1, (Input) arg2));
    }
    // ensure reference is the first argument.
    if (!arg1IsReference) {
        return new Function(geoPointInfo, Arrays.asList(arg2, arg1));
    }
    if (literalConverted) {
        return new Function(geoPointInfo, Arrays.asList(arg1, arg2));
    }
    return symbol;
}
Also used : Function(io.crate.analyze.symbol.Function) Input(io.crate.data.Input) Symbol(io.crate.analyze.symbol.Symbol) DataType(io.crate.types.DataType)

Example 19 with Function

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

the class IntersectsFunction method normalizeSymbol.

@Override
public Symbol normalizeSymbol(Function symbol, TransactionContext transactionContext) {
    Symbol left = symbol.arguments().get(0);
    Symbol right = symbol.arguments().get(1);
    int numLiterals = 0;
    boolean literalConverted = false;
    if (left.symbolType().isValueSymbol()) {
        numLiterals++;
        Symbol converted = convertTo(DataTypes.GEO_SHAPE, (Literal) left);
        literalConverted = converted != right;
        left = converted;
    }
    if (right.symbolType().isValueSymbol()) {
        numLiterals++;
        Symbol converted = convertTo(DataTypes.GEO_SHAPE, (Literal) right);
        literalConverted = literalConverted || converted != right;
        right = converted;
    }
    if (numLiterals == 2) {
        return Literal.of(evaluate((Input) left, (Input) right));
    }
    if (literalConverted) {
        return new Function(SHAPE_INFO, Arrays.asList(left, right));
    }
    return symbol;
}
Also used : Function(io.crate.analyze.symbol.Function) Input(io.crate.data.Input) Symbol(io.crate.analyze.symbol.Symbol)

Example 20 with Function

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

the class AndOperator method join.

public static Symbol join(Iterable<? extends Symbol> symbols) {
    Iterator<? extends Symbol> it = symbols.iterator();
    assert it.hasNext() : "argument symbols must have at least one item";
    Symbol first = it.next();
    while (it.hasNext()) {
        first = new Function(INFO, Arrays.asList(first, it.next()));
    }
    return first;
}
Also used : Function(io.crate.analyze.symbol.Function) Symbol(io.crate.analyze.symbol.Symbol)

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