Search in sources :

Example 1 with FunctionInfo

use of io.confluent.ksql.rest.entity.FunctionInfo in project ksql by confluentinc.

the class DescribeFunctionExecutor method describeNonAggregateFunction.

private static FunctionDescriptionList describeNonAggregateFunction(final KsqlExecutionContext executionContext, final FunctionName functionName, final String statementText) {
    final UdfFactory udfFactory = executionContext.getMetaStore().getUdfFactory(functionName);
    final ImmutableList.Builder<FunctionInfo> listBuilder = ImmutableList.builder();
    udfFactory.eachFunction(func -> listBuilder.add(getFunctionInfo(func.parameterInfo(), func.declaredReturnType(), func.getDescription(), func.isVariadic())));
    return createFunctionDescriptionList(statementText, udfFactory.getMetadata(), listBuilder.build(), FunctionType.SCALAR);
}
Also used : ImmutableList(com.google.common.collect.ImmutableList) FunctionInfo(io.confluent.ksql.rest.entity.FunctionInfo) UdfFactory(io.confluent.ksql.function.UdfFactory)

Example 2 with FunctionInfo

use of io.confluent.ksql.rest.entity.FunctionInfo in project ksql by confluentinc.

the class DescribeFunctionExecutor method getFunctionInfo.

private static FunctionInfo getFunctionInfo(final List<ParameterInfo> argTypes, final ParamType returnTypeSchema, final String description, final boolean variadic) {
    final List<ArgumentInfo> args = new ArrayList<>();
    for (int i = 0; i < argTypes.size(); i++) {
        final ParameterInfo param = argTypes.get(i);
        final boolean isVariadic = variadic && i == (argTypes.size() - 1);
        final String type = isVariadic ? ((ArrayType) param.type()).element().toString() : param.type().toString();
        args.add(new ArgumentInfo(param.name(), type, param.description(), isVariadic));
    }
    return new FunctionInfo(args, returnTypeSchema.toString(), description);
}
Also used : ArrayType(io.confluent.ksql.function.types.ArrayType) ArrayList(java.util.ArrayList) FunctionInfo(io.confluent.ksql.rest.entity.FunctionInfo) ParameterInfo(io.confluent.ksql.function.ParameterInfo) ArgumentInfo(io.confluent.ksql.rest.entity.ArgumentInfo)

Example 3 with FunctionInfo

use of io.confluent.ksql.rest.entity.FunctionInfo in project ksql by confluentinc.

the class DescribeFunctionExecutor method describeAggregateFunction.

private static FunctionDescriptionList describeAggregateFunction(final KsqlExecutionContext ksqlEngine, final FunctionName functionName, final String statementText) {
    final AggregateFunctionFactory aggregateFactory = ksqlEngine.getMetaStore().getAggregateFactory(functionName);
    final ImmutableList.Builder<FunctionInfo> listBuilder = ImmutableList.builder();
    aggregateFactory.eachFunction(func -> listBuilder.add(getFunctionInfo(func.parameterInfo(), func.declaredReturnType(), func.getDescription(), false)));
    return createFunctionDescriptionList(statementText, aggregateFactory.getMetadata(), listBuilder.build(), FunctionType.AGGREGATE);
}
Also used : AggregateFunctionFactory(io.confluent.ksql.function.AggregateFunctionFactory) ImmutableList(com.google.common.collect.ImmutableList) FunctionInfo(io.confluent.ksql.rest.entity.FunctionInfo)

Example 4 with FunctionInfo

use of io.confluent.ksql.rest.entity.FunctionInfo in project ksql by confluentinc.

the class DescribeFunctionExecutorTest method shouldDescribeUDTF.

@Test
public void shouldDescribeUDTF() {
    // When:
    final FunctionDescriptionList functionList = (FunctionDescriptionList) CUSTOM_EXECUTORS.describeFunction().execute((ConfiguredStatement<DescribeFunction>) engine.configure("DESCRIBE FUNCTION TEST_UDTF1;"), mock(SessionProperties.class), engine.getEngine(), engine.getServiceContext()).getEntity().orElseThrow(IllegalStateException::new);
    // Then:
    assertThat(functionList, new TypeSafeMatcher<FunctionDescriptionList>() {

        @Override
        protected boolean matchesSafely(final FunctionDescriptionList item) {
            return item.getName().equals("TEST_UDTF1") && item.getType().equals(FunctionType.TABLE);
        }

        @Override
        public void describeTo(final Description description) {
            description.appendText(functionList.getName());
        }
    });
    assertThat(functionList.getFunctions(), hasSize(2));
    final FunctionInfo expected1 = new FunctionInfo(Arrays.asList(new ArgumentInfo("foo", "INT", "", false)), "INT", "test_udtf1 int");
    assertTrue(functionList.getFunctions().contains(expected1));
    final FunctionInfo expected2 = new FunctionInfo(Arrays.asList(new ArgumentInfo("foo", "DOUBLE", "", false)), "DOUBLE", "test_udtf1 double");
    assertTrue(functionList.getFunctions().contains(expected2));
}
Also used : ConfiguredStatement(io.confluent.ksql.statement.ConfiguredStatement) Description(org.hamcrest.Description) FunctionInfo(io.confluent.ksql.rest.entity.FunctionInfo) FunctionDescriptionList(io.confluent.ksql.rest.entity.FunctionDescriptionList) ArgumentInfo(io.confluent.ksql.rest.entity.ArgumentInfo) Test(org.junit.Test)

Example 5 with FunctionInfo

use of io.confluent.ksql.rest.entity.FunctionInfo in project ksql by confluentinc.

the class DescribeFunctionExecutor method describeTableFunction.

private static FunctionDescriptionList describeTableFunction(final KsqlExecutionContext executionContext, final FunctionName functionName, final String statementText) {
    final TableFunctionFactory tableFunctionFactory = executionContext.getMetaStore().getTableFunctionFactory(functionName);
    final ImmutableList.Builder<FunctionInfo> listBuilder = ImmutableList.builder();
    tableFunctionFactory.eachFunction(func -> listBuilder.add(getFunctionInfo(func.parameterInfo(), func.declaredReturnType(), func.getDescription(), func.isVariadic())));
    return createFunctionDescriptionList(statementText, tableFunctionFactory.getMetadata(), listBuilder.build(), FunctionType.TABLE);
}
Also used : TableFunctionFactory(io.confluent.ksql.function.TableFunctionFactory) ImmutableList(com.google.common.collect.ImmutableList) FunctionInfo(io.confluent.ksql.rest.entity.FunctionInfo)

Aggregations

FunctionInfo (io.confluent.ksql.rest.entity.FunctionInfo)6 ImmutableList (com.google.common.collect.ImmutableList)3 ArgumentInfo (io.confluent.ksql.rest.entity.ArgumentInfo)3 FunctionDescriptionList (io.confluent.ksql.rest.entity.FunctionDescriptionList)2 Test (org.junit.Test)2 AggregateFunctionFactory (io.confluent.ksql.function.AggregateFunctionFactory)1 ParameterInfo (io.confluent.ksql.function.ParameterInfo)1 TableFunctionFactory (io.confluent.ksql.function.TableFunctionFactory)1 UdfFactory (io.confluent.ksql.function.UdfFactory)1 ArrayType (io.confluent.ksql.function.types.ArrayType)1 KsqlEntityList (io.confluent.ksql.rest.entity.KsqlEntityList)1 ConfiguredStatement (io.confluent.ksql.statement.ConfiguredStatement)1 ArrayList (java.util.ArrayList)1 Description (org.hamcrest.Description)1 Matchers.containsString (org.hamcrest.Matchers.containsString)1