Search in sources :

Example 16 with ArrayType

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;
    }
}
Also used : ArrayType(io.crate.types.ArrayType) ColumnIdent(io.crate.metadata.ColumnIdent) Reference(io.crate.metadata.Reference) DataType(io.crate.types.DataType)

Example 17 with ArrayType

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)));
}
Also used : ArrayType(io.crate.types.ArrayType) DataType(io.crate.types.DataType) XContentBuilder(org.elasticsearch.common.xcontent.XContentBuilder) IndexMetaData(org.elasticsearch.cluster.metadata.IndexMetaData) Test(org.junit.Test) CrateUnitTest(io.crate.test.integration.CrateUnitTest)

Example 18 with ArrayType

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)));
}
Also used : ArrayType(io.crate.types.ArrayType) DataType(io.crate.types.DataType) Test(org.junit.Test) CrateUnitTest(io.crate.test.integration.CrateUnitTest)

Example 19 with ArrayType

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);
}
Also used : ArrayType(io.crate.types.ArrayType) DocTableInfo(io.crate.metadata.doc.DocTableInfo) SetType(io.crate.types.SetType) QualifiedName(io.crate.sql.tree.QualifiedName) DocTableRelation(io.crate.analyze.relations.DocTableRelation) SqlExpressions(io.crate.testing.SqlExpressions) Before(org.junit.Before)

Example 20 with ArrayType

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();
}
Also used : ArrayType(io.crate.types.ArrayType) Input(io.crate.data.Input) ArrayList(java.util.ArrayList) DataType(io.crate.types.DataType)

Aggregations

ArrayType (io.crate.types.ArrayType)76 Test (org.junit.Test)53 DataType (io.crate.types.DataType)35 CrateUnitTest (io.crate.test.integration.CrateUnitTest)20 CrateDummyClusterServiceUnitTest (io.crate.test.integration.CrateDummyClusterServiceUnitTest)15 Symbol (io.crate.expression.symbol.Symbol)9 ArrayList (java.util.ArrayList)8 List (java.util.List)8 BytesRef (org.apache.lucene.util.BytesRef)8 DocTableInfo (io.crate.metadata.doc.DocTableInfo)7 Literal (io.crate.analyze.symbol.Literal)6 Literal (io.crate.expression.symbol.Literal)6 ColumnIdent (io.crate.metadata.ColumnIdent)6 Input (io.crate.data.Input)5 HashMap (java.util.HashMap)5 Function (io.crate.analyze.symbol.Function)4 Reference (io.crate.metadata.Reference)4 DataTypes (io.crate.types.DataTypes)4 AnalyzedRelation (io.crate.analyze.relations.AnalyzedRelation)3 TransactionContext (io.crate.metadata.TransactionContext)3