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();
}
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);
}
}
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));
}
}
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)));
}
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)));
}
Aggregations