use of io.crate.metadata.FunctionImplementation in project crate by crate.
the class HyperLogLogDistinctAggregationTest method testReturnTypeIsAlwaysLong.
@Test
public void testReturnTypeIsAlwaysLong() {
// Return type is fixed to Long
FunctionImplementation func = nodeCtx.functions().get(null, HyperLogLogDistinctAggregation.NAME, List.of(Literal.of(1)), SearchPath.pathWithPGCatalogAndDoc());
assertEquals(DataTypes.LONG, func.info().returnType());
func = nodeCtx.functions().get(null, HyperLogLogDistinctAggregation.NAME, List.of(Literal.of(1), Literal.of(2)), SearchPath.pathWithPGCatalogAndDoc());
assertEquals(DataTypes.LONG, func.info().returnType());
}
use of io.crate.metadata.FunctionImplementation in project crate by crate.
the class WindowAggProjectionSerialisationTest method test_window_agg_projection_serialization_with_filter_before_4_1_0.
@Test
public void test_window_agg_projection_serialization_with_filter_before_4_1_0() throws IOException {
FunctionImplementation sumFunctionImpl = getSumFunction();
WindowDefinition partitionByOneWindowDef = new WindowDefinition(singletonList(Literal.of(1L)), null, null);
WindowFunction windowFunction = new WindowFunction(sumFunctionImpl.signature(), singletonList(Literal.of(2L)), sumFunctionImpl.boundSignature().getReturnType().createType(), null, partitionByOneWindowDef, null);
Symbol standaloneInput = Literal.of(42L);
var windowAggProjection = new WindowAggProjection(partitionByOneWindowDef, List.of(windowFunction), List.of(standaloneInput));
var output = new BytesStreamOutput();
output.setVersion(Version.V_4_0_0);
windowAggProjection.writeTo(output);
var input = output.bytes().streamInput();
input.setVersion(Version.V_4_0_0);
var actualWindowAggProjection = new WindowAggProjection(input);
assertThat(actualWindowAggProjection.outputs(), contains(standaloneInput, windowFunction));
assertThat(actualWindowAggProjection.windowFunctions().get(0).filter(), Matchers.nullValue());
}
use of io.crate.metadata.FunctionImplementation 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(txnCtx, i -> Literal.of("foo"));
Input<?> input = ctx.add(function);
FunctionExpression expression = (FunctionExpression) input;
java.lang.reflect.Field f = FunctionExpression.class.getDeclaredField("scalar");
f.setAccessible(true);
FunctionImplementation impl = (FunctionImplementation) f.get(expression);
assertThat(impl.signature(), is(function.signature()));
FunctionImplementation uncompiled = expressions.nodeCtx.functions().getQualified(function, txnCtx.sessionSettings().searchPath());
assertThat(uncompiled, not(sameInstance(impl)));
}
use of io.crate.metadata.FunctionImplementation in project crate by crate.
the class HandlerSideLevelCollectTest method testInformationSchemaTables.
@Test
public void testInformationSchemaTables() throws Exception {
InformationSchemaInfo schemaInfo = internalCluster().getInstance(InformationSchemaInfo.class);
TableInfo tablesTableInfo = schemaInfo.getTableInfo("tables");
Routing routing = tablesTableInfo.getRouting(clusterService().state(), routingProvider, WhereClause.MATCH_ALL, RoutingProvider.ShardSelection.ANY, SessionContext.systemSessionContext());
List<Symbol> toCollect = new ArrayList<>();
for (Reference reference : tablesTableInfo.columns()) {
toCollect.add(reference);
}
Symbol tableNameRef = toCollect.get(12);
List<Symbol> arguments = Arrays.asList(tableNameRef, Literal.of("shards"));
FunctionImplementation eqImpl = functions.get(null, EqOperator.NAME, arguments, SearchPath.pathWithPGCatalogAndDoc());
Function whereClause = new Function(eqImpl.signature(), arguments, EqOperator.RETURN_TYPE);
RoutedCollectPhase collectNode = collectNode(routing, toCollect, RowGranularity.DOC, new WhereClause(whereClause));
Bucket result = collect(collectNode);
assertThat(TestingHelpers.printedTable(result), is("NULL| NULL| NULL| strict| NULL| NULL| NULL| SYSTEM GENERATED| NULL| NULL| NULL| sys| shards| sys| BASE TABLE| NULL\n"));
}
use of io.crate.metadata.FunctionImplementation in project crate by crate.
the class GeometricMeanAggregationtest method test_functions_return_type_is_always_double_for_any_argument_type.
@Test
public void test_functions_return_type_is_always_double_for_any_argument_type() {
for (DataType<?> type : Stream.concat(DataTypes.NUMERIC_PRIMITIVE_TYPES.stream(), Stream.of(DataTypes.TIMESTAMPZ)).collect(Collectors.toList())) {
FunctionImplementation stddev = nodeCtx.functions().get(null, GeometricMeanAggregation.NAME, List.of(Literal.of(type, null)), SearchPath.pathWithPGCatalogAndDoc());
assertThat(stddev.boundSignature().getReturnType().createType(), is(DataTypes.DOUBLE));
}
}
Aggregations