Package io.crate.planner.symbol

Examples of io.crate.planner.symbol.Literal


    private Object[] eval(final Object objects, DataType innerType) {
        final DataType arrayType = new ArrayType(innerType);
        ToDoubleArrayFunction impl = (ToDoubleArrayFunction)functions.get(
                new FunctionIdent(ToDoubleArrayFunction.NAME, ImmutableList.of(arrayType)));

        Literal input = new Literal() {
            @Override
            public Object value() {
                return objects;
            }
View Full Code Here


    private Object[] eval(final Object objects, DataType innerType) {
        final DataType arrayType = new ArrayType(innerType);
        ToBooleanArrayFunction impl = (ToBooleanArrayFunction)functions.get(
                new FunctionIdent(ToBooleanArrayFunction.NAME, ImmutableList.of(arrayType)));

        Literal input = new Literal() {
            @Override
            public Object value() {
                return objects;
            }
View Full Code Here

                new Double[] { 10.0d, 20.0d }, DataTypes.GEO_POINT);
    }

    @Test
    public void testNormalizeWithValidGeoPointLiterals() throws Exception {
        Literal symbol = (Literal) normalize(Arrays.<Symbol>asList(
                Literal.newLiteral(DataTypes.GEO_POINT, DataTypes.GEO_POINT.value("POINT (10 20)")),
                Literal.newLiteral(DataTypes.GEO_POINT, DataTypes.GEO_POINT.value("POINT (30 40)"))
        ));
        assertThat(symbol.value(), instanceOf(Double.class));

        // args reversed
        symbol = (Literal) normalize(Arrays.<Symbol>asList(
                Literal.newLiteral(DataTypes.GEO_POINT, DataTypes.GEO_POINT.value("POINT (30 40)")),
                Literal.newLiteral(DataTypes.GEO_POINT, DataTypes.GEO_POINT.value("POINT (10 20)"))
        ));
        assertThat(symbol.value(), instanceOf(Double.class));
    }
View Full Code Here

    @Override
    public Scalar<BytesRef[], Object> compile(List<Symbol> arguments) {
        assert arguments.size() > 1;
        String pattern = null;
        if (arguments.get(1).symbolType() == SymbolType.LITERAL) {
            Literal literal = (Literal) arguments.get(1);
            Object patternVal = literal.value();
            if (patternVal == null) {
                return this;
            }
            pattern = ((BytesRef) patternVal).utf8ToString();
        }
View Full Code Here

    @Override
    public Scalar<BytesRef, Object> compile(List<Symbol> arguments) {
        assert arguments.size() >= 3;
        String pattern = null;
        if (arguments.get(1).symbolType() == SymbolType.LITERAL) {
            Literal literal = (Literal) arguments.get(1);
            Object patternVal = literal.value();
            if (patternVal == null) {
                return this;
            }
            pattern = ((BytesRef) patternVal).utf8ToString();
        }
View Full Code Here

                }
            }
        }
        symbol = process(expression, context);
        if (symbol.symbolType().isValueSymbol()) {
            Literal longLiteral;
            try {
                longLiteral = Literal.toLiteral(symbol, DataTypes.LONG);
            } catch (ClassCastException | IllegalArgumentException e) {
                throw new UnsupportedOperationException(String.format(
                        "Cannot use %s in %s clause", SymbolFormatter.format(symbol), clause));
View Full Code Here

    }

    @Override
    public boolean hasNoResult() {
        if (havingClause != null && havingClause.symbolType() == SymbolType.LITERAL) {
            Literal havingLiteral = (Literal)havingClause;
            if (havingLiteral.value() == false) {
                return true;
            }
        }

        if (globalAggregate()) {
View Full Code Here

            if (argSymbol instanceof DataTypeSymbol) {
                argumentTypes.add(((DataTypeSymbol) argSymbol).valueType());
                arguments.add(argSymbol);
            } else if (argSymbol.symbolType() == SymbolType.PARAMETER) {
                Literal literal = Literal.fromParameter((Parameter)argSymbol);
                argumentTypes.add(literal.valueType());
                arguments.add(literal);
            } else {
                // TODO: verify how this can happen
                throw new RuntimeException("Got an argument Symbol that doesn't have a type");
            }
View Full Code Here

        DataType argumentType;
        Symbol argSymbol = node.getExpression().accept(this, context);
        if (argSymbol instanceof DataTypeSymbol) {
            argumentType = ((DataTypeSymbol) argSymbol).valueType();
        } else if (argSymbol.symbolType() == SymbolType.PARAMETER) {
            Literal literal = Literal.fromParameter((Parameter)argSymbol);
            argumentType = literal.valueType();
            argSymbol = literal;
        } else {
            // TODO: verify how this can happen
            throw new RuntimeException("Got an argument Symbol that doesn't have a type");
        }
View Full Code Here

        validateSystemColumnPredicate(left);

        Set<Object> rightValues = new HashSet<>();
        for (Expression expression : ((InListExpression)node.getValueList()).getValues()) {
            Symbol right = expression.accept(this, context);
            Literal rightLiteral;
            try {
                rightLiteral = Literal.toLiteral(right, leftType);
                rightValues.add(rightLiteral.value());
            } catch (IllegalArgumentException | ClassCastException e) {
                   throw new IllegalArgumentException(
                           String.format(Locale.ENGLISH, "invalid IN LIST value %s. expected type '%s'",
                                   SymbolFormatter.format(right),
                                   leftType.getName()));
View Full Code Here

TOP

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

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.