Search in sources :

Example 41 with ArrayType

use of io.crate.types.ArrayType in project crate by crate.

the class CastFunctionTest method test_cast_wkt_point_string_array_to_geo_shape_array.

@Test
public void test_cast_wkt_point_string_array_to_geo_shape_array() {
    Symbol funcSymbol = sqlExpressions.asSymbol("['POINT(2 3)']::array(geo_shape)");
    assertThat(funcSymbol.valueType(), is(new ArrayType<>(GEO_SHAPE)));
    // noinspection unchecked
    var geoShapes = (List<Map<String, Object>>) ((Literal<?>) funcSymbol).value();
    assertThat(GEO_SHAPE.compare(geoShapes.get(0), Map.of(GeoJSONUtils.TYPE_FIELD, GeoJSONUtils.POINT, GeoJSONUtils.COORDINATES_FIELD, new Double[] { 2.0, 3.0 })), is(0));
}
Also used : ArrayType(io.crate.types.ArrayType) Symbol(io.crate.expression.symbol.Symbol) List(java.util.List) BitString(io.crate.sql.tree.BitString) Test(org.junit.Test)

Example 42 with ArrayType

use of io.crate.types.ArrayType in project crate by crate.

the class SysNodesTableInfoTest method test_column_that_is_a_child_of_an_array_has_array_type_on_select.

@Test
public void test_column_that_is_a_child_of_an_array_has_array_type_on_select() {
    var table = SysNodesTableInfo.create();
    Reference ref = table.getReference(new ColumnIdent("fs", List.of("data", "path")));
    assertThat(ref.valueType(), is(new ArrayType<>(DataTypes.STRING)));
    SQLExecutor e = SQLExecutor.builder(clusterService).build();
    AnalyzedRelation statement = e.analyze("select fs['data']['path'] from sys.nodes");
    assertThat(statement.outputs().get(0).valueType(), is(new ArrayType<>(DataTypes.STRING)));
}
Also used : ArrayType(io.crate.types.ArrayType) SQLExecutor(io.crate.testing.SQLExecutor) AnalyzedRelation(io.crate.analyze.relations.AnalyzedRelation) Test(org.junit.Test) CrateDummyClusterServiceUnitTest(io.crate.test.integration.CrateDummyClusterServiceUnitTest)

Example 43 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.equalTo(new ArrayType(DataTypes.STRING)));
}
Also used : ArrayType(io.crate.types.ArrayType) ColumnIdent(io.crate.metadata.ColumnIdent) DataType(io.crate.types.DataType) CrateDummyClusterServiceUnitTest(io.crate.test.integration.CrateDummyClusterServiceUnitTest) Test(org.junit.Test)

Example 44 with ArrayType

use of io.crate.types.ArrayType in project crate by crate.

the class DocIndexMetadataTest method testStringArrayWithFulltextIndex.

@Test
public void testStringArrayWithFulltextIndex() throws Exception {
    DocIndexMetadata metadata = getDocIndexMetadataFromStatement("create table t (tags array(string) index using fulltext)");
    Reference reference = metadata.columns().iterator().next();
    assertThat(reference.valueType(), equalTo(new ArrayType(DataTypes.STRING)));
}
Also used : ArrayType(io.crate.types.ArrayType) GeneratedReference(io.crate.metadata.GeneratedReference) BytesReference(org.elasticsearch.common.bytes.BytesReference) SymbolMatchers.isReference(io.crate.testing.SymbolMatchers.isReference) IndexReference(io.crate.metadata.IndexReference) Reference(io.crate.metadata.Reference) CrateDummyClusterServiceUnitTest(io.crate.test.integration.CrateDummyClusterServiceUnitTest) Test(org.junit.Test)

Example 45 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").endObject().startObject("title").field("type", "string").field("index", "false").endObject().startObject("array_col").field("type", "array").startObject("inner").field("type", "ip").endObject().endObject().startObject("nested").field("type", "object").startObject("properties").startObject("inner_nested").field("type", "array").startObject("inner").field("type", "date").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(new ArrayType(DataTypes.IP)));
    assertThat(docIndexMetadata.references().get(ColumnIdent.fromPath("nested.inner_nested")).valueType(), is(new ArrayType(DataTypes.TIMESTAMPZ)));
}
Also used : ArrayType(io.crate.types.ArrayType) IndexMetadata(org.elasticsearch.cluster.metadata.IndexMetadata) XContentBuilder(org.elasticsearch.common.xcontent.XContentBuilder) CrateDummyClusterServiceUnitTest(io.crate.test.integration.CrateDummyClusterServiceUnitTest) Test(org.junit.Test)

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