Package io.crate.metadata

Examples of io.crate.metadata.FunctionImplementation


    @Test
    @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

        List<Symbol> args = Arrays.<Symbol>asList(
                Literal.newLiteral("%tY"),
                Literal.newLiteral(DataTypes.TIMESTAMP, DataTypes.TIMESTAMP.value("2014-03-02")));
        Function function = createFunction(FormatFunction.NAME, DataTypes.STRING, args);

        FunctionImplementation format = functions.get(function.info().ident());
        Symbol result = format.normalizeSymbol(function);

        assertLiteralSymbol(result, "2014");
    }
View Full Code Here

                DataTypes.DOUBLE,
                DataTypes.STRING
                );
        for (DataType dataType : supportedTypes) {
            FunctionIdent ident = new FunctionIdent(functionName, Arrays.asList(dataType));
            FunctionImplementation implementation = functions.get(ident);
            assertThat(implementation, instanceOf(ToTimestampFunction.class));
            assertEquals(((ToTimestampFunction) implementation).returnType, DataTypes.TIMESTAMP);
        }
    }
View Full Code Here

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

        FunctionImplementation castIntegerToString = functions.get(new FunctionIdent(ToStringFunction.NAME, ImmutableList.<DataType>of(DataTypes.INTEGER)));

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

        FunctionImplementation castFloatToString = functions.get(new FunctionIdent(ToStringFunction.NAME, ImmutableList.<DataType>of(DataTypes.FLOAT)));
        function = new Function(castFloatToString.info(), Arrays.<Symbol>asList(Literal.newLiteral(0.5f)));
        result = castFloatToString.normalizeSymbol(function);
        assertLiteralSymbol(result, "0.5");

        FunctionImplementation castStringToString = functions.get(new FunctionIdent(ToStringFunction.NAME, ImmutableList.<DataType>of(DataTypes.STRING)));
        function = new Function(castStringToString.info(), Arrays.<Symbol>asList(Literal.newLiteral("hello")));
        result = castStringToString.normalizeSymbol(function);
        assertLiteralSymbol(result, "hello");
    }
View Full Code Here

        return functions;
    }

    @Override
    public Input<?> visitFunction(Function function, C context) {
        final FunctionImplementation functionImplementation = functions.get(function.info().ident());
        if (functionImplementation != null && functionImplementation instanceof Scalar<?, ?>) {

            List<Symbol> arguments = function.arguments();
            Input[] argumentInputs = new Input[arguments.size()];
            int i = 0;
View Full Code Here

        return result;
    }

    @Override
    public Input<?> visitAggregation(Aggregation symbol, Context context) {
        FunctionImplementation impl = functions.get(symbol.functionIdent());
        if (impl == null) {
            throw new UnsupportedOperationException(
                    SymbolFormatter.format("Can't load aggregation impl for symbol %s", symbol));
        }
View Full Code Here

        return normalizeFunctionSymbol(function);
    }

    @SuppressWarnings("unchecked")
    private Symbol normalizeFunctionSymbol(Function function) {
        FunctionImplementation impl = functions.get(function.info().ident());
        if (impl != null) {
            return impl.normalizeSymbol(function);
        }
        if (logger.isTraceEnabled()) {
            logger.trace(SymbolFormatter.format("No implementation found for function %s", function));
        }
        return function;
View Full Code Here

TOP

Related Classes of io.crate.metadata.FunctionImplementation

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.