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));
}
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));
}
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));
}
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));
}
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()));
}
Aggregations