Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
9f6e108
Support for Create Pipe If Not Exists Semantics
luoluoyuyu Jul 18, 2024
b5ff79e
Support for Drop Pipe If Exists Semantics
luoluoyuyu Jul 18, 2024
d0f6bd6
Support for Create PipePlugin If Not Exists and Drop PipePlugin If Ex…
luoluoyuyu Jul 18, 2024
14b98fc
Support for Create PipePlugin If Not Exists and Drop PipePlugin If Ex…
luoluoyuyu Jul 18, 2024
4f06652
Add Create Pipe If Not Exists And Drop Pipe If Exists Integration Tests
luoluoyuyu Jul 19, 2024
2ab70f2
Modify the code format
luoluoyuyu Jul 19, 2024
e37b3a9
Modify IoTDBPipeCreateAndDrop Integration Test
luoluoyuyu Jul 19, 2024
8aa7b86
Modify IoTDBPipeCreateAndDrop Integration Test
luoluoyuyu Jul 19, 2024
c26560d
Supports Create Topic IF NOT EXISTS and Drop Topic IF EXISTS semantics.
luoluoyuyu Jul 19, 2024
953c5ea
Supports Alter Pipe IF EXISTS semantics.
luoluoyuyu Jul 19, 2024
9f677a8
pass the CI test
luoluoyuyu Jul 21, 2024
2ba5fe8
Reimplement Drop Topic semantics
luoluoyuyu Jul 22, 2024
51ceb74
fix code
luoluoyuyu Jul 23, 2024
894873a
Modify the code
luoluoyuyu Jul 24, 2024
30a2caf
Modify the code
luoluoyuyu Jul 24, 2024
1c53165
Modify code comments
luoluoyuyu Jul 25, 2024
7e5289a
Modify code comments
luoluoyuyu Jul 25, 2024
152679e
Modify code comments
luoluoyuyu Jul 26, 2024
f096590
Modify code comments
luoluoyuyu Jul 26, 2024
32b87e3
Merge branch 'apache:master' into if-not-exists-support
luoluoyuyu Jul 29, 2024
49cdf1b
Fix Drop If Exits Topic
luoluoyuyu Jul 30, 2024
e818ab8
Merge branch 'master' of https://github.com/apache/iotdb into pr/12969
SteveYurongSu Jul 31, 2024
9e856c7
refactor
SteveYurongSu Jul 31, 2024
4a1b799
refactor
SteveYurongSu Jul 31, 2024
5a2dcbf
Update PipeTaskCoordinator.java
SteveYurongSu Jul 31, 2024
99f0c68
Update SubscriptionCoordinator.java
SteveYurongSu Jul 31, 2024
60aa892
refactor
SteveYurongSu Jul 31, 2024
ff66c0b
Update ASTVisitor.java
SteveYurongSu Jul 31, 2024
14d7300
refactor
SteveYurongSu Jul 31, 2024
e7678d2
Update ClusterConfigTaskExecutor.java
SteveYurongSu Jul 31, 2024
f515702
Update ClusterConfigTaskExecutor.java
SteveYurongSu Jul 31, 2024
9d284b4
refactor
SteveYurongSu Jul 31, 2024
437e709
Update SubscriptionInfo.java
SteveYurongSu Jul 31, 2024
2f2796d
Update PipeTaskInfo.java
SteveYurongSu Jul 31, 2024
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,228 @@
/*
* 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.pipe.it.autocreate;

import org.apache.iotdb.commons.client.sync.SyncConfigNodeIServiceClient;
import org.apache.iotdb.confignode.rpc.thrift.TShowPipeInfo;
import org.apache.iotdb.confignode.rpc.thrift.TShowPipeReq;
import org.apache.iotdb.it.env.cluster.node.DataNodeWrapper;
import org.apache.iotdb.it.framework.IoTDBTestRunner;
import org.apache.iotdb.itbase.category.MultiClusterIT2AutoCreateSchema;

import org.junit.Assert;
import org.junit.Test;
import org.junit.experimental.categories.Category;
import org.junit.runner.RunWith;

import java.sql.Connection;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.List;

import static org.junit.Assert.fail;

@RunWith(IoTDBTestRunner.class)
@Category({MultiClusterIT2AutoCreateSchema.class})
public class IoTDBPipeConditionalOperationsIT extends AbstractPipeDualAutoIT {

@Test
public void testBasicCreatePipeIfNotExists() throws Exception {
final DataNodeWrapper receiverDataNode = receiverEnv.getDataNodeWrapper(0);

// Create pipe
String sql =
String.format(
"create pipe If Not Exists a2b with source ('source'='iotdb-source', 'source.pattern'='root.test1', 'source.realtime.mode'='stream') with processor ('processor'='do-nothing-processor') with sink ('node-urls'='%s')",
receiverDataNode.getIpAndPortString());
try (final Connection connection = senderEnv.getConnection();
final Statement statement = connection.createStatement()) {
statement.execute(sql);
} catch (SQLException e) {
fail(e.getMessage());
}

// show pipe
long creationTime;
try (final SyncConfigNodeIServiceClient client =
(SyncConfigNodeIServiceClient) senderEnv.getLeaderConfigNodeConnection()) {
final List<TShowPipeInfo> showPipeResult = client.showPipe(new TShowPipeReq()).pipeInfoList;
Assert.assertEquals(1, showPipeResult.size());
// Check status
Assert.assertEquals("RUNNING", showPipeResult.get(0).state);
// Check configurations
Assert.assertTrue(showPipeResult.get(0).pipeExtractor.contains("source=iotdb-source"));
Assert.assertTrue(showPipeResult.get(0).pipeExtractor.contains("source.pattern=root.test1"));
Assert.assertTrue(
showPipeResult.get(0).pipeExtractor.contains("source.realtime.mode=stream"));
Assert.assertTrue(
showPipeResult.get(0).pipeProcessor.contains("processor=do-nothing-processor"));
Assert.assertTrue(
showPipeResult
.get(0)
.pipeConnector
.contains(String.format("node-urls=%s", receiverDataNode.getIpAndPortString())));
// Record last creation time
creationTime = showPipeResult.get(0).creationTime;
}

// Create pipe If Not Exists
sql =
String.format(
"create pipe If Not Exists a2b with source ('source'='iotdb-source', 'source.path'='root.test2.**') with sink ('node-urls'='%s')",
receiverDataNode.getIpAndPortString());
try (final Connection connection = senderEnv.getConnection();
final Statement statement = connection.createStatement()) {
statement.execute(sql);
} catch (SQLException e) {
fail(e.getMessage());
}

// show pipe
try (final SyncConfigNodeIServiceClient client =
(SyncConfigNodeIServiceClient) senderEnv.getLeaderConfigNodeConnection()) {
final List<TShowPipeInfo> showPipeResult = client.showPipe(new TShowPipeReq()).pipeInfoList;
Assert.assertEquals(1, showPipeResult.size());
// Check status
Assert.assertEquals("RUNNING", showPipeResult.get(0).state);
// Check configurations
Assert.assertTrue(showPipeResult.get(0).pipeExtractor.contains("source=iotdb-source"));
Assert.assertTrue(showPipeResult.get(0).pipeExtractor.contains("source.pattern=root.test1"));
Assert.assertTrue(
showPipeResult.get(0).pipeExtractor.contains("source.realtime.mode=stream"));
Assert.assertTrue(
showPipeResult.get(0).pipeProcessor.contains("processor=do-nothing-processor"));
Assert.assertTrue(
showPipeResult
.get(0)
.pipeConnector
.contains(String.format("node-urls=%s", receiverDataNode.getIpAndPortString())));
Assert.assertFalse(showPipeResult.get(0).pipeExtractor.contains("source.path=root.test2.**"));
Assert.assertEquals(creationTime, showPipeResult.get(0).creationTime);
}
}

@Test
public void testBasicDropPipeIfExists() throws Exception {
final DataNodeWrapper receiverDataNode = receiverEnv.getDataNodeWrapper(0);

// Create pipe
final String sql =
String.format(
"create pipe If Not Exists a2b with source ('source'='iotdb-source', 'source.path'='root.test1.**') with processor ('processor'='do-nothing-processor') with sink ('node-urls'='%s')",
receiverDataNode.getIpAndPortString());
try (final Connection connection = senderEnv.getConnection();
final Statement statement = connection.createStatement()) {
statement.execute(sql);
} catch (SQLException e) {
fail(e.getMessage());
}

// Drop pipe If Exists
try (final Connection connection = senderEnv.getConnection();
final Statement statement = connection.createStatement()) {
statement.execute("Drop pipe If Exists a2b");
} catch (SQLException e) {
fail(e.getMessage());
}

// show pipe
try (final SyncConfigNodeIServiceClient client =
(SyncConfigNodeIServiceClient) senderEnv.getLeaderConfigNodeConnection()) {
final List<TShowPipeInfo> showPipeResult = client.showPipe(new TShowPipeReq()).pipeInfoList;
Assert.assertEquals(0, showPipeResult.size());
}

// Drop pipe If Exists
try (final Connection connection = senderEnv.getConnection();
final Statement statement = connection.createStatement()) {
statement.execute("Drop pipe If Exists a2b");
} catch (SQLException e) {
fail(e.getMessage());
}
}

public void testBasicAlterPipeIfExists() throws Exception {
final DataNodeWrapper receiverDataNode = receiverEnv.getDataNodeWrapper(0);

// Alter pipe If Exists
String sql =
String.format(
"Alter pipe If Exists a2b replace sink ('node-urls'='%s')",
receiverDataNode.getIpAndPortString());
try (final Connection connection = senderEnv.getConnection();
final Statement statement = connection.createStatement()) {
statement.execute(sql);
} catch (SQLException e) {
fail(e.getMessage());
}

// show pipe
try (final SyncConfigNodeIServiceClient client =
(SyncConfigNodeIServiceClient) senderEnv.getLeaderConfigNodeConnection()) {
final List<TShowPipeInfo> showPipeResult = client.showPipe(new TShowPipeReq()).pipeInfoList;
Assert.assertEquals(0, showPipeResult.size());
}

// Create pipe
sql =
String.format(
"create pipe If Not Exists a2b with source ('source'='iotdb-source', 'source.pattern'='root.test1', 'source.realtime.mode'='stream') with processor ('processor'='do-nothing-processor') with sink ('node-urls'='%s')",
receiverDataNode.getIpAndPortString());
try (final Connection connection = senderEnv.getConnection();
final Statement statement = connection.createStatement()) {
statement.execute(sql);
} catch (SQLException e) {
fail(e.getMessage());
}

// Alter pipe If Exists
sql =
String.format(
"Alter pipe If Exists a2b replace source () replace processor () replace sink ('node-urls'='%s')",
receiverDataNode.getIpAndPortString());
try (final Connection connection = senderEnv.getConnection();
final Statement statement = connection.createStatement()) {
statement.execute(sql);
} catch (SQLException e) {
fail(e.getMessage());
}

// show pipe
try (final SyncConfigNodeIServiceClient client =
(SyncConfigNodeIServiceClient) senderEnv.getLeaderConfigNodeConnection()) {
final List<TShowPipeInfo> showPipeResult = client.showPipe(new TShowPipeReq()).pipeInfoList;
Assert.assertEquals(1, showPipeResult.size());
// Check status
Assert.assertEquals("RUNNING", showPipeResult.get(0).state);
// Check configurations
Assert.assertFalse(showPipeResult.get(0).pipeExtractor.contains("source=iotdb-source"));
Assert.assertFalse(showPipeResult.get(0).pipeExtractor.contains("source.pattern=root.test1"));
Assert.assertFalse(
showPipeResult.get(0).pipeExtractor.contains("source.realtime.mode=stream"));
Assert.assertFalse(
showPipeResult.get(0).pipeProcessor.contains("processor=do-nothing-processor"));
Assert.assertTrue(
showPipeResult
.get(0)
.pipeConnector
.contains(String.format("node-urls=%s", receiverDataNode.getIpAndPortString())));
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -250,6 +250,7 @@ public enum TSStatusCode {
ALTER_TOPIC_ERROR(2002),
SHOW_TOPIC_ERROR(2003),
TOPIC_PUSH_META_ERROR(2004),
TOPIC_NOT_EXIST_ERROR(2005),

// Consumer
CREATE_CONSUMER_ERROR(2100),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -535,7 +535,7 @@ verifyConnection

// Pipe Task =========================================================================================
createPipe
: CREATE PIPE pipeName=identifier
: CREATE PIPE (IF NOT EXISTS)? pipeName=identifier
extractorAttributesClause?
processorAttributesClause?
connectorAttributesClause
Expand Down Expand Up @@ -575,7 +575,7 @@ connectorAttributeClause
;

alterPipe
: ALTER PIPE pipeName=identifier
: ALTER PIPE (IF EXISTS)? pipeName=identifier
alterExtractorAttributesClause?
alterProcessorAttributesClause?
alterConnectorAttributesClause?
Expand Down Expand Up @@ -603,7 +603,7 @@ alterConnectorAttributesClause
;

dropPipe
: DROP PIPE pipeName=identifier
: DROP PIPE (IF EXISTS)? pipeName=identifier
;

startPipe
Expand All @@ -620,11 +620,11 @@ showPipes

// Pipe Plugin =========================================================================================
createPipePlugin
: CREATE PIPEPLUGIN pluginName=identifier AS className=STRING_LITERAL uriClause
: CREATE PIPEPLUGIN (IF NOT EXISTS)? pluginName=identifier AS className=STRING_LITERAL uriClause
;

dropPipePlugin
: DROP PIPEPLUGIN pluginName=identifier
: DROP PIPEPLUGIN (IF EXISTS)? pluginName=identifier
;

showPipePlugins
Expand All @@ -633,7 +633,7 @@ showPipePlugins

// Topic =========================================================================================
createTopic
: CREATE TOPIC topicName=identifier topicAttributesClause?
: CREATE TOPIC (IF NOT EXISTS)? topicName=identifier topicAttributesClause?
;

topicAttributesClause
Expand All @@ -645,7 +645,7 @@ topicAttributeClause
;

dropTopic
: DROP TOPIC topicName=identifier
: DROP TOPIC (IF EXISTS)? topicName=identifier
;

showTopics
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -286,6 +286,10 @@ EVERY
: E V E R Y
;

EXISTS
: E X I S T S
;

EXPLAIN
: E X P L A I N
;
Expand Down Expand Up @@ -942,10 +946,15 @@ ELSE
: E L S E
;

IF
: I F
;

INF
: I N F
;


// Privileges Keywords

PRIVILEGE_VALUE
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,9 @@
import org.apache.iotdb.confignode.rpc.thrift.TDeleteLogicalViewReq;
import org.apache.iotdb.confignode.rpc.thrift.TDeleteTimeSeriesReq;
import org.apache.iotdb.confignode.rpc.thrift.TDropCQReq;
import org.apache.iotdb.confignode.rpc.thrift.TDropPipePluginReq;
import org.apache.iotdb.confignode.rpc.thrift.TDropPipeReq;
import org.apache.iotdb.confignode.rpc.thrift.TDropTopicReq;
import org.apache.iotdb.confignode.rpc.thrift.TDropTriggerReq;
import org.apache.iotdb.confignode.rpc.thrift.TGetAllPipeInfoResp;
import org.apache.iotdb.confignode.rpc.thrift.TGetAllSubscriptionInfoResp;
Expand Down Expand Up @@ -1441,10 +1444,10 @@ public TSStatus createPipePlugin(TCreatePipePluginReq req) {
}

@Override
public TSStatus dropPipePlugin(String pipePluginName) {
public TSStatus dropPipePlugin(TDropPipePluginReq req) {
TSStatus status = confirmLeader();
return status.getCode() == TSStatusCode.SUCCESS_STATUS.getStatusCode()
? pipeManager.getPipePluginCoordinator().dropPipePlugin(pipePluginName)
? pipeManager.getPipePluginCoordinator().dropPipePlugin(req)
: status;
}

Expand Down Expand Up @@ -2026,10 +2029,10 @@ public TSStatus stopPipe(String pipeName) {
}

@Override
public TSStatus dropPipe(String pipeName) {
public TSStatus dropPipe(TDropPipeReq req) {
TSStatus status = confirmLeader();
return status.getCode() == TSStatusCode.SUCCESS_STATUS.getStatusCode()
? pipeManager.getPipeTaskCoordinator().dropPipe(pipeName)
? pipeManager.getPipeTaskCoordinator().dropPipe(req)
: status;
}

Expand Down Expand Up @@ -2058,10 +2061,10 @@ public TSStatus createTopic(TCreateTopicReq req) {
}

@Override
public TSStatus dropTopic(String topicName) {
public TSStatus dropTopic(TDropTopicReq req) {
TSStatus status = confirmLeader();
return status.getCode() == TSStatusCode.SUCCESS_STATUS.getStatusCode()
? subscriptionManager.getSubscriptionCoordinator().dropTopic(topicName)
? subscriptionManager.getSubscriptionCoordinator().dropTopic(req)
: status;
}

Expand Down
Loading