use of io.crate.metadata.FunctionIdent in project crate by crate.
the class GroupingIntegerCollectorBenchmark method createGroupBySumCollector.
private GroupingCollector createGroupBySumCollector(Functions functions) {
InputCollectExpression keyInput = new InputCollectExpression(0);
List<Input<?>> keyInputs = Arrays.<Input<?>>asList(keyInput);
CollectExpression[] collectExpressions = new CollectExpression[] { keyInput };
FunctionIdent functionIdent = new FunctionIdent(SumAggregation.NAME, Arrays.asList(DataTypes.INTEGER));
FunctionInfo functionInfo = new FunctionInfo(functionIdent, DataTypes.INTEGER, FunctionInfo.Type.AGGREGATE);
AggregationFunction sumAgg = (AggregationFunction) functions.get(functionIdent);
Aggregation aggregation = Aggregation.finalAggregation(functionInfo, Arrays.asList(new InputColumn(0)), Aggregation.Step.ITER);
Aggregator[] aggregators = new Aggregator[] { new Aggregator(RAM_ACCOUNTING_CONTEXT, aggregation, sumAgg, new Input[] { keyInput }) };
return GroupingCollector.singleKey(collectExpressions, aggregators, RAM_ACCOUNTING_CONTEXT, keyInputs.get(0), DataTypes.INTEGER);
}
use of io.crate.metadata.FunctionIdent in project crate by crate.
the class SymbolFormatterTest method testFormat.
@Test
public void testFormat() throws Exception {
Function f = new Function(new FunctionInfo(new FunctionIdent("foo", Arrays.<DataType>asList(DataTypes.STRING, DataTypes.UNDEFINED)), DataTypes.DOUBLE), Arrays.<Symbol>asList(Literal.of("bar"), Literal.of(3.4)));
assertThat(SymbolFormatter.format("This Symbol is formatted %s", f), is("This Symbol is formatted foo('bar', 3.4)"));
}
use of io.crate.metadata.FunctionIdent in project crate by crate.
the class FunctionTest method testCloning.
@Test
public void testCloning() throws Exception {
Function fn = new Function(new FunctionInfo(new FunctionIdent(randomAsciiOfLength(10), ImmutableList.of(DataTypes.BOOLEAN)), TestingHelpers.randomPrimitiveType(), FunctionInfo.Type.SCALAR, randomFeatures()), Collections.singletonList(TestingHelpers.createReference(randomAsciiOfLength(2), DataTypes.BOOLEAN)));
Function fn2 = fn.clone();
assertThat(fn, is(equalTo(fn2)));
assertThat(fn.hashCode(), is(fn2.hashCode()));
}
use of io.crate.metadata.FunctionIdent in project crate by crate.
the class PercentileAggregation method register.
public static void register(AggregationImplModule mod) {
for (DataType<?> t : DataTypes.NUMERIC_PRIMITIVE_TYPES) {
mod.register(new PercentileAggregation(new FunctionInfo(new FunctionIdent(NAME, ImmutableList.<DataType>of(t, DataTypes.DOUBLE)), DataTypes.DOUBLE, FunctionInfo.Type.AGGREGATE)));
mod.register(new PercentileAggregation(new FunctionInfo(new FunctionIdent(NAME, ImmutableList.of(t, DataTypes.DOUBLE_ARRAY)), DataTypes.DOUBLE_ARRAY, FunctionInfo.Type.AGGREGATE)));
}
}
use of io.crate.metadata.FunctionIdent 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 } };
}
Aggregations