Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Subscription: support table model subscription session and consumer #14406

Draft
wants to merge 6 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/

package org.apache.iotdb;

import org.apache.iotdb.isession.subscription.ISubscriptionTableSession;
import org.apache.iotdb.rpc.subscription.config.TopicConstant;
import org.apache.iotdb.session.subscription.SubscriptionTableSessionBuilder;

import java.util.Properties;

public class TableModelSubscriptionSessionExample {

public static void main(final String[] args) throws Exception {
try (final ISubscriptionTableSession session =
new SubscriptionTableSessionBuilder().host("localhost").port(6667).build()) {
// no need to open
final Properties config = new Properties();
config.put(TopicConstant.DATABASE_KEY, "test");
config.put(TopicConstant.TABLE_KEY, "test");
config.put(TopicConstant.START_TIME_KEY, 25);
config.put(TopicConstant.END_TIME_KEY, 75);
session.createTopic("test", config);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,11 @@

package org.apache.iotdb.subscription.it.local;

import org.apache.iotdb.isession.subscription.model.Topic;
import org.apache.iotdb.it.env.EnvFactory;
import org.apache.iotdb.it.framework.IoTDBTestRunner;
import org.apache.iotdb.itbase.category.LocalStandaloneIT;
import org.apache.iotdb.session.subscription.SubscriptionSession;
import org.apache.iotdb.session.subscription.model.Topic;

import org.junit.Assert;
import org.junit.Before;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,132 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/

package org.apache.iotdb.isession.subscription;

import org.apache.iotdb.isession.subscription.model.Subscription;
import org.apache.iotdb.isession.subscription.model.Topic;
import org.apache.iotdb.rpc.IoTDBConnectionException;
import org.apache.iotdb.rpc.StatementExecutionException;

import java.util.Optional;
import java.util.Properties;
import java.util.Set;

public interface ISubscriptionSession extends AutoCloseable {

void open() throws IoTDBConnectionException;

/////////////////////////////// topic ///////////////////////////////

/**
* Creates a topic with the specified name.
*
* <p>If the topic name contains single quotes, it must be enclosed in backticks (`). For example,
* to create a topic named 'topic', the value passed in as topicName should be `'topic'`
*
* @param topicName If the created topic name contains single quotes, the passed parameter needs
* to be enclosed in backticks.
* @throws IoTDBConnectionException If there is an issue with the connection to IoTDB.
* @throws StatementExecutionException If there is an issue executing the SQL statement.
*/
void createTopic(final String topicName)
throws IoTDBConnectionException, StatementExecutionException;

/**
* Creates a topic with the specified name only if it does not already exist.
*
* <p>This method is similar to {@link #createTopic(String)}, but includes the 'IF NOT EXISTS'
* condition. If the topic name contains single quotes, it must be enclosed in backticks (`).
*
* @param topicName If the created topic name contains single quotes, the passed parameter needs
* to be enclosed in backticks.
* @throws IoTDBConnectionException If there is an issue with the connection to IoTDB.
* @throws StatementExecutionException If there is an issue executing the SQL statement.
*/
void createTopicIfNotExists(final String topicName)
throws IoTDBConnectionException, StatementExecutionException;

/**
* Creates a topic with the specified name and properties.
*
* <p>Topic names with single quotes must be enclosed in backticks (`). Property keys and values
* are included in the SQL statement automatically.
*
* @param topicName If the created topic name contains single quotes, the passed parameter needs
* to be enclosed in backticks.
* @param properties A {@link Properties} object containing the topic's properties.
* @throws IoTDBConnectionException If a connection issue occurs with IoTDB.
* @throws StatementExecutionException If a statement execution issue occurs.
*/
void createTopic(final String topicName, final Properties properties)
throws IoTDBConnectionException, StatementExecutionException;

/**
* Creates a topic with the specified properties if it does not already exist. Topic names with
* single quotes must be enclosed in backticks (`).
*
* @param topicName If the created topic name contains single quotes, the passed parameter needs
* to be enclosed in backticks.
* @param properties A {@link Properties} object containing the topic's properties.
* @throws IoTDBConnectionException If a connection issue occurs.
* @throws StatementExecutionException If the SQL statement execution fails.
*/
void createTopicIfNotExists(final String topicName, final Properties properties)
throws IoTDBConnectionException, StatementExecutionException;

/**
* Drops the specified topic.
*
* <p>This method removes the specified topic from the database. If the topic name contains single
* quotes, it must be enclosed in backticks (`).
*
* @param topicName The name of the topic to be deleted, if it contains single quotes, needs to be
* enclosed in backticks.
* @throws IoTDBConnectionException If there is an issue with the connection to IoTDB.
* @throws StatementExecutionException If there is an issue executing the SQL statement.
*/
void dropTopic(final String topicName)
throws IoTDBConnectionException, StatementExecutionException;

/**
* Drops the specified topic if it exists.
*
* <p>This method is similar to {@link #dropTopic(String)}, but includes the 'IF EXISTS'
* condition. If the topic name contains single quotes, it must be enclosed in backticks (`).
*
* @param topicName The name of the topic to be deleted, if it contains single quotes, needs to be
* enclosed in backticks.
* @throws IoTDBConnectionException If there is an issue with the connection to IoTDB.
* @throws StatementExecutionException If there is an issue executing the SQL statement.
*/
void dropTopicIfExists(final String topicName)
throws IoTDBConnectionException, StatementExecutionException;

Set<Topic> getTopics() throws IoTDBConnectionException, StatementExecutionException;

Optional<Topic> getTopic(final String topicName)
throws IoTDBConnectionException, StatementExecutionException;

/////////////////////////////// subscription ///////////////////////////////

Set<Subscription> getSubscriptions() throws IoTDBConnectionException, StatementExecutionException;

Set<Subscription> getSubscriptions(final String topicName)
throws IoTDBConnectionException, StatementExecutionException;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,132 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/

package org.apache.iotdb.isession.subscription;

import org.apache.iotdb.isession.subscription.model.Subscription;
import org.apache.iotdb.isession.subscription.model.Topic;
import org.apache.iotdb.rpc.IoTDBConnectionException;
import org.apache.iotdb.rpc.StatementExecutionException;

import java.util.Optional;
import java.util.Properties;
import java.util.Set;

public interface ISubscriptionTableSession extends AutoCloseable {

void open() throws IoTDBConnectionException;

/////////////////////////////// topic ///////////////////////////////

/**
* Creates a topic with the specified name.
*
* <p>If the topic name contains single quotes, it must be enclosed in backticks (`). For example,
* to create a topic named 'topic', the value passed in as topicName should be `'topic'`
*
* @param topicName If the created topic name contains single quotes, the passed parameter needs
* to be enclosed in backticks.
* @throws IoTDBConnectionException If there is an issue with the connection to IoTDB.
* @throws StatementExecutionException If there is an issue executing the SQL statement.
*/
void createTopic(final String topicName)
throws IoTDBConnectionException, StatementExecutionException;

/**
* Creates a topic with the specified name only if it does not already exist.
*
* <p>This method is similar to {@link #createTopic(String)}, but includes the 'IF NOT EXISTS'
* condition. If the topic name contains single quotes, it must be enclosed in backticks (`).
*
* @param topicName If the created topic name contains single quotes, the passed parameter needs
* to be enclosed in backticks.
* @throws IoTDBConnectionException If there is an issue with the connection to IoTDB.
* @throws StatementExecutionException If there is an issue executing the SQL statement.
*/
void createTopicIfNotExists(final String topicName)
throws IoTDBConnectionException, StatementExecutionException;

/**
* Creates a topic with the specified name and properties.
*
* <p>Topic names with single quotes must be enclosed in backticks (`). Property keys and values
* are included in the SQL statement automatically.
*
* @param topicName If the created topic name contains single quotes, the passed parameter needs
* to be enclosed in backticks.
* @param properties A {@link Properties} object containing the topic's properties.
* @throws IoTDBConnectionException If a connection issue occurs with IoTDB.
* @throws StatementExecutionException If a statement execution issue occurs.
*/
void createTopic(final String topicName, final Properties properties)
throws IoTDBConnectionException, StatementExecutionException;

/**
* Creates a topic with the specified properties if it does not already exist. Topic names with
* single quotes must be enclosed in backticks (`).
*
* @param topicName If the created topic name contains single quotes, the passed parameter needs
* to be enclosed in backticks.
* @param properties A {@link Properties} object containing the topic's properties.
* @throws IoTDBConnectionException If a connection issue occurs.
* @throws StatementExecutionException If the SQL statement execution fails.
*/
void createTopicIfNotExists(final String topicName, final Properties properties)
throws IoTDBConnectionException, StatementExecutionException;

/**
* Drops the specified topic.
*
* <p>This method removes the specified topic from the database. If the topic name contains single
* quotes, it must be enclosed in backticks (`).
*
* @param topicName The name of the topic to be deleted, if it contains single quotes, needs to be
* enclosed in backticks.
* @throws IoTDBConnectionException If there is an issue with the connection to IoTDB.
* @throws StatementExecutionException If there is an issue executing the SQL statement.
*/
void dropTopic(final String topicName)
throws IoTDBConnectionException, StatementExecutionException;

/**
* Drops the specified topic if it exists.
*
* <p>This method is similar to {@link #dropTopic(String)}, but includes the 'IF EXISTS'
* condition. If the topic name contains single quotes, it must be enclosed in backticks (`).
*
* @param topicName The name of the topic to be deleted, if it contains single quotes, needs to be
* enclosed in backticks.
* @throws IoTDBConnectionException If there is an issue with the connection to IoTDB.
* @throws StatementExecutionException If there is an issue executing the SQL statement.
*/
void dropTopicIfExists(final String topicName)
throws IoTDBConnectionException, StatementExecutionException;

Set<Topic> getTopics() throws IoTDBConnectionException, StatementExecutionException;

Optional<Topic> getTopic(final String topicName)
throws IoTDBConnectionException, StatementExecutionException;

/////////////////////////////// subscription ///////////////////////////////

Set<Subscription> getSubscriptions() throws IoTDBConnectionException, StatementExecutionException;

Set<Subscription> getSubscriptions(final String topicName)
throws IoTDBConnectionException, StatementExecutionException;
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,16 @@
* under the License.
*/

package org.apache.iotdb.session.subscription.model;
package org.apache.iotdb.isession.subscription.model;

public class Subscription {

private final String topicName;
private final String consumerGroupId;
private final String consumerIds;

public Subscription(String topicName, String consumerGroupId, String consumerIds) {
public Subscription(
final String topicName, final String consumerGroupId, final String consumerIds) {
this.topicName = topicName;
this.consumerGroupId = consumerGroupId;
this.consumerIds = consumerIds;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,14 @@
* under the License.
*/

package org.apache.iotdb.session.subscription.model;
package org.apache.iotdb.isession.subscription.model;

public class Topic {

private final String topicName;
private final String topicAttributes;

public Topic(String topicName, String topicAttributes) {
public Topic(final String topicName, final String topicAttributes) {
this.topicName = topicName;
this.topicAttributes = topicAttributes;
}
Expand Down
Loading
Loading