Search in sources :

Example 21 with DataType

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

the class DocIndexMetaDataTest method testNewArrayMapping.

@Test
public void testNewArrayMapping() throws Exception {
    XContentBuilder builder = XContentFactory.jsonBuilder().startObject().startObject("_meta").field("primary_keys", "id").endObject().startObject("properties").startObject("id").field("type", "integer").field("index", "not_analyzed").endObject().startObject("title").field("type", "string").field("index", "no").endObject().startObject("array_col").field("type", "array").startObject("inner").field("type", "ip").field("index", "not_analyzed").endObject().endObject().startObject("nested").field("type", "object").startObject("properties").startObject("inner_nested").field("type", "array").startObject("inner").field("type", "date").field("index", "not_analyzed").endObject().endObject().endObject().endObject().endObject().endObject();
    IndexMetaData indexMetaData = getIndexMetaData("test1", builder);
    DocIndexMetaData docIndexMetaData = newMeta(indexMetaData, "test1");
    assertThat(docIndexMetaData.references().get(ColumnIdent.fromPath("array_col")).valueType(), is((DataType) new ArrayType(DataTypes.IP)));
    assertThat(docIndexMetaData.references().get(ColumnIdent.fromPath("nested.inner_nested")).valueType(), is((DataType) new ArrayType(DataTypes.TIMESTAMP)));
}
Also used : ArrayType(io.crate.types.ArrayType) DataType(io.crate.types.DataType) XContentBuilder(org.elasticsearch.common.xcontent.XContentBuilder) IndexMetaData(org.elasticsearch.cluster.metadata.IndexMetaData) Test(org.junit.Test) CrateUnitTest(io.crate.test.integration.CrateUnitTest)

Example 22 with DataType

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

the class DocIndexMetaDataTest method testCreateTableMappingGenerationAndParsingArrayInsideObject.

@Test
public void testCreateTableMappingGenerationAndParsingArrayInsideObject() throws Exception {
    DocIndexMetaData md = getDocIndexMetaDataFromStatement("create table t1 (" + "id int primary key," + "details object as (names array(string))" + ") with (number_of_replicas=0)");
    DataType type = md.references().get(new ColumnIdent("details", "names")).valueType();
    assertThat(type, Matchers.<DataType>equalTo(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 23 with DataType

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

the class AggregationTest method executeAggregation.

public Object[][] executeAggregation(String name, DataType dataType, Object[][] data, List<DataType> argumentTypes) throws Exception {
    FunctionIdent fi;
    InputCollectExpression[] inputs;
    if (dataType != null) {
        fi = new FunctionIdent(name, argumentTypes);
        inputs = new InputCollectExpression[argumentTypes.size()];
        for (int i = 0; i < argumentTypes.size(); i++) {
            inputs[i] = new InputCollectExpression(i);
        }
    } else {
        fi = new FunctionIdent(name, ImmutableList.<DataType>of());
        inputs = new InputCollectExpression[0];
    }
    AggregationFunction impl = (AggregationFunction) functions.get(fi);
    Object state = impl.newState(ramAccountingContext);
    ArrayBucket bucket = new ArrayBucket(data);
    for (Row row : bucket) {
        for (InputCollectExpression i : inputs) {
            i.setNextRow(row);
        }
        state = impl.iterate(ramAccountingContext, state, inputs);
    }
    state = impl.terminatePartial(ramAccountingContext, state);
    return new Object[][] { { state } };
}
Also used : ArrayBucket(io.crate.data.ArrayBucket) FunctionIdent(io.crate.metadata.FunctionIdent) InputCollectExpression(io.crate.operation.collect.InputCollectExpression) DataType(io.crate.types.DataType) Row(io.crate.data.Row)

Example 24 with DataType

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

the class AggregationTest method normalize.

protected Symbol normalize(String functionName, Symbol... args) {
    DataType[] argTypes = new DataType[args.length];
    for (int i = 0; i < args.length; i++) {
        argTypes[i] = args[i].valueType();
    }
    AggregationFunction function = (AggregationFunction) functions.get(new FunctionIdent(functionName, Arrays.asList(argTypes)));
    return function.normalizeSymbol(new Function(function.info(), Arrays.asList(args)), new TransactionContext(SessionContext.SYSTEM_SESSION));
}
Also used : Function(io.crate.analyze.symbol.Function) FunctionIdent(io.crate.metadata.FunctionIdent) TransactionContext(io.crate.metadata.TransactionContext) DataType(io.crate.types.DataType)

Example 25 with DataType

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

the class PercentileAggregationTest method testAllTypesReturnSameResult.

@Test
public void testAllTypesReturnSameResult() throws Exception {
    for (DataType dataType : DataTypes.NUMERIC_PRIMITIVE_TYPES) {
        Double[] fractions = { 0.5, 0.8 };
        Object[][] rows = new Object[10][];
        Object[][] rowsArray = new Object[10][];
        for (int i = 0; i < rows.length; i++) {
            rows[i] = new Object[] { dataType.value(i), fractions[0] };
            rowsArray[i] = new Object[] { dataType.value(i), fractions };
        }
        Object[][] result = executeAggregation(dataType, rows);
        assertEquals(4.5, result[0][0]);
        result = executeAggregation(dataType, rowsArray);
        assertTrue(result[0][0].getClass().isArray());
        assertEquals(2, ((Object[]) result[0][0]).length);
        assertEquals(4.5, ((Object[]) result[0][0])[0]);
        assertEquals(7.2, ((Object[]) result[0][0])[1]);
    }
}
Also used : DataType(io.crate.types.DataType) Test(org.junit.Test) AggregationTest(io.crate.operation.aggregation.AggregationTest)

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