Search in sources :

Example 1 with FunctionNameList

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

the class ClientTest method shouldFailToListFunctionsViaExecuteStatement.

@Test
public void shouldFailToListFunctionsViaExecuteStatement() {
    // Given
    final FunctionNameList entity = new FunctionNameList("list functions;", Collections.emptyList());
    testEndpoints.setKsqlEndpointResponse(Collections.singletonList(entity));
    // When
    final Exception e = assertThrows(// thrown from .get() when the future completes exceptionally
    ExecutionException.class, () -> javaClient.executeStatement("list functions;").get());
    // Then
    assertThat(e.getCause(), instanceOf(KsqlClientException.class));
    assertThat(e.getCause().getMessage(), containsString(EXECUTE_STATEMENT_USAGE_DOC));
    assertThat(e.getCause().getMessage(), containsString("does not currently support 'DESCRIBE <FUNCTION>' statements or listing functions"));
}
Also used : KsqlClientException(io.confluent.ksql.api.client.exception.KsqlClientException) FunctionNameList(io.confluent.ksql.rest.entity.FunctionNameList) KafkaResponseGetFailedException(io.confluent.ksql.exception.KafkaResponseGetFailedException) KsqlClientException(io.confluent.ksql.api.client.exception.KsqlClientException) KsqlApiException(io.confluent.ksql.api.server.KsqlApiException) ExecutionException(java.util.concurrent.ExecutionException) ParseFailedException(io.confluent.ksql.parser.exception.ParseFailedException) KsqlException(io.confluent.ksql.api.client.exception.KsqlException) BaseApiTest(io.confluent.ksql.api.BaseApiTest) Test(org.junit.Test)

Example 2 with FunctionNameList

use of io.confluent.ksql.rest.entity.FunctionNameList 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 3 with FunctionNameList

use of io.confluent.ksql.rest.entity.FunctionNameList 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 4 with FunctionNameList

use of io.confluent.ksql.rest.entity.FunctionNameList 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 5 with FunctionNameList

use of io.confluent.ksql.rest.entity.FunctionNameList 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)5 SimpleFunctionInfo (io.confluent.ksql.rest.entity.SimpleFunctionInfo)4 Test (org.junit.Test)3 ConfiguredStatement (io.confluent.ksql.statement.ConfiguredStatement)2 List (java.util.List)2 ImmutableList (com.google.common.collect.ImmutableList)1 KsqlExecutionContext (io.confluent.ksql.KsqlExecutionContext)1 BaseApiTest (io.confluent.ksql.api.BaseApiTest)1 KsqlClientException (io.confluent.ksql.api.client.exception.KsqlClientException)1 KsqlException (io.confluent.ksql.api.client.exception.KsqlException)1 KsqlApiException (io.confluent.ksql.api.server.KsqlApiException)1 Builder (io.confluent.ksql.cli.console.table.Table.Builder)1 KafkaResponseGetFailedException (io.confluent.ksql.exception.KafkaResponseGetFailedException)1 FunctionRegistry (io.confluent.ksql.function.FunctionRegistry)1 ParseFailedException (io.confluent.ksql.parser.exception.ParseFailedException)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