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"));
}
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)));
}
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)));
}
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();
}
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)));
}
Aggregations