use of io.crate.types.ArrayType 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.ArrayType in project crate by crate.
the class DocIndexMetaDataTest method testNewArrayMapping.
@Test
public void testNewArrayMapping() throws Exception {
XContentBuilder builder = XContentFactory.jsonBuilder().startObject().startObject("_meta").field("primary_keys", "id").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", "array").startObject("inner").field("type", "ip").field("index", "not_analyzed").endObject().endObject().startObject("nested").field("type", "object").startObject("properties").startObject("inner_nested").field("type", "array").startObject("inner").field("type", "date").field("index", "not_analyzed").endObject().endObject().endObject().endObject().endObject().endObject();
IndexMetaData indexMetaData = getIndexMetaData("test1", builder);
DocIndexMetaData docIndexMetaData = newMeta(indexMetaData, "test1");
assertThat(docIndexMetaData.references().get(ColumnIdent.fromPath("array_col")).valueType(), is((DataType) new ArrayType(DataTypes.IP)));
assertThat(docIndexMetaData.references().get(ColumnIdent.fromPath("nested.inner_nested")).valueType(), is((DataType) new ArrayType(DataTypes.TIMESTAMP)));
}
use of io.crate.types.ArrayType in project crate by crate.
the class DocIndexMetaDataTest method testCreateTableMappingGenerationAndParsingArrayInsideObject.
@Test
public void testCreateTableMappingGenerationAndParsingArrayInsideObject() throws Exception {
DocIndexMetaData md = getDocIndexMetaDataFromStatement("create table t1 (" + "id int primary key," + "details object as (names array(string))" + ") with (number_of_replicas=0)");
DataType type = md.references().get(new ColumnIdent("details", "names")).valueType();
assertThat(type, Matchers.<DataType>equalTo(new ArrayType(DataTypes.STRING)));
}
use of io.crate.types.ArrayType in project crate by crate.
the class AbstractScalarFunctionsTest method prepareFunctions.
@Before
public void prepareFunctions() throws Exception {
DocTableInfo tableInfo = TestingTableInfo.builder(new TableIdent(DocSchemaInfo.NAME, "users"), null).add("id", DataTypes.INTEGER).add("name", DataTypes.STRING).add("tags", new ArrayType(DataTypes.STRING)).add("age", DataTypes.INTEGER).add("a", DataTypes.INTEGER).add("x", DataTypes.LONG).add("shape", DataTypes.GEO_SHAPE).add("timestamp", DataTypes.TIMESTAMP).add("timezone", DataTypes.STRING).add("interval", DataTypes.STRING).add("time_format", DataTypes.STRING).add("long_array", new ArrayType(DataTypes.LONG)).add("int_array", new ArrayType(DataTypes.INTEGER)).add("long_set", new SetType(DataTypes.LONG)).add("regex_pattern", DataTypes.STRING).add("geoshape", DataTypes.GEO_SHAPE).add("geopoint", DataTypes.GEO_POINT).add("geostring", DataTypes.STRING).add("is_awesome", DataTypes.BOOLEAN).add("double_val", DataTypes.DOUBLE).add("float_val", DataTypes.DOUBLE).add("short_val", DataTypes.SHORT).add("obj", DataTypes.OBJECT, ImmutableList.of()).build();
DocTableRelation tableRelation = new DocTableRelation(tableInfo);
tableSources = ImmutableMap.of(new QualifiedName("users"), tableRelation);
sqlExpressions = new SqlExpressions(tableSources);
functions = sqlExpressions.getInstance(Functions.class);
}
use of io.crate.types.ArrayType in project crate by crate.
the class ArrayCatFunction method evaluate.
@Override
public Object[] evaluate(Input[] args) {
DataType innerType = ((ArrayType) this.info().returnType()).innerType();
List<Object> resultList = new ArrayList<>();
for (Input array : args) {
Object arrayValue = array.value();
if (arrayValue == null) {
continue;
}
Object[] arg = (Object[]) arrayValue;
for (Object element : arg) {
resultList.add(innerType.value(element));
}
}
return resultList.toArray();
}
Aggregations