Search in sources :

Example 41 with DataType

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

Example 42 with DataType

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

Example 43 with DataType

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

Example 44 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 45 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)

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