Skip to content

Commit b5d43ce

Browse files
committed
optimize codes.
1 parent 069a3c3 commit b5d43ce

File tree

3 files changed

+58
-53
lines changed

3 files changed

+58
-53
lines changed

integration-test/src/test/java/org/apache/iotdb/relational/it/schema/IoTDBAlterTimeSeriesTypeIT.java renamed to integration-test/src/test/java/org/apache/iotdb/db/it/schema/IoTDBAlterTimeSeriesTypeIT.java

Lines changed: 44 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
* under the License.
1818
*/
1919

20-
package org.apache.iotdb.relational.it.schema;
20+
package org.apache.iotdb.db.it.schema;
2121

2222
import org.apache.iotdb.commons.utils.MetadataUtils;
2323
import org.apache.iotdb.db.utils.SchemaUtils;
@@ -100,25 +100,15 @@ public class IoTDBAlterTimeSeriesTypeIT {
100100
public static void setUp() throws Exception {
101101
EnvFactory.getEnv().getConfig().getDataNodeConfig().setCompactionScheduleInterval(1000);
102102
EnvFactory.getEnv().initClusterEnvironment();
103-
try (ISession session = EnvFactory.getEnv().getSessionConnection()) {
104-
// session.createDatabase(database);
105-
}
106103
}
107104

108105
@AfterClass
109106
public static void tearDown() throws Exception {
110-
try (ISession session = EnvFactory.getEnv().getSessionConnection()) {
111-
// session.deleteDatabase(database);
112-
}
113107
EnvFactory.getEnv().cleanClusterEnvironment();
114108
}
115109

116110
@Test
117-
public void testWriteAndAlter()
118-
throws IoTDBConnectionException,
119-
StatementExecutionException,
120-
IOException,
121-
WriteProcessException {
111+
public void testWriteAndAlter() throws Exception {
122112
Set<TSDataType> typesToTest = new HashSet<>();
123113
Collections.addAll(typesToTest, TSDataType.values());
124114
typesToTest.remove(TSDataType.VECTOR);
@@ -1080,11 +1070,7 @@ public void testLoadAndAccumulator()
10801070
}
10811071
}
10821072

1083-
public void testNonAlignDeviceSequenceDataQuery(TSDataType from, TSDataType to)
1084-
throws IoTDBConnectionException,
1085-
StatementExecutionException,
1086-
IOException,
1087-
WriteProcessException {
1073+
public void testNonAlignDeviceSequenceDataQuery(TSDataType from, TSDataType to) throws Exception {
10881074
try (ISession session = EnvFactory.getEnv().getSessionConnection()) {
10891075
session.executeNonQueryStatement("SET CONFIGURATION 'enable_unseq_space_compaction'='false'");
10901076

@@ -1200,8 +1186,11 @@ public void testNonAlignDeviceSequenceDataQuery(TSDataType from, TSDataType to)
12001186
standardSelectTestAfterAlterColumnType(from, session, newType);
12011187
// Accumulator query test
12021188
standardAccumulatorQueryTest(session, from, newType);
1189+
} catch (NotSupportedException e) {
1190+
log.info(e.getMessage());
12031191
} catch (Exception e) {
12041192
log.info(e.getMessage());
1193+
throw new Exception(e);
12051194
}
12061195

12071196
if (from == TSDataType.DATE) {
@@ -1223,11 +1212,7 @@ public void testNonAlignDeviceSequenceDataQuery(TSDataType from, TSDataType to)
12231212
}
12241213
}
12251214

1226-
public void testAlignDeviceSequenceDataQuery(TSDataType from, TSDataType to)
1227-
throws IoTDBConnectionException,
1228-
StatementExecutionException,
1229-
IOException,
1230-
WriteProcessException {
1215+
public void testAlignDeviceSequenceDataQuery(TSDataType from, TSDataType to) throws Exception {
12311216
try (ISession session = EnvFactory.getEnv().getSessionConnection()) {
12321217
session.executeNonQueryStatement("SET CONFIGURATION 'enable_unseq_space_compaction'='false'");
12331218

@@ -1308,8 +1293,11 @@ public void testAlignDeviceSequenceDataQuery(TSDataType from, TSDataType to)
13081293
try {
13091294
standardSelectTest(session, from, to);
13101295
standardAccumulatorQueryTest(session, from);
1296+
} catch (NotSupportedException e) {
1297+
log.info(e.getMessage());
13111298
} catch (Exception e) {
13121299
log.info(e.getMessage());
1300+
throw new Exception(e);
13131301
}
13141302

13151303
// alter the type to "to"
@@ -1347,8 +1335,11 @@ public void testAlignDeviceSequenceDataQuery(TSDataType from, TSDataType to)
13471335
standardSelectTestAfterAlterColumnType(from, session, newType);
13481336
// Accumulator query test
13491337
standardAccumulatorQueryTest(session, from, newType);
1338+
} catch (NotSupportedException e) {
1339+
log.info(e.getMessage());
13501340
} catch (Exception e) {
13511341
log.info(e.getMessage());
1342+
throw new Exception(e);
13521343
}
13531344

13541345
if (from == TSDataType.DATE) {
@@ -1371,10 +1362,7 @@ public void testAlignDeviceSequenceDataQuery(TSDataType from, TSDataType to)
13711362
}
13721363

13731364
public void testNonAlignDeviceUnSequenceDataQuery(TSDataType from, TSDataType to)
1374-
throws IoTDBConnectionException,
1375-
StatementExecutionException,
1376-
IOException,
1377-
WriteProcessException {
1365+
throws Exception {
13781366
try (ISession session = EnvFactory.getEnv().getSessionConnection()) {
13791367
session.executeNonQueryStatement("SET CONFIGURATION 'enable_unseq_space_compaction'='false'");
13801368

@@ -1444,8 +1432,11 @@ public void testNonAlignDeviceUnSequenceDataQuery(TSDataType from, TSDataType to
14441432
try {
14451433
standardSelectTest(session, from, to);
14461434
standardAccumulatorQueryTest(session, from);
1435+
} catch (NotSupportedException e) {
1436+
log.info(e.getMessage());
14471437
} catch (Exception e) {
14481438
log.info(e.getMessage());
1439+
throw new Exception(e);
14491440
}
14501441

14511442
// alter the type to "to"
@@ -1483,8 +1474,11 @@ public void testNonAlignDeviceUnSequenceDataQuery(TSDataType from, TSDataType to
14831474
standardSelectTestAfterAlterColumnType(from, session, newType);
14841475
// Accumulator query test
14851476
standardAccumulatorQueryTest(session, from, newType);
1477+
} catch (NotSupportedException e) {
1478+
log.info(e.getMessage());
14861479
} catch (Exception e) {
14871480
log.info(e.getMessage());
1481+
throw new Exception(e);
14881482
}
14891483

14901484
if (from == TSDataType.DATE) {
@@ -1506,11 +1500,7 @@ public void testNonAlignDeviceUnSequenceDataQuery(TSDataType from, TSDataType to
15061500
}
15071501
}
15081502

1509-
public void testAlignDeviceUnSequenceDataQuery(TSDataType from, TSDataType to)
1510-
throws IoTDBConnectionException,
1511-
StatementExecutionException,
1512-
IOException,
1513-
WriteProcessException {
1503+
public void testAlignDeviceUnSequenceDataQuery(TSDataType from, TSDataType to) throws Exception {
15141504
try (ISession session = EnvFactory.getEnv().getSessionConnection()) {
15151505
session.executeNonQueryStatement("SET CONFIGURATION 'enable_unseq_space_compaction'='false'");
15161506

@@ -1584,8 +1574,11 @@ public void testAlignDeviceUnSequenceDataQuery(TSDataType from, TSDataType to)
15841574
try {
15851575
standardSelectTest(session, from, to);
15861576
standardAccumulatorQueryTest(session, from);
1577+
} catch (NotSupportedException e) {
1578+
log.info(e.getMessage());
15871579
} catch (Exception e) {
15881580
log.info(e.getMessage());
1581+
throw new Exception(e);
15891582
}
15901583

15911584
// alter the type to "to"
@@ -1623,8 +1616,11 @@ public void testAlignDeviceUnSequenceDataQuery(TSDataType from, TSDataType to)
16231616
standardSelectTestAfterAlterColumnType(from, session, newType);
16241617
// Accumulator query test
16251618
standardAccumulatorQueryTest(session, from, newType);
1619+
} catch (NotSupportedException e) {
1620+
log.info(e.getMessage());
16261621
} catch (Exception e) {
16271622
log.info(e.getMessage());
1623+
throw new Exception(e);
16281624
}
16291625

16301626
if (from == TSDataType.DATE) {
@@ -1647,10 +1643,7 @@ public void testAlignDeviceUnSequenceDataQuery(TSDataType from, TSDataType to)
16471643
}
16481644

16491645
public void testNonAlignDeviceUnSequenceOverlappedDataQuery(TSDataType from, TSDataType to)
1650-
throws IoTDBConnectionException,
1651-
StatementExecutionException,
1652-
IOException,
1653-
WriteProcessException {
1646+
throws Exception {
16541647
try (ISession session = EnvFactory.getEnv().getSessionConnection()) {
16551648
session.executeNonQueryStatement("SET CONFIGURATION 'enable_unseq_space_compaction'='false'");
16561649

@@ -1720,8 +1713,11 @@ public void testNonAlignDeviceUnSequenceOverlappedDataQuery(TSDataType from, TSD
17201713
try {
17211714
standardSelectTest(session, from, to);
17221715
standardAccumulatorQueryTest(session, from);
1716+
} catch (NotSupportedException e) {
1717+
log.info(e.getMessage());
17231718
} catch (Exception e) {
17241719
log.info(e.getMessage());
1720+
throw new Exception(e);
17251721
}
17261722

17271723
// alter the type to "to"
@@ -1759,8 +1755,11 @@ public void testNonAlignDeviceUnSequenceOverlappedDataQuery(TSDataType from, TSD
17591755
standardSelectTestAfterAlterColumnType(from, session, newType);
17601756
// Accumulator query test
17611757
standardAccumulatorQueryTest(session, from, newType);
1758+
} catch (NotSupportedException e) {
1759+
log.info(e.getMessage());
17621760
} catch (Exception e) {
17631761
log.info(e.getMessage());
1762+
throw new Exception(e);
17641763
}
17651764

17661765
if (from == TSDataType.DATE) {
@@ -1783,10 +1782,7 @@ public void testNonAlignDeviceUnSequenceOverlappedDataQuery(TSDataType from, TSD
17831782
}
17841783

17851784
public void testAlignDeviceUnSequenceOverlappedDataQuery(TSDataType from, TSDataType to)
1786-
throws IoTDBConnectionException,
1787-
StatementExecutionException,
1788-
IOException,
1789-
WriteProcessException {
1785+
throws Exception {
17901786
try (ISession session = EnvFactory.getEnv().getSessionConnection()) {
17911787
session.executeNonQueryStatement("SET CONFIGURATION 'enable_unseq_space_compaction'='false'");
17921788

@@ -1860,8 +1856,11 @@ public void testAlignDeviceUnSequenceOverlappedDataQuery(TSDataType from, TSData
18601856
try {
18611857
standardSelectTest(session, from, to);
18621858
standardAccumulatorQueryTest(session, from);
1859+
} catch (NotSupportedException e) {
1860+
log.info(e.getMessage());
18631861
} catch (Exception e) {
18641862
log.info(e.getMessage());
1863+
throw new Exception(e);
18651864
}
18661865

18671866
// alter the type to "to"
@@ -2348,7 +2347,7 @@ private static void standardAccumulatorQueryTest(ISession session, TSDataType ne
23482347
RowRecord rec;
23492348
if (!UNSUPPORT_ACCUMULATOR_QUERY_DATA_TYPE_LIST.contains(newType)) {
23502349
int[] expectedValue;
2351-
2350+
int max = 4;
23522351
if (DATA_TYPE_LIST.contains(newType)) {
23532352
dataSet =
23542353
session.executeQueryStatement(
@@ -2364,6 +2363,7 @@ private static void standardAccumulatorQueryTest(ISession session, TSDataType ne
23642363
} else if (newType == TSDataType.BOOLEAN) {
23652364
expectedValue = new int[] {19700102, 19721021};
23662365
}
2366+
max = 2;
23672367
} else {
23682368
dataSet =
23692369
session.executeQueryStatement(
@@ -2382,7 +2382,7 @@ private static void standardAccumulatorQueryTest(ISession session, TSDataType ne
23822382
}
23832383

23842384
if (newType != TSDataType.BOOLEAN) {
2385-
for (int i = 0; i < 4; i++) {
2385+
for (int i = 0; i < max; i++) {
23862386
if (newType == TSDataType.BLOB) {
23872387
assertEquals(genValue(newType, expectedValue[i]), rec.getFields().get(i).getBinaryV());
23882388
} else if (newType == TSDataType.DATE) {
@@ -2459,13 +2459,15 @@ private static void standardAccumulatorQueryTest(
24592459
} else {
24602460
SessionDataSet dataSet;
24612461
int[] expectedValue;
2462+
int max = 4;
24622463
if (DATA_TYPE_LIST.contains(newType)) {
24632464
dataSet =
24642465
session.executeQueryStatement(
24652466
"select first_value(s1),last_value(s1) from "
24662467
+ database
24672468
+ ".construct_and_alter_column_type");
24682469
expectedValue = new int[] {1, 1024};
2470+
max = 2;
24692471
} else {
24702472
dataSet =
24712473
session.executeQueryStatement(
@@ -2486,7 +2488,7 @@ private static void standardAccumulatorQueryTest(
24862488
// expectedValue = new int[] {19700102, 19721021, 19700102, 19721021};
24872489
// }
24882490
if (newType != TSDataType.BOOLEAN) {
2489-
for (int i = 0; i < 4; i++) {
2491+
for (int i = 0; i < max; i++) {
24902492
if (newType == TSDataType.BLOB) {
24912493
assertEquals(genValue(newType, expectedValue[i]), rec.getFields().get(i).getBinaryV());
24922494
} else if (newType == TSDataType.DATE) {

integration-test/src/test/java/org/apache/iotdb/relational/it/schema/IoTDBAlterColumnTypeIT.java

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,12 @@ public void testWriteAndAlter()
127127

128128
for (TSDataType from : typesToTest) {
129129
for (TSDataType to : typesToTest) {
130+
if (from == TSDataType.TEXT && to == TSDataType.STRING) {
131+
// continue;
132+
} else {
133+
continue;
134+
}
135+
130136
if (from != to && to.isCompatible(from)) {
131137
System.out.printf("testing %s to %s%n", from, to);
132138
doWriteAndAlter(from, to);
@@ -327,9 +333,6 @@ public void testAlterWithoutWrite() throws IoTDBConnectionException, StatementEx
327333
Collections.addAll(typesToTest, TSDataType.values());
328334
typesToTest.remove(TSDataType.VECTOR);
329335
typesToTest.remove(TSDataType.UNKNOWN);
330-
// typesToTest.remove(TSDataType.STRING);
331-
// typesToTest.remove(TSDataType.TEXT);
332-
// typesToTest.remove(TSDataType.DATE);
333336

334337
for (TSDataType from : typesToTest) {
335338
for (TSDataType to : typesToTest) {
@@ -1336,7 +1339,7 @@ public void testAlignDeviceSequenceDataQuery(TSDataType from, TSDataType to)
13361339
dataSet.close();
13371340

13381341
try {
1339-
// standardSelectTest(session, from, to);
1342+
standardSelectTest(session, from, to);
13401343
standardAccumulatorQueryTest(session, from);
13411344
} catch (Exception e) {
13421345
log.error("{}", e.getStackTrace());

iotdb-core/datanode/src/main/java/org/apache/iotdb/db/utils/SchemaUtils.java

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -312,7 +312,7 @@ public static void changeMetadataModified(
312312
return;
313313
}
314314
if (!SchemaUtils.isUsingSameColumn(timeseriesMetadata.getTsDataType(), targetDataType)
315-
&& Arrays.asList(TSDataType.STRING, TSDataType.TEXT).contains(targetDataType)) {
315+
&& ((targetDataType == TSDataType.STRING) || (targetDataType == TSDataType.TEXT))) {
316316
timeseriesMetadata.setModified(true);
317317
if (timeseriesMetadata.getChunkMetadataList() != null) {
318318
timeseriesMetadata.setChunkMetadataList(
@@ -341,8 +341,8 @@ public static void changeAlignedMetadataModified(
341341
if ((timeseriesMetadata != null)
342342
&& !SchemaUtils.isUsingSameColumn(
343343
timeseriesMetadata.getTsDataType(), targetDataTypeList.get(i))
344-
&& Arrays.asList(TSDataType.STRING, TSDataType.TEXT)
345-
.contains(targetDataTypeList.get(i))) {
344+
&& ((targetDataTypeList.get(i) == TSDataType.STRING)
345+
|| (targetDataTypeList.get(i) == TSDataType.TEXT))) {
346346
timeseriesMetadata.setModified(true);
347347
alignedTimeSeriesMetadata.setModified(true);
348348
if (timeseriesMetadata.getChunkMetadataList() != null) {
@@ -368,7 +368,7 @@ public static void changeAlignedMetadataModified(
368368
}
369369

370370
if (!SchemaUtils.isUsingSameColumn(timeseriesMetadata.getTsDataType(), targetDataType)
371-
&& Arrays.asList(TSDataType.STRING, TSDataType.TEXT).contains(targetDataType)) {
371+
&& ((targetDataType == TSDataType.STRING) || (targetDataType == TSDataType.TEXT))) {
372372
timeseriesMetadata.setModified(true);
373373
if (timeseriesMetadata.getChunkMetadataList() != null) {
374374
timeseriesMetadata.setChunkMetadataList(
@@ -390,7 +390,7 @@ public static void changeMetadataModified(
390390
return;
391391
}
392392
if (!SchemaUtils.isUsingSameColumn(sourceDataType, targetDataType)
393-
&& Arrays.asList(TSDataType.STRING, TSDataType.TEXT).contains(targetDataType)) {
393+
&& ((targetDataType == TSDataType.STRING) || (targetDataType == TSDataType.TEXT))) {
394394
chunkMetadata.setModified(true);
395395
}
396396
}
@@ -406,8 +406,8 @@ public static void changeAlignedMetadataModified(
406406
for (IChunkMetadata iChunkMetadata : chunkMetadata.getValueChunkMetadataList()) {
407407
if ((iChunkMetadata != null)
408408
&& !SchemaUtils.isUsingSameColumn(sourceDataType, targetDataTypeList.get(i))
409-
&& Arrays.asList(TSDataType.STRING, TSDataType.TEXT)
410-
.contains(targetDataTypeList.get(i))) {
409+
&& ((targetDataTypeList.get(i) == TSDataType.STRING)
410+
|| (targetDataTypeList.get(i) == TSDataType.TEXT))) {
411411
iChunkMetadata.setModified(true);
412412
chunkMetadata.setModified(true);
413413
}

0 commit comments

Comments
 (0)