Search in sources :

Example 1 with Input

use of io.crate.data.Input in project crate by crate.

the class AnyLikeOperatorTest method testNegateLike.

@Test
public void testNegateLike() throws Exception {
    Literal patternLiteral = Literal.of("A");
    Literal valuesLiteral = Literal.of(new ArrayType(DataTypes.STRING), new Object[] { new BytesRef("A"), new BytesRef("B") });
    FunctionImplementation impl = new AnyLikeOperator.AnyLikeResolver().getForTypes(Arrays.asList(DataTypes.STRING, valuesLiteral.valueType()));
    Function anyLikeFunction = new Function(impl.info(), Arrays.<Symbol>asList(patternLiteral, valuesLiteral));
    Input<Boolean> normalized = (Input<Boolean>) impl.normalizeSymbol(anyLikeFunction, new TransactionContext(SessionContext.SYSTEM_SESSION));
    assertThat(normalized.value(), is(true));
    assertThat(new NotPredicate().evaluate(normalized), is(false));
}
Also used : ArrayType(io.crate.types.ArrayType) Function(io.crate.analyze.symbol.Function) Input(io.crate.data.Input) TransactionContext(io.crate.metadata.TransactionContext) Literal(io.crate.analyze.symbol.Literal) FunctionImplementation(io.crate.metadata.FunctionImplementation) NotPredicate(io.crate.operation.predicate.NotPredicate) BytesRef(org.apache.lucene.util.BytesRef) Test(org.junit.Test) CrateUnitTest(io.crate.test.integration.CrateUnitTest)

Example 2 with Input

use of io.crate.data.Input in project crate by crate.

the class AnyNotLikeOperatorTest method testNegateNotLike.

@Test
public void testNegateNotLike() throws Exception {
    Literal patternLiteral = Literal.of("A");
    Literal valuesLiteral = Literal.of(new ArrayType(DataTypes.STRING), new Object[] { new BytesRef("A"), new BytesRef("B") });
    FunctionImplementation impl = new AnyNotLikeOperator.AnyNotLikeResolver().getForTypes(Arrays.asList(DataTypes.STRING, valuesLiteral.valueType()));
    Function anyNotLikeFunction = new Function(impl.info(), Arrays.<Symbol>asList(patternLiteral, valuesLiteral));
    Input<Boolean> normalized = (Input<Boolean>) impl.normalizeSymbol(anyNotLikeFunction, new TransactionContext(SessionContext.SYSTEM_SESSION));
    assertThat(normalized.value(), is(true));
    assertThat(new NotPredicate().evaluate(normalized), is(false));
}
Also used : ArrayType(io.crate.types.ArrayType) Function(io.crate.analyze.symbol.Function) Input(io.crate.data.Input) TransactionContext(io.crate.metadata.TransactionContext) Literal(io.crate.analyze.symbol.Literal) FunctionImplementation(io.crate.metadata.FunctionImplementation) NotPredicate(io.crate.operation.predicate.NotPredicate) BytesRef(org.apache.lucene.util.BytesRef) Test(org.junit.Test) CrateUnitTest(io.crate.test.integration.CrateUnitTest)

Example 3 with Input

use of io.crate.data.Input in project crate by crate.

the class SysNodesExpressionsTest method testLoad.

@Test
public void testLoad() throws Exception {
    Reference refInfo = refInfo("sys.nodes.load", DataTypes.OBJECT, RowGranularity.NODE);
    io.crate.operation.reference.NestedObjectExpression load = (io.crate.operation.reference.NestedObjectExpression) resolver.getChildImplementation(refInfo.ident().columnIdent().name());
    Map<String, Object> v = load.value();
    assertNull(v.get("something"));
    assertEquals(1D, v.get("1"));
    assertEquals(5D, v.get("5"));
    assertEquals(15D, v.get("15"));
    Input ci = load.getChildImplementation("1");
    assertEquals(1D, ci.value());
    ci = load.getChildImplementation("5");
    assertEquals(5D, ci.value());
    ci = load.getChildImplementation("15");
    assertEquals(15D, ci.value());
}
Also used : Input(io.crate.data.Input) Reference(io.crate.metadata.Reference) TestingHelpers.mapToSortedString(io.crate.testing.TestingHelpers.mapToSortedString) NestedObjectExpression(io.crate.operation.reference.NestedObjectExpression) NestedObjectExpression(io.crate.operation.reference.NestedObjectExpression) Test(org.junit.Test) CrateUnitTest(io.crate.test.integration.CrateUnitTest)

Example 4 with Input

use of io.crate.data.Input in project crate by crate.

the class BaseImplementationSymbolVisitor method visitFunction.

@Override
public Input<?> visitFunction(Function function, C context) {
    final FunctionImplementation functionImplementation = functions.get(function.info().ident());
    if (functionImplementation instanceof Scalar<?, ?>) {
        List<Symbol> arguments = function.arguments();
        Scalar<?, ?> scalarImpl = ((Scalar) functionImplementation).compile(arguments);
        Input[] argumentInputs = new Input[arguments.size()];
        int i = 0;
        for (Symbol argument : function.arguments()) {
            argumentInputs[i++] = process(argument, context);
        }
        return new FunctionExpression<>(scalarImpl, argumentInputs);
    } else {
        throw new IllegalArgumentException(SymbolFormatter.format("Cannot find implementation for function %s", function));
    }
}
Also used : Input(io.crate.data.Input) FunctionExpression(io.crate.operation.aggregation.FunctionExpression) FunctionImplementation(io.crate.metadata.FunctionImplementation) Scalar(io.crate.metadata.Scalar)

Example 5 with Input

use of io.crate.data.Input in project crate by crate.

the class TableFunctionCollectSource method getCollector.

@Override
public CrateCollector getCollector(CollectPhase collectPhase, BatchConsumer consumer, JobCollectContext jobCollectContext) {
    TableFunctionCollectPhase phase = (TableFunctionCollectPhase) collectPhase;
    WhereClause whereClause = phase.whereClause();
    if (whereClause.noMatch()) {
        return RowsCollector.empty(consumer);
    }
    TableFunctionImplementation functionImplementation = phase.relation().functionImplementation();
    TableInfo tableInfo = functionImplementation.createTableInfo(clusterService);
    //noinspection unchecked  Only literals can be passed to table functions. Anything else is invalid SQL
    List<Input<?>> inputs = (List<Input<?>>) (List) phase.relation().function().arguments();
    List<Reference> columns = new ArrayList<>(tableInfo.columns());
    List<Input<?>> topLevelInputs = new ArrayList<>(phase.toCollect().size());
    InputFactory.Context<InputCollectExpression> ctx = inputFactory.ctxForRefs(i -> new InputCollectExpression(columns.indexOf(i)));
    for (Symbol symbol : phase.toCollect()) {
        topLevelInputs.add(ctx.add(symbol));
    }
    Iterable<Row> rows = Iterables.transform(functionImplementation.execute(inputs), new ValueAndInputRow<>(topLevelInputs, ctx.expressions()));
    if (whereClause.hasQuery()) {
        Input<Boolean> condition = (Input<Boolean>) ctx.add(whereClause.query());
        rows = Iterables.filter(rows, InputCondition.asPredicate(condition));
    }
    OrderBy orderBy = phase.orderBy();
    if (orderBy != null) {
        rows = RowsTransformer.sortRows(Iterables.transform(rows, Row::materialize), phase);
    }
    return RowsCollector.forRows(rows, phase.toCollect().size(), consumer);
}
Also used : OrderBy(io.crate.analyze.OrderBy) InputFactory(io.crate.operation.InputFactory) TableFunctionImplementation(io.crate.metadata.tablefunctions.TableFunctionImplementation) Reference(io.crate.metadata.Reference) Symbol(io.crate.analyze.symbol.Symbol) WhereClause(io.crate.analyze.WhereClause) ArrayList(java.util.ArrayList) Input(io.crate.data.Input) TableInfo(io.crate.metadata.table.TableInfo) ArrayList(java.util.ArrayList) List(java.util.List) Row(io.crate.data.Row) TableFunctionCollectPhase(io.crate.planner.node.dql.TableFunctionCollectPhase)

Aggregations

Input (io.crate.data.Input)31 Symbol (io.crate.analyze.symbol.Symbol)15 Test (org.junit.Test)9 CrateUnitTest (io.crate.test.integration.CrateUnitTest)8 InputFactory (io.crate.operation.InputFactory)6 CollectExpression (io.crate.operation.collect.CollectExpression)6 Function (io.crate.analyze.symbol.Function)5 BytesRef (org.apache.lucene.util.BytesRef)5 Literal (io.crate.analyze.symbol.Literal)4 Row (io.crate.data.Row)4 FunctionImplementation (io.crate.metadata.FunctionImplementation)4 ArrayType (io.crate.types.ArrayType)4 ArrayList (java.util.ArrayList)4 InputColumn (io.crate.analyze.symbol.InputColumn)3 AddFunction (io.crate.operation.scalar.arithmetic.AddFunction)3 DataType (io.crate.types.DataType)3 Aggregation (io.crate.analyze.symbol.Aggregation)2 RowN (io.crate.data.RowN)2 Reference (io.crate.metadata.Reference)2 TransactionContext (io.crate.metadata.TransactionContext)2