You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@shardingsphere.apache.org by wu...@apache.org on 2021/06/24 09:10:50 UTC
[shardingsphere] 08/08: Adapt openGauss batch bind (#10953)
This is an automated email from the ASF dual-hosted git repository.
wuweijie pushed a commit to branch opengauss_adapt
in repository https://gitbox.apache.org/repos/asf/shardingsphere.git
commit af2f1d981b22cc94f3807d0cb46a8d2e2ac113f2
Author: 吴伟杰 <wu...@apache.org>
AuthorDate: Thu Jun 24 11:00:24 2021 +0800
Adapt openGauss batch bind (#10953)
---
.../binary/bind/OpenGaussComBatchBindPacket.java | 26 +++++-----------------
.../binary/bind/OpenGaussComBatchBindExecutor.java | 11 ++++++---
2 files changed, 13 insertions(+), 24 deletions(-)
diff --git a/shardingsphere-db-protocol/shardingsphere-db-protocol-postgresql/src/main/java/org/apache/shardingsphere/db/protocol/postgresql/packet/command/query/binary/bind/OpenGaussComBatchBindPacket.java b/shardingsphere-db-protocol/shardingsphere-db-protocol-postgresql/src/main/java/org/apache/shardingsphere/db/protocol/postgresql/packet/command/query/binary/bind/OpenGaussComBatchBindPacket.java
index 8c290e9..b13c64e 100644
--- a/shardingsphere-db-protocol/shardingsphere-db-protocol-postgresql/src/main/java/org/apache/shardingsphere/db/protocol/postgresql/packet/command/query/binary/bind/OpenGaussComBatchBindPacket.java
+++ b/shardingsphere-db-protocol/shardingsphere-db-protocol-postgresql/src/main/java/org/apache/shardingsphere/db/protocol/postgresql/packet/command/query/binary/bind/OpenGaussComBatchBindPacket.java
@@ -20,7 +20,7 @@ package org.apache.shardingsphere.db.protocol.postgresql.packet.command.query.bi
import com.google.common.collect.Lists;
import lombok.Getter;
import org.apache.shardingsphere.db.protocol.postgresql.constant.PostgreSQLBinaryColumnType;
-import org.apache.shardingsphere.db.protocol.postgresql.constant.PostgreSQLColumnFormat;
+import org.apache.shardingsphere.db.protocol.postgresql.constant.PostgreSQLValueFormat;
import org.apache.shardingsphere.db.protocol.postgresql.packet.command.PostgreSQLCommandPacket;
import org.apache.shardingsphere.db.protocol.postgresql.packet.command.PostgreSQLCommandPacketType;
import org.apache.shardingsphere.db.protocol.postgresql.packet.command.query.binary.PostgreSQLBinaryStatement;
@@ -48,10 +48,10 @@ public final class OpenGaussComBatchBindPacket extends PostgreSQLCommandPacket {
private final String sql;
- private final List<Integer> resultFormatCodes;
-
private final List<List<Object>> parameters;
+ private final List<PostgreSQLValueFormat> resultFormats;
+
public OpenGaussComBatchBindPacket(final PostgreSQLPacketPayload payload, final int connectionId) {
payload.readInt4();
payload.readInt4();
@@ -63,9 +63,9 @@ public final class OpenGaussComBatchBindPacket extends PostgreSQLCommandPacket {
parameterFormats.add(payload.readInt2());
}
int resultFormatsLength = payload.readInt2();
- resultFormatCodes = new ArrayList<>(resultFormatsLength);
+ resultFormats = new ArrayList<>(resultFormatsLength);
for (int i = 0; i < resultFormatsLength; i++) {
- resultFormatCodes.add(payload.readInt2());
+ resultFormats.add(PostgreSQLValueFormat.valueOf(payload.readInt2()));
}
PostgreSQLBinaryStatement binaryStatement = PostgreSQLBinaryStatementRegistry.getInstance().get(connectionId).getBinaryStatement(statementId);
sql = null == binaryStatement ? null : binaryStatement.getSql();
@@ -152,22 +152,6 @@ public final class OpenGaussComBatchBindPacket extends PostgreSQLCommandPacket {
return binaryProtocolValue.read(payload, parameterValueLength);
}
- /**
- * Get result format by column index.
- *
- * @param columnIndex column index
- * @return result format
- */
- public PostgreSQLColumnFormat getResultFormatByColumnIndex(final int columnIndex) {
- if (resultFormatCodes.isEmpty()) {
- return PostgreSQLColumnFormat.TEXT;
- }
- if (1 == resultFormatCodes.size()) {
- return PostgreSQLColumnFormat.valueOf(resultFormatCodes.get(0));
- }
- return PostgreSQLColumnFormat.valueOf(resultFormatCodes.get(columnIndex));
- }
-
@Override
public void write(final PostgreSQLPacketPayload payload) {
}
diff --git a/shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-postgresql/src/main/java/org/apache/shardingsphere/proxy/frontend/postgresql/command/query/binary/bind/OpenGaussComBatchBindExecutor.java b/shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-postgresql/src/main/java/org/apache/shardingsphere/proxy/frontend/postgresql/command/query/binary/bind/OpenGaussComBatchBindExecutor.java
index b85a712..ee879bd 100644
--- a/shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-postgresql/src/main/java/org/apache/shardingsphere/proxy/frontend/postgresql/command/query/binary/bind/OpenGaussComBatchBindExecutor.java
+++ b/shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-postgresql/src/main/java/org/apache/shardingsphere/proxy/frontend/postgresql/command/query/binary/bind/OpenGaussComBatchBindExecutor.java
@@ -22,7 +22,7 @@ import lombok.RequiredArgsConstructor;
import org.apache.shardingsphere.db.protocol.binary.BinaryCell;
import org.apache.shardingsphere.db.protocol.packet.DatabasePacket;
import org.apache.shardingsphere.db.protocol.postgresql.constant.PostgreSQLBinaryColumnType;
-import org.apache.shardingsphere.db.protocol.postgresql.constant.PostgreSQLColumnFormat;
+import org.apache.shardingsphere.db.protocol.postgresql.constant.PostgreSQLValueFormat;
import org.apache.shardingsphere.db.protocol.postgresql.packet.PostgreSQLPacket;
import org.apache.shardingsphere.db.protocol.postgresql.packet.command.query.PostgreSQLColumnDescription;
import org.apache.shardingsphere.db.protocol.postgresql.packet.command.query.PostgreSQLRowDescriptionPacket;
@@ -159,12 +159,17 @@ public final class OpenGaussComBatchBindExecutor implements QueryCommandExecutor
List<Object> result = new ArrayList<>(cells.size());
List<QueryResponseCell> columns = new ArrayList<>(cells);
for (int i = 0; i < columns.size(); i++) {
- PostgreSQLColumnFormat format = packet.getResultFormatByColumnIndex(i);
- result.add(PostgreSQLColumnFormat.BINARY == format ? createBinaryCell(columns.get(i)) : columns.get(i).getData());
+ PostgreSQLValueFormat format = determineValueFormat(i);
+ result.add(PostgreSQLValueFormat.BINARY == format ? createBinaryCell(columns.get(i)) : columns.get(i).getData());
}
return result;
}
+ private PostgreSQLValueFormat determineValueFormat(final int columnIndex) {
+ List<PostgreSQLValueFormat> resultFormats = packet.getResultFormats();
+ return resultFormats.isEmpty() ? PostgreSQLValueFormat.TEXT : resultFormats.get(columnIndex % resultFormats.size());
+ }
+
private BinaryCell createBinaryCell(final QueryResponseCell cell) {
return new BinaryCell(PostgreSQLBinaryColumnType.valueOfJDBCType(((BinaryQueryResponseCell) cell).getJdbcType()), cell.getData());
}