Search in sources :

Example 61 with ArrayType

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

the class DataTypeTest method testForValueWithList.

@Test
public void testForValueWithList() {
    List<String> strings = Arrays.asList("foo", "bar");
    DataType dataType = DataTypes.guessType(strings);
    assertEquals(dataType, new ArrayType(DataTypes.STRING));
    List<Integer> integers = Arrays.asList(1, 2, 3);
    dataType = DataTypes.guessType(integers);
    assertEquals(dataType, new ArrayType(DataTypes.INTEGER));
}
Also used : ArrayType(io.crate.types.ArrayType) DataType(io.crate.types.DataType) Test(org.junit.Test)

Example 62 with ArrayType

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

the class DataTypeTest method testForValueWithArray.

@Test
public void testForValueWithArray() {
    Boolean[] booleans = new Boolean[] { true, false };
    DataType dataType = DataTypes.guessType(booleans);
    assertEquals(dataType, new ArrayType(DataTypes.BOOLEAN));
}
Also used : ArrayType(io.crate.types.ArrayType) DataType(io.crate.types.DataType) Test(org.junit.Test)

Example 63 with ArrayType

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

the class DataTypeTest method testForValueNestedList.

@Test
public void testForValueNestedList() {
    List<List<String>> nestedStrings = Arrays.asList(Arrays.asList("foo", "bar"), Arrays.asList("f", "b"));
    assertEquals(new ArrayType(new ArrayType(DataTypes.STRING)), DataTypes.guessType(nestedStrings));
}
Also used : ArrayType(io.crate.types.ArrayType) List(java.util.List) Test(org.junit.Test)

Example 64 with ArrayType

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

the class UserDefinedFunctionsMetadataTest method testDataTypeStreaming.

@Test
public void testDataTypeStreaming() throws Exception {
    XContentBuilder builder = XContentFactory.jsonBuilder();
    var type = new ArrayType<>(new ArrayType<>(DataTypes.STRING));
    UserDefinedFunctionMetadata.DataTypeXContent.toXContent(type, builder, ToXContent.EMPTY_PARAMS);
    XContentParser parser = JsonXContent.JSON_XCONTENT.createParser(xContentRegistry(), DeprecationHandler.THROW_UNSUPPORTED_OPERATION, BytesReference.toBytes(BytesReference.bytes(builder)));
    // enter START_OBJECT
    parser.nextToken();
    ArrayType type2 = (ArrayType) UserDefinedFunctionMetadata.DataTypeXContent.fromXContent(parser);
    assertTrue(type.equals(type2));
}
Also used : ArrayType(io.crate.types.ArrayType) XContentBuilder(org.elasticsearch.common.xcontent.XContentBuilder) XContentParser(org.elasticsearch.common.xcontent.XContentParser) Test(org.junit.Test)

Example 65 with ArrayType

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

the class SysSnapshotsTest method testQueryAllColumns.

@Test
public void testQueryAllColumns() throws Exception {
    execute("create table tbl (id int primary key) ");
    Object[][] bulkArgs = new Object[10][];
    for (int i = 0; i < 10; i++) {
        bulkArgs[i] = new Object[] { i };
    }
    execute("insert into tbl (id) values (?)", bulkArgs);
    execute("refresh table tbl");
    ThreadPool threadPool = internalCluster().getInstance(ThreadPool.class);
    execute("CREATE REPOSITORY r1 TYPE fs WITH (location = ?, compress = true)", new Object[] { TEMP_FOLDER.newFolder("backup_s1").getAbsolutePath() });
    long createdTime = threadPool.absoluteTimeInMillis();
    execute("CREATE SNAPSHOT r1.s1 TABLE tbl WITH (wait_for_completion = true)");
    long finishedTime = threadPool.absoluteTimeInMillis();
    execute("select * from sys.snapshots");
    assertThat(response.rowCount(), is(1L));
    assertThat(response.cols(), arrayContaining("concrete_indices", "failures", "finished", "name", "repository", "started", "state", "table_partitions", "tables", "version"));
    ArrayType<String> stringArray = new ArrayType<>(DataTypes.STRING);
    assertThat(response.columnTypes(), arrayContaining(stringArray, stringArray, TimestampType.INSTANCE_WITH_TZ, StringType.INSTANCE, StringType.INSTANCE, TimestampType.INSTANCE_WITH_TZ, StringType.INSTANCE, new ArrayType<>(ObjectType.builder().setInnerType("values", stringArray).setInnerType("table_schema", StringType.INSTANCE).setInnerType("table_name", StringType.INSTANCE).build()), stringArray, StringType.INSTANCE));
    Object[] firstRow = response.rows()[0];
    assertThat((List<Object>) firstRow[0], Matchers.contains(getFqn("tbl")));
    assertThat((List<Object>) firstRow[1], Matchers.empty());
    assertThat((Long) firstRow[2], lessThanOrEqualTo(finishedTime));
    assertThat(firstRow[3], is("s1"));
    assertThat(firstRow[4], is("r1"));
    assertThat((Long) firstRow[5], greaterThanOrEqualTo(createdTime));
    assertThat(firstRow[6], is(SnapshotState.SUCCESS.name()));
    assertThat((List<Object>) firstRow[7], Matchers.empty());
    assertThat((List<Object>) firstRow[8], Matchers.contains(getFqn("tbl")));
    assertThat(firstRow[9], is(Version.CURRENT.toString()));
}
Also used : ArrayType(io.crate.types.ArrayType) ThreadPool(org.elasticsearch.threadpool.ThreadPool) 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