use of io.crate.types.DataType in project crate by crate.
the class DocIndexMetaDataTest method testCreateTableMappingGenerationAndParsingCompat.
@Test
public void testCreateTableMappingGenerationAndParsingCompat() throws Exception {
DocIndexMetaData md = getDocIndexMetaDataFromStatement("create table foo (" + "id int primary key," + "tags array(string)," + "o object as (" + " age int," + " name string" + ")," + "date timestamp primary key" + ") partitioned by (date)");
assertThat(md.columns().size(), is(4));
assertThat(md.primaryKey(), Matchers.contains(new ColumnIdent("id"), new ColumnIdent("date")));
assertThat(md.references().get(new ColumnIdent("tags")).valueType(), is((DataType) new ArrayType(DataTypes.STRING)));
}
use of io.crate.types.DataType in project crate by crate.
the class ReferenceTest method testEquals.
@Test
public void testEquals() throws Exception {
TableIdent tableIdent = new TableIdent("doc", "test");
ReferenceIdent referenceIdent = new ReferenceIdent(tableIdent, "object_column");
DataType dataType1 = new ArrayType(DataTypes.OBJECT);
DataType dataType2 = new ArrayType(DataTypes.OBJECT);
Reference reference1 = new Reference(referenceIdent, RowGranularity.DOC, dataType1);
Reference reference2 = new Reference(referenceIdent, RowGranularity.DOC, dataType2);
assertTrue(reference1.equals(reference2));
}
use of io.crate.types.DataType in project crate by crate.
the class DocIndexMetaDataTest method testCreateArrayMapping.
@Test
public void testCreateArrayMapping() throws Exception {
DocIndexMetaData md = getDocIndexMetaDataFromStatement("create table t (" + " id integer primary key," + " tags array(string)," + " scores array(short)" + ")");
assertThat(md.references().get(ColumnIdent.fromPath("tags")).valueType(), is((DataType) new ArrayType(DataTypes.STRING)));
assertThat(md.references().get(ColumnIdent.fromPath("scores")).valueType(), is((DataType) new ArrayType(DataTypes.SHORT)));
}
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;
}
Aggregations