Search in sources :

Example 1 with FunctionDescriptionList

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

the class ClientTest method shouldFailToDescribeFunctionViaExecuteStatement.

@Test
public void shouldFailToDescribeFunctionViaExecuteStatement() {
    // Given
    final FunctionDescriptionList entity = new FunctionDescriptionList("describe function;", "SUM", "sum", "Confluent", "version", "path", Collections.emptyList(), FunctionType.AGGREGATE);
    testEndpoints.setKsqlEndpointResponse(Collections.singletonList(entity));
    // When
    final Exception e = assertThrows(// thrown from .get() when the future completes exceptionally
    ExecutionException.class, () -> javaClient.executeStatement("describe function;").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) FunctionDescriptionList(io.confluent.ksql.rest.entity.FunctionDescriptionList) 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 FunctionDescriptionList

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

the class DescribeFunctionExecutorTest method shouldDescribeUDF.

@Test
public void shouldDescribeUDF() {
    // When:
    final FunctionDescriptionList functionList = (FunctionDescriptionList) CUSTOM_EXECUTORS.describeFunction().execute((ConfiguredStatement<DescribeFunction>) engine.configure("DESCRIBE FUNCTION TEST_UDF_1;"), 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 functionList.getName().equals("TEST_UDF_1") && functionList.getType().equals(FunctionType.SCALAR);
        }

        @Override
        public void describeTo(final Description description) {
            description.appendText(functionList.getName());
        }
    });
}
Also used : ConfiguredStatement(io.confluent.ksql.statement.ConfiguredStatement) Description(org.hamcrest.Description) FunctionDescriptionList(io.confluent.ksql.rest.entity.FunctionDescriptionList) Test(org.junit.Test)

Example 3 with FunctionDescriptionList

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

the class DescribeFunctionExecutorTest method shouldDescribeUDAF.

@Test
public void shouldDescribeUDAF() {
    // When:
    final FunctionDescriptionList functionList = (FunctionDescriptionList) CUSTOM_EXECUTORS.describeFunction().execute((ConfiguredStatement<DescribeFunction>) engine.configure("DESCRIBE FUNCTION MAX;"), 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 functionList.getName().equals("MAX") && functionList.getType().equals(FunctionType.AGGREGATE);
        }

        @Override
        public void describeTo(final Description description) {
            description.appendText(functionList.getName());
        }
    });
}
Also used : ConfiguredStatement(io.confluent.ksql.statement.ConfiguredStatement) Description(org.hamcrest.Description) FunctionDescriptionList(io.confluent.ksql.rest.entity.FunctionDescriptionList) Test(org.junit.Test)

Example 4 with FunctionDescriptionList

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

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

the class ConsoleTest method shouldPrintFunctionDescription.

@Test
public void shouldPrintFunctionDescription() {
    final KsqlEntityList entityList = new KsqlEntityList(ImmutableList.of(new FunctionDescriptionList("DESCRIBE FUNCTION foo;", "FOO", "Description that is very, very, very, very, very, very, very, very, very, " + "very, very, very, very, very, very, very, very, very, very, very, very long\n" + "and containing new lines\n" + "\tAND TABS\n" + "too!", "Andy", "v1.1.0", "some.jar", ImmutableList.of(new FunctionInfo(ImmutableList.of(new ArgumentInfo("arg1", "INT", "Another really, really, really, really, really, really, really," + "really, really, really, really, really, really, really, really " + " really, really, really, really, really, really, really, long\n" + "description\n" + "\tContaining Tabs\n" + "and stuff", true)), "LONG", "The function description, which too can be really, really, really, " + "really, really, really, really, really, really, really, really, really, " + "really, really, really, really, really, really, really, really, long\n" + "and contains\n\ttabs and stuff")), FunctionType.SCALAR)));
    console.printKsqlEntityList(entityList);
    final String output = terminal.getOutputString();
    Approvals.verify(output, approvalOptions);
}
Also used : KsqlEntityList(io.confluent.ksql.rest.entity.KsqlEntityList) FunctionInfo(io.confluent.ksql.rest.entity.FunctionInfo) Matchers.containsString(org.hamcrest.Matchers.containsString) FunctionDescriptionList(io.confluent.ksql.rest.entity.FunctionDescriptionList) ArgumentInfo(io.confluent.ksql.rest.entity.ArgumentInfo) Test(org.junit.Test)

Aggregations

FunctionDescriptionList (io.confluent.ksql.rest.entity.FunctionDescriptionList)5 Test (org.junit.Test)5 ConfiguredStatement (io.confluent.ksql.statement.ConfiguredStatement)3 Description (org.hamcrest.Description)3 ArgumentInfo (io.confluent.ksql.rest.entity.ArgumentInfo)2 FunctionInfo (io.confluent.ksql.rest.entity.FunctionInfo)2 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 KafkaResponseGetFailedException (io.confluent.ksql.exception.KafkaResponseGetFailedException)1 ParseFailedException (io.confluent.ksql.parser.exception.ParseFailedException)1 KsqlEntityList (io.confluent.ksql.rest.entity.KsqlEntityList)1 ExecutionException (java.util.concurrent.ExecutionException)1 Matchers.containsString (org.hamcrest.Matchers.containsString)1