You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@shardingsphere.apache.org by ji...@apache.org on 2024/09/13 06:07:34 UTC
(shardingsphere) branch master updated: For #32843, support array type prepared param in PostgreSQL (#32845)
This is an automated email from the ASF dual-hosted git repository.
jiangmaolin pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/shardingsphere.git
The following commit(s) were added to refs/heads/master by this push:
new acaf38e2ebc For #32843, support array type prepared param in PostgreSQL (#32845)
acaf38e2ebc is described below
commit acaf38e2ebc034460237a2f00822b6144cabdb92
Author: Raigor <ra...@gmail.com>
AuthorDate: Fri Sep 13 14:07:28 2024 +0800
For #32843, support array type prepared param in PostgreSQL (#32845)
---
.../query/extended/PostgreSQLColumnType.java | 7 ++--
.../text/impl/PostgreSQLTextArrayValueParser.java | 42 ++++++++++++++++++++++
.../impl/PostgreSQLVarcharArrayValueParser.java | 42 ++++++++++++++++++++++
3 files changed, 89 insertions(+), 2 deletions(-)
diff --git a/db-protocol/postgresql/src/main/java/org/apache/shardingsphere/db/protocol/postgresql/packet/command/query/extended/PostgreSQLColumnType.java b/db-protocol/postgresql/src/main/java/org/apache/shardingsphere/db/protocol/postgresql/packet/command/query/extended/PostgreSQLColumnType.java
index fd7e74b7459..0d79dd2a1b6 100644
--- a/db-protocol/postgresql/src/main/java/org/apache/shardingsphere/db/protocol/postgresql/packet/command/query/extended/PostgreSQLColumnType.java
+++ b/db-protocol/postgresql/src/main/java/org/apache/shardingsphere/db/protocol/postgresql/packet/command/query/extended/PostgreSQLColumnType.java
@@ -32,9 +32,11 @@ import org.apache.shardingsphere.db.protocol.postgresql.packet.command.query.ext
import org.apache.shardingsphere.db.protocol.postgresql.packet.command.query.extended.bind.protocol.text.impl.PostgreSQLJsonValueParser;
import org.apache.shardingsphere.db.protocol.postgresql.packet.command.query.extended.bind.protocol.text.impl.PostgreSQLLongValueParser;
import org.apache.shardingsphere.db.protocol.postgresql.packet.command.query.extended.bind.protocol.text.impl.PostgreSQLNumericValueParser;
+import org.apache.shardingsphere.db.protocol.postgresql.packet.command.query.extended.bind.protocol.text.impl.PostgreSQLTextArrayValueParser;
import org.apache.shardingsphere.db.protocol.postgresql.packet.command.query.extended.bind.protocol.text.impl.PostgreSQLTimeValueParser;
import org.apache.shardingsphere.db.protocol.postgresql.packet.command.query.extended.bind.protocol.text.impl.PostgreSQLTimestampValueParser;
import org.apache.shardingsphere.db.protocol.postgresql.packet.command.query.extended.bind.protocol.text.impl.PostgreSQLUnspecifiedValueParser;
+import org.apache.shardingsphere.db.protocol.postgresql.packet.command.query.extended.bind.protocol.text.impl.PostgreSQLVarcharArrayValueParser;
import org.apache.shardingsphere.db.protocol.postgresql.packet.command.query.extended.bind.protocol.text.impl.PostgreSQLVarcharValueParser;
import java.sql.Types;
@@ -64,7 +66,7 @@ public enum PostgreSQLColumnType implements BinaryColumnType {
TEXT(25, new PostgreSQLVarcharValueParser()),
- TEXT_ARRAY(1009, new PostgreSQLVarcharValueParser()),
+ TEXT_ARRAY(1009, new PostgreSQLTextArrayValueParser()),
NUMERIC(1700, new PostgreSQLNumericValueParser()),
@@ -108,7 +110,7 @@ public enum PostgreSQLColumnType implements BinaryColumnType {
VARCHAR(1043, new PostgreSQLVarcharValueParser()),
- VARCHAR_ARRAY(1015, new PostgreSQLVarcharValueParser()),
+ VARCHAR_ARRAY(1015, new PostgreSQLVarcharArrayValueParser()),
OID(26, new PostgreSQLVarcharValueParser()),
@@ -195,6 +197,7 @@ public enum PostgreSQLColumnType implements BinaryColumnType {
JDBC_TYPE_AND_COLUMN_TYPE_MAP.put(Types.BOOLEAN, BOOL);
// TODO Temporary solution for https://github.com/apache/shardingsphere/issues/22522
JDBC_TYPE_AND_COLUMN_TYPE_MAP.put(Types.STRUCT, VARCHAR);
+ JDBC_TYPE_AND_COLUMN_TYPE_MAP.put(Types.ARRAY, TEXT_ARRAY);
}
/**
diff --git a/db-protocol/postgresql/src/main/java/org/apache/shardingsphere/db/protocol/postgresql/packet/command/query/extended/bind/protocol/text/impl/PostgreSQLTextArrayValueParser.java b/db-protocol/postgresql/src/main/java/org/apache/shardingsphere/db/protocol/postgresql/packet/command/query/extended/bind/protocol/text/impl/PostgreSQLTextArrayValueParser.java
new file mode 100644
index 00000000000..e06886d47e6
--- /dev/null
+++ b/db-protocol/postgresql/src/main/java/org/apache/shardingsphere/db/protocol/postgresql/packet/command/query/extended/bind/protocol/text/impl/PostgreSQLTextArrayValueParser.java
@@ -0,0 +1,42 @@
+/*
+ * 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.shardingsphere.db.protocol.postgresql.packet.command.query.extended.bind.protocol.text.impl;
+
+import org.apache.shardingsphere.db.protocol.postgresql.packet.command.query.extended.bind.protocol.text.PostgreSQLTextValueParser;
+import org.apache.shardingsphere.infra.exception.core.external.sql.type.wrapper.SQLWrapperException;
+import org.postgresql.util.PGobject;
+
+import java.sql.SQLException;
+
+/**
+ * Text array value parser of PostgreSQL.
+ */
+public final class PostgreSQLTextArrayValueParser implements PostgreSQLTextValueParser<PGobject> {
+
+ @Override
+ public PGobject parse(final String value) {
+ try {
+ PGobject result = new PGobject();
+ result.setType("text[]");
+ result.setValue(value);
+ return result;
+ } catch (final SQLException ex) {
+ throw new SQLWrapperException(ex);
+ }
+ }
+}
diff --git a/db-protocol/postgresql/src/main/java/org/apache/shardingsphere/db/protocol/postgresql/packet/command/query/extended/bind/protocol/text/impl/PostgreSQLVarcharArrayValueParser.java b/db-protocol/postgresql/src/main/java/org/apache/shardingsphere/db/protocol/postgresql/packet/command/query/extended/bind/protocol/text/impl/PostgreSQLVarcharArrayValueParser.java
new file mode 100644
index 00000000000..a9de253ea22
--- /dev/null
+++ b/db-protocol/postgresql/src/main/java/org/apache/shardingsphere/db/protocol/postgresql/packet/command/query/extended/bind/protocol/text/impl/PostgreSQLVarcharArrayValueParser.java
@@ -0,0 +1,42 @@
+/*
+ * 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.shardingsphere.db.protocol.postgresql.packet.command.query.extended.bind.protocol.text.impl;
+
+import org.apache.shardingsphere.db.protocol.postgresql.packet.command.query.extended.bind.protocol.text.PostgreSQLTextValueParser;
+import org.apache.shardingsphere.infra.exception.core.external.sql.type.wrapper.SQLWrapperException;
+import org.postgresql.util.PGobject;
+
+import java.sql.SQLException;
+
+/**
+ * Varchar array value parser of PostgreSQL.
+ */
+public final class PostgreSQLVarcharArrayValueParser implements PostgreSQLTextValueParser<PGobject> {
+
+ @Override
+ public PGobject parse(final String value) {
+ try {
+ PGobject result = new PGobject();
+ result.setType("varchar[]");
+ result.setValue(value);
+ return result;
+ } catch (final SQLException ex) {
+ throw new SQLWrapperException(ex);
+ }
+ }
+}