Search in sources :

Example 31 with ArrayType

use of io.crate.types.ArrayType in project crate by crate.

the class DataTypeTest method testForValueWithArrayWithNullValues.

@Test
public void testForValueWithArrayWithNullValues() {
    DataType dataType = DataTypes.guessType(new String[] { "foo", null, "bar" });
    assertEquals(dataType, new ArrayType(DataTypes.STRING));
}
Also used : ArrayType(io.crate.types.ArrayType) DataType(io.crate.types.DataType) Test(org.junit.Test)

Example 32 with ArrayType

use of io.crate.types.ArrayType in project crate by crate.

the class LiteralTest method testNestedArrayLiteral.

@Test
public void testNestedArrayLiteral() throws Exception {
    for (DataType<?> type : DataTypes.PRIMITIVE_TYPES) {
        DataType<?> nestedType = new ArrayType<>(new ArrayType<>(type));
        Object value;
        if (type.id() == BooleanType.ID) {
            value = true;
        } else if (type.id() == DataTypes.IP.id()) {
            value = type.sanitizeValue("123.34.243.23");
        } else if (type.id() == DataTypes.INTERVAL.id()) {
            value = type.sanitizeValue(new Period().withSeconds(100));
        } else {
            value = type.implicitCast("0");
        }
        var nestedValue = List.of(List.of(value));
        Literal<?> nestedLiteral = Literal.ofUnchecked(nestedType, nestedValue);
        assertThat(nestedLiteral.valueType(), is(nestedType));
        assertThat(nestedLiteral.value(), is(nestedValue));
    }
}
Also used : ArrayType(io.crate.types.ArrayType) Period(org.joda.time.Period) Test(org.junit.Test)

Example 33 with ArrayType

use of io.crate.types.ArrayType in project crate by crate.

the class UpdateAnalyzerTest method testUpdateDynamicNestedArrayParamLiteral.

@Test
public void testUpdateDynamicNestedArrayParamLiteral() throws Exception {
    AnalyzedUpdateStatement update = analyze("update users set new=[[1.9, 4.8], [9.7, 12.7]]");
    DataType dataType = update.assignmentByTargetCol().values().iterator().next().valueType();
    assertThat(dataType, is(new ArrayType(new ArrayType(DoubleType.INSTANCE))));
}
Also used : ArrayType(io.crate.types.ArrayType) DataType(io.crate.types.DataType) CrateDummyClusterServiceUnitTest(io.crate.test.integration.CrateDummyClusterServiceUnitTest) Test(org.junit.Test)

Example 34 with ArrayType

use of io.crate.types.ArrayType in project crate by crate.

the class UpdateAnalyzerTest method testUpdateDynamicNestedArrayParam.

@Test
public void testUpdateDynamicNestedArrayParam() throws Exception {
    Object[] params = { new Object[] { new Object[] { 1.9, 4.8 }, new Object[] { 9.7, 12.7 } } };
    AnalyzedUpdateStatement update = analyze("update users set new=? where id=1");
    Assignments assignments = Assignments.convert(update.assignmentByTargetCol(), e.nodeCtx);
    Symbol[] sources = assignments.bindSources(((DocTableInfo) update.table().tableInfo()), new RowN(params), SubQueryResults.EMPTY);
    DataType dataType = sources[0].valueType();
    assertThat(dataType, is(new ArrayType(new ArrayType(DoubleType.INSTANCE))));
}
Also used : ArrayType(io.crate.types.ArrayType) DocTableInfo(io.crate.metadata.doc.DocTableInfo) RowN(io.crate.data.RowN) ParameterSymbol(io.crate.expression.symbol.ParameterSymbol) Symbol(io.crate.expression.symbol.Symbol) Assignments(io.crate.expression.symbol.Assignments) DataType(io.crate.types.DataType) CrateDummyClusterServiceUnitTest(io.crate.test.integration.CrateDummyClusterServiceUnitTest) Test(org.junit.Test)

Example 35 with ArrayType

use of io.crate.types.ArrayType in project crate by crate.

the class UpdateAnalyzerTest method testUpdateWithEmptyObjectArray.

@Test
public void testUpdateWithEmptyObjectArray() throws Exception {
    Object[] params = { new Map[0], 0 };
    AnalyzedUpdateStatement update = analyze("update users set friends=? where other_id=0");
    Assignments assignments = Assignments.convert(update.assignmentByTargetCol(), e.nodeCtx);
    Symbol[] sources = assignments.bindSources(((DocTableInfo) update.table().tableInfo()), new RowN(params), SubQueryResults.EMPTY);
    assertThat(sources[0].valueType().id(), is(ArrayType.ID));
    assertThat(((ArrayType) sources[0].valueType()).innerType().id(), is(ObjectType.ID));
    assertThat(((List) ((Literal) sources[0]).value()).size(), is(0));
}
Also used : ArrayType(io.crate.types.ArrayType) DocTableInfo(io.crate.metadata.doc.DocTableInfo) RowN(io.crate.data.RowN) ParameterSymbol(io.crate.expression.symbol.ParameterSymbol) Symbol(io.crate.expression.symbol.Symbol) Literal(io.crate.expression.symbol.Literal) SymbolMatchers.isLiteral(io.crate.testing.SymbolMatchers.isLiteral) Assignments(io.crate.expression.symbol.Assignments) CrateDummyClusterServiceUnitTest(io.crate.test.integration.CrateDummyClusterServiceUnitTest) Test(org.junit.Test)

Aggregations

ArrayType (io.crate.types.ArrayType)76 Test (org.junit.Test)53 DataType (io.crate.types.DataType)35 CrateUnitTest (io.crate.test.integration.CrateUnitTest)20 CrateDummyClusterServiceUnitTest (io.crate.test.integration.CrateDummyClusterServiceUnitTest)15 Symbol (io.crate.expression.symbol.Symbol)9 ArrayList (java.util.ArrayList)8 List (java.util.List)8 BytesRef (org.apache.lucene.util.BytesRef)8 DocTableInfo (io.crate.metadata.doc.DocTableInfo)7 Literal (io.crate.analyze.symbol.Literal)6 Literal (io.crate.expression.symbol.Literal)6 ColumnIdent (io.crate.metadata.ColumnIdent)6 Input (io.crate.data.Input)5 HashMap (java.util.HashMap)5 Function (io.crate.analyze.symbol.Function)4 Reference (io.crate.metadata.Reference)4 DataTypes (io.crate.types.DataTypes)4 AnalyzedRelation (io.crate.analyze.relations.AnalyzedRelation)3 TransactionContext (io.crate.metadata.TransactionContext)3