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