Package io.crate.planner.symbol

Examples of io.crate.planner.symbol.Literal


        Symbol left = function.arguments().get(0);
        if (!left.symbolType().isValueSymbol()) {
            return function;
        }
        Object inValue = ((Literal) left).value();
        Literal inList = (Literal) function.arguments().get(1);
        assert inList.valueType().id() == SetType.ID;
        Set values = (Set)inList.value();

        if (!values.contains(inValue)) {
            return Literal.newLiteral(false);
        }
View Full Code Here


        if (!symbol.arguments().get(0).symbolType().isValueSymbol()) {
            return symbol;
        }

        Literal expression = (Literal) symbol.arguments().get(0);
        Literal pattern = (Literal) symbol.arguments().get(1);
        return Literal.newLiteral(evaluate(expression, pattern));
    }
View Full Code Here

    @Test
    public void testObjectLiteral() throws Exception {
        Symbol s = analyzeExpression("{}");
        assertThat(s, instanceOf(Literal.class));
        Literal l = (Literal)s;
        assertThat(l.value(), is((Object)new HashMap<String, Object>()));

        Literal objectLiteral = (Literal)analyzeExpression("{ident='value'}");
        assertThat(objectLiteral.symbolType(), is(SymbolType.LITERAL));
        assertThat(objectLiteral.valueType(), is((DataType)ObjectType.INSTANCE));
        assertThat(objectLiteral.value(), is((Object) new MapBuilder<String, Object>().put("ident", "value").map()));

        Literal multipleObjectLiteral = (Literal)analyzeExpression("{\"Ident\"=123.4, a={}, ident='string'}");
        Map<String, Object> values = (Map<String, Object>)multipleObjectLiteral.value();
        assertThat(values, is(new MapBuilder<String, Object>()
                .put("Ident", 123.4d)
                .put("a", new HashMap<String, Object>())
                .put("ident", "string")
                .map()));
View Full Code Here

                .map()));
    }

    @Test
    public void testObjectliteralWithParameter() throws Exception {
        Literal objectLiteral = (Literal) analyzeExpression("{ident=?}", new Object[]{1});
        assertThat(objectLiteral.valueType(), is((DataType)ObjectType.INSTANCE));
        assertThat(objectLiteral.value(), is((Object) new MapBuilder<String, Object>().put("ident", 1).map()));
    }
View Full Code Here

        analyzeExpression("{a=1, a=2}");
    }

    @Test
    public void testArrayLiteral() throws Exception {
        Literal emptyArray = (Literal) analyzeExpression("[]");
        assertThat((Object[])emptyArray.value(), is(new Object[0]));
        assertThat(emptyArray.valueType(), is((DataType)new ArrayType(UndefinedType.INSTANCE)));

        Literal singleArray = (Literal) analyzeExpression("[1]");
        assertThat(singleArray.valueType(), is((DataType)new ArrayType(LongType.INSTANCE)));
        assertThat(((Object[])singleArray.value()).length, is(1));
        assertThat(((Object[])singleArray.value())[0], is((Object)1L));

        Literal multiArray = (Literal) analyzeExpression("[1, 2, 3]");
        assertThat(multiArray.valueType(), is((DataType)new ArrayType(LongType.INSTANCE)));
        assertThat(((Object[])multiArray.value()).length, is(3));
        assertThat((Object[])multiArray.value(), is(new Object[]{1L,2L,3L}));
    }
View Full Code Here

        assertThat((Object[])multiArray.value(), is(new Object[]{1L,2L,3L}));
    }

    @Test
    public void testArrayLiteralWithParameter() throws Exception {
        Literal array = (Literal) analyzeExpression("[1, ?]", new Object[]{4L});
        assertThat(array.valueType(), is((DataType)new ArrayType(LongType.INSTANCE)));
        assertThat(((Object[])array.value()).length, is(2));
        assertThat((Object[])array.value(), is(new Object[]{1L, 4L}));
    }
View Full Code Here

    private Object[] eval(final Object objects, DataType innerType) {
        final DataType arrayType = new ArrayType(innerType);
        ToIntArrayFunction impl = (ToIntArrayFunction)functions.get(
                new FunctionIdent(ToIntArrayFunction.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);
        ToFloatArrayFunction impl = (ToFloatArrayFunction)functions.get(
                new FunctionIdent(ToFloatArrayFunction.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);
        ToShortArrayFunction impl = (ToShortArrayFunction)functions.get(
                new FunctionIdent(ToShortArrayFunction.NAME, ImmutableList.of(arrayType)));

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

        Function function = new Function(implementation.info(), Arrays.<Symbol>asList(
                Literal.newLiteral("day"),
                Literal.newLiteral(1401777485000L)
        ));
        Literal day = (Literal)implementation.normalizeSymbol(function);
        assertThat((Long)day.value(), is(1401753600000L));
    }
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.