Search in sources :

Example 11 with DataType

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

Example 12 with DataType

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

Example 13 with DataType

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"));
}
Also used : DataType(io.crate.types.DataType) Map(java.util.Map) File(java.io.File) Test(org.junit.Test)

Example 14 with DataType

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);
}
Also used : FeatureMatcher(org.hamcrest.FeatureMatcher) Matcher(org.hamcrest.Matcher) DataType(io.crate.types.DataType)

Example 15 with DataType

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);
    }
}
Also used : DataType(io.crate.types.DataType) IntArrayList(com.carrotsearch.hppc.IntArrayList)

Aggregations

DataType (io.crate.types.DataType)64 ArrayType (io.crate.types.ArrayType)30 Test (org.junit.Test)30 CrateUnitTest (io.crate.test.integration.CrateUnitTest)28 FunctionIdent (io.crate.metadata.FunctionIdent)8 FunctionInfo (io.crate.metadata.FunctionInfo)7 WhereClause (io.crate.analyze.WhereClause)6 Symbol (io.crate.analyze.symbol.Symbol)4 Function (io.crate.analyze.symbol.Function)3 Input (io.crate.data.Input)3 Map (java.util.Map)3 ColumnUnknownException (io.crate.exceptions.ColumnUnknownException)2 ColumnIdent (io.crate.metadata.ColumnIdent)2 Reference (io.crate.metadata.Reference)2 DocTableInfo (io.crate.metadata.doc.DocTableInfo)2 TableInfo (io.crate.metadata.table.TableInfo)2 SubscriptFunction (io.crate.operation.scalar.SubscriptFunction)2 AddFunction (io.crate.operation.scalar.arithmetic.AddFunction)2 DistanceFunction (io.crate.operation.scalar.geo.DistanceFunction)2 MatchesFunction (io.crate.operation.scalar.regex.MatchesFunction)2