This is an automated email from the ASF dual-hosted git repository.

jiangtian pushed a commit to branch new_test_case
in repository https://gitbox.apache.org/repos/asf/iotdb.git

commit 9ccf0d6bd921e69bdf161f72e534838af4cbb663
Author: Tian Jiang <[email protected]>
AuthorDate: Fri Jan 3 10:59:40 2025 +0800

    add new test case
---
 .../it/session/IoTDBSessionRelationalIT.java       | 151 ++++++++++++++++-----
 1 file changed, 116 insertions(+), 35 deletions(-)

diff --git 
a/integration-test/src/test/java/org/apache/iotdb/relational/it/session/IoTDBSessionRelationalIT.java
 
b/integration-test/src/test/java/org/apache/iotdb/relational/it/session/IoTDBSessionRelationalIT.java
index 50ae3f55b6e..99c6759690b 100644
--- 
a/integration-test/src/test/java/org/apache/iotdb/relational/it/session/IoTDBSessionRelationalIT.java
+++ 
b/integration-test/src/test/java/org/apache/iotdb/relational/it/session/IoTDBSessionRelationalIT.java
@@ -801,7 +801,7 @@ public class IoTDBSessionRelationalIT {
 
   @Test
   @Category({LocalStandaloneIT.class, ClusterIT.class})
-  public void autoCreatetagColumnTest()
+  public void autoCreateTagColumnTest()
       throws IoTDBConnectionException, StatementExecutionException {
     try (ITableSession session = 
EnvFactory.getEnv().getTableSessionConnection()) {
       session.executeNonQueryStatement("USE \"db1\"");
@@ -824,52 +824,54 @@ public class IoTDBSessionRelationalIT {
               columnTypes,
               15);
 
-      for (long row = 0; row < 15; row++) {
-        int rowIndex = tablet.getRowSize();
-        tablet.addTimestamp(rowIndex, timestamp + row);
-        tablet.addValue("tag2", rowIndex, "tag:" + row);
-        tablet.addValue("attr1", rowIndex, "attr:" + row);
-        tablet.addValue("m1", rowIndex, row * 1.0);
-        if (tablet.getRowSize() == tablet.getMaxRowNumber()) {
-          session.insert(tablet);
-          tablet.reset();
-        }
+      for (int row = 0; row < 15; row++) {
+        tablet.addTimestamp(row, timestamp);
+        tablet.addValue("tag2", row, "tag:" + timestamp);
+        tablet.addValue("attr1", row, "attr:" + timestamp);
+        tablet.addValue("m1", row, timestamp * 1.0);
+        timestamp ++;
       }
 
-      if (tablet.getRowSize() != 0) {
-        session.insert(tablet);
-        tablet.reset();
+      session.insert(tablet);
+      tablet.reset();
+
+      SessionDataSet dataSet = session.executeQueryStatement("select * from 
table8 order by time");
+      int cnt = 0;
+      while (dataSet.hasNext()) {
+        RowRecord rowRecord = dataSet.next();
+        long t = rowRecord.getFields().get(0).getLongV();
+        // tag 1 should be null
+        assertNull(rowRecord.getFields().get(1).getDataType());
+        assertEquals("tag:" + t, 
rowRecord.getFields().get(2).getBinaryV().toString());
+        assertEquals("attr:" + t, 
rowRecord.getFields().get(3).getBinaryV().toString());
+        assertEquals(t * 1.0, rowRecord.getFields().get(4).getDoubleV(), 
0.0001);
+        cnt++;
       }
+      assertEquals(15, cnt);
 
       session.executeNonQueryStatement("FLush");
 
-      for (long row = 15; row < 30; row++) {
-        int rowIndex = tablet.getRowSize();
-        tablet.addTimestamp(rowIndex, timestamp + row);
-        tablet.addValue("tag2", rowIndex, "tag:" + row);
-        tablet.addValue("attr1", rowIndex, "attr:" + row);
-        tablet.addValue("m1", rowIndex, row * 1.0);
-        if (tablet.getRowSize() == tablet.getMaxRowNumber()) {
-          session.insert(tablet);
-          tablet.reset();
-        }
+      for (int row = 0; row < 15; row++) {
+        tablet.addTimestamp(row, timestamp);
+        tablet.addValue("tag2", row, "tag:" + timestamp);
+        tablet.addValue("attr1", row, "attr:" + timestamp);
+        tablet.addValue("m1", row, timestamp * 1.0);
+        timestamp ++;
       }
 
-      if (tablet.getRowSize() != 0) {
-        session.insert(tablet);
-        tablet.reset();
-      }
+      session.insert(tablet);
+      tablet.reset();
 
-      SessionDataSet dataSet = session.executeQueryStatement("select * from 
table8 order by time");
-      int cnt = 0;
+      dataSet = session.executeQueryStatement("select * from table8 order by 
time");
+      cnt = 0;
       while (dataSet.hasNext()) {
         RowRecord rowRecord = dataSet.next();
-        timestamp = rowRecord.getFields().get(0).getLongV();
+        long t = rowRecord.getFields().get(0).getLongV();
         // tag 1 should be null
         assertNull(rowRecord.getFields().get(1).getDataType());
-        assertEquals("tag:" + timestamp, 
rowRecord.getFields().get(2).getBinaryV().toString());
-        assertEquals("attr:" + timestamp, 
rowRecord.getFields().get(3).getBinaryV().toString());
-        assertEquals(timestamp * 1.0, 
rowRecord.getFields().get(4).getDoubleV(), 0.0001);
+        assertEquals("tag:" + t, 
rowRecord.getFields().get(2).getBinaryV().toString());
+        assertEquals("attr:" + t, 
rowRecord.getFields().get(3).getBinaryV().toString());
+        assertEquals(t * 1.0, rowRecord.getFields().get(4).getDoubleV(), 
0.0001);
         cnt++;
       }
       assertEquals(30, cnt);
@@ -878,7 +880,7 @@ public class IoTDBSessionRelationalIT {
 
   @Test
   @Category({LocalStandaloneIT.class, ClusterIT.class})
-  public void autoAdjusttagTest() throws IoTDBConnectionException, 
StatementExecutionException {
+  public void autoAdjustTagTest() throws IoTDBConnectionException, 
StatementExecutionException {
     try (ITableSession session = 
EnvFactory.getEnv().getTableSessionConnection()) {
       session.executeNonQueryStatement("USE \"db1\"");
       // the tag order in the table is (tag1, tag2)
@@ -1464,4 +1466,83 @@ public class IoTDBSessionRelationalIT {
       session.executeNonQueryStatement("SET CONFIGURATION 
\"enable_partial_insert\"=\"true\"");
     }
   }
+
+  @Test
+  @Category({LocalStandaloneIT.class, ClusterIT.class})
+  public void autoCreateTagColumnTest2()
+      throws IoTDBConnectionException, StatementExecutionException {
+    int testNum = 17;
+    try (ITableSession session = 
EnvFactory.getEnv().getTableSessionConnection()) {
+      session.executeNonQueryStatement("USE \"db1\"");
+      // only one column in this table, and others should be auto-created
+      session.executeNonQueryStatement("CREATE TABLE table" + testNum + " 
(tag1 string tag, s1 text field)");
+
+      List<IMeasurementSchema> schemaList = new ArrayList<>();
+      schemaList.add(new MeasurementSchema("tag2", TSDataType.STRING));
+      schemaList.add(new MeasurementSchema("s2", TSDataType.INT64));
+      final List<ColumnCategory> columnTypes =
+          Arrays.asList(ColumnCategory.TAG, ColumnCategory.FIELD);
+
+      long timestamp = 0;
+      Tablet tablet =
+          new Tablet(
+              "table" + testNum,
+              IMeasurementSchema.getMeasurementNameList(schemaList),
+              IMeasurementSchema.getDataTypeList(schemaList),
+              columnTypes,
+              15);
+
+      for (int row = 0; row < 15; row++) {
+        tablet.addTimestamp(row, timestamp);
+        tablet.addValue("tag2", row, "tag:" + timestamp);
+        tablet.addValue("s2", row, timestamp);
+        timestamp ++;
+      }
+
+      session.insert(tablet);
+      tablet.reset();
+
+      SessionDataSet dataSet = session.executeQueryStatement("select * from 
table" + testNum + " order by time");
+      int cnt = 0;
+      while (dataSet.hasNext()) {
+        RowRecord rowRecord = dataSet.next();
+        long t = rowRecord.getFields().get(0).getLongV();
+        // tag 1 should be null
+        assertNull(rowRecord.getFields().get(1).getDataType());
+        // s1 should be null
+        assertNull(rowRecord.getFields().get(2).getDataType());
+        assertEquals("tag:" + t, 
rowRecord.getFields().get(3).getBinaryV().toString());
+        assertEquals(t, rowRecord.getFields().get(4).getLongV());
+        cnt++;
+      }
+      assertEquals(15, cnt);
+
+      session.executeNonQueryStatement("FLush");
+
+      for (int row = 0; row < 15; row++) {
+        tablet.addTimestamp(row, timestamp);
+        tablet.addValue("tag2", row, "tag:" + timestamp);
+        tablet.addValue("s2", row, timestamp);
+        timestamp ++;
+      }
+
+      session.insert(tablet);
+      tablet.reset();
+
+      dataSet = session.executeQueryStatement("select * from table" + testNum 
+ " order by time");
+      cnt = 0;
+      while (dataSet.hasNext()) {
+        RowRecord rowRecord = dataSet.next();
+        long t = rowRecord.getFields().get(0).getLongV();
+        // tag 1 should be null
+        assertNull(rowRecord.getFields().get(1).getDataType());
+        // s1 should be null
+        assertNull(rowRecord.getFields().get(2).getDataType());
+        assertEquals("tag:" + t, 
rowRecord.getFields().get(3).getBinaryV().toString());
+        assertEquals(t, rowRecord.getFields().get(4).getLongV());
+        cnt++;
+      }
+      assertEquals(30, cnt);
+    }
+  }
 }

Reply via email to