Search in sources :

Example 1 with MetaStoreImpl

use of io.confluent.ksql.metastore.MetaStoreImpl in project ksql by confluentinc.

the class CommandStoreTest method shouldCollectTerminatedQueries.

@Test
public void shouldCollectTerminatedQueries() {
    final CommandId terminated = new CommandId(CommandId.Type.TERMINATE, "queryId", CommandId.Action.EXECUTE);
    final ConsumerRecords<CommandId, Command> records = new ConsumerRecords<>(Collections.singletonMap(new TopicPartition("topic", 0), Collections.singletonList(new ConsumerRecord<>("topic", 0, 0, terminated, new Command("terminate query 'queryId'", Collections.emptyMap())))));
    EasyMock.expect(commandConsumer.partitionsFor(COMMAND_TOPIC)).andReturn(Collections.emptyList());
    EasyMock.expect(commandConsumer.poll(anyLong())).andReturn(records).andReturn(new ConsumerRecords<>(Collections.emptyMap()));
    EasyMock.replay(commandConsumer);
    final CommandStore commandStore = new CommandStore(COMMAND_TOPIC, commandConsumer, commandProducer, new CommandIdAssigner(new MetaStoreImpl()));
    final RestoreCommands restoreCommands = commandStore.getRestoreCommands();
    assertThat(restoreCommands.terminatedQueries(), equalTo(Collections.singletonMap(new QueryId("queryId"), terminated)));
}
Also used : TopicPartition(org.apache.kafka.common.TopicPartition) MetaStoreImpl(io.confluent.ksql.metastore.MetaStoreImpl) QueryId(io.confluent.ksql.query.QueryId) ConsumerRecords(org.apache.kafka.clients.consumer.ConsumerRecords) Test(org.junit.Test)

Example 2 with MetaStoreImpl

use of io.confluent.ksql.metastore.MetaStoreImpl in project ksql by confluentinc.

the class MetaStoreFixture method getNewMetaStore.

public static MetaStore getNewMetaStore() {
    MetaStore metaStore = new MetaStoreImpl();
    SchemaBuilder schemaBuilder1 = SchemaBuilder.struct().field("COL0", SchemaBuilder.INT64_SCHEMA).field("COL1", SchemaBuilder.STRING_SCHEMA).field("COL2", SchemaBuilder.STRING_SCHEMA).field("COL3", SchemaBuilder.FLOAT64_SCHEMA).field("COL4", SchemaBuilder.array(SchemaBuilder.FLOAT64_SCHEMA)).field("COL5", SchemaBuilder.map(SchemaBuilder.STRING_SCHEMA, SchemaBuilder.FLOAT64_SCHEMA));
    KsqlTopic ksqlTopic1 = new KsqlTopic("TEST1", "test1", new KsqlJsonTopicSerDe());
    KsqlStream ksqlStream = new KsqlStream("sqlexpression", "TEST1", schemaBuilder1, schemaBuilder1.field("COL0"), null, ksqlTopic1);
    metaStore.putTopic(ksqlTopic1);
    metaStore.putSource(ksqlStream);
    SchemaBuilder schemaBuilder2 = SchemaBuilder.struct().field("COL0", SchemaBuilder.INT64_SCHEMA).field("COL1", SchemaBuilder.STRING_SCHEMA).field("COL2", SchemaBuilder.STRING_SCHEMA).field("COL3", SchemaBuilder.FLOAT64_SCHEMA).field("COL4", SchemaBuilder.BOOLEAN_SCHEMA);
    KsqlTopic ksqlTopic2 = new KsqlTopic("TEST2", "test2", new KsqlJsonTopicSerDe());
    KsqlTable ksqlTable = new KsqlTable("sqlexpression", "TEST2", schemaBuilder2, schemaBuilder2.field("COL0"), null, ksqlTopic2, "TEST2", false);
    metaStore.putTopic(ksqlTopic2);
    metaStore.putSource(ksqlTable);
    SchemaBuilder schemaBuilderOrders = SchemaBuilder.struct().field("ORDERTIME", SchemaBuilder.INT64_SCHEMA).field("ORDERID", SchemaBuilder.STRING_SCHEMA).field("ITEMID", SchemaBuilder.STRING_SCHEMA).field("ORDERUNITS", SchemaBuilder.FLOAT64_SCHEMA);
    KsqlTopic ksqlTopicOrders = new KsqlTopic("ORDERS_TOPIC", "orders_topic", new KsqlJsonTopicSerDe());
    KsqlStream ksqlStreamOrders = new KsqlStream("sqlexpression", "ORDERS", schemaBuilderOrders, schemaBuilderOrders.field("ORDERTIME"), null, ksqlTopicOrders);
    metaStore.putTopic(ksqlTopicOrders);
    metaStore.putSource(ksqlStreamOrders);
    return metaStore;
}
Also used : MetaStore(io.confluent.ksql.metastore.MetaStore) KsqlStream(io.confluent.ksql.metastore.KsqlStream) MetaStoreImpl(io.confluent.ksql.metastore.MetaStoreImpl) KsqlJsonTopicSerDe(io.confluent.ksql.serde.json.KsqlJsonTopicSerDe) KsqlTable(io.confluent.ksql.metastore.KsqlTable) SchemaBuilder(org.apache.kafka.connect.data.SchemaBuilder) KsqlTopic(io.confluent.ksql.metastore.KsqlTopic)

Example 3 with MetaStoreImpl

use of io.confluent.ksql.metastore.MetaStoreImpl in project ksql by confluentinc.

the class KsqlContext method create.

public static KsqlContext create(KsqlConfig ksqlConfig, SchemaRegistryClient schemaRegistryClient) {
    if (ksqlConfig == null) {
        ksqlConfig = new KsqlConfig(Collections.emptyMap());
    }
    Map<String, Object> streamsProperties = ksqlConfig.getKsqlStreamConfigProps();
    if (!streamsProperties.containsKey(StreamsConfig.APPLICATION_ID_CONFIG)) {
        streamsProperties.put(StreamsConfig.APPLICATION_ID_CONFIG, APPLICATION_ID_OPTION_DEFAULT);
    }
    if (!streamsProperties.containsKey(StreamsConfig.BOOTSTRAP_SERVERS_CONFIG)) {
        streamsProperties.put(StreamsConfig.BOOTSTRAP_SERVERS_CONFIG, KAFKA_BOOTSTRAP_SERVER_OPTION_DEFAULT);
    }
    AdminClient adminClient = AdminClient.create(ksqlConfig.getKsqlAdminClientConfigProps());
    KafkaTopicClient topicClient = new KafkaTopicClientImpl(adminClient);
    if (schemaRegistryClient == null) {
        return new KsqlContext(adminClient, topicClient, new KsqlEngine(ksqlConfig, topicClient));
    } else {
        return new KsqlContext(adminClient, topicClient, new KsqlEngine(ksqlConfig, topicClient, schemaRegistryClient, new MetaStoreImpl()));
    }
}
Also used : KafkaTopicClient(io.confluent.ksql.util.KafkaTopicClient) MetaStoreImpl(io.confluent.ksql.metastore.MetaStoreImpl) KsqlConfig(io.confluent.ksql.util.KsqlConfig) KafkaTopicClientImpl(io.confluent.ksql.util.KafkaTopicClientImpl) AdminClient(org.apache.kafka.clients.admin.AdminClient)

Example 4 with MetaStoreImpl

use of io.confluent.ksql.metastore.MetaStoreImpl in project ksql by confluentinc.

the class KsqlResourceTest method setUp.

@Before
public void setUp() throws IOException, RestClientException {
    SchemaRegistryClient schemaRegistryClient = new MockSchemaRegistryClient();
    registerSchema(schemaRegistryClient);
    ksqlRestConfig = new KsqlRestConfig(TestKsqlResourceUtil.getDefaultKsqlConfig());
    KsqlConfig ksqlConfig = new KsqlConfig(ksqlRestConfig.getKsqlConfigProperties());
    ksqlEngine = new KsqlEngine(ksqlConfig, new MockKafkaTopicClient(), schemaRegistryClient, new MetaStoreImpl());
}
Also used : KsqlEngine(io.confluent.ksql.KsqlEngine) MockSchemaRegistryClient(io.confluent.kafka.schemaregistry.client.MockSchemaRegistryClient) KsqlRestConfig(io.confluent.ksql.rest.server.KsqlRestConfig) MockKafkaTopicClient(io.confluent.ksql.rest.server.mock.MockKafkaTopicClient) MetaStoreImpl(io.confluent.ksql.metastore.MetaStoreImpl) KsqlConfig(io.confluent.ksql.util.KsqlConfig) SchemaRegistryClient(io.confluent.kafka.schemaregistry.client.SchemaRegistryClient) MockSchemaRegistryClient(io.confluent.kafka.schemaregistry.client.MockSchemaRegistryClient) Before(org.junit.Before)

Aggregations

MetaStoreImpl (io.confluent.ksql.metastore.MetaStoreImpl)4 KsqlConfig (io.confluent.ksql.util.KsqlConfig)2 MockSchemaRegistryClient (io.confluent.kafka.schemaregistry.client.MockSchemaRegistryClient)1 SchemaRegistryClient (io.confluent.kafka.schemaregistry.client.SchemaRegistryClient)1 KsqlEngine (io.confluent.ksql.KsqlEngine)1 KsqlStream (io.confluent.ksql.metastore.KsqlStream)1 KsqlTable (io.confluent.ksql.metastore.KsqlTable)1 KsqlTopic (io.confluent.ksql.metastore.KsqlTopic)1 MetaStore (io.confluent.ksql.metastore.MetaStore)1 QueryId (io.confluent.ksql.query.QueryId)1 KsqlRestConfig (io.confluent.ksql.rest.server.KsqlRestConfig)1 MockKafkaTopicClient (io.confluent.ksql.rest.server.mock.MockKafkaTopicClient)1 KsqlJsonTopicSerDe (io.confluent.ksql.serde.json.KsqlJsonTopicSerDe)1 KafkaTopicClient (io.confluent.ksql.util.KafkaTopicClient)1 KafkaTopicClientImpl (io.confluent.ksql.util.KafkaTopicClientImpl)1 AdminClient (org.apache.kafka.clients.admin.AdminClient)1 ConsumerRecords (org.apache.kafka.clients.consumer.ConsumerRecords)1 TopicPartition (org.apache.kafka.common.TopicPartition)1 SchemaBuilder (org.apache.kafka.connect.data.SchemaBuilder)1 Before (org.junit.Before)1