Skip to content

Commit 06ca819

Browse files
CaideyipiJackieTien97
authored andcommitted
Changed the SQL of AlterEncodingCompressor statement & banned the "root" timeSeries & handled the empty intersection path & refactored the IT (#16725)
1 parent 93efc0a commit 06ca819

File tree

5 files changed

+46
-12
lines changed

5 files changed

+46
-12
lines changed

integration-test/src/test/java/org/apache/iotdb/db/it/schema/IoTDBAlterEncodingCompressorIT.java

Lines changed: 33 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,15 @@ public void alterEncodingAndCompressorTest() throws Exception {
7272
statement.execute("create timeSeries root.vehicle.wind.a int32");
7373

7474
try {
75-
statement.execute("alter timeSeries root.nonExist.** set encoding=PLAIN");
75+
statement.execute("alter timeSeries root set STORAGE_PROPERTIES encoding=PLAIN");
76+
fail();
77+
} catch (final SQLException e) {
78+
Assert.assertEquals("701: The timeSeries shall not be root.", e.getMessage());
79+
}
80+
81+
try {
82+
statement.execute(
83+
"alter timeSeries root.nonExist.** set STORAGE_PROPERTIES encoding=PLAIN");
7684
fail();
7785
} catch (final SQLException e) {
7886
Assert.assertEquals(
@@ -81,41 +89,47 @@ public void alterEncodingAndCompressorTest() throws Exception {
8189
}
8290

8391
try {
84-
statement.execute("alter timeSeries if exists root.nonExist.** set encoding=PLAIN");
92+
statement.execute(
93+
"alter timeSeries if exists root.nonExist.** set STORAGE_PROPERTIES encoding=PLAIN");
8594
} catch (final SQLException e) {
8695
fail(
8796
"Alter encoding & compressor shall not fail when timeSeries not exists if set if exists");
8897
}
8998

9099
try {
91-
statement.execute("alter timeSeries if exists root.vehicle.** set encoding=aaa");
100+
statement.execute(
101+
"alter timeSeries if exists root.vehicle.** set STORAGE_PROPERTIES encoding=aaa");
92102
fail();
93103
} catch (final SQLException e) {
94104
Assert.assertEquals("701: Unsupported encoding: AAA", e.getMessage());
95105
}
96106

97107
try {
98-
statement.execute("alter timeSeries if exists root.vehicle.** set compressor=aaa");
108+
statement.execute(
109+
"alter timeSeries if exists root.vehicle.** set STORAGE_PROPERTIES compressor=aaa");
99110
fail();
100111
} catch (final SQLException e) {
101112
Assert.assertEquals("701: Unsupported compressor: AAA", e.getMessage());
102113
}
103114

104115
try {
105-
statement.execute("alter timeSeries if exists root.vehicle.** set falseKey=aaa");
116+
statement.execute(
117+
"alter timeSeries if exists root.vehicle.** set STORAGE_PROPERTIES falseKey=aaa");
106118
fail();
107119
} catch (final SQLException e) {
108120
Assert.assertEquals("701: property falsekey is unsupported yet.", e.getMessage());
109121
}
110122

111123
try {
112-
statement.execute("alter timeSeries if exists root.vehicle.** set encoding=DICTIONARY");
124+
statement.execute(
125+
"alter timeSeries if exists root.vehicle.** set STORAGE_PROPERTIES encoding=DICTIONARY");
113126
fail();
114127
} catch (final SQLException e) {
115128
Assert.assertTrue(e.getMessage().contains("encoding DICTIONARY does not support INT32"));
116129
}
117130

118-
statement.execute("alter timeSeries root.** set encoding=Plain, compressor=LZMA2");
131+
statement.execute(
132+
"alter timeSeries root.** set STORAGE_PROPERTIES encoding=Plain, compressor=LZMA2");
119133

120134
try (final ResultSet resultSet = statement.executeQuery("SHOW TIMESERIES")) {
121135
while (resultSet.next()) {
@@ -133,17 +147,18 @@ public void alterEncodingAndCompressorTest() throws Exception {
133147
EnvFactory.getEnv().getConnection("IoTDBUser", "!@#$!dfdfzvd343");
134148
final Statement statement = connection.createStatement()) {
135149
try {
136-
statement.execute("alter timeSeries root.vechile.** set encoding=PLAIN, compressor=LZMA2");
150+
statement.execute(
151+
"alter timeSeries root.vehicle.** set STORAGE_PROPERTIES encoding=PLAIN, compressor=LZMA2");
137152
fail();
138153
} catch (final SQLException e) {
139154
Assert.assertEquals(
140-
"803: No permissions for this operation, please add privilege WRITE_SCHEMA on [root.vechile.**]",
155+
"803: No permissions for this operation, please add privilege WRITE_SCHEMA on [root.vehicle.**]",
141156
e.getMessage());
142157
}
143158

144159
try {
145160
statement.execute(
146-
"alter timeSeries root.vechile.wind.a, root.__audit.** set encoding=PLAIN, compressor=LZMA2");
161+
"alter timeSeries root.vehicle.wind.a, root.__audit.** set STORAGE_PROPERTIES encoding=PLAIN, compressor=LZMA2");
147162
fail();
148163
} catch (final SQLException e) {
149164
Assert.assertEquals(
@@ -153,10 +168,17 @@ public void alterEncodingAndCompressorTest() throws Exception {
153168

154169
try {
155170
statement.execute(
156-
"alter timeSeries if permitted root.vehicle.**, root.__audit.** set encoding=GORILLA, compressor=GZIP");
171+
"alter timeSeries if permitted root.vehicle.**, root.__audit.** set STORAGE_PROPERTIES encoding=GORILLA, compressor=GZIP");
157172
} catch (final SQLException e) {
158173
fail("Alter encoding & compressor shall not fail when no privileges if set if permitted");
159174
}
175+
176+
try {
177+
statement.execute(
178+
"alter timeSeries if permitted root.nonExist.** set STORAGE_PROPERTIES encoding=GORILLA, compressor=GZIP");
179+
} catch (final SQLException e) {
180+
fail("Alter encoding & compressor shall not fail if the intersected paths are empty");
181+
}
160182
}
161183

162184
try (final Connection connection = EnvFactory.getEnv().getConnection();

iotdb-core/antlr/src/main/antlr4/org/apache/iotdb/db/qp/sql/IoTDBSqlParser.g4

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,7 @@ alterClause
178178
;
179179

180180
alterEncodingCompressor
181-
: ALTER TIMESERIES (IF EXISTS)? (IF PERMITTED)? prefixPath (COMMA prefixPath)* SET attributePair (COMMA attributePair)*
181+
: ALTER TIMESERIES (IF EXISTS)? (IF PERMITTED)? prefixPath (COMMA prefixPath)* SET STORAGE_PROPERTIES attributePair (COMMA attributePair)*
182182
;
183183

184184
aliasClause

iotdb-core/antlr/src/main/antlr4/org/apache/iotdb/db/qp/sql/SqlLexer.g4

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -842,6 +842,10 @@ STOP
842842
: S T O P
843843
;
844844

845+
STORAGE_PROPERTIES
846+
: S T O R A G E '_' P R O P E R T I E S
847+
;
848+
845849
SUBSCRIPTION
846850
: S U B S C R I P T I O N
847851
;

iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/execution/config/executor/ClusterConfigTaskExecutor.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2610,6 +2610,11 @@ public SettableFuture<ConfigTaskResult> alterEncodingCompressor(
26102610
final String queryId,
26112611
final AlterEncodingCompressorStatement alterEncodingCompressorStatement) {
26122612
final SettableFuture<ConfigTaskResult> future = SettableFuture.create();
2613+
// Will only occur if no permission
2614+
if (alterEncodingCompressorStatement.getPatternTree().isEmpty()) {
2615+
future.set(new ConfigTaskResult(TSStatusCode.SUCCESS_STATUS));
2616+
return future;
2617+
}
26132618
final ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
26142619
final DataOutputStream dataOutputStream = new DataOutputStream(byteArrayOutputStream);
26152620
try {

iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/parser/ASTVisitor.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -694,6 +694,9 @@ public Statement visitAlterEncodingCompressor(
694694
}
695695
}
696696

697+
if (tree.isEmpty()) {
698+
throw new SemanticException("The timeSeries shall not be root.");
699+
}
697700
return new AlterEncodingCompressorStatement(
698701
tree,
699702
encoding,

0 commit comments

Comments
 (0)