Search in sources :

Example 21 with Literal

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

the class ValueNormalizerTest method testNormalizeDynamicEmptyObjectLiteral.

@Test
@SuppressWarnings("unchecked")
public void testNormalizeDynamicEmptyObjectLiteral() throws Exception {
    Reference objRef = userTableInfo.getReference(new ColumnIdent("dyn_empty"));
    Map<String, Object> map = new HashMap<>();
    map.put("time", "2014-02-16T00:00:01");
    map.put("false", true);
    Literal<Map<String, Object>> normalized = (Literal) normalizeInputForReference(Literal.of(map), objRef);
    assertThat((String) normalized.value().get("time"), is("2014-02-16T00:00:01"));
    assertThat((Boolean) normalized.value().get("false"), is(true));
}
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 22 with Literal

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

the class ValueNormalizerTest method testNormalizeDynamicObjectLiteralWithAdditionalColumn.

@Test
public void testNormalizeDynamicObjectLiteralWithAdditionalColumn() throws Exception {
    Reference objInfo = userTableInfo.getReference(new ColumnIdent("dyn"));
    Map<String, Object> map = new HashMap<>();
    map.put("d", 2.9d);
    map.put("half", "1.45");
    Symbol normalized = normalizeInputForReference(Literal.of(map), objInfo);
    assertThat(normalized, instanceOf(Literal.class));
    // stays the same
    assertThat(((Literal) normalized).value(), Matchers.<Object>is(map));
}
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 23 with Literal

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

the class ValueNormalizerTest method testNormalizeDynamicNewColumnTimestamp.

@Test
public void testNormalizeDynamicNewColumnTimestamp() throws Exception {
    Reference objInfo = userTableInfo.getReference(new ColumnIdent("dyn"));
    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 24 with Literal

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

the class ValueNormalizerTest method testNormalizeObjectLiteralConvertFromString.

@Test
public void testNormalizeObjectLiteralConvertFromString() throws Exception {
    Reference objInfo = userTableInfo.getReference(new ColumnIdent("dyn"));
    Map<String, Object> map = new HashMap<>();
    map.put("d", "2.9");
    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));
}
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 25 with Literal

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

the class ValueNormalizerTest method testNormalizeDynamicNewColumnNoTimestamp.

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

        {
            put("no_time", "1970");
        }
    };
    Literal<Map<String, Object>> literal = (Literal) normalizeInputForReference(Literal.of(map), objInfo);
    assertThat((String) literal.value().get("no_time"), is("1970"));
}
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)

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