use of io.crate.types.DataType in project crate by crate.
the class DataTypeTest method testForValueWithArrayWithNullValues.
@Test
public void testForValueWithArrayWithNullValues() {
DataType dataType = DataTypes.guessType(new String[] { "foo", null, "bar" });
assertEquals(dataType, new ArrayType(DataTypes.STRING));
}
use of io.crate.types.DataType in project crate by crate.
the class DataTypeTest method testForValueWithObjectList.
@Test
public void testForValueWithObjectList() {
Map<String, Object> objA = new HashMap<>();
objA.put("a", 1);
Map<String, Object> objB = new HashMap<>();
Map<String, Object> objBNested = new HashMap<>();
objB.put("b", objBNested);
objBNested.put("bn1", 1);
objBNested.put("bn2", 2);
List<Object> objects = Arrays.<Object>asList(objA, objB);
DataType dataType = DataTypes.guessType(objects);
assertEquals(dataType, new ArrayType(DataTypes.OBJECT));
}
use of io.crate.types.DataType in project crate by crate.
the class SysRepositoriesServiceTest method testQueryAllColumns.
@Test
public void testQueryAllColumns() throws Exception {
execute("select * from sys.repositories");
assertThat(response.rowCount(), is(1L));
assertThat(response.cols().length, is(3));
assertThat(response.cols(), is(new String[] { "name", "settings", "type" }));
assertThat(response.columnTypes(), is(new DataType[] { StringType.INSTANCE, ObjectType.INSTANCE, StringType.INSTANCE }));
assertThat((String) response.rows()[0][0], is("test-repo"));
Map<String, Object> settings = (Map<String, Object>) response.rows()[0][1];
assertThat(settings.size(), is(3));
assertThat((String) settings.get("location"), is(new File(TEMP_FOLDER.getRoot(), "backup").getAbsolutePath()));
assertThat((String) settings.get("chunk_size"), is("5k"));
assertThat((String) settings.get("compress"), is("false"));
assertThat((String) response.rows()[0][2], is("fs"));
}
use of io.crate.types.DataType in project crate by crate.
the class SymbolMatchers method isFunction.
public static Matcher<Symbol> isFunction(final String name, @Nullable final List<DataType> argumentTypes) {
if (argumentTypes == null) {
return isFunction(name);
}
Matcher[] argMatchers = new Matcher[argumentTypes.size()];
ListIterator<DataType> it = argumentTypes.listIterator();
while (it.hasNext()) {
int i = it.nextIndex();
DataType type = it.next();
argMatchers[i] = hasDataType(type);
}
//noinspection unchecked
return isFunction(name, argMatchers);
}
use of io.crate.types.DataType in project crate by crate.
the class BytesRefUtils method ensureStringTypesAreStrings.
public static void ensureStringTypesAreStrings(DataType[] dataTypes, Object[][] rows) {
if (rows.length == 0) {
return;
}
// NOTE: currently BytesRef inside Maps aren't converted here because
// if the map is coming from a ESSearchTask/EsGetTask they already contain strings
// and we have no case in which another Task returns a Map with ByteRefs/Strings inside.
final IntArrayList stringColumns = new IntArrayList();
final IntArrayList stringCollectionColumns = new IntArrayList();
int idx = 0;
for (DataType dataType : dataTypes) {
if (BYTES_REF_TYPES.contains(dataType)) {
stringColumns.add(idx);
} else if ((DataTypes.isCollectionType(dataType) && (BYTES_REF_TYPES.contains(((CollectionType) dataType).innerType())))) {
stringCollectionColumns.add(idx);
}
idx++;
}
for (Object[] row : rows) {
convertStringColumns(row, stringColumns);
convertStringCollectionColumns(row, stringCollectionColumns);
}
}
Aggregations