Search in sources :

Example 36 with DataType

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

the class DocIndexMetaData method getAnalyzers.

private ImmutableMap<ColumnIdent, String> getAnalyzers(ColumnIdent columnIdent, Map<String, Object> propertiesMap) {
    ImmutableMap.Builder<ColumnIdent, String> builder = ImmutableMap.builder();
    for (Map.Entry<String, Object> columnEntry : propertiesMap.entrySet()) {
        Map<String, Object> columnProperties = (Map) columnEntry.getValue();
        DataType columnDataType = getColumnDataType(columnProperties);
        ColumnIdent newIdent = childIdent(columnIdent, columnEntry.getKey());
        columnProperties = furtherColumnProperties(columnProperties);
        if (columnDataType == DataTypes.OBJECT || (columnDataType.id() == ArrayType.ID && ((ArrayType) columnDataType).innerType() == DataTypes.OBJECT)) {
            if (columnProperties.get("properties") != null) {
                builder.putAll(getAnalyzers(newIdent, (Map<String, Object>) columnProperties.get("properties")));
            }
        }
        String analyzer = (String) columnProperties.get("analyzer");
        if (analyzer != null) {
            builder.put(newIdent, analyzer);
        }
    }
    return builder.build();
}
Also used : ArrayType(io.crate.types.ArrayType) DataType(io.crate.types.DataType)

Example 37 with DataType

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

the class FunctionIdent method writeTo.

@Override
public void writeTo(StreamOutput out) throws IOException {
    out.writeString(name);
    out.writeVInt(argumentTypes.size());
    for (DataType argumentType : argumentTypes) {
        DataTypes.toStream(argumentType, out);
    }
}
Also used : DataType(io.crate.types.DataType)

Example 38 with DataType

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

the class WhereClauseAnalyzerTest method testAnyLikeArrayLiteral.

@Test
public void testAnyLikeArrayLiteral() throws Exception {
    WhereClause whereClause = analyzeSelectWhere("select * from users where name like any(['a', 'b', 'c'])");
    assertThat(whereClause.query(), isFunction(AnyLikeOperator.NAME, ImmutableList.<DataType>of(DataTypes.STRING, new ArrayType(DataTypes.STRING))));
}
Also used : ArrayType(io.crate.types.ArrayType) WhereClause(io.crate.analyze.WhereClause) DataType(io.crate.types.DataType) Test(org.junit.Test) CrateUnitTest(io.crate.test.integration.CrateUnitTest)

Example 39 with DataType

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

the class WhereClauseAnalyzerTest method testInConvertedToAnyIfOnlyLiterals.

@Test
public void testInConvertedToAnyIfOnlyLiterals() throws Exception {
    StringBuilder sb = new StringBuilder("select id from sys.shards where id in (");
    int i = 0;
    for (; i < 1500; i++) {
        sb.append(i);
        sb.append(',');
    }
    sb.append(i++);
    sb.append(')');
    String s = sb.toString();
    WhereClause whereClause = analyzeSelectWhere(s);
    assertThat(whereClause.query(), isFunction(AnyEqOperator.NAME, ImmutableList.<DataType>of(DataTypes.INTEGER, new ArrayType(DataTypes.INTEGER))));
}
Also used : ArrayType(io.crate.types.ArrayType) WhereClause(io.crate.analyze.WhereClause) DataType(io.crate.types.DataType) Test(org.junit.Test) CrateUnitTest(io.crate.test.integration.CrateUnitTest)

Example 40 with DataType

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

the class LiteralTest method testNestedArrayLiteral.

@Test
public void testNestedArrayLiteral() throws Exception {
    for (DataType type : DataTypes.PRIMITIVE_TYPES) {
        DataType nestedType = new ArrayType(new ArrayType(type));
        Object value;
        if (type.id() == BooleanType.ID) {
            value = true;
        } else if (type.id() == DataTypes.IP.id()) {
            value = type.value("123.34.243.23");
        } else {
            value = type.value("0");
        }
        Object nestedValue = new Object[][] { new Object[] { value } };
        Literal nestedLiteral = Literal.of(nestedType, nestedValue);
        assertThat(nestedLiteral.valueType(), is(nestedType));
        assertThat(nestedLiteral.value(), is(nestedValue));
    }
}
Also used : ArrayType(io.crate.types.ArrayType) DataType(io.crate.types.DataType) Test(org.junit.Test) CrateUnitTest(io.crate.test.integration.CrateUnitTest)

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