Package io.crate.planner.symbol

Examples of io.crate.planner.symbol.Function


    @Test
    public void testCollectWithTrueWhereClause() throws Exception {
        CollectNode collectNode = new CollectNode("whereClause", testRouting);
        collectNode.toCollect(Arrays.<Symbol>asList(testNodeReference));
        collectNode.whereClause(new WhereClause(new Function(
                AndOperator.INFO,
                Arrays.<Symbol>asList(Literal.newLiteral(true), Literal.newLiteral(true))
        )));
        collectNode.maxRowGranularity(RowGranularity.NODE);
        Object[][] result = operation.collect(collectNode).get();
View Full Code Here


    public void testCollectWithNullWhereClause() throws Exception {
        EqOperator op = (EqOperator) functions.get(new FunctionIdent(
                EqOperator.NAME, ImmutableList.<DataType>of(DataTypes.INTEGER, DataTypes.INTEGER)));
        CollectNode collectNode = new CollectNode("whereClause", testRouting);
        collectNode.toCollect(Arrays.<Symbol>asList(testNodeReference));
        collectNode.whereClause(new WhereClause(new Function(
                op.info(),
                Arrays.<Symbol>asList(Literal.NULL, Literal.NULL)
        )));
        Object[][] result = operation.collect(collectNode).get();
        assertArrayEquals(new Object[0][], result);
View Full Code Here

                EqOperator.NAME, ImmutableList.<DataType>of(DataTypes.INTEGER, DataTypes.INTEGER)));

        CollectNode collectNode = new CollectNode("shardCollect", shardRouting(0, 1));
        collectNode.toCollect(Arrays.<Symbol>asList(testShardIdReference));
        collectNode.whereClause(new WhereClause(
                new Function(op.info(), Arrays.<Symbol>asList(testShardIdReference, Literal.newLiteral(0)))));
        collectNode.maxRowGranularity(RowGranularity.SHARD);
        Object[][] result = operation.collect(collectNode).get();
        assertThat(result.length, is(equalTo(1)));
        assertThat((Integer) result[0][0], is(0));
    }
View Full Code Here

            @Override
            public DataType valueType() {
                return arrayType;
            }
        };
        Symbol normalized = impl.normalizeSymbol(new Function(impl.info(), Arrays.<Symbol>asList(input)));
        Object[] integers = impl.evaluate(new Input[]{input});

        assertThat(integers, is(((Input) normalized).value()));
        return integers;
    }
View Full Code Here

        return getFunction(type).evaluate(input);
    }

    private Symbol normalize(Object value, DataType type) {
        ToDoubleFunction function = getFunction(type);
        return function.normalizeSymbol(new Function(function.info(),
                Arrays.<Symbol>asList(Literal.newLiteral(type, value))));
    }
View Full Code Here

        return getFunction(type).evaluate(input);
    }

    private Symbol normalize(Object value, DataType type) {
        ToFloatFunction function = getFunction(type);
        return function.normalizeSymbol(new Function(function.info(),
                Arrays.<Symbol>asList(Literal.newLiteral(type, value))));
    }
View Full Code Here

    public void testNormalize() throws Exception {
        List<Symbol> arguments = Arrays.<Symbol>asList(
                Literal.newLiteral(new Integer[]{ 1, 2, 3 }, new ArrayType(DataTypes.INTEGER))
        );
        BytesRef[] expected = new BytesRef[]{ new BytesRef("1"), new BytesRef("2"), new BytesRef("3") };
        Function function = createFunction(ToStringArrayFunction.NAME, new ArrayType(DataTypes.STRING), arguments);
        ToStringArrayFunction arrayFunction = (ToStringArrayFunction) functions.get(function.info().ident());

        Symbol result = arrayFunction.normalizeSymbol(function);
        assertLiteralSymbol(result, expected, new ArrayType(DataTypes.STRING));

        arguments.set(0, Literal.newLiteral(new Float[]{ 1.0f, 2.0f, 3.0f }, new ArrayType(DataTypes.FLOAT)));
        expected = new BytesRef[]{ new BytesRef("1.0"), new BytesRef("2.0"), new BytesRef("3.0") };
        function = createFunction(ToStringArrayFunction.NAME, new ArrayType(DataTypes.STRING), arguments);
        arrayFunction = (ToStringArrayFunction) functions.get(function.info().ident());

        result = arrayFunction.normalizeSymbol(function);
        assertLiteralSymbol(result, expected, new ArrayType(DataTypes.STRING));
    }
View Full Code Here

    public void testEvaluate() throws Exception {
        List<Symbol> arguments = Arrays.<Symbol>asList(
                createReference("int_array", new ArrayType(DataTypes.INTEGER))
        );
        Object[] expected = new BytesRef[]{ new BytesRef("1"), new BytesRef("2"), new BytesRef("3") };
        Function function = createFunction(ToStringArrayFunction.NAME, new ArrayType(DataTypes.STRING), arguments);
        ToStringArrayFunction arrayFunction = (ToStringArrayFunction) functions.get(function.info().ident());

        Input[] args = new Input[1];
        args[0] = new Input<Object>() {
            @Override
            public Object value() {
View Full Code Here

    @SuppressWarnings("unchecked")
    public void testNormalizeSymbol() throws Exception {

        FunctionImplementation castStringToInteger = functions.get(new FunctionIdent(ToIntFunction.NAME, ImmutableList.<DataType>of(DataTypes.STRING)));

        Function function = new Function(castStringToInteger.info(), Arrays.<Symbol>asList(Literal.newLiteral("123")));
        Symbol result = castStringToInteger.normalizeSymbol(function);
        assertLiteralSymbol(result, 123);

        FunctionImplementation castFloatToInteger = functions.get(new FunctionIdent(ToIntFunction.NAME, ImmutableList.<DataType>of(DataTypes.FLOAT)));

        function = new Function(castFloatToInteger.info(), Arrays.<Symbol>asList(Literal.newLiteral(12.5f)));
        result = castStringToInteger.normalizeSymbol(function);
        assertLiteralSymbol(result, 12);
    }
View Full Code Here

    @Test
    public void testNormalizeInvalidString() throws Exception {
        expectedException.expect(NumberFormatException.class);
        expectedException.expectMessage("For input string: \"hello\"");
        FunctionImplementation castStringToInteger = functions.get(new FunctionIdent(ToIntFunction.NAME, ImmutableList.<DataType>of(DataTypes.STRING)));
        Function function = new Function(castStringToInteger.info(), Arrays.<Symbol>asList(Literal.newLiteral("hello")));
        castStringToInteger.normalizeSymbol(function);
    }
View Full Code Here

TOP

Related Classes of io.crate.planner.symbol.Function

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.