Search in sources :

Example 61 with DataType

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

the class DocIndexMetaDataTest method testCreateObjectArrayMapping.

@Test
public void testCreateObjectArrayMapping() throws Exception {
    DocIndexMetaData md = getDocIndexMetaDataFromStatement("create table t (" + "  id integer primary key," + "  tags array(object(strict) as (" + "    size double index off," + "    numbers array(integer)," + "    quote string index using fulltext" + "  ))" + ")");
    assertThat(md.references().get(ColumnIdent.fromPath("tags")).valueType(), is((DataType) new ArrayType(DataTypes.OBJECT)));
    assertThat(md.references().get(ColumnIdent.fromPath("tags")).columnPolicy(), is(ColumnPolicy.STRICT));
    assertThat(md.references().get(ColumnIdent.fromPath("tags.size")).valueType(), is((DataType) DataTypes.DOUBLE));
    assertThat(md.references().get(ColumnIdent.fromPath("tags.size")).indexType(), is(Reference.IndexType.NO));
    assertThat(md.references().get(ColumnIdent.fromPath("tags.numbers")).valueType(), is((DataType) new ArrayType(DataTypes.INTEGER)));
    assertThat(md.references().get(ColumnIdent.fromPath("tags.quote")).valueType(), is((DataType) DataTypes.STRING));
    assertThat(md.references().get(ColumnIdent.fromPath("tags.quote")).indexType(), is(Reference.IndexType.ANALYZED));
}
Also used : ArrayType(io.crate.types.ArrayType) DataType(io.crate.types.DataType) Test(org.junit.Test) CrateUnitTest(io.crate.test.integration.CrateUnitTest)

Example 62 with DataType

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

the class MapComparator method compareMaps.

public static <K, V> int compareMaps(Map<K, V> m1, Map<K, V> m2) {
    Preconditions.checkNotNull(m1, "map is null");
    Preconditions.checkNotNull(m2, "map is null");
    int sizeCompare = Integer.compare(m1.size(), m2.size());
    if (sizeCompare != 0)
        return sizeCompare;
    for (Map.Entry<K, V> entry : m1.entrySet()) {
        V thisValue = entry.getValue();
        V otherValue = m2.get(entry.getKey());
        if (thisValue == null) {
            if (otherValue != null) {
                return 1;
            } else {
                continue;
            }
        }
        if (!thisValue.equals(otherValue)) {
            if (otherValue == null) {
                return -1;
            }
            if (!thisValue.getClass().equals(otherValue.getClass())) {
                DataType leftType = DataTypes.guessType(thisValue);
                int cmp = leftType.compareValueTo(leftType.value(thisValue), leftType.value(otherValue));
                if (cmp == 0) {
                    continue;
                }
                return cmp;
            }
            return 1;
        }
    }
    return 0;
}
Also used : DataType(io.crate.types.DataType) Map(java.util.Map)

Example 63 with DataType

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

the class LengthFunction method register.

private static void register(ScalarFunctionModule module, String name, Function<BytesRef, Integer> func) {
    for (DataType inputType : SUPPORTED_INPUT_TYPES) {
        FunctionIdent ident = new FunctionIdent(name, Collections.singletonList(inputType));
        module.register(new UnaryScalar<>(new FunctionInfo(ident, DataTypes.INTEGER), func));
    }
}
Also used : FunctionIdent(io.crate.metadata.FunctionIdent) DataType(io.crate.types.DataType) FunctionInfo(io.crate.metadata.FunctionInfo)

Example 64 with DataType

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

the class DateFormatFunction method register.

public static void register(ScalarFunctionModule module) {
    List<DataType> supportedTimestampTypes = ImmutableList.<DataType>of(DataTypes.TIMESTAMP, DataTypes.LONG, DataTypes.STRING);
    for (DataType dataType : supportedTimestampTypes) {
        // without format
        module.register(new DateFormatFunction(new FunctionInfo(new FunctionIdent(NAME, ImmutableList.of(dataType)), DataTypes.STRING)));
        // with format
        module.register(new DateFormatFunction(new FunctionInfo(new FunctionIdent(NAME, ImmutableList.of(DataTypes.STRING, dataType)), DataTypes.STRING)));
        // time zone aware variant
        module.register(new DateFormatFunction(new FunctionInfo(new FunctionIdent(NAME, ImmutableList.of(DataTypes.STRING, DataTypes.STRING, dataType)), DataTypes.STRING)));
    }
}
Also used : FunctionIdent(io.crate.metadata.FunctionIdent) DataType(io.crate.types.DataType) FunctionInfo(io.crate.metadata.FunctionInfo)

Example 65 with DataType

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

the class DateTruncFunction method register.

public static void register(ScalarFunctionModule module) {
    List<DataType> supportedTimestampTypes = ImmutableList.of(DataTypes.TIMESTAMP, DataTypes.LONG, DataTypes.STRING);
    for (DataType dataType : supportedTimestampTypes) {
        module.register(new DateTruncFunction(info(DataTypes.STRING, dataType)));
        // time zone aware variant
        module.register(new DateTruncFunction(info(DataTypes.STRING, DataTypes.STRING, dataType)));
    }
}
Also used : DataType(io.crate.types.DataType)

Aggregations

DataType (io.crate.types.DataType)95 ArrayType (io.crate.types.ArrayType)35 Test (org.junit.Test)33 ArrayList (java.util.ArrayList)17 Map (java.util.Map)17 CrateUnitTest (io.crate.test.integration.CrateUnitTest)14 List (java.util.List)12 Symbol (io.crate.expression.symbol.Symbol)11 Literal (io.crate.expression.symbol.Literal)9 ColumnIdent (io.crate.metadata.ColumnIdent)9 HashMap (java.util.HashMap)9 FunctionIdent (io.crate.metadata.FunctionIdent)8 NodeContext (io.crate.metadata.NodeContext)8 Reference (io.crate.metadata.Reference)8 Row (io.crate.data.Row)7 Symbols (io.crate.expression.symbol.Symbols)7 CrateDummyClusterServiceUnitTest (io.crate.test.integration.CrateDummyClusterServiceUnitTest)7 Locale (java.util.Locale)7 Lists2 (io.crate.common.collections.Lists2)6 FunctionInfo (io.crate.metadata.FunctionInfo)6