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