use of io.crate.types.DataType in project crate by crate.
the class WhereClauseAnalyzerTest method testAnyEqConvertableArrayTypeLiterals.
@Test
public void testAnyEqConvertableArrayTypeLiterals() throws Exception {
WhereClause whereClause = analyzeSelectWhere("select * from users where name = any([1, 2, 3])");
assertThat(whereClause.query(), isFunction(AnyEqOperator.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 testAnyLikeConvertableArrayTypeLiterals.
@Test
public void testAnyLikeConvertableArrayTypeLiterals() throws Exception {
WhereClause whereClause = analyzeSelectWhere("select * from users where name like any([1, 2, 3])");
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 ValueNormalizer method normalizeObjectValue.
@SuppressWarnings("unchecked")
private void normalizeObjectValue(Map<String, Object> value, Reference info) {
for (Map.Entry<String, Object> entry : value.entrySet()) {
AnalyzedColumnDefinition.validateName(entry.getKey());
ColumnIdent nestedIdent = ColumnIdent.getChild(info.ident().columnIdent(), entry.getKey());
TableInfo tableInfo = schemas.getTableInfo(info.ident().tableIdent());
Reference nestedInfo = tableInfo.getReference(nestedIdent);
if (nestedInfo == null) {
if (info.columnPolicy() == ColumnPolicy.IGNORED) {
continue;
}
DynamicReference dynamicReference = null;
if (tableInfo instanceof DocTableInfo) {
dynamicReference = ((DocTableInfo) tableInfo).getDynamic(nestedIdent, true);
}
if (dynamicReference == null) {
throw new ColumnUnknownException(nestedIdent.sqlFqn());
}
DataType type = DataTypes.guessType(entry.getValue());
if (type == null) {
throw new ColumnValidationException(info.ident().columnIdent().sqlFqn(), "Invalid value");
}
dynamicReference.valueType(type);
nestedInfo = dynamicReference;
} else {
if (entry.getValue() == null) {
continue;
}
}
if (nestedInfo.valueType() == DataTypes.OBJECT && entry.getValue() instanceof Map) {
normalizeObjectValue((Map<String, Object>) entry.getValue(), nestedInfo);
} else if (isObjectArray(nestedInfo.valueType()) && entry.getValue() instanceof Object[]) {
normalizeObjectArrayValue((Object[]) entry.getValue(), nestedInfo);
} else {
entry.setValue(normalizePrimitiveValue(entry.getValue(), nestedInfo));
}
}
}
use of io.crate.types.DataType in project crate by crate.
the class AbstractTableRelation method checkNestedArray.
protected Reference checkNestedArray(ColumnIdent ci, Reference reference) {
// TODO: build type correctly as array when the tableInfo is created and remove the conversion here
DataType dataType = null;
ColumnIdent tmpCI = ci;
Reference tmpRI = reference;
while (!tmpCI.isColumn() && hasMatchingParent(tmpRI, IS_OBJECT_ARRAY)) {
if (DataTypes.isCollectionType(reference.valueType())) {
// TODO: remove this limitation with next type refactoring
throw new UnsupportedOperationException("cannot query for arrays inside object arrays explicitly");
}
// return references of primitive types as array
if (dataType == null) {
dataType = new ArrayType(reference.valueType());
if (hasNestedObjectReference(tmpRI))
break;
} else {
dataType = new ArrayType(dataType);
}
tmpCI = tmpCI.getParent();
tmpRI = tableInfo.getReference(tmpCI);
}
if (dataType != null) {
return new Reference(reference.ident(), reference.granularity(), dataType, reference.columnPolicy(), reference.indexType(), reference.isNullable());
} else {
return reference;
}
}
use of io.crate.types.DataType in project crate by crate.
the class DocIndexMetaDataTest method testNoBackwardCompatibleArrayMapping.
@Test
public void testNoBackwardCompatibleArrayMapping() throws Exception {
XContentBuilder builder = XContentFactory.jsonBuilder().startObject().startObject("_meta").field("primary_keys", "id").startObject("columns").startObject("array_col").field("collection_type", "array").endObject().startObject("nested").startObject("properties").startObject("inner_nested").field("collection_type", "array").endObject().endObject().endObject().endObject().endObject().startObject("properties").startObject("id").field("type", "integer").field("index", "not_analyzed").endObject().startObject("title").field("type", "string").field("index", "no").endObject().startObject("array_col").field("type", "ip").field("index", "not_analyzed").endObject().startObject("nested").field("type", "nested").startObject("properties").startObject("inner_nested").field("type", "date").field("index", "not_analyzed").endObject().endObject().endObject().endObject().endObject();
IndexMetaData indexMetaData = getIndexMetaData("test1", builder);
DocIndexMetaData docIndexMetaData = newMeta(indexMetaData, "test1");
// ARRAY TYPES NOT DETECTED
assertThat(docIndexMetaData.references().get(ColumnIdent.fromPath("array_col")).valueType(), is((DataType) DataTypes.IP));
assertThat(docIndexMetaData.references().get(ColumnIdent.fromPath("nested.inner_nested")).valueType(), is((DataType) DataTypes.TIMESTAMP));
}
Aggregations