Search in sources :

Example 56 with DataType

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

the class DocIndexMetaData method getAnalyzers.

private ImmutableMap<ColumnIdent, String> getAnalyzers(ColumnIdent columnIdent, Map<String, Object> propertiesMap) {
    ImmutableMap.Builder<ColumnIdent, String> builder = ImmutableMap.builder();
    for (Map.Entry<String, Object> columnEntry : propertiesMap.entrySet()) {
        Map<String, Object> columnProperties = (Map) columnEntry.getValue();
        DataType columnDataType = getColumnDataType(columnProperties);
        ColumnIdent newIdent = childIdent(columnIdent, columnEntry.getKey());
        columnProperties = furtherColumnProperties(columnProperties);
        if (columnDataType == DataTypes.OBJECT || (columnDataType.id() == ArrayType.ID && ((ArrayType) columnDataType).innerType() == DataTypes.OBJECT)) {
            if (columnProperties.get("properties") != null) {
                builder.putAll(getAnalyzers(newIdent, (Map<String, Object>) columnProperties.get("properties")));
            }
        }
        String analyzer = (String) columnProperties.get("analyzer");
        if (analyzer != null) {
            builder.put(newIdent, analyzer);
        }
    }
    return builder.build();
}
Also used : ArrayType(io.crate.types.ArrayType) DataType(io.crate.types.DataType)

Example 57 with DataType

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

the class FunctionIdent method writeTo.

@Override
public void writeTo(StreamOutput out) throws IOException {
    out.writeString(name);
    out.writeVInt(argumentTypes.size());
    for (DataType argumentType : argumentTypes) {
        DataTypes.toStream(argumentType, out);
    }
}
Also used : DataType(io.crate.types.DataType)

Example 58 with DataType

use of io.crate.types.DataType 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.value("123.34.243.23");
        } else {
            value = type.value("0");
        }
        Object nestedValue = new Object[][] { new Object[] { value } };
        Literal nestedLiteral = Literal.of(nestedType, nestedValue);
        assertThat(nestedLiteral.valueType(), is(nestedType));
        assertThat(nestedLiteral.value(), is(nestedValue));
    }
}
Also used : ArrayType(io.crate.types.ArrayType) DataType(io.crate.types.DataType) Test(org.junit.Test) CrateUnitTest(io.crate.test.integration.CrateUnitTest)

Example 59 with DataType

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

the class DocIndexMetaDataTest method testCreateTableMappingGenerationAndParsingCompat.

@Test
public void testCreateTableMappingGenerationAndParsingCompat() throws Exception {
    DocIndexMetaData md = getDocIndexMetaDataFromStatement("create table foo (" + "id int primary key," + "tags array(string)," + "o object as (" + "   age int," + "   name string" + ")," + "date timestamp primary key" + ") partitioned by (date)");
    assertThat(md.columns().size(), is(4));
    assertThat(md.primaryKey(), Matchers.contains(new ColumnIdent("id"), new ColumnIdent("date")));
    assertThat(md.references().get(new ColumnIdent("tags")).valueType(), is((DataType) new ArrayType(DataTypes.STRING)));
}
Also used : ArrayType(io.crate.types.ArrayType) DataType(io.crate.types.DataType) Test(org.junit.Test) CrateUnitTest(io.crate.test.integration.CrateUnitTest)

Example 60 with DataType

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

the class DocIndexMetaDataTest method testCreateArrayMapping.

@Test
public void testCreateArrayMapping() throws Exception {
    DocIndexMetaData md = getDocIndexMetaDataFromStatement("create table t (" + "  id integer primary key," + "  tags array(string)," + "  scores array(short)" + ")");
    assertThat(md.references().get(ColumnIdent.fromPath("tags")).valueType(), is((DataType) new ArrayType(DataTypes.STRING)));
    assertThat(md.references().get(ColumnIdent.fromPath("scores")).valueType(), is((DataType) new ArrayType(DataTypes.SHORT)));
}
Also used : ArrayType(io.crate.types.ArrayType) DataType(io.crate.types.DataType) Test(org.junit.Test) CrateUnitTest(io.crate.test.integration.CrateUnitTest)

Aggregations

DataType (io.crate.types.DataType)95 ArrayType (io.crate.types.ArrayType)35 Test (org.junit.Test)33 ArrayList (java.util.ArrayList)17 Map (java.util.Map)17 CrateUnitTest (io.crate.test.integration.CrateUnitTest)14 List (java.util.List)12 Symbol (io.crate.expression.symbol.Symbol)11 Literal (io.crate.expression.symbol.Literal)9 ColumnIdent (io.crate.metadata.ColumnIdent)9 HashMap (java.util.HashMap)9 FunctionIdent (io.crate.metadata.FunctionIdent)8 NodeContext (io.crate.metadata.NodeContext)8 Reference (io.crate.metadata.Reference)8 Row (io.crate.data.Row)7 Symbols (io.crate.expression.symbol.Symbols)7 CrateDummyClusterServiceUnitTest (io.crate.test.integration.CrateDummyClusterServiceUnitTest)7 Locale (java.util.Locale)7 Lists2 (io.crate.common.collections.Lists2)6 FunctionInfo (io.crate.metadata.FunctionInfo)6