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 WhereClauseAnalyzerTest method testAnyLikeArrayLiteral.
@Test
public void testAnyLikeArrayLiteral() throws Exception {
WhereClause whereClause = analyzeSelectWhere("select * from users where name like any(['a', 'b', 'c'])");
assertThat(whereClause.query(), isFunction(AnyLikeOperator.NAME, ImmutableList.<DataType>of(DataTypes.STRING, new ArrayType(DataTypes.STRING))));
}
use of io.crate.types.DataType in project crate by crate.
the class WhereClauseAnalyzerTest method testInConvertedToAnyIfOnlyLiterals.
@Test
public void testInConvertedToAnyIfOnlyLiterals() throws Exception {
StringBuilder sb = new StringBuilder("select id from sys.shards where id in (");
int i = 0;
for (; i < 1500; i++) {
sb.append(i);
sb.append(',');
}
sb.append(i++);
sb.append(')');
String s = sb.toString();
WhereClause whereClause = analyzeSelectWhere(s);
assertThat(whereClause.query(), isFunction(AnyEqOperator.NAME, ImmutableList.<DataType>of(DataTypes.INTEGER, new ArrayType(DataTypes.INTEGER))));
}
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));
}
}
Aggregations