Search in sources :

Example 1 with SimpleFunctionInfo

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

the class ListFunctionsExecutor method execute.

public static StatementExecutorResponse execute(final ConfiguredStatement<ListFunctions> statement, final SessionProperties sessionProperties, final KsqlExecutionContext executionContext, final ServiceContext serviceContext) {
    final FunctionRegistry functionRegistry = executionContext.getMetaStore();
    final List<SimpleFunctionInfo> all = functionRegistry.listFunctions().stream().map(factory -> new SimpleFunctionInfo(factory.getName().toUpperCase(), FunctionType.SCALAR, factory.getMetadata().getCategory())).collect(Collectors.toList());
    functionRegistry.listTableFunctions().stream().map(factory -> new SimpleFunctionInfo(factory.getName().toUpperCase(), FunctionType.TABLE, factory.getMetadata().getCategory())).forEach(all::add);
    functionRegistry.listAggregateFunctions().stream().map(factory -> new SimpleFunctionInfo(factory.getName().toUpperCase(), FunctionType.AGGREGATE, factory.getMetadata().getCategory())).forEach(all::add);
    return StatementExecutorResponse.handled(Optional.of(new FunctionNameList(statement.getStatementText(), all)));
}
Also used : FunctionNameList(io.confluent.ksql.rest.entity.FunctionNameList) FunctionType(io.confluent.ksql.rest.entity.FunctionType) List(java.util.List) SessionProperties(io.confluent.ksql.rest.SessionProperties) KsqlExecutionContext(io.confluent.ksql.KsqlExecutionContext) FunctionRegistry(io.confluent.ksql.function.FunctionRegistry) ServiceContext(io.confluent.ksql.services.ServiceContext) ListFunctions(io.confluent.ksql.parser.tree.ListFunctions) Optional(java.util.Optional) ConfiguredStatement(io.confluent.ksql.statement.ConfiguredStatement) SimpleFunctionInfo(io.confluent.ksql.rest.entity.SimpleFunctionInfo) Collectors(java.util.stream.Collectors) FunctionRegistry(io.confluent.ksql.function.FunctionRegistry) FunctionNameList(io.confluent.ksql.rest.entity.FunctionNameList) SimpleFunctionInfo(io.confluent.ksql.rest.entity.SimpleFunctionInfo)

Example 2 with SimpleFunctionInfo

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

the class KsqlResourceTest method shouldListFunctions.

@Test
public void shouldListFunctions() {
    // When:
    final FunctionNameList functionList = makeSingleRequest("LIST FUNCTIONS;", FunctionNameList.class);
    // Then:
    assertThat(functionList.getFunctions(), hasItems(new SimpleFunctionInfo("TRIM", FunctionType.SCALAR, FunctionCategory.STRING), new SimpleFunctionInfo("TOPK", FunctionType.AGGREGATE, FunctionCategory.AGGREGATE), new SimpleFunctionInfo("MAX", FunctionType.AGGREGATE, FunctionCategory.AGGREGATE)));
}
Also used : FunctionNameList(io.confluent.ksql.rest.entity.FunctionNameList) SimpleFunctionInfo(io.confluent.ksql.rest.entity.SimpleFunctionInfo) Test(org.junit.Test)

Example 3 with SimpleFunctionInfo

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

the class FunctionNameListTableBuilder method buildTable.

@Override
public Table buildTable(final FunctionNameList functionNameList) {
    final Builder builder = new Builder().withColumnHeaders(HEADERS);
    // poor mans version check for the case we are running against an older ksqlDB server
    final Iterator<SimpleFunctionInfo> funcs = functionNameList.getFunctions().iterator();
    if (!funcs.hasNext() || funcs.next().getCategory().isEmpty()) {
        final Stream<List<String>> rows = functionNameList.getFunctions().stream().sorted(Comparator.comparing(SimpleFunctionInfo::getName)).map(func -> ImmutableList.of(func.getName(), func.getType().name().toUpperCase()));
        builder.withRows(rows);
    } else {
        // category info present, use new display layout
        final List<SimpleFunctionInfo> sortedFunctions = functionNameList.getFunctions().stream().sorted(Comparator.comparing(SimpleFunctionInfo::getCategory).thenComparing(SimpleFunctionInfo::getName)).collect(Collectors.toList());
        String prevCategory = sortedFunctions.get(0).getCategory();
        for (SimpleFunctionInfo fn : sortedFunctions) {
            if (!fn.getCategory().equals(prevCategory)) {
                builder.withRow(EMPTY_ROW);
            }
            builder.withRow(fn.getName(), fn.getCategory());
            prevCategory = fn.getCategory();
        }
    }
    builder.withFooterLine("For detailed information about a function, run: DESCRIBE FUNCTION <Function Name>;");
    return builder.build();
}
Also used : Builder(io.confluent.ksql.cli.console.table.Table.Builder) FunctionNameList(io.confluent.ksql.rest.entity.FunctionNameList) List(java.util.List) ImmutableList(com.google.common.collect.ImmutableList) SimpleFunctionInfo(io.confluent.ksql.rest.entity.SimpleFunctionInfo)

Example 4 with SimpleFunctionInfo

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

the class ListFunctionsExecutorTest method shouldListFunctions.

@Test
public void shouldListFunctions() {
    // When:
    final FunctionNameList functionList = (FunctionNameList) CUSTOM_EXECUTORS.listFunctions().execute((ConfiguredStatement<ListFunctions>) engine.configure("LIST FUNCTIONS;"), mock(SessionProperties.class), engine.getEngine(), engine.getServiceContext()).getEntity().orElseThrow(IllegalStateException::new);
    // Then:
    final Collection<SimpleFunctionInfo> functions = functionList.getFunctions();
    assertThat(functions, hasItems(new SimpleFunctionInfo("TEST_UDF_1", FunctionType.SCALAR, FunctionCategory.OTHER), new SimpleFunctionInfo("TOPK", FunctionType.AGGREGATE, FunctionCategory.AGGREGATE), new SimpleFunctionInfo("MAX", FunctionType.AGGREGATE, FunctionCategory.AGGREGATE), new SimpleFunctionInfo("TEST_UDTF1", FunctionType.TABLE, FunctionCategory.TABLE), new SimpleFunctionInfo("TEST_UDTF2", FunctionType.TABLE, FunctionCategory.TABLE)));
}
Also used : ConfiguredStatement(io.confluent.ksql.statement.ConfiguredStatement) FunctionNameList(io.confluent.ksql.rest.entity.FunctionNameList) SimpleFunctionInfo(io.confluent.ksql.rest.entity.SimpleFunctionInfo) Test(org.junit.Test)

Aggregations

FunctionNameList (io.confluent.ksql.rest.entity.FunctionNameList)4 SimpleFunctionInfo (io.confluent.ksql.rest.entity.SimpleFunctionInfo)4 ConfiguredStatement (io.confluent.ksql.statement.ConfiguredStatement)2 List (java.util.List)2 Test (org.junit.Test)2 ImmutableList (com.google.common.collect.ImmutableList)1 KsqlExecutionContext (io.confluent.ksql.KsqlExecutionContext)1 Builder (io.confluent.ksql.cli.console.table.Table.Builder)1 FunctionRegistry (io.confluent.ksql.function.FunctionRegistry)1 ListFunctions (io.confluent.ksql.parser.tree.ListFunctions)1 SessionProperties (io.confluent.ksql.rest.SessionProperties)1 FunctionType (io.confluent.ksql.rest.entity.FunctionType)1 ServiceContext (io.confluent.ksql.services.ServiceContext)1 Optional (java.util.Optional)1 Collectors (java.util.stream.Collectors)1