Search in sources :

Example 36 with Function

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

the class EvaluatingNormalizerTest method prepareFunctionTree.

/**
     * prepare the following where clause as function symbol tree:
     * <p>
     * where test.dummy.load = 0.08 or name != 'x' and name != 'y'
     * <p>
     * test.dummy.load is a expression that can be evaluated on node level
     * name would be a doc level reference and is untouched
     */
private Function prepareFunctionTree() {
    Reference load_1 = dummyLoadInfo;
    Literal<Double> d01 = Literal.of(0.08);
    Function load_eq_01 = new Function(functionInfo(EqOperator.NAME, DataTypes.DOUBLE), Arrays.<Symbol>asList(load_1, d01));
    Symbol name_ref = new Reference(new ReferenceIdent(new TableIdent(null, "foo"), "name"), RowGranularity.DOC, DataTypes.STRING);
    Symbol x_literal = Literal.of("x");
    Symbol y_literal = Literal.of("y");
    Function name_eq_x = new Function(functionInfo(EqOperator.NAME, DataTypes.STRING), Arrays.<Symbol>asList(name_ref, x_literal));
    Function name_neq_x = new Function(functionInfo(NotPredicate.NAME, DataTypes.BOOLEAN, true), Arrays.<Symbol>asList(name_eq_x));
    Function name_eq_y = new Function(functionInfo(EqOperator.NAME, DataTypes.STRING), Arrays.<Symbol>asList(name_ref, y_literal));
    Function name_neq_y = new Function(functionInfo(NotPredicate.NAME, DataTypes.BOOLEAN, true), Arrays.<Symbol>asList(name_eq_y));
    Function op_and = new Function(functionInfo(AndOperator.NAME, DataTypes.BOOLEAN), Arrays.<Symbol>asList(name_neq_x, name_neq_y));
    return new Function(functionInfo(OrOperator.NAME, DataTypes.BOOLEAN), Arrays.<Symbol>asList(load_eq_01, op_and));
}
Also used : Function(io.crate.analyze.symbol.Function) Symbol(io.crate.analyze.symbol.Symbol)

Example 37 with Function

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

the class DocLevelCollectTest method testCollectDocLevelWhereClause.

@Test
public void testCollectDocLevelWhereClause() throws Throwable {
    EqOperator op = (EqOperator) functions.get(new FunctionIdent(EqOperator.NAME, ImmutableList.<DataType>of(DataTypes.INTEGER, DataTypes.INTEGER)));
    List<Symbol> toCollect = Collections.<Symbol>singletonList(testDocLevelReference);
    WhereClause whereClause = new WhereClause(new Function(op.info(), Arrays.<Symbol>asList(testDocLevelReference, Literal.of(2))));
    RoutedCollectPhase collectNode = getCollectNode(toCollect, whereClause);
    Bucket result = collect(collectNode);
    assertThat(result, contains(isRow(2)));
}
Also used : Function(io.crate.analyze.symbol.Function) EqOperator(io.crate.operation.operator.EqOperator) Bucket(io.crate.data.Bucket) Symbol(io.crate.analyze.symbol.Symbol) WhereClause(io.crate.analyze.WhereClause) RoutedCollectPhase(io.crate.planner.node.dql.RoutedCollectPhase) SQLTransportIntegrationTest(io.crate.integrationtests.SQLTransportIntegrationTest) Test(org.junit.Test)

Example 38 with Function

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

the class HandlerSideLevelCollectTest method testInformationSchemaTables.

@Test
public void testInformationSchemaTables() throws Exception {
    InformationSchemaInfo schemaInfo = internalCluster().getInstance(InformationSchemaInfo.class);
    TableInfo tablesTableInfo = schemaInfo.getTableInfo("tables");
    Routing routing = tablesTableInfo.getRouting(WhereClause.MATCH_ALL, null);
    List<Symbol> toCollect = new ArrayList<>();
    for (Reference reference : tablesTableInfo.columns()) {
        toCollect.add(reference);
    }
    Symbol tableNameRef = toCollect.get(8);
    FunctionImplementation eqImpl = functions.get(new FunctionIdent(EqOperator.NAME, ImmutableList.of(DataTypes.STRING, DataTypes.STRING)));
    Function whereClause = new Function(eqImpl.info(), Arrays.asList(tableNameRef, Literal.of("shards")));
    RoutedCollectPhase collectNode = collectNode(routing, toCollect, RowGranularity.DOC, new WhereClause(whereClause));
    Bucket result = collect(collectNode);
    assertThat(TestingHelpers.printedTable(result), is("NULL| NULL| strict| 0| 1| NULL| NULL| NULL| shards| sys| NULL\n"));
}
Also used : Symbol(io.crate.analyze.symbol.Symbol) ArrayList(java.util.ArrayList) WhereClause(io.crate.analyze.WhereClause) Function(io.crate.analyze.symbol.Function) InformationSchemaInfo(io.crate.metadata.information.InformationSchemaInfo) Bucket(io.crate.data.Bucket) CollectionBucket(io.crate.data.CollectionBucket) TableInfo(io.crate.metadata.table.TableInfo) SysClusterTableInfo(io.crate.metadata.sys.SysClusterTableInfo) RoutedCollectPhase(io.crate.planner.node.dql.RoutedCollectPhase) SQLTransportIntegrationTest(io.crate.integrationtests.SQLTransportIntegrationTest) Test(org.junit.Test)

Example 39 with Function

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

the class RegexpMatchCaseInsensitiveOperatorTest method normalizeSymbol.

private static Symbol normalizeSymbol(String source, String pattern) {
    RegexpMatchCaseInsensitiveOperator op = new RegexpMatchCaseInsensitiveOperator();
    Function function = new Function(op.info(), Arrays.<Symbol>asList(Literal.of(source), Literal.of(pattern)));
    return op.normalizeSymbol(function, new TransactionContext(SessionContext.SYSTEM_SESSION));
}
Also used : Function(io.crate.analyze.symbol.Function) TransactionContext(io.crate.metadata.TransactionContext)

Example 40 with Function

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

the class AnyLikeOperatorTest method normalizeSymbol.

private static Symbol normalizeSymbol(String pattern, String... expressions) {
    Literal patternLiteral = Literal.of(pattern);
    Object[] value = new Object[expressions.length];
    for (int i = 0; i < expressions.length; i++) {
        value[i] = expressions[i] == null ? null : new BytesRef(expressions[i]);
    }
    Literal valuesLiteral = Literal.of(new ArrayType(DataTypes.STRING), value);
    AnyLikeOperator impl = (AnyLikeOperator) new AnyLikeOperator.AnyLikeResolver().getForTypes(Arrays.asList(patternLiteral.valueType(), valuesLiteral.valueType()));
    Function function = new Function(impl.info(), Arrays.<Symbol>asList(patternLiteral, valuesLiteral));
    return impl.normalizeSymbol(function, new TransactionContext(SessionContext.SYSTEM_SESSION));
}
Also used : ArrayType(io.crate.types.ArrayType) Function(io.crate.analyze.symbol.Function) TransactionContext(io.crate.metadata.TransactionContext) Literal(io.crate.analyze.symbol.Literal) BytesRef(org.apache.lucene.util.BytesRef)

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