Search in sources :

Example 66 with ConfiguredStatement

use of io.confluent.ksql.statement.ConfiguredStatement 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 67 with ConfiguredStatement

use of io.confluent.ksql.statement.ConfiguredStatement 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 68 with ConfiguredStatement

use of io.confluent.ksql.statement.ConfiguredStatement in project ksql by confluentinc.

the class KsqlResourceTest method shouldSupportTopicInferenceInVerification.

@Test
public void shouldSupportTopicInferenceInVerification() {
    // Given:
    givenMockEngine();
    givenSource(DataSourceType.KSTREAM, "ORDERS1", "ORDERS1", SOME_SCHEMA);
    final String sql = "CREATE STREAM orders2 AS SELECT * FROM orders1;";
    final String sqlWithTopic = "CREATE STREAM orders2 WITH(kafka_topic='orders2') AS SELECT * FROM orders1;";
    final PreparedStatement<?> statementWithTopic = ksqlEngine.prepare(ksqlEngine.parse(sqlWithTopic).get(0), Collections.emptyMap());
    final ConfiguredStatement<?> configuredStatement = ConfiguredStatement.of(statementWithTopic, SessionConfig.of(ksqlConfig, ImmutableMap.of()));
    when(sandboxTopicInjector.inject(argThat(is(configured(preparedStatementText(sql)))))).thenReturn((ConfiguredStatement<Statement>) configuredStatement);
    // When:
    makeRequest(sql);
    // Then:
    verify(sandbox).plan(any(SandboxedServiceContext.class), eq(configuredStatement));
    verify(commandStore).enqueueCommand(any(), argThat(is(commandWithStatement(sql))), any(Producer.class));
}
Also used : Producer(org.apache.kafka.clients.producer.Producer) ConfiguredStatement(io.confluent.ksql.statement.ConfiguredStatement) Statement(io.confluent.ksql.parser.tree.Statement) PreparedStatement(io.confluent.ksql.parser.KsqlParser.PreparedStatement) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) SandboxedServiceContext(io.confluent.ksql.services.SandboxedServiceContext) Test(org.junit.Test)

Example 69 with ConfiguredStatement

use of io.confluent.ksql.statement.ConfiguredStatement in project ksql by confluentinc.

the class KsqlResourceTest method shouldSupportTopicInferenceInExecution.

@Test
public void shouldSupportTopicInferenceInExecution() {
    // Given:
    givenMockEngine();
    givenSource(DataSourceType.KSTREAM, "ORDERS1", "ORDERS1", SOME_SCHEMA);
    final String sql = "CREATE STREAM orders2 AS SELECT * FROM orders1;";
    final String sqlWithTopic = "CREATE STREAM orders2 WITH(kafka_topic='orders2') AS SELECT * FROM orders1;";
    final PreparedStatement<?> statementWithTopic = ksqlEngine.prepare(ksqlEngine.parse(sqlWithTopic).get(0), Collections.emptyMap());
    final ConfiguredStatement<?> configured = ConfiguredStatement.of(statementWithTopic, SessionConfig.of(ksqlConfig, ImmutableMap.of()));
    when(topicInjector.inject(argThat(is(configured(preparedStatementText(sql)))))).thenReturn((ConfiguredStatement<Statement>) configured);
    // When:
    makeRequest(sql);
    // Then:
    verify(commandStore).enqueueCommand(any(), argThat(is(commandWithStatement(sqlWithTopic))), any());
}
Also used : ConfiguredStatement(io.confluent.ksql.statement.ConfiguredStatement) Statement(io.confluent.ksql.parser.tree.Statement) PreparedStatement(io.confluent.ksql.parser.KsqlParser.PreparedStatement) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) Test(org.junit.Test)

Example 70 with ConfiguredStatement

use of io.confluent.ksql.statement.ConfiguredStatement in project ksql by confluentinc.

the class ListPropertiesExecutorTest method shouldNotListUnrecognizedConnectProps.

@Test
public void shouldNotListUnrecognizedConnectProps() throws Exception {
    // Given:
    givenConnectWorkerProperties("group.id=list_properties_unit_test\n" + "key.converter=io.confluent.connect.avro.AvroConverter\n" + "value.converter=io.confluent.connect.avro.AvroConverter\n" + "offset.storage.topic=topic1\n" + "config.storage.topic=topic2\n" + "status.storage.topic=topic3\n" + "other.config=<potentially sensitive data that should not be shown>\n" + "sasl.jaas.config=<potentially sensitive data that should not be shown even though it's a recognized config>\n");
    // When:
    final PropertiesList properties = (PropertiesList) CUSTOM_EXECUTORS.listProperties().execute((ConfiguredStatement<ListProperties>) engine.configure("LIST PROPERTIES;").withConfig(new KsqlConfig(ImmutableMap.of("ksql.connect.worker.config", connectPropsFile))), mock(SessionProperties.class), engine.getEngine(), engine.getServiceContext()).getEntity().orElseThrow(IllegalStateException::new);
    // Then:
    assertThat(properties.getProperties(), hasItem(new Property("ksql.connect.worker.config", "KSQL", connectPropsFile)));
    assertThat(properties.getProperties(), hasItem(new Property("value.converter", "EMBEDDED CONNECT WORKER", "io.confluent.connect.avro.AvroConverter")));
    assertThat(toMap(properties), not(hasKey("other.config")));
    assertThat(toMap(properties), not(hasKey("sasl.jaas.config")));
}
Also used : ConfiguredStatement(io.confluent.ksql.statement.ConfiguredStatement) PropertiesList(io.confluent.ksql.rest.entity.PropertiesList) KsqlConfig(io.confluent.ksql.util.KsqlConfig) Property(io.confluent.ksql.rest.entity.PropertiesList.Property) Test(org.junit.Test)

Aggregations

ConfiguredStatement (io.confluent.ksql.statement.ConfiguredStatement)84 Test (org.junit.Test)57 KsqlException (io.confluent.ksql.util.KsqlException)23 Statement (io.confluent.ksql.parser.tree.Statement)22 PreparedStatement (io.confluent.ksql.parser.KsqlParser.PreparedStatement)19 Optional (java.util.Optional)19 ServiceContext (io.confluent.ksql.services.ServiceContext)18 PersistentQueryMetadata (io.confluent.ksql.util.PersistentQueryMetadata)18 KsqlEngine (io.confluent.ksql.engine.KsqlEngine)17 KsqlConfig (io.confluent.ksql.util.KsqlConfig)16 Map (java.util.Map)14 DataSource (io.confluent.ksql.metastore.model.DataSource)12 QueryId (io.confluent.ksql.query.QueryId)12 LogicalSchema (io.confluent.ksql.schema.ksql.LogicalSchema)12 Collectors (java.util.stream.Collectors)12 ImmutableMap (com.google.common.collect.ImmutableMap)11 ListQueries (io.confluent.ksql.parser.tree.ListQueries)11 KsqlStatementException (io.confluent.ksql.util.KsqlStatementException)11 List (java.util.List)11 Query (io.confluent.ksql.parser.tree.Query)10