You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@iotdb.apache.org by ji...@apache.org on 2026/10/12 03:38:50 UTC
(iotdb) 07/20: tmp
This is an automated email from the ASF dual-hosted git repository.
jt2594838 pushed a commit to branch insert_numeric_row
in repository https://gitbox.apache.org/repos/asf/iotdb.git
commit 07d73d28b1b737928c4492fbacd345d95d18dea8
Author: Tian Jiang <jt...@163.com>
AuthorDate: Wed Sep 16 15:56:00 2026 +0800
tmp
---
.../iotdb/isession/i18n/ISessionMessages.java | 2 +
.../iotdb/isession/i18n/ISessionMessages.java | 2 +
.../org/apache/iotdb/session/TableSession.java | 87 ++++++++++++++++++++++
.../iotdb/session/pool/TableSessionWrapper.java | 2 +
4 files changed, 93 insertions(+)
diff --git a/iotdb-client/isession/src/main/i18n/en/org/apache/iotdb/isession/i18n/ISessionMessages.java b/iotdb-client/isession/src/main/i18n/en/org/apache/iotdb/isession/i18n/ISessionMessages.java
index bc593534c60..3a15370611a 100644
--- a/iotdb-client/isession/src/main/i18n/en/org/apache/iotdb/isession/i18n/ISessionMessages.java
+++ b/iotdb-client/isession/src/main/i18n/en/org/apache/iotdb/isession/i18n/ISessionMessages.java
@@ -31,6 +31,8 @@ public final class ISessionMessages {
public static final String NOT_DIRECT_CHILD_OF_TEMPLATE =
"It is not a direct child of the template: ";
+ public static final String EXCEPTION_UNSUPPORTED_NUMERIC_TYPE_06DD3044 = "Unsupported numeric type";
+
private ISessionMessages() {}
// ---------------------------------------------------------------------------
// Additional auto-collected messages
diff --git a/iotdb-client/isession/src/main/i18n/zh/org/apache/iotdb/isession/i18n/ISessionMessages.java b/iotdb-client/isession/src/main/i18n/zh/org/apache/iotdb/isession/i18n/ISessionMessages.java
index 5514a76c0f7..a6316202ebc 100644
--- a/iotdb-client/isession/src/main/i18n/zh/org/apache/iotdb/isession/i18n/ISessionMessages.java
+++ b/iotdb-client/isession/src/main/i18n/zh/org/apache/iotdb/isession/i18n/ISessionMessages.java
@@ -31,6 +31,8 @@ public final class ISessionMessages {
public static final String NOT_DIRECT_CHILD_OF_TEMPLATE =
"这不是该模板的直接子节点:";
+ public static final String EXCEPTION_UNSUPPORTED_NUMERIC_TYPE_06DD3044 = "不支持的数值类型";
+
private ISessionMessages() {}
// ---------------------------------------------------------------------------
// Additional auto-collected messages
diff --git a/iotdb-client/session/src/main/java/org/apache/iotdb/session/TableSession.java b/iotdb-client/session/src/main/java/org/apache/iotdb/session/TableSession.java
index f7154b3c5f7..7833557e10b 100644
--- a/iotdb-client/session/src/main/java/org/apache/iotdb/session/TableSession.java
+++ b/iotdb-client/session/src/main/java/org/apache/iotdb/session/TableSession.java
@@ -55,6 +55,93 @@ public class TableSession implements ITableSession {
session.insertRelationalRecord(row);
}
+ @Override
+ public NumericRowPreparedStatement prepareInsertNumericRow(
+ String tableName,
+ List<String> columnNames,
+ List<TSDataType> dataTypes,
+ List<ColumnCategory> columnCategories)
+ throws StatementExecutionException, IoTDBConnectionException {
+ List<String> names = new ArrayList<>();
+ List<TSDataType> types = new ArrayList<>();
+ List<ColumnCategory> categories = new ArrayList<>();
+ for (ColumnCategory category :
+ new ColumnCategory[] {ColumnCategory.TAG, ColumnCategory.FIELD}) {
+ for (int i = 0; i < columnNames.size(); i++) {
+ if (columnCategories.get(i) == category) {
+ names.add(columnNames.get(i));
+ types.add(dataTypes.get(i));
+ categories.add(category);
+ }
+ }
+ }
+ TSPrepareNumericRowReq request = new TSPrepareNumericRowReq();
+ request
+ .setTableName(tableName)
+ .setMeasurements(names)
+ .setDataTypes(types.stream().map(TSDataType::ordinal).toList())
+ .setColumnCategories(categories.stream().map(c -> (byte) c.ordinal()).toList());
+ NumericRowPreparedStatement prepared =
+ new NumericRowPreparedStatement(tableName, names, types, categories);
+ SessionConnection connection = session.getDefaultSessionConnection();
+ prepared.bind(
+ connection.prepareNumericRow(request),
+ connection,
+ () -> {
+ try {
+ connection.closePreparedNumericRow(prepared.getPreparedId());
+ } catch (IoTDBConnectionException ignored) {
+ // Closing the session releases all server-side prepared rows.
+ }
+ });
+ return prepared;
+ }
+
+ @Override
+ public void executePreparedInsertNumericRow(
+ NumericRowPreparedStatement prepared, long timestamp, long[] values, String[] tagValues)
+ throws StatementExecutionException, IoTDBConnectionException {
+ SessionConnection connection = session.getDefaultSessionConnection();
+ if (prepared == null || prepared.isClosed() || prepared.getOwner() != connection) {
+ throw new IoTDBConnectionException(
+ SessionMessages
+ .EXCEPTION_PREPARED_NUMERIC_ROW_IS_CLOSED_OR_BELONGS_TO_ANOTHER_CONNECTION_PREPARE_IT_AGAIN_055CC7BC);
+ }
+ int tagCount = prepared.getTagCount();
+ int fieldCount = prepared.getDataTypes().size() - tagCount;
+ if (values.length != fieldCount || tagValues.length != tagCount) {
+ throw new IllegalArgumentException(
+ SessionMessages.EXCEPTION_PREPARED_NUMERIC_ROW_VALUE_COUNT_MISMATCH_9ACD3A0C);
+ }
+ int tagBytes = 0;
+ for (String tag : tagValues) {
+ tagBytes += ReadWriteIOUtils.sizeToWrite(tag);
+ }
+ ByteBuffer tagBuffer = prepared.prepareTagBuffer(tagBytes);
+ for (String tag : tagValues) {
+ ReadWriteIOUtils.write(tag, tagBuffer);
+ }
+ tagBuffer.flip();
+ ByteBuffer valueBuffer = prepared.prepareValueBuffer();
+ int valueIndex = 0;
+ for (int i = 0; i < prepared.getDataTypes().size(); i++) {
+ if (prepared.getColumnCategories().get(i) == ColumnCategory.FIELD) {
+ long value = values[valueIndex++];
+ switch (prepared.getDataTypes().get(i)) {
+ case BOOLEAN -> valueBuffer.put((byte) (value == 0 ? 0 : 1));
+ case INT32, DATE, FLOAT -> valueBuffer.putInt((int) value);
+ case INT64, TIMESTAMP, DOUBLE -> valueBuffer.putLong(value);
+ default ->
+ throw new IllegalArgumentException(
+ SessionMessages.EXCEPTION_UNSUPPORTED_NUMERIC_TYPE_06DD3044);
+ }
+ }
+ }
+ valueBuffer.flip();
+ connection.executePreparedNumericRow(
+ prepared.getPreparedId(), timestamp, valueBuffer, tagBuffer);
+ }
+
@Override
public void executeNonQueryStatement(String sql)
throws IoTDBConnectionException, StatementExecutionException {
diff --git a/iotdb-client/session/src/main/java/org/apache/iotdb/session/pool/TableSessionWrapper.java b/iotdb-client/session/src/main/java/org/apache/iotdb/session/pool/TableSessionWrapper.java
index 8f158f4ab4f..9478c35d3cb 100644
--- a/iotdb-client/session/src/main/java/org/apache/iotdb/session/pool/TableSessionWrapper.java
+++ b/iotdb-client/session/src/main/java/org/apache/iotdb/session/pool/TableSessionWrapper.java
@@ -21,10 +21,12 @@ package org.apache.iotdb.session.pool;
import org.apache.iotdb.isession.ITableSession;
import org.apache.iotdb.isession.NumericRow;
+import org.apache.iotdb.isession.NumericRowPreparedStatement;
import org.apache.iotdb.isession.SessionDataSet;
import org.apache.iotdb.rpc.IoTDBConnectionException;
import org.apache.iotdb.rpc.StatementExecutionException;
import org.apache.iotdb.session.Session;
+import org.apache.iotdb.session.TableSession;
import org.apache.iotdb.session.i18n.SessionMessages;
import org.apache.tsfile.write.record.Tablet;