Search in sources :

Example 6 with Literal

use of io.crate.expression.symbol.Literal in project crate by crate.

the class ValueNormalizerTest method testNormalizeIgnoredNewColumnTimestamp.

@Test
public void testNormalizeIgnoredNewColumnTimestamp() throws Exception {
    Reference objInfo = userTableInfo.getReference(new ColumnIdent("ignored"));
    Map<String, Object> map = new HashMap<String, Object>() {

        {
            put("time", "1970-01-01T00:00:00");
        }
    };
    Literal<Map<String, Object>> literal = (Literal) normalizeInputForReference(Literal.of(map), objInfo);
    assertThat((String) literal.value().get("time"), is("1970-01-01T00:00:00"));
}
Also used : ColumnIdent(io.crate.metadata.ColumnIdent) HashMap(java.util.HashMap) Reference(io.crate.metadata.Reference) Literal(io.crate.expression.symbol.Literal) SymbolMatchers.isLiteral(io.crate.testing.SymbolMatchers.isLiteral) HashMap(java.util.HashMap) Map(java.util.Map) CrateDummyClusterServiceUnitTest(io.crate.test.integration.CrateDummyClusterServiceUnitTest) Test(org.junit.Test)

Example 7 with Literal

use of io.crate.expression.symbol.Literal in project crate by crate.

the class ValueNormalizerTest method testNormalizeStringToNumberColumn.

@Test
public void testNormalizeStringToNumberColumn() throws Exception {
    Reference objInfo = userTableInfo.getReference(new ColumnIdent("d"));
    Literal<String> stringDoubleLiteral = Literal.of("298.444");
    Literal literal = (Literal) normalizeInputForReference(stringDoubleLiteral, objInfo);
    assertThat(literal, isLiteral(298.444d, DataTypes.DOUBLE));
}
Also used : ColumnIdent(io.crate.metadata.ColumnIdent) Reference(io.crate.metadata.Reference) Literal(io.crate.expression.symbol.Literal) SymbolMatchers.isLiteral(io.crate.testing.SymbolMatchers.isLiteral) CrateDummyClusterServiceUnitTest(io.crate.test.integration.CrateDummyClusterServiceUnitTest) Test(org.junit.Test)

Example 8 with Literal

use of io.crate.expression.symbol.Literal in project crate by crate.

the class ValueNormalizerTest method testNormalizeObjectLiteral.

@Test
public void testNormalizeObjectLiteral() throws Exception {
    Reference objInfo = userTableInfo.getReference(new ColumnIdent("dyn"));
    Map<String, Object> map = new HashMap<String, Object>() {

        {
            put("d", 2.9d);
            put("inner_strict", new HashMap<String, Object>() {

                {
                    put("double", "-88.7");
                }
            });
        }
    };
    normalizeInputForReference(Literal.of(map), objInfo);
    Symbol normalized = normalizeInputForReference(Literal.of(map), objInfo);
    assertThat(normalized, instanceOf(Literal.class));
    assertThat(((Literal<Map<String, Object>>) normalized).value().get("d"), Matchers.<Object>is(2.9d));
    assertThat(((Literal<Map<String, Object>>) normalized).value().get("inner_strict"), Matchers.<Object>is(new HashMap<String, Object>() {

        {
            put("double", -88.7d);
        }
    }));
}
Also used : ColumnIdent(io.crate.metadata.ColumnIdent) HashMap(java.util.HashMap) Reference(io.crate.metadata.Reference) Symbol(io.crate.expression.symbol.Symbol) Literal(io.crate.expression.symbol.Literal) SymbolMatchers.isLiteral(io.crate.testing.SymbolMatchers.isLiteral) CrateDummyClusterServiceUnitTest(io.crate.test.integration.CrateDummyClusterServiceUnitTest) Test(org.junit.Test)

Example 9 with Literal

use of io.crate.expression.symbol.Literal in project crate by crate.

the class ExpressionAnalyzerTest method testInterval.

@Test
public void testInterval() throws Exception {
    Literal literal = (Literal) expressions.asSymbol("INTERVAL '1' MONTH");
    assertThat(literal.valueType(), is(DataTypes.INTERVAL));
    Period period = (Period) literal.value();
    assertThat(period, is(new Period().withMonths(1)));
}
Also used : Literal(io.crate.expression.symbol.Literal) SymbolMatchers.isLiteral(io.crate.testing.SymbolMatchers.isLiteral) Period(org.joda.time.Period) CrateDummyClusterServiceUnitTest(io.crate.test.integration.CrateDummyClusterServiceUnitTest) Test(org.junit.Test)

Example 10 with Literal

use of io.crate.expression.symbol.Literal in project crate by crate.

the class ExpressionAnalyzerTest method testIntervalConversion.

@Test
public void testIntervalConversion() throws Exception {
    Literal literal = (Literal) expressions.asSymbol("INTERVAL '1' HOUR to SECOND");
    assertThat(literal.valueType(), is(DataTypes.INTERVAL));
    Period period = (Period) literal.value();
    assertThat(period, is(new Period().withSeconds(1)));
}
Also used : Literal(io.crate.expression.symbol.Literal) SymbolMatchers.isLiteral(io.crate.testing.SymbolMatchers.isLiteral) Period(org.joda.time.Period) CrateDummyClusterServiceUnitTest(io.crate.test.integration.CrateDummyClusterServiceUnitTest) Test(org.junit.Test)

Aggregations

Literal (io.crate.expression.symbol.Literal)27 CrateDummyClusterServiceUnitTest (io.crate.test.integration.CrateDummyClusterServiceUnitTest)17 Symbol (io.crate.expression.symbol.Symbol)16 Test (org.junit.Test)16 SymbolMatchers.isLiteral (io.crate.testing.SymbolMatchers.isLiteral)13 HashMap (java.util.HashMap)12 ColumnIdent (io.crate.metadata.ColumnIdent)11 Reference (io.crate.metadata.Reference)11 Map (java.util.Map)11 Function (io.crate.expression.symbol.Function)5 DocTableInfo (io.crate.metadata.doc.DocTableInfo)5 List (java.util.List)5 Nullable (javax.annotation.Nullable)5 Lists2 (io.crate.common.collections.Lists2)4 EvaluatingNormalizer (io.crate.expression.eval.EvaluatingNormalizer)4 CoordinatorTxnCtx (io.crate.metadata.CoordinatorTxnCtx)4 DocTableRelation (io.crate.analyze.relations.DocTableRelation)3 Iterables (io.crate.common.collections.Iterables)3 Tuple (io.crate.common.collections.Tuple)3 Input (io.crate.data.Input)3