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

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


The following commit(s) were added to refs/heads/TableModelIngestion by this 
push:
     new 3a3c8d629de apply spotless and fix databaseName nullability
3a3c8d629de is described below

commit 3a3c8d629de66806d524d14fd0f3138bf2c1544c
Author: jt2594838 <[email protected]>
AuthorDate: Wed Jul 3 09:14:23 2024 +0800

    apply spotless and fix databaseName nullability
---
 .../iotdb/session/it/IoTDBSessionRelationalIT.java | 111 +++++++++++++++++++++
 .../db/queryengine/plan/analyze/AnalyzeUtils.java  |  10 +-
 .../queryengine/plan/analyze/AnalyzeVisitor.java   |   6 +-
 .../db/queryengine/plan/analyze/Analyzer.java      |   2 +-
 .../plan/analyze/schema/SchemaValidator.java       |   8 +-
 .../config/executor/ClusterConfigTaskExecutor.java |   2 +-
 .../planner/plan/node/write/InsertTabletNode.java  |  10 +-
 .../node/write/RelationalInsertTabletNode.java     |   1 -
 .../plan/relational/metadata/TableSchema.java      |   5 +
 .../dataregion/memtable/TsFileProcessor.java       |   4 +-
 .../java/org/apache/iotdb/db/utils/MemUtils.java   |   9 +-
 .../db/utils/datastructure/AlignedTVList.java      |  12 ++-
 .../plan/statement/StatementTestUtils.java         |  53 +++++-----
 .../storageengine/dataregion/DataRegionTest.java   |  38 ++++---
 .../iotdb/commons/partition/DataPartition.java     |   8 ++
 15 files changed, 216 insertions(+), 63 deletions(-)

diff --git 
a/integration-test/src/test/java/org/apache/iotdb/session/it/IoTDBSessionRelationalIT.java
 
b/integration-test/src/test/java/org/apache/iotdb/session/it/IoTDBSessionRelationalIT.java
new file mode 100644
index 00000000000..2e49e93bb00
--- /dev/null
+++ 
b/integration-test/src/test/java/org/apache/iotdb/session/it/IoTDBSessionRelationalIT.java
@@ -0,0 +1,111 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.iotdb.session.it;
+
+import org.apache.iotdb.isession.ISession;
+import org.apache.iotdb.isession.SessionDataSet;
+import org.apache.iotdb.it.env.EnvFactory;
+import org.apache.iotdb.it.framework.IoTDBTestRunner;
+import org.apache.iotdb.itbase.category.ClusterIT;
+import org.apache.iotdb.itbase.category.LocalStandaloneIT;
+import org.apache.iotdb.rpc.IoTDBConnectionException;
+import org.apache.iotdb.rpc.StatementExecutionException;
+
+import org.apache.tsfile.enums.TSDataType;
+import org.apache.tsfile.read.common.RowRecord;
+import org.apache.tsfile.write.record.Tablet;
+import org.apache.tsfile.write.schema.IMeasurementSchema;
+import org.apache.tsfile.write.schema.MeasurementSchema;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.experimental.categories.Category;
+import org.junit.runner.RunWith;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import static org.apache.iotdb.itbase.env.BaseEnv.TABLE_SQL_DIALECT;
+import static org.junit.Assert.assertEquals;
+
+@RunWith(IoTDBTestRunner.class)
+public class IoTDBSessionRelationalIT {
+
+  private static Logger LOGGER = 
LoggerFactory.getLogger(IoTDBSessionRelationalIT.class);
+
+  @Before
+  public void setUp() throws Exception {
+    EnvFactory.getEnv().initClusterEnvironment();
+    try (ISession session = 
EnvFactory.getEnv().getSessionConnection(TABLE_SQL_DIALECT)) {
+      session.executeNonQueryStatement("CREATE DATABASE db1");
+    }
+  }
+
+  @After
+  public void tearDown() throws Exception {
+    try (ISession session = 
EnvFactory.getEnv().getSessionConnection(TABLE_SQL_DIALECT)) {
+      session.executeNonQueryStatement("DROP DATABASE db1");
+    }
+    EnvFactory.getEnv().cleanClusterEnvironment();
+  }
+
+  @Test
+  @Category({LocalStandaloneIT.class, ClusterIT.class})
+  public void insertRelationalTabletTest()
+      throws IoTDBConnectionException, StatementExecutionException {
+    try (ISession session = 
EnvFactory.getEnv().getSessionConnection(TABLE_SQL_DIALECT)) {
+      session.executeNonQueryStatement("USE db1");
+
+      List<IMeasurementSchema> schemaList = new ArrayList<>();
+      schemaList.add(new MeasurementSchema("id1", TSDataType.STRING));
+      schemaList.add(new MeasurementSchema("attr1", TSDataType.STRING));
+      schemaList.add(new MeasurementSchema("m1", TSDataType.DOUBLE));
+
+      Tablet tablet = new Tablet("table1", schemaList, 10);
+
+      long timestamp = System.currentTimeMillis();
+
+      for (long row = 0; row < 15; row++) {
+        int rowIndex = tablet.rowSize++;
+        tablet.addTimestamp(rowIndex, timestamp + row);
+        tablet.addValue("id1", rowIndex, "id:" + row);
+        tablet.addValue("attr1", rowIndex, "attr:" + row);
+        tablet.addValue("m1", rowIndex, row * 1.0);
+        if (tablet.rowSize == tablet.getMaxRowNumber()) {
+          session.insertRelationalTablet(tablet, true);
+          tablet.reset();
+        }
+        timestamp++;
+      }
+
+      if (tablet.rowSize != 0) {
+        session.insertRelationalTablet(tablet);
+        tablet.reset();
+      }
+
+      SessionDataSet dataSet = session.executeQueryStatement("select count(*) 
from table1");
+      while (dataSet.hasNext()) {
+        RowRecord rowRecord = dataSet.next();
+        assertEquals(15L, rowRecord.getFields().get(0).getLongV());
+      }
+    }
+  }
+}
diff --git 
a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/analyze/AnalyzeUtils.java
 
b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/analyze/AnalyzeUtils.java
index 00852f1d728..2634a21951d 100644
--- 
a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/analyze/AnalyzeUtils.java
+++ 
b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/analyze/AnalyzeUtils.java
@@ -94,7 +94,7 @@ public class AnalyzeUtils {
             .add(insertTabletStatement.getTimePartitionSlot(i));
       }
       return computeDataPartitionParams(
-          timePartitionSlotMap, context.getSession().getDatabaseName().get());
+          timePartitionSlotMap, 
context.getSession().getDatabaseName().orElse(null));
     } else if (statement instanceof InsertMultiTabletsStatement) {
       InsertMultiTabletsStatement insertMultiTabletsStatement =
           (InsertMultiTabletsStatement) statement;
@@ -108,7 +108,7 @@ public class AnalyzeUtils {
         }
       }
       return computeDataPartitionParams(
-          timePartitionSlotMap, context.getSession().getDatabaseName().get());
+          timePartitionSlotMap, 
context.getSession().getDatabaseName().orElse(null));
     }
     throw new UnsupportedOperationException("computeDataPartitionParams for " 
+ statement);
   }
@@ -122,7 +122,7 @@ public class AnalyzeUtils {
           insertTabletStatement.getDevicePath().getIDeviceIDAsFullDevice());
       dataPartitionQueryParam.setTimePartitionSlotList(
           insertTabletStatement.getTimePartitionSlots());
-      
dataPartitionQueryParam.setDatabaseName(context.getSession().getDatabaseName().get());
+      
dataPartitionQueryParam.setDatabaseName(context.getSession().getDatabaseName().orElse(null));
       return Collections.singletonList(dataPartitionQueryParam);
     } else if (statement instanceof InsertMultiTabletsStatement) {
       InsertMultiTabletsStatement insertMultiTabletsStatement =
@@ -137,7 +137,7 @@ public class AnalyzeUtils {
         
timePartitionSlotSet.addAll(insertTabletStatement.getTimePartitionSlots());
       }
       return computeDataPartitionParams(
-          dataPartitionQueryParamMap, 
context.getSession().getDatabaseName().get());
+          dataPartitionQueryParamMap, 
context.getSession().getDatabaseName().orElse(null));
     } else if (statement instanceof InsertRowsStatement) {
       final InsertRowsStatement insertRowsStatement = (InsertRowsStatement) 
statement;
       Map<IDeviceID, Set<TTimePartitionSlot>> dataPartitionQueryParamMap = new 
HashMap<>();
@@ -150,7 +150,7 @@ public class AnalyzeUtils {
         timePartitionSlotSet.add(insertRowStatement.getTimePartitionSlot());
       }
       return computeDataPartitionParams(
-          dataPartitionQueryParamMap, 
context.getSession().getDatabaseName().get());
+          dataPartitionQueryParamMap, 
context.getSession().getDatabaseName().orElse(null));
     }
     throw new UnsupportedOperationException("computeDataPartitionParams for " 
+ statement);
   }
diff --git 
a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/analyze/AnalyzeVisitor.java
 
b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/analyze/AnalyzeVisitor.java
index a49170b6f7c..e45011c8f20 100644
--- 
a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/analyze/AnalyzeVisitor.java
+++ 
b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/analyze/AnalyzeVisitor.java
@@ -246,7 +246,7 @@ public class AnalyzeVisitor extends 
StatementVisitor<Analysis, MPPQueryContext>
     Analysis analysis = visitQuery(explainStatement.getQueryStatement(), 
context);
     analysis.setRealStatement(explainStatement);
     analysis.setFinishQueryAfterAnalyze(true);
-    analysis.setDatabaseName(context.getSession().getDatabaseName().get());
+    
analysis.setDatabaseName(context.getSession().getDatabaseName().orElse(null));
     return analysis;
   }
 
@@ -261,7 +261,7 @@ public class AnalyzeVisitor extends 
StatementVisitor<Analysis, MPPQueryContext>
             Collections.singletonList(
                 new ColumnHeader(ColumnHeaderConstant.EXPLAIN_ANALYZE, 
TSDataType.TEXT, null)),
             true));
-    analysis.setDatabaseName(context.getSession().getDatabaseName().get());
+    
analysis.setDatabaseName(context.getSession().getDatabaseName().orElse(null));
     return analysis;
   }
 
@@ -2795,7 +2795,7 @@ public class AnalyzeVisitor extends 
StatementVisitor<Analysis, MPPQueryContext>
   public Analysis visitPipeEnrichedStatement(
       PipeEnrichedStatement pipeEnrichedStatement, MPPQueryContext context) {
     Analysis analysis = pipeEnrichedStatement.getInnerStatement().accept(this, 
context);
-    analysis.setDatabaseName(context.getSession().getDatabaseName().get());
+    
analysis.setDatabaseName(context.getSession().getDatabaseName().orElse(null));
 
     // statement may be changed because of logical view
     pipeEnrichedStatement.setInnerStatement(analysis.getTreeStatement());
diff --git 
a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/analyze/Analyzer.java
 
b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/analyze/Analyzer.java
index ed3b686b977..1f650a4c1ad 100644
--- 
a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/analyze/Analyzer.java
+++ 
b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/analyze/Analyzer.java
@@ -45,7 +45,7 @@ public class Analyzer {
     long startTime = System.nanoTime();
     Analysis analysis =
         new AnalyzeVisitor(partitionFetcher, schemaFetcher).process(statement, 
context);
-    analysis.setDatabaseName(context.getSession().getDatabaseName().get());
+    
analysis.setDatabaseName(context.getSession().getDatabaseName().orElse(null));
 
     if (statement.isQuery()) {
       QueryPlanCostMetricSet.getInstance().recordPlanCost(ANALYZER, 
System.nanoTime() - startTime);
diff --git 
a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/analyze/schema/SchemaValidator.java
 
b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/analyze/schema/SchemaValidator.java
index 9967767c11d..5661fa27690 100644
--- 
a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/analyze/schema/SchemaValidator.java
+++ 
b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/analyze/schema/SchemaValidator.java
@@ -35,11 +35,15 @@ import 
org.apache.iotdb.db.queryengine.plan.statement.crud.InsertRowsStatement;
 import org.apache.tsfile.enums.TSDataType;
 import org.apache.tsfile.file.metadata.enums.CompressionType;
 import org.apache.tsfile.file.metadata.enums.TSEncoding;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
 
 import java.util.List;
 
 public class SchemaValidator {
 
+  private static final Logger LOGGER = 
LoggerFactory.getLogger(SchemaValidator.class);
+
   public static void validate(
       ISchemaFetcher schemaFetcher, InsertBaseStatement insertStatement, 
MPPQueryContext context) {
     try {
@@ -61,10 +65,12 @@ public class SchemaValidator {
   public static void validate(
       Metadata metadata, WrappedInsertStatement insertStatement, 
MPPQueryContext context) {
     try {
-      String databaseName = context.getSession().getDatabaseName().get();
+      String databaseName = 
context.getSession().getDatabaseName().orElse(null);
       final TableSchema incomingSchema = insertStatement.getTableSchema();
       final TableSchema realSchema =
           metadata.validateTableHeaderSchema(databaseName, incomingSchema, 
context);
+      LOGGER.info("incoming table header schema: {}", incomingSchema);
+      LOGGER.info("real table header schema: {}", realSchema);
       insertStatement.validate(realSchema);
       metadata.validateDeviceSchema(insertStatement, context);
       insertStatement.updateAfterSchemaValidation(context);
diff --git 
a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/execution/config/executor/ClusterConfigTaskExecutor.java
 
b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/execution/config/executor/ClusterConfigTaskExecutor.java
index 409f0fba0f1..3083f9a89b6 100644
--- 
a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/execution/config/executor/ClusterConfigTaskExecutor.java
+++ 
b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/execution/config/executor/ClusterConfigTaskExecutor.java
@@ -2273,7 +2273,7 @@ public class ClusterConfigTaskExecutor implements 
IConfigTaskExecutor {
     
createLogicalViewStatement.setQueryStatement(alterLogicalViewStatement.getQueryStatement());
 
     final Analysis analysis = Analyzer.analyze(createLogicalViewStatement, 
context);
-    analysis.setDatabaseName(context.getSession().getDatabaseName().get());
+    
analysis.setDatabaseName(context.getSession().getDatabaseName().orElse(null));
     if (analysis.isFailed()) {
       future.setException(
           new IoTDBException(
diff --git 
a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/planner/plan/node/write/InsertTabletNode.java
 
b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/planner/plan/node/write/InsertTabletNode.java
index daee42d16f2..ec28d716997 100644
--- 
a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/planner/plan/node/write/InsertTabletNode.java
+++ 
b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/planner/plan/node/write/InsertTabletNode.java
@@ -19,7 +19,6 @@
 
 package org.apache.iotdb.db.queryengine.plan.planner.plan.node.write;
 
-import java.nio.charset.StandardCharsets;
 import org.apache.iotdb.common.rpc.thrift.TRegionReplicaSet;
 import org.apache.iotdb.common.rpc.thrift.TSStatus;
 import org.apache.iotdb.common.rpc.thrift.TTimePartitionSlot;
@@ -36,7 +35,6 @@ import 
org.apache.iotdb.db.queryengine.plan.planner.plan.node.PlanNodeId;
 import org.apache.iotdb.db.queryengine.plan.planner.plan.node.PlanNodeType;
 import org.apache.iotdb.db.queryengine.plan.planner.plan.node.PlanVisitor;
 import org.apache.iotdb.db.queryengine.plan.planner.plan.node.WritePlanNode;
-import org.apache.iotdb.db.storageengine.dataregion.tsfile.TsFileResource;
 import 
org.apache.iotdb.db.storageengine.dataregion.wal.buffer.IWALByteBufferView;
 import org.apache.iotdb.db.storageengine.dataregion.wal.buffer.WALEntryValue;
 import org.apache.iotdb.db.storageengine.dataregion.wal.utils.WALWriteUtils;
@@ -62,6 +60,7 @@ import java.io.DataInputStream;
 import java.io.DataOutputStream;
 import java.io.IOException;
 import java.nio.ByteBuffer;
+import java.nio.charset.StandardCharsets;
 import java.util.ArrayList;
 import java.util.Arrays;
 import java.util.Collections;
@@ -1198,7 +1197,8 @@ public class InsertTabletNode extends InsertNode 
implements WALEntryValue {
       case STRING:
         String[] stringValues = (String[]) columns[measurementIndex];
         value =
-            new TsPrimitiveType.TsBinary(new 
Binary(stringValues[lastIdx].getBytes(StandardCharsets.UTF_8)));
+            new TsPrimitiveType.TsBinary(
+                new 
Binary(stringValues[lastIdx].getBytes(StandardCharsets.UTF_8)));
         break;
       default:
         throw new UnSupportedDataTypeException(
@@ -1208,6 +1208,10 @@ public class InsertTabletNode extends InsertNode 
implements WALEntryValue {
   }
 
   public IDeviceID getDeviceID(int rowIdx) {
+    if (deviceID != null) {
+      return deviceID;
+    }
+    deviceID = devicePath.getIDeviceID();
     return deviceID;
   }
 
diff --git 
a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/planner/plan/node/write/RelationalInsertTabletNode.java
 
b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/planner/plan/node/write/RelationalInsertTabletNode.java
index 4fabc0a369c..28a2e209440 100644
--- 
a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/planner/plan/node/write/RelationalInsertTabletNode.java
+++ 
b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/planner/plan/node/write/RelationalInsertTabletNode.java
@@ -27,7 +27,6 @@ import 
org.apache.iotdb.db.queryengine.plan.planner.plan.node.PlanNodeId;
 import org.apache.iotdb.db.queryengine.plan.planner.plan.node.PlanNodeType;
 import org.apache.iotdb.db.queryengine.plan.planner.plan.node.PlanVisitor;
 
-import org.apache.iotdb.db.storageengine.dataregion.tsfile.TsFileResource;
 import org.apache.tsfile.enums.TSDataType;
 import org.apache.tsfile.file.metadata.IDeviceID;
 import org.apache.tsfile.file.metadata.IDeviceID.Factory;
diff --git 
a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/relational/metadata/TableSchema.java
 
b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/relational/metadata/TableSchema.java
index d8e21024b4d..f60600b976c 100644
--- 
a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/relational/metadata/TableSchema.java
+++ 
b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/relational/metadata/TableSchema.java
@@ -94,4 +94,9 @@ public class TableSchema {
   public int hashCode() {
     return Objects.hash(tableName, columns);
   }
+
+  @Override
+  public String toString() {
+    return "TableSchema{" + "tableName='" + tableName + '\'' + ", columns=" + 
columns + '}';
+  }
 }
diff --git 
a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/storageengine/dataregion/memtable/TsFileProcessor.java
 
b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/storageengine/dataregion/memtable/TsFileProcessor.java
index 8875647bcfc..514f99c6163 100644
--- 
a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/storageengine/dataregion/memtable/TsFileProcessor.java
+++ 
b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/storageengine/dataregion/memtable/TsFileProcessor.java
@@ -562,7 +562,7 @@ public class TsFileProcessor {
       // For sequence tsfile, we update the endTime only when the file is 
prepared to be closed.
       // For unsequence tsfile, we have to update the endTime for each 
insertion.
       tsFileResource.updateEndTime(
-          deviceEndOffsetPairs.get(0).left,  
deviceEndOffsetPairs.get(0).right);
+          deviceEndOffsetPairs.get(0).left, deviceEndOffsetPairs.get(0).right);
     }
     for (int i = 1; i < deviceEndOffsetPairs.size(); i++) {
       // the end offset of i - 1 is the start offset of i
@@ -570,7 +570,7 @@ public class TsFileProcessor {
           deviceEndOffsetPairs.get(i).left, deviceEndOffsetPairs.get(i - 
1).right);
       if (!sequence) {
         tsFileResource.updateEndTime(
-            deviceEndOffsetPairs.get(i).left,  
deviceEndOffsetPairs.get(i).right);
+            deviceEndOffsetPairs.get(i).left, 
deviceEndOffsetPairs.get(i).right);
       }
     }
 
diff --git 
a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/utils/MemUtils.java 
b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/utils/MemUtils.java
index 3e21535aba5..04266bbd529 100644
--- a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/utils/MemUtils.java
+++ b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/utils/MemUtils.java
@@ -22,8 +22,8 @@ package org.apache.iotdb.db.utils;
 import org.apache.iotdb.common.rpc.thrift.TSStatus;
 import org.apache.iotdb.commons.conf.IoTDBConstant;
 import 
org.apache.iotdb.db.queryengine.plan.planner.plan.node.write.InsertTabletNode;
-
 import org.apache.iotdb.rpc.TSStatusCode;
+
 import org.apache.tsfile.common.conf.TSFileConfig;
 import org.apache.tsfile.enums.TSDataType;
 import org.apache.tsfile.utils.Binary;
@@ -101,7 +101,9 @@ public class MemUtils {
     long memSize = 0;
     memSize += (long) (end - start) * 
RamUsageEstimator.NUM_BYTES_OBJECT_HEADER;
     for (int i = start; i < end; i++) {
-      if (results == null || results[i] == null || results[i].code == 
TSStatusCode.SUCCESS_STATUS.getStatusCode()) {
+      if (results == null
+          || results[i] == null
+          || results[i].code == TSStatusCode.SUCCESS_STATUS.getStatusCode()) {
         memSize += RamUsageEstimator.sizeOf(column[i].getValues());
       }
     }
@@ -142,7 +144,8 @@ public class MemUtils {
         memSize += (long) (end - start) * 
insertTabletNode.getDataTypes()[i].getDataTypeSize();
       } else {
         for (int j = start; j < end; j++) {
-          if (results[j] == null || results[j].code == 
TSStatusCode.SUCCESS_STATUS.getStatusCode()) {
+          if (results[j] == null
+              || results[j].code == 
TSStatusCode.SUCCESS_STATUS.getStatusCode()) {
             memSize += insertTabletNode.getDataTypes()[i].getDataTypeSize();
           }
         }
diff --git 
a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/utils/datastructure/AlignedTVList.java
 
b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/utils/datastructure/AlignedTVList.java
index 3a08d0d05a2..d03df111c5a 100644
--- 
a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/utils/datastructure/AlignedTVList.java
+++ 
b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/utils/datastructure/AlignedTVList.java
@@ -25,8 +25,8 @@ import 
org.apache.iotdb.db.storageengine.dataregion.wal.buffer.IWALByteBufferVie
 import org.apache.iotdb.db.storageengine.dataregion.wal.utils.WALWriteUtils;
 import org.apache.iotdb.db.storageengine.rescon.memory.PrimitiveArrayManager;
 import org.apache.iotdb.db.utils.MathUtils;
-
 import org.apache.iotdb.rpc.TSStatusCode;
+
 import org.apache.tsfile.block.column.ColumnBuilder;
 import org.apache.tsfile.enums.TSDataType;
 import org.apache.tsfile.file.metadata.enums.TSEncoding;
@@ -746,8 +746,9 @@ public abstract class AlignedTVList extends TVList {
           for (int j = 0; j < values.size(); j++) {
             if (value[j] == null
                 || bitMaps != null && bitMaps[j] != null && 
bitMaps[j].isMarked(idx + i)
-                || results != null && results[idx + i] != null && results[idx
-                 + i].code != TSStatusCode.SUCCESS_STATUS.getStatusCode()) {
+                || results != null
+                    && results[idx + i] != null
+                    && results[idx + i].code != 
TSStatusCode.SUCCESS_STATUS.getStatusCode()) {
               markNullValue(j, arrayIdx, elementIdx + i);
             }
           }
@@ -764,8 +765,9 @@ public abstract class AlignedTVList extends TVList {
           for (int j = 0; j < values.size(); j++) {
             if (value[j] == null
                 || bitMaps != null && bitMaps[j] != null && 
bitMaps[j].isMarked(idx + i)
-                || results != null && results[idx + i] != null && results[idx
-                + i].code != TSStatusCode.SUCCESS_STATUS.getStatusCode()) {
+                || results != null
+                    && results[idx + i] != null
+                    && results[idx + i].code != 
TSStatusCode.SUCCESS_STATUS.getStatusCode()) {
               markNullValue(j, arrayIdx, elementIdx + i);
             }
           }
diff --git 
a/iotdb-core/datanode/src/test/java/org/apache/iotdb/db/queryengine/plan/statement/StatementTestUtils.java
 
b/iotdb-core/datanode/src/test/java/org/apache/iotdb/db/queryengine/plan/statement/StatementTestUtils.java
index 2f7fb06d1ba..284b81eae6f 100644
--- 
a/iotdb-core/datanode/src/test/java/org/apache/iotdb/db/queryengine/plan/statement/StatementTestUtils.java
+++ 
b/iotdb-core/datanode/src/test/java/org/apache/iotdb/db/queryengine/plan/statement/StatementTestUtils.java
@@ -35,10 +35,10 @@ import org.apache.tsfile.enums.TSDataType;
 import org.apache.tsfile.file.metadata.enums.CompressionType;
 import org.apache.tsfile.file.metadata.enums.TSEncoding;
 import org.apache.tsfile.read.common.type.TypeFactory;
+import org.apache.tsfile.write.schema.MeasurementSchema;
 
 import java.util.ArrayList;
 import java.util.List;
-import org.apache.tsfile.write.schema.MeasurementSchema;
 
 public class StatementTestUtils {
 
@@ -51,24 +51,24 @@ public class StatementTestUtils {
   }
 
   public static String[] genColumnNames() {
-    return new String[]{"id1", "attr1", "m1"};
+    return new String[] {"id1", "attr1", "m1"};
   }
 
   public static TSDataType[] genDataTypes() {
-    return new TSDataType[]{TSDataType.STRING, TSDataType.STRING, 
TSDataType.DOUBLE};
+    return new TSDataType[] {TSDataType.STRING, TSDataType.STRING, 
TSDataType.DOUBLE};
   }
 
   public static MeasurementSchema[] genMeasurementSchemas() {
-    return new MeasurementSchema[]{
-        new MeasurementSchema("id1", TSDataType.STRING),
-        new MeasurementSchema("attr1", TSDataType.STRING),
-        new MeasurementSchema("m1", TSDataType.DOUBLE)
+    return new MeasurementSchema[] {
+      new MeasurementSchema("id1", TSDataType.STRING),
+      new MeasurementSchema("attr1", TSDataType.STRING),
+      new MeasurementSchema("m1", TSDataType.DOUBLE)
     };
   }
 
   public static TsTableColumnCategory[] genColumnCategories() {
-    return new TsTableColumnCategory[]{
-        TsTableColumnCategory.ID, TsTableColumnCategory.ATTRIBUTE, 
TsTableColumnCategory.MEASUREMENT
+    return new TsTableColumnCategory[] {
+      TsTableColumnCategory.ID, TsTableColumnCategory.ATTRIBUTE, 
TsTableColumnCategory.MEASUREMENT
     };
   }
 
@@ -104,9 +104,7 @@ public class StatementTestUtils {
       values[i] = (i + offset) * 1.0;
     }
 
-    return new Object[]{
-        ids, attrs, values
-    };
+    return new Object[] {ids, attrs, values};
   }
 
   public static long[] genTimestamps() {
@@ -121,8 +119,8 @@ public class StatementTestUtils {
     return timestamps;
   }
 
-  public static InsertTabletStatement genInsertTabletStatement(boolean 
writeToTable, int rowCnt,
-      int offset) {
+  public static InsertTabletStatement genInsertTabletStatement(
+      boolean writeToTable, int rowCnt, int offset) {
     String[] measurements = genColumnNames();
     TSDataType[] dataTypes = genDataTypes();
     TsTableColumnCategory[] columnCategories = genColumnCategories();
@@ -131,7 +129,7 @@ public class StatementTestUtils {
     long[] timestamps = genTimestamps(rowCnt, offset);
 
     InsertTabletStatement insertTabletStatement = new InsertTabletStatement();
-    insertTabletStatement.setDevicePath(new PartialPath(new 
String[]{tableName()}));
+    insertTabletStatement.setDevicePath(new PartialPath(new String[] 
{tableName()}));
     insertTabletStatement.setMeasurements(measurements);
     insertTabletStatement.setDataTypes(dataTypes);
     insertTabletStatement.setColumnCategories(columnCategories);
@@ -143,8 +141,7 @@ public class StatementTestUtils {
     return insertTabletStatement;
   }
 
-  public static RelationalInsertTabletNode genInsertTabletNode(int rowCnt,
-      int offset) {
+  public static RelationalInsertTabletNode genInsertTabletNode(int rowCnt, int 
offset) {
     String[] measurements = genColumnNames();
     TSDataType[] dataTypes = genDataTypes();
     TsTableColumnCategory[] columnCategories = genColumnCategories();
@@ -153,11 +150,18 @@ public class StatementTestUtils {
     Object[] columns = genColumns(rowCnt, offset);
     long[] timestamps = genTimestamps(rowCnt, offset);
 
-    return
-        new RelationalInsertTabletNode(new PlanNodeId(offset + "-" + rowCnt),
-            new PartialPath(new String[]{tableName()}),
-            true,
-            measurements, dataTypes, measurementSchemas, timestamps, null, 
columns, rowCnt, columnCategories);
+    return new RelationalInsertTabletNode(
+        new PlanNodeId(offset + "-" + rowCnt),
+        new PartialPath(new String[] {tableName()}),
+        true,
+        measurements,
+        dataTypes,
+        measurementSchemas,
+        timestamps,
+        null,
+        columns,
+        rowCnt,
+        columnCategories);
   }
 
   public static InsertTabletStatement genInsertTabletStatement(boolean 
writeToTable) {
@@ -179,8 +183,9 @@ public class StatementTestUtils {
           break;
         case MEASUREMENT:
         default:
-          tsTable.addColumnSchema(new MeasurementColumnSchema(measurements[i], 
dataTypes[i],
-              TSEncoding.PLAIN, CompressionType.UNCOMPRESSED));
+          tsTable.addColumnSchema(
+              new MeasurementColumnSchema(
+                  measurements[i], dataTypes[i], TSEncoding.PLAIN, 
CompressionType.UNCOMPRESSED));
           break;
       }
     }
diff --git 
a/iotdb-core/datanode/src/test/java/org/apache/iotdb/db/storageengine/dataregion/DataRegionTest.java
 
b/iotdb-core/datanode/src/test/java/org/apache/iotdb/db/storageengine/dataregion/DataRegionTest.java
index 79e77c6b0d6..89a92968bcb 100644
--- 
a/iotdb-core/datanode/src/test/java/org/apache/iotdb/db/storageengine/dataregion/DataRegionTest.java
+++ 
b/iotdb-core/datanode/src/test/java/org/apache/iotdb/db/storageengine/dataregion/DataRegionTest.java
@@ -19,9 +19,6 @@
 
 package org.apache.iotdb.db.storageengine.dataregion;
 
-import static 
org.apache.iotdb.db.queryengine.plan.statement.StatementTestUtils.genInsertTabletNode;
-
-import java.util.Arrays;
 import org.apache.iotdb.commons.conf.CommonConfig;
 import org.apache.iotdb.commons.conf.CommonDescriptor;
 import org.apache.iotdb.commons.consensus.DataRegionId;
@@ -35,7 +32,6 @@ import org.apache.iotdb.commons.path.NonAlignedFullPath;
 import org.apache.iotdb.commons.path.PartialPath;
 import org.apache.iotdb.db.conf.IoTDBConfig;
 import org.apache.iotdb.db.conf.IoTDBDescriptor;
-import org.apache.iotdb.db.exception.BatchProcessException;
 import org.apache.iotdb.db.exception.DataRegionException;
 import org.apache.iotdb.db.exception.TsFileProcessorException;
 import org.apache.iotdb.db.exception.WriteProcessException;
@@ -93,6 +89,8 @@ import java.util.ArrayList;
 import java.util.Collections;
 import java.util.List;
 
+import static 
org.apache.iotdb.db.queryengine.plan.statement.StatementTestUtils.genInsertTabletNode;
+
 public class DataRegionTest {
   private static final IoTDBConfig config = 
IoTDBDescriptor.getInstance().getConfig();
   private static final CommonConfig COMMON_CONFIG = 
CommonDescriptor.getInstance().getConfig();
@@ -121,10 +119,10 @@ public class DataRegionTest {
     dataRegion = new DummyDataRegion(systemDir, storageGroup);
     StorageEngine.getInstance().setDataRegion(new DataRegionId(0), dataRegion);
     CompactionTaskManager.getInstance().start();
-    
DataNodeTableCache.getInstance().preCreateTable(dataRegion.getDatabaseName(),
-        StatementTestUtils.genTsTable());
-    
DataNodeTableCache.getInstance().commitCreateTable(dataRegion.getDatabaseName(),
-        StatementTestUtils.tableName());
+    DataNodeTableCache.getInstance()
+        .preCreateTable(dataRegion.getDatabaseName(), 
StatementTestUtils.genTsTable());
+    DataNodeTableCache.getInstance()
+        .commitCreateTable(dataRegion.getDatabaseName(), 
StatementTestUtils.tableName());
   }
 
   @After
@@ -280,17 +278,29 @@ public class DataRegionTest {
 
     QueryDataSource queryDataSource =
         dataRegion.query(
-            Collections.singletonList(new AlignedFullPath(deviceID1,
-                Collections.singletonList(measurementName), 
Collections.singletonList(measurementSchema))),
-            deviceID1, context, null, null);
+            Collections.singletonList(
+                new AlignedFullPath(
+                    deviceID1,
+                    Collections.singletonList(measurementName),
+                    Collections.singletonList(measurementSchema))),
+            deviceID1,
+            context,
+            null,
+            null);
     Assert.assertEquals(1, queryDataSource.getSeqResources().size());
     Assert.assertEquals(0, queryDataSource.getUnseqResources().size());
 
     queryDataSource =
         dataRegion.query(
-            Collections.singletonList(new AlignedFullPath(deviceID2,
-                Collections.singletonList(measurementName), 
Collections.singletonList(measurementSchema))),
-            deviceID2, context, null, null);
+            Collections.singletonList(
+                new AlignedFullPath(
+                    deviceID2,
+                    Collections.singletonList(measurementName),
+                    Collections.singletonList(measurementSchema))),
+            deviceID2,
+            context,
+            null,
+            null);
     Assert.assertEquals(1, queryDataSource.getSeqResources().size());
     Assert.assertEquals(0, queryDataSource.getUnseqResources().size());
     for (TsFileResource resource : queryDataSource.getSeqResources()) {
diff --git 
a/iotdb-core/node-commons/src/main/java/org/apache/iotdb/commons/partition/DataPartition.java
 
b/iotdb-core/node-commons/src/main/java/org/apache/iotdb/commons/partition/DataPartition.java
index f82b9cc0cfb..03a37dc5d3c 100644
--- 
a/iotdb-core/node-commons/src/main/java/org/apache/iotdb/commons/partition/DataPartition.java
+++ 
b/iotdb-core/node-commons/src/main/java/org/apache/iotdb/commons/partition/DataPartition.java
@@ -26,6 +26,8 @@ import org.apache.iotdb.commons.utils.TimePartitionUtils;
 
 import org.apache.tsfile.file.metadata.IDeviceID;
 import org.apache.tsfile.read.filter.basic.Filter;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
 
 import java.util.ArrayList;
 import java.util.Collections;
@@ -38,6 +40,8 @@ import static java.util.Objects.requireNonNull;
 import static java.util.stream.Collectors.toList;
 
 public class DataPartition extends Partition {
+
+  private static final Logger LOGGER = 
LoggerFactory.getLogger(DataPartition.class);
   public static final TRegionReplicaSet NOT_ASSIGNED = new TRegionReplicaSet();
   // Map<StorageGroup, Map<TSeriesPartitionSlot, Map<TTimePartitionSlot, 
List<TRegionMessage>>>>
   private Map<String, Map<TSeriesPartitionSlot, Map<TTimePartitionSlot, 
List<TRegionReplicaSet>>>>
@@ -170,6 +174,9 @@ public class DataPartition extends Partition {
 
   public List<TRegionReplicaSet> getDataRegionReplicaSetForWriting(
       IDeviceID deviceID, List<TTimePartitionSlot> timePartitionSlotList, 
String databaseName) {
+    if (databaseName == null) {
+      databaseName = getStorageGroupByDevice(deviceID);
+    }
     // A list of data region replica sets will store data in a same time 
partition.
     // We will insert data to the last set in the list.
     // TODO return the latest dataRegionReplicaSet for each time partition
@@ -179,6 +186,7 @@ public class DataPartition extends Partition {
     List<TRegionReplicaSet> dataRegionReplicaSets = new ArrayList<>();
     Map<TSeriesPartitionSlot, Map<TTimePartitionSlot, List<TRegionReplicaSet>>>
         dataBasePartitionMap = dataPartitionMap.get(databaseName);
+    LOGGER.info("DataPartitionMap {} and database name {}", dataPartitionMap, 
databaseName);
     Map<TTimePartitionSlot, List<TRegionReplicaSet>> slotReplicaSetMap =
         dataBasePartitionMap.get(seriesPartitionSlot);
     for (TTimePartitionSlot timePartitionSlot : timePartitionSlotList) {


Reply via email to