use of io.crate.operation.aggregation.FunctionExpression in project crate by crate.
the class BaseImplementationSymbolVisitor method visitFunction.
@Override
public Input<?> visitFunction(Function function, C context) {
final FunctionImplementation functionImplementation = functions.get(function.info().ident());
if (functionImplementation instanceof Scalar<?, ?>) {
List<Symbol> arguments = function.arguments();
Scalar<?, ?> scalarImpl = ((Scalar) functionImplementation).compile(arguments);
Input[] argumentInputs = new Input[arguments.size()];
int i = 0;
for (Symbol argument : function.arguments()) {
argumentInputs[i++] = process(argument, context);
}
return new FunctionExpression<>(scalarImpl, argumentInputs);
} else {
throw new IllegalArgumentException(SymbolFormatter.format("Cannot find implementation for function %s", function));
}
}
use of io.crate.operation.aggregation.FunctionExpression in project crate by crate.
the class InputFactoryTest method testCompiled.
@Test
public void testCompiled() throws Exception {
Function function = (Function) expressions.normalize(expressions.asSymbol("a like 'f%'"));
InputFactory.Context<Input<?>> ctx = factory.ctxForRefs(i -> Literal.of("foo"));
Input<?> input = ctx.add(function);
FunctionExpression expression = (FunctionExpression) input;
java.lang.reflect.Field f = FunctionExpression.class.getDeclaredField("functionImplementation");
f.setAccessible(true);
FunctionImplementation impl = (FunctionImplementation) f.get(expression);
assertThat(impl.info(), is(function.info()));
FunctionImplementation uncompiled = expressions.functions().get(function.info().ident());
assertThat(uncompiled, not(sameInstance(impl)));
}
use of io.crate.operation.aggregation.FunctionExpression in project crate by crate.
the class SimpleTopNProjectorTest method testFunctionExpression.
@Test
public void testFunctionExpression() throws Throwable {
Scalar floor = (Scalar) TestingHelpers.getFunctions().get(new FunctionIdent("floor", Collections.<DataType>singletonList(DataTypes.DOUBLE)));
FunctionExpression<Number, ?> funcExpr = new FunctionExpression<>(floor, new Input[] { input });
Projector projector = new SimpleTopNProjector(ImmutableList.<Input<?>>of(funcExpr), COLLECT_EXPRESSIONS, 10, TopN.NO_OFFSET);
Iterable<Row> rows = RowGenerator.fromSingleColValues(() -> IntStream.range(0, 12).mapToDouble(i -> 42.3d).iterator());
BatchIterator batchIterator = projector.apply(RowsBatchIterator.newInstance(rows, 1));
consumer.accept(batchIterator, null);
Bucket result = consumer.getBucket();
assertThat(result.size(), is(10));
assertThat(result.iterator().next(), isRow(42L));
}
Aggregations