This is an automated email from the ASF dual-hosted git repository.
yx9o 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 63567276d65 Implement write method in
PostgreSQLBoolBinaryProtocolValue (#35831)
63567276d65 is described below
commit 63567276d656b29f6be8722394070a3a7f263a27
Author: Raigor <[email protected]>
AuthorDate: Sat Jun 28 15:58:59 2025 +0800
Implement write method in PostgreSQLBoolBinaryProtocolValue (#35831)
* Implement write method in PostgreSQLBoolBinaryProtocolValue
* Update RELEASE-NOTES.md
---
RELEASE-NOTES.md | 1 +
.../PostgreSQLBoolBinaryProtocolValue.java | 3 +-
.../PostgreSQLBinaryProtocolValueFactoryTest.java | 6 +++
.../PostgreSQLBoolBinaryProtocolValueTest.java | 52 ++++++++++++++++++++++
4 files changed, 60 insertions(+), 2 deletions(-)
diff --git a/RELEASE-NOTES.md b/RELEASE-NOTES.md
index 04e4dd54be4..559859a5ba2 100644
--- a/RELEASE-NOTES.md
+++ b/RELEASE-NOTES.md
@@ -48,6 +48,7 @@
1. SQL Parser: Support mysql quantify operator parse and upgrade calcite to
1.40.0 - [#35675](https://github.com/apache/shardingsphere/pull/35675)
1. SQL Parser: Support Oracle create table with lob storage clause sql parsing
- [#35782](https://github.com/apache/shardingsphere/pull/35782)
1. SQL Parser: Support Oracle multiple backslash literal parsing -
[#35784](https://github.com/apache/shardingsphere/pull/35784)
+1. Proxy: Implement write method for PostgreSQL bool binary data type -
[#35831](https://github.com/apache/shardingsphere/pull/35831)
### Bug Fixes
diff --git
a/db-protocol/postgresql/src/main/java/org/apache/shardingsphere/db/protocol/postgresql/packet/command/query/extended/bind/protocol/PostgreSQLBoolBinaryProtocolValue.java
b/db-protocol/postgresql/src/main/java/org/apache/shardingsphere/db/protocol/postgresql/packet/command/query/extended/bind/protocol/PostgreSQLBoolBinaryProtocolValue.java
index 37174691c4b..65df26ab336 100644
---
a/db-protocol/postgresql/src/main/java/org/apache/shardingsphere/db/protocol/postgresql/packet/command/query/extended/bind/protocol/PostgreSQLBoolBinaryProtocolValue.java
+++
b/db-protocol/postgresql/src/main/java/org/apache/shardingsphere/db/protocol/postgresql/packet/command/query/extended/bind/protocol/PostgreSQLBoolBinaryProtocolValue.java
@@ -19,7 +19,6 @@ package
org.apache.shardingsphere.db.protocol.postgresql.packet.command.query.ex
import lombok.extern.slf4j.Slf4j;
import
org.apache.shardingsphere.db.protocol.postgresql.payload.PostgreSQLPacketPayload;
-import
org.apache.shardingsphere.infra.exception.generic.UnsupportedSQLOperationException;
/**
* Binary protocol value for bool for PostgreSQL.
@@ -39,6 +38,6 @@ public final class PostgreSQLBoolBinaryProtocolValue
implements PostgreSQLBinary
@Override
public void write(final PostgreSQLPacketPayload payload, final Object
value) {
- throw new
UnsupportedSQLOperationException("PostgreSQLBoolBinaryProtocolValue.write()");
+ payload.getByteBuf().writeBoolean("t".equals(value.toString()));
}
}
diff --git
a/db-protocol/postgresql/src/test/java/org/apache/shardingsphere/db/protocol/postgresql/packet/command/query/extended/bind/protocol/PostgreSQLBinaryProtocolValueFactoryTest.java
b/db-protocol/postgresql/src/test/java/org/apache/shardingsphere/db/protocol/postgresql/packet/command/query/extended/bind/protocol/PostgreSQLBinaryProtocolValueFactoryTest.java
index cc9b0d8a8ed..ddef20841e9 100644
---
a/db-protocol/postgresql/src/test/java/org/apache/shardingsphere/db/protocol/postgresql/packet/command/query/extended/bind/protocol/PostgreSQLBinaryProtocolValueFactoryTest.java
+++
b/db-protocol/postgresql/src/test/java/org/apache/shardingsphere/db/protocol/postgresql/packet/command/query/extended/bind/protocol/PostgreSQLBinaryProtocolValueFactoryTest.java
@@ -86,6 +86,12 @@ class PostgreSQLBinaryProtocolValueFactoryTest {
assertThat(binaryProtocolValue,
instanceOf(PostgreSQLTimeBinaryProtocolValue.class));
}
+ @Test
+ void assertGetBoolBinaryProtocolValue() {
+ PostgreSQLBinaryProtocolValue binaryProtocolValue =
PostgreSQLBinaryProtocolValueFactory.getBinaryProtocolValue(PostgreSQLColumnType.BOOL);
+ assertThat(binaryProtocolValue,
instanceOf(PostgreSQLBoolBinaryProtocolValue.class));
+ }
+
@Test
void assertGetBinaryProtocolValueExThrown() {
assertThrows(IllegalArgumentException.class, () ->
PostgreSQLBinaryProtocolValueFactory.getBinaryProtocolValue(PostgreSQLColumnType.XML));
diff --git
a/db-protocol/postgresql/src/test/java/org/apache/shardingsphere/db/protocol/postgresql/packet/command/query/extended/bind/protocol/PostgreSQLBoolBinaryProtocolValueTest.java
b/db-protocol/postgresql/src/test/java/org/apache/shardingsphere/db/protocol/postgresql/packet/command/query/extended/bind/protocol/PostgreSQLBoolBinaryProtocolValueTest.java
new file mode 100644
index 00000000000..6930010dc59
--- /dev/null
+++
b/db-protocol/postgresql/src/test/java/org/apache/shardingsphere/db/protocol/postgresql/packet/command/query/extended/bind/protocol/PostgreSQLBoolBinaryProtocolValueTest.java
@@ -0,0 +1,52 @@
+/*
+ * 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;
+
+import io.netty.buffer.ByteBuf;
+import
org.apache.shardingsphere.db.protocol.postgresql.payload.PostgreSQLPacketPayload;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.extension.ExtendWith;
+import org.mockito.Mock;
+import org.mockito.junit.jupiter.MockitoExtension;
+
+import static org.hamcrest.CoreMatchers.is;
+import static org.hamcrest.MatcherAssert.assertThat;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.when;
+
+@ExtendWith(MockitoExtension.class)
+class PostgreSQLBoolBinaryProtocolValueTest {
+
+ @Mock
+ private PostgreSQLPacketPayload payload;
+
+ @Mock
+ private ByteBuf byteBuf;
+
+ @Test
+ void assertNewInstance() {
+ PostgreSQLBoolBinaryProtocolValue actual = new
PostgreSQLBoolBinaryProtocolValue();
+ assertThat(actual.getColumnLength(null), is(1));
+ when(payload.getByteBuf()).thenReturn(byteBuf);
+ when(byteBuf.readBoolean()).thenReturn(true);
+ assertTrue((boolean) actual.read(payload, 1));
+ actual.write(payload, "f");
+ verify(payload.getByteBuf()).writeBoolean(false);
+ }
+}