Skip to content

Commit f5ca57d

Browse files
committed
Add an overlapped data case on the scene of query.
1 parent ce83051 commit f5ca57d

File tree

1 file changed

+108
-0
lines changed

1 file changed

+108
-0
lines changed

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

Lines changed: 108 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,7 @@ public void testWriteAndAlter()
132132
doWriteAndAlter(from, to);
133133
testAlignDeviceSequenceDataQuery(from, to);
134134
testAlignDeviceUnSequenceDataQuery(from, to);
135+
testAlignDeviceUnSequenceOverlappedDataQuery(from, to);
135136
}
136137
}
137138
}
@@ -1490,6 +1491,113 @@ public void testAlignDeviceUnSequenceDataQuery(TSDataType from, TSDataType to)
14901491
}
14911492
}
14921493

1494+
public void testAlignDeviceUnSequenceOverlappedDataQuery(TSDataType from, TSDataType to)
1495+
throws IoTDBConnectionException,
1496+
StatementExecutionException,
1497+
IOException,
1498+
WriteProcessException {
1499+
try (ITableSession session = EnvFactory.getEnv().getTableSessionConnectionWithDB("test")) {
1500+
session.executeNonQueryStatement("SET CONFIGURATION enable_unseq_space_compaction='false'");
1501+
1502+
// create a table with type of "from"
1503+
session.executeNonQueryStatement(
1504+
"CREATE TABLE IF NOT EXISTS construct_and_alter_column_type (s1 "
1505+
+ from
1506+
+ ", s2 "
1507+
+ from
1508+
+ ")");
1509+
1510+
// write a sequence tsfile point of "from"
1511+
Tablet tablet =
1512+
new Tablet(
1513+
"construct_and_alter_column_type",
1514+
Arrays.asList("s1", "s2"),
1515+
Arrays.asList(from, from),
1516+
Arrays.asList(ColumnCategory.FIELD, ColumnCategory.FIELD));
1517+
1518+
System.out.println(tablet.getSchemas().toString());
1519+
1520+
for (int i = 513; i <= 1024; i++) {
1521+
int rowIndex = tablet.getRowSize();
1522+
tablet.addTimestamp(0, i);
1523+
tablet.addValue("s1", rowIndex, genValue(from, i));
1524+
tablet.addValue("s2", rowIndex, genValue(from, i * 2));
1525+
session.insert(tablet);
1526+
tablet.reset();
1527+
}
1528+
1529+
session.executeNonQueryStatement("FLUSH");
1530+
1531+
for (int i = 1; i <= 520; i++) {
1532+
int rowIndex = tablet.getRowSize();
1533+
tablet.addTimestamp(0, i);
1534+
tablet.addValue("s1", rowIndex, genValue(from, i));
1535+
tablet.addValue("s2", rowIndex, genValue(from, i * 2));
1536+
session.insert(tablet);
1537+
tablet.reset();
1538+
}
1539+
// session.executeNonQueryStatement("FLUSH");
1540+
1541+
SessionDataSet dataSet =
1542+
session.executeQueryStatement(
1543+
"select min(s1),max(s1),first(s1),last(s1) from construct_and_alter_column_type");
1544+
RowRecord rec = dataSet.next();
1545+
while (rec != null) {
1546+
System.out.println(rec.getFields().toString());
1547+
rec = dataSet.next();
1548+
}
1549+
dataSet.close();
1550+
1551+
try {
1552+
standardSelectTest(session, from, to);
1553+
standardAccumulatorQueryTest(session, from);
1554+
} catch (Exception e) {
1555+
log.error("{}", e.getStackTrace());
1556+
log.info(e.getMessage());
1557+
}
1558+
1559+
// alter the type to "to"
1560+
boolean isCompatible = MetadataUtils.canAlter(from, to);
1561+
if (isCompatible) {
1562+
session.executeNonQueryStatement(
1563+
"ALTER TABLE construct_and_alter_column_type ALTER COLUMN s1 SET DATA TYPE " + to);
1564+
} else {
1565+
try {
1566+
session.executeNonQueryStatement(
1567+
"ALTER TABLE construct_and_alter_column_type ALTER COLUMN s1 SET DATA TYPE " + to);
1568+
} catch (StatementExecutionException e) {
1569+
assertEquals(
1570+
"701: New type " + to + " is not compatible with the existing one " + from,
1571+
e.getMessage());
1572+
}
1573+
}
1574+
1575+
System.out.println(
1576+
"[testAlignDeviceUnSequenceDataQuery] AFTER ALTER COLUMN s1 SET DATA TYPE ");
1577+
1578+
// If don't execute the flush" operation, verify if result can get valid value, not be null
1579+
// when query memtable.
1580+
// session.executeNonQueryStatement("FLUSH");
1581+
1582+
TSDataType newType = isCompatible ? to : from;
1583+
1584+
try {
1585+
standardSelectTestAfterAlterColumnType(from, session, newType);
1586+
// Accumulator query test
1587+
standardAccumulatorQueryTest(session, from, newType);
1588+
} catch (Exception e) {
1589+
log.error("{}", e.getStackTrace());
1590+
log.info(e.getMessage());
1591+
}
1592+
1593+
if (from == TSDataType.DATE) {
1594+
accumulatorQueryTestForDateType(session, to);
1595+
}
1596+
1597+
session.executeNonQueryStatement("DROP TABLE construct_and_alter_column_type");
1598+
}
1599+
}
1600+
14931601
// Don't support for non-align device unsequence data query, because non-align timeseries is not
14941602
// exist in the table model, only exist align timeseries.
14951603
// Though support for non-align timeseries in the tree model, can let tree transfer to table, but

0 commit comments

Comments
 (0)