Skip to content
Merged
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
Expand Up @@ -157,13 +157,6 @@ public void success1C4DIoTTestUseTableSQL() throws Exception {
successTest(2, 3, 1, 4, 1, 2, true, SQLModel.TABLE_MODEL_SQL, ConsensusFactory.IOT_CONSENSUS);
}

@Test
public void success1C5DRemoveTwoDataNodesUseSQL() throws Exception {
// Setup 1C5D, and remove 2D in a single "remove datanode a, b" statement; 3 DataNodes remain
// which is enough to keep both the data (factor 2) and schema (factor 3) replicas.
successTest(2, 3, 1, 5, 2, 2, true, SQLModel.TREE_MODEL_SQL, ConsensusFactory.IOT_CONSENSUS);
}

// @Test
public void success1C4DIoTV2TestUseTableSQL() throws Exception {
// Setup 1C4D, and remove 1D, this test should success
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -598,7 +598,7 @@ verifyConnection

// ---- Remove DataNode
removeDataNode
: REMOVE DATANODE dataNodeIds+=INTEGER_LITERAL (COMMA dataNodeIds+=INTEGER_LITERAL)*
: REMOVE DATANODE dataNodeId=INTEGER_LITERAL
;

// ---- Remove ConfigNode
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4704,8 +4704,7 @@ public Statement visitRemoveRegion(IoTDBSqlParser.RemoveRegionContext ctx) {

@Override
public Statement visitRemoveDataNode(IoTDBSqlParser.RemoveDataNodeContext ctx) {
List<Integer> nodeIds =
ctx.dataNodeIds.stream().map(token -> Integer.parseInt(token.getText())).collect(toList());
List<Integer> nodeIds = Collections.singletonList(Integer.parseInt(ctx.dataNodeId.getText()));
return new RemoveDataNodeStatement(nodeIds);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1608,8 +1608,7 @@ public Node visitRemoveRegionStatement(RelationalSqlParser.RemoveRegionStatement

@Override
public Node visitRemoveDataNodeStatement(RelationalSqlParser.RemoveDataNodeStatementContext ctx) {
List<Integer> nodeIds =
ctx.dataNodeIds.stream().map(token -> Integer.parseInt(token.getText())).collect(toList());
List<Integer> nodeIds = Collections.singletonList(Integer.parseInt(ctx.dataNodeId.getText()));
return new RemoveDataNode(nodeIds);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,22 +20,21 @@
package org.apache.iotdb.db.queryengine.plan.parser;

import org.apache.iotdb.db.queryengine.plan.statement.Statement;
import org.apache.iotdb.db.queryengine.plan.statement.metadata.RemoveConfigNodeStatement;
import org.apache.iotdb.db.queryengine.plan.statement.metadata.RemoveDataNodeStatement;

import org.antlr.v4.runtime.misc.ParseCancellationException;
import org.junit.Test;

import java.time.ZoneId;
import java.util.Arrays;
import java.util.Collections;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertThrows;
import static org.junit.Assert.assertTrue;

/**
* Parsing tests for the tree-model SQL that lets REMOVE DATANODE remove multiple DataNodes in a
* single statement.
*/
public class RemoveDataNodeMultiNodeParseTest {
/** Parsing tests for tree-model REMOVE DATANODE and REMOVE CONFIGNODE statements. */
public class RemoveNodeSingleNodeParseTest {

private static Statement parse(String sql) {
return StatementGenerator.createStatement(sql, ZoneId.systemDefault());
Expand All @@ -49,11 +48,15 @@ public void testRemoveSingleDataNode() {
}

@Test
public void testRemoveMultipleDataNodes() {
Statement statement = parse("remove datanode 3, 4, 5");
assertTrue(statement instanceof RemoveDataNodeStatement);
RemoveDataNodeStatement removeDataNodeStatement = (RemoveDataNodeStatement) statement;
assertEquals(3, removeDataNodeStatement.getNodeIds().size());
assertTrue(removeDataNodeStatement.getNodeIds().containsAll(Arrays.asList(3, 4, 5)));
public void testRemoveSingleConfigNode() {
Statement statement = parse("remove confignode 3");
assertTrue(statement instanceof RemoveConfigNodeStatement);
assertEquals(3, ((RemoveConfigNodeStatement) statement).getNodeId().intValue());
}

@Test
public void testRejectRemovingMultipleNodes() {
assertThrows(ParseCancellationException.class, () -> parse("remove datanode 3, 4"));
assertThrows(ParseCancellationException.class, () -> parse("remove confignode 3, 4"));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,25 +20,24 @@
package org.apache.iotdb.db.queryengine.plan.relational.sql.parser;

import org.apache.iotdb.commons.queryengine.plan.relational.sql.ast.Statement;
import org.apache.iotdb.commons.queryengine.plan.relational.sql.parser.ParsingException;
import org.apache.iotdb.db.protocol.session.IClientSession;
import org.apache.iotdb.db.protocol.session.InternalClientSession;
import org.apache.iotdb.db.queryengine.plan.relational.sql.ast.RemoveConfigNode;
import org.apache.iotdb.db.queryengine.plan.relational.sql.ast.RemoveDataNode;

import org.junit.Before;
import org.junit.Test;

import java.time.ZoneId;
import java.util.Arrays;
import java.util.Collections;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertThrows;
import static org.junit.Assert.assertTrue;

/**
* Parsing tests for the table-model SQL that lets REMOVE DATANODE remove multiple DataNodes in a
* single statement.
*/
public class RemoveDataNodeMultiNodeStatementTest {
/** Parsing tests for table-model REMOVE DATANODE and REMOVE CONFIGNODE statements. */
public class RemoveNodeSingleNodeStatementTest {

private SqlParser sqlParser;
private IClientSession clientSession;
Expand All @@ -61,9 +60,15 @@ public void testRemoveSingleDataNode() {
}

@Test
public void testRemoveMultipleDataNodes() {
Statement statement = parse("remove datanode 3, 4, 5");
assertTrue(statement instanceof RemoveDataNode);
assertEquals(Arrays.asList(3, 4, 5), ((RemoveDataNode) statement).getNodeIds());
public void testRemoveSingleConfigNode() {
Statement statement = parse("remove confignode 3");
assertTrue(statement instanceof RemoveConfigNode);
assertEquals(3, ((RemoveConfigNode) statement).getNodeId().intValue());
}

@Test
public void testRejectRemovingMultipleNodes() {
assertThrows(ParsingException.class, () -> parse("remove datanode 3, 4"));
assertThrows(ParsingException.class, () -> parse("remove confignode 3, 4"));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -660,7 +660,7 @@ removeRegionStatement
;

removeDataNodeStatement
: REMOVE DATANODE dataNodeIds+=INTEGER_VALUE (',' dataNodeIds+=INTEGER_VALUE)*
: REMOVE DATANODE dataNodeId=INTEGER_VALUE
;

removeConfigNodeStatement
Expand Down
Loading