This is an automated email from the ASF dual-hosted git repository.
terrymanu 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 ea0c6f22a5b Fix BOOLEAN type handling in Firebird Proxy (#38655)
ea0c6f22a5b is described below
commit ea0c6f22a5b5bc3c0d296f185a28b55ae54bf709
Author: Maxim Sentyabrskiy <[email protected]>
AuthorDate: Tue Jun 2 15:52:20 2026 +0300
Fix BOOLEAN type handling in Firebird Proxy (#38655)
* fix: insert with boolean fix
* fix: select with boolean fix
* spotless fix
* refactor: introduce FirebirdBooleanBinaryProtocolValue for boolean type
handling
* checkstyle fix
* fix ci
* fix boolean protocol review comments
---------
Co-authored-by: makssent <[email protected]>
---
.../FirebirdBinaryProtocolValueFactory.java | 6 +-
.../FirebirdBooleanBinaryProtocolValue.java} | 41 +++++------
.../FirebirdExecuteStatementPacketTest.java | 5 +-
.../FirebirdBinaryProtocolValueFactoryTest.java | 4 +-
.../FirebirdBooleanBinaryProtocolValueTest.java | 79 ++++++++++++++++++++++
.../FirebirdInt1BinaryProtocolValueTest.java | 2 +-
.../generic/FirebirdFetchResponsePacketTest.java | 14 ++++
7 files changed, 119 insertions(+), 32 deletions(-)
diff --git
a/database/protocol/dialect/firebird/src/main/java/org/apache/shardingsphere/database/protocol/firebird/packet/command/query/statement/execute/protocol/FirebirdBinaryProtocolValueFactory.java
b/database/protocol/dialect/firebird/src/main/java/org/apache/shardingsphere/database/protocol/firebird/packet/command/query/statement/execute/protocol/FirebirdBinaryProtocolValueFactory.java
index b632fefe03e..e15d41a8c70 100644
---
a/database/protocol/dialect/firebird/src/main/java/org/apache/shardingsphere/database/protocol/firebird/packet/command/query/statement/execute/protocol/FirebirdBinaryProtocolValueFactory.java
+++
b/database/protocol/dialect/firebird/src/main/java/org/apache/shardingsphere/database/protocol/firebird/packet/command/query/statement/execute/protocol/FirebirdBinaryProtocolValueFactory.java
@@ -41,7 +41,7 @@ public final class FirebirdBinaryProtocolValueFactory {
setInt8BinaryProtocolValue();
setInt4BinaryProtocolValue();
setInt2BinaryProtocolValue();
- setInt1BinaryProtocolValue();
+ setBooleanBinaryProtocolValue();
setDoubleBinaryProtocolValue();
setFloatBinaryProtocolValue();
setDateBinaryProtocolValue();
@@ -90,8 +90,8 @@ public final class FirebirdBinaryProtocolValueFactory {
BINARY_PROTOCOL_VALUES.put(FirebirdBinaryColumnType.SHORT,
binaryProtocolValue);
}
- private static void setInt1BinaryProtocolValue() {
- FirebirdInt1BinaryProtocolValue binaryProtocolValue = new
FirebirdInt1BinaryProtocolValue();
+ private static void setBooleanBinaryProtocolValue() {
+ FirebirdBooleanBinaryProtocolValue binaryProtocolValue = new
FirebirdBooleanBinaryProtocolValue();
BINARY_PROTOCOL_VALUES.put(FirebirdBinaryColumnType.BOOLEAN,
binaryProtocolValue);
}
diff --git
a/database/protocol/dialect/firebird/src/test/java/org/apache/shardingsphere/database/protocol/firebird/packet/command/query/statement/execute/protocol/FirebirdInt1BinaryProtocolValueTest.java
b/database/protocol/dialect/firebird/src/main/java/org/apache/shardingsphere/database/protocol/firebird/packet/command/query/statement/execute/protocol/FirebirdBooleanBinaryProtocolValue.java
similarity index 53%
copy from
database/protocol/dialect/firebird/src/test/java/org/apache/shardingsphere/database/protocol/firebird/packet/command/query/statement/execute/protocol/FirebirdInt1BinaryProtocolValueTest.java
copy to
database/protocol/dialect/firebird/src/main/java/org/apache/shardingsphere/database/protocol/firebird/packet/command/query/statement/execute/protocol/FirebirdBooleanBinaryProtocolValue.java
index 08842f17a2b..5b986fcca03 100644
---
a/database/protocol/dialect/firebird/src/test/java/org/apache/shardingsphere/database/protocol/firebird/packet/command/query/statement/execute/protocol/FirebirdInt1BinaryProtocolValueTest.java
+++
b/database/protocol/dialect/firebird/src/main/java/org/apache/shardingsphere/database/protocol/firebird/packet/command/query/statement/execute/protocol/FirebirdBooleanBinaryProtocolValue.java
@@ -18,36 +18,27 @@
package
org.apache.shardingsphere.database.protocol.firebird.packet.command.query.statement.execute.protocol;
import
org.apache.shardingsphere.database.protocol.firebird.payload.FirebirdPacketPayload;
-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.Matchers.is;
-import static org.hamcrest.MatcherAssert.assertThat;
-import static org.mockito.Mockito.verify;
-import static org.mockito.Mockito.when;
-
-@ExtendWith(MockitoExtension.class)
-class FirebirdInt1BinaryProtocolValueTest {
-
- @Mock
- private FirebirdPacketPayload payload;
+/**
+ * Binary protocol value for boolean for Firebird.
+ */
+public final class FirebirdBooleanBinaryProtocolValue implements
FirebirdBinaryProtocolValue {
- @Test
- void assertRead() {
- when(payload.readInt1Unsigned()).thenReturn(1);
- assertThat(new FirebirdInt1BinaryProtocolValue().read(payload), is(1));
+ @Override
+ public Object read(final FirebirdPacketPayload payload) {
+ boolean result = 1 == payload.readInt1Unsigned();
+ payload.skipReserved(3);
+ return result;
}
- @Test
- void assertWrite() {
- new FirebirdInt1BinaryProtocolValue().write(payload, 1);
- verify(payload).writeInt2(1);
+ @Override
+ public void write(final FirebirdPacketPayload payload, final Object value)
{
+ payload.writeInt1((Boolean) value ? 1 : 0);
+ payload.getByteBuf().writeZero(3);
}
- @Test
- void assertGetLength() {
- assertThat(new FirebirdInt1BinaryProtocolValue().getLength(payload),
is(1));
+ @Override
+ public int getLength(final FirebirdPacketPayload payload) {
+ return 4;
}
}
diff --git
a/database/protocol/dialect/firebird/src/test/java/org/apache/shardingsphere/database/protocol/firebird/packet/command/query/statement/execute/FirebirdExecuteStatementPacketTest.java
b/database/protocol/dialect/firebird/src/test/java/org/apache/shardingsphere/database/protocol/firebird/packet/command/query/statement/execute/FirebirdExecuteStatementPacketTest.java
index 9b48733d150..5e123c6cb45 100644
---
a/database/protocol/dialect/firebird/src/test/java/org/apache/shardingsphere/database/protocol/firebird/packet/command/query/statement/execute/FirebirdExecuteStatementPacketTest.java
+++
b/database/protocol/dialect/firebird/src/test/java/org/apache/shardingsphere/database/protocol/firebird/packet/command/query/statement/execute/FirebirdExecuteStatementPacketTest.java
@@ -57,6 +57,9 @@ class FirebirdExecuteStatementPacketTest {
void assertExecuteStatementPacket(final String name, final short blrType,
final FirebirdBinaryColumnType expectedParameterType, final Object
expectedParameterValue) {
when(payload.readInt4()).thenReturn(FirebirdCommandPacketType.EXECUTE.getValue(),
1, 2, 0, 1, 123);
when(payload.readInt1()).thenReturn(0);
+ if (FirebirdBinaryColumnType.BOOLEAN == expectedParameterType) {
+ when(payload.readInt1Unsigned()).thenReturn(1);
+ }
when(payload.readBuffer()).thenReturn(byteBuf);
when(byteBuf.isReadable()).thenReturn(true);
when(byteBuf.readUnsignedByte()).thenReturn((short) 5, (short) 0,
blrType, (short) BlrConstants.blr_end);
@@ -150,7 +153,7 @@ class FirebirdExecuteStatementPacketTest {
Arguments.of("skip_count_4", (short)
BlrConstants.blr_varying2, FirebirdBinaryColumnType.VARYING, null),
Arguments.of("skip_count_2", (short) BlrConstants.blr_text,
FirebirdBinaryColumnType.LEGACY_TEXT, null),
Arguments.of("skip_count_1", (short) BlrConstants.blr_long,
FirebirdBinaryColumnType.LONG, 123),
- Arguments.of("skip_count_0", (short) BlrConstants.blr_bool,
FirebirdBinaryColumnType.BOOLEAN, 0),
+ Arguments.of("skip_count_0", (short) BlrConstants.blr_bool,
FirebirdBinaryColumnType.BOOLEAN, true),
Arguments.of("blob_parameter", (short) BlrConstants.blr_quad,
FirebirdBinaryColumnType.BLOB, 0L));
}
diff --git
a/database/protocol/dialect/firebird/src/test/java/org/apache/shardingsphere/database/protocol/firebird/packet/command/query/statement/execute/protocol/FirebirdBinaryProtocolValueFactoryTest.java
b/database/protocol/dialect/firebird/src/test/java/org/apache/shardingsphere/database/protocol/firebird/packet/command/query/statement/execute/protocol/FirebirdBinaryProtocolValueFactoryTest.java
index 7f2cdad7c82..6130ac08199 100644
---
a/database/protocol/dialect/firebird/src/test/java/org/apache/shardingsphere/database/protocol/firebird/packet/command/query/statement/execute/protocol/FirebirdBinaryProtocolValueFactoryTest.java
+++
b/database/protocol/dialect/firebird/src/test/java/org/apache/shardingsphere/database/protocol/firebird/packet/command/query/statement/execute/protocol/FirebirdBinaryProtocolValueFactoryTest.java
@@ -64,9 +64,9 @@ class FirebirdBinaryProtocolValueFactoryTest {
}
@Test
- void assertGetInt1BinaryProtocolValue() {
+ void assertGetBooleanBinaryProtocolValue() {
FirebirdBinaryProtocolValue actual =
FirebirdBinaryProtocolValueFactory.getBinaryProtocolValue(FirebirdBinaryColumnType.BOOLEAN);
- assertThat(actual, isA(FirebirdInt1BinaryProtocolValue.class));
+ assertThat(actual, isA(FirebirdBooleanBinaryProtocolValue.class));
}
@Test
diff --git
a/database/protocol/dialect/firebird/src/test/java/org/apache/shardingsphere/database/protocol/firebird/packet/command/query/statement/execute/protocol/FirebirdBooleanBinaryProtocolValueTest.java
b/database/protocol/dialect/firebird/src/test/java/org/apache/shardingsphere/database/protocol/firebird/packet/command/query/statement/execute/protocol/FirebirdBooleanBinaryProtocolValueTest.java
new file mode 100644
index 00000000000..8802f38f9cb
--- /dev/null
+++
b/database/protocol/dialect/firebird/src/test/java/org/apache/shardingsphere/database/protocol/firebird/packet/command/query/statement/execute/protocol/FirebirdBooleanBinaryProtocolValueTest.java
@@ -0,0 +1,79 @@
+/*
+ * 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.database.protocol.firebird.packet.command.query.statement.execute.protocol;
+
+import io.netty.buffer.ByteBuf;
+import io.netty.buffer.Unpooled;
+import
org.apache.shardingsphere.database.protocol.firebird.payload.FirebirdPacketPayload;
+import org.junit.jupiter.api.Test;
+
+import java.nio.charset.StandardCharsets;
+
+import static org.hamcrest.MatcherAssert.assertThat;
+import static org.hamcrest.Matchers.is;
+import static org.junit.jupiter.api.Assertions.assertFalse;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+
+class FirebirdBooleanBinaryProtocolValueTest {
+
+ @Test
+ void assertReadTrue() {
+ ByteBuf byteBuf = Unpooled.wrappedBuffer(new byte[]{1, 0, 0, 0});
+ assertTrue((Boolean) new FirebirdBooleanBinaryProtocolValue().read(new
FirebirdPacketPayload(byteBuf, StandardCharsets.UTF_8)));
+ assertThat(byteBuf.readerIndex(), is(4));
+ }
+
+ @Test
+ void assertReadFalse() {
+ ByteBuf byteBuf = Unpooled.wrappedBuffer(new byte[]{0, 0, 0, 0});
+ assertFalse((Boolean) new
FirebirdBooleanBinaryProtocolValue().read(new FirebirdPacketPayload(byteBuf,
StandardCharsets.UTF_8)));
+ assertThat(byteBuf.readerIndex(), is(4));
+ }
+
+ @Test
+ void assertReadFalseWithUnexpectedValue() {
+ ByteBuf byteBuf = Unpooled.wrappedBuffer(new byte[]{2, 0, 0, 0});
+ assertFalse((Boolean) new
FirebirdBooleanBinaryProtocolValue().read(new FirebirdPacketPayload(byteBuf,
StandardCharsets.UTF_8)));
+ assertThat(byteBuf.readerIndex(), is(4));
+ }
+
+ @Test
+ void assertWriteWithTrue() {
+ ByteBuf byteBuf = Unpooled.buffer();
+ new FirebirdBooleanBinaryProtocolValue().write(new
FirebirdPacketPayload(byteBuf, StandardCharsets.UTF_8), true);
+ assertThat(byteBuf.readByte(), is((byte) 1));
+ assertThat(byteBuf.readByte(), is((byte) 0));
+ assertThat(byteBuf.readByte(), is((byte) 0));
+ assertThat(byteBuf.readByte(), is((byte) 0));
+ }
+
+ @Test
+ void assertWriteWithFalse() {
+ ByteBuf byteBuf = Unpooled.buffer();
+ new FirebirdBooleanBinaryProtocolValue().write(new
FirebirdPacketPayload(byteBuf, StandardCharsets.UTF_8), false);
+ assertThat(byteBuf.readByte(), is((byte) 0));
+ assertThat(byteBuf.readByte(), is((byte) 0));
+ assertThat(byteBuf.readByte(), is((byte) 0));
+ assertThat(byteBuf.readByte(), is((byte) 0));
+ }
+
+ @Test
+ void assertGetLength() {
+ assertThat(new FirebirdBooleanBinaryProtocolValue().getLength(new
FirebirdPacketPayload(Unpooled.buffer(), StandardCharsets.UTF_8)), is(4));
+ }
+}
diff --git
a/database/protocol/dialect/firebird/src/test/java/org/apache/shardingsphere/database/protocol/firebird/packet/command/query/statement/execute/protocol/FirebirdInt1BinaryProtocolValueTest.java
b/database/protocol/dialect/firebird/src/test/java/org/apache/shardingsphere/database/protocol/firebird/packet/command/query/statement/execute/protocol/FirebirdInt1BinaryProtocolValueTest.java
index 08842f17a2b..b155a89b3e0 100644
---
a/database/protocol/dialect/firebird/src/test/java/org/apache/shardingsphere/database/protocol/firebird/packet/command/query/statement/execute/protocol/FirebirdInt1BinaryProtocolValueTest.java
+++
b/database/protocol/dialect/firebird/src/test/java/org/apache/shardingsphere/database/protocol/firebird/packet/command/query/statement/execute/protocol/FirebirdInt1BinaryProtocolValueTest.java
@@ -23,8 +23,8 @@ import org.junit.jupiter.api.extension.ExtendWith;
import org.mockito.Mock;
import org.mockito.junit.jupiter.MockitoExtension;
-import static org.hamcrest.Matchers.is;
import static org.hamcrest.MatcherAssert.assertThat;
+import static org.hamcrest.Matchers.is;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
diff --git
a/database/protocol/dialect/firebird/src/test/java/org/apache/shardingsphere/database/protocol/firebird/packet/generic/FirebirdFetchResponsePacketTest.java
b/database/protocol/dialect/firebird/src/test/java/org/apache/shardingsphere/database/protocol/firebird/packet/generic/FirebirdFetchResponsePacketTest.java
index 343c7a27457..e8a372e68e5 100644
---
a/database/protocol/dialect/firebird/src/test/java/org/apache/shardingsphere/database/protocol/firebird/packet/generic/FirebirdFetchResponsePacketTest.java
+++
b/database/protocol/dialect/firebird/src/test/java/org/apache/shardingsphere/database/protocol/firebird/packet/generic/FirebirdFetchResponsePacketTest.java
@@ -18,6 +18,7 @@
package org.apache.shardingsphere.database.protocol.firebird.packet.generic;
import io.netty.buffer.ByteBuf;
+import io.netty.buffer.Unpooled;
import org.apache.shardingsphere.database.protocol.binary.BinaryCell;
import org.apache.shardingsphere.database.protocol.binary.BinaryRow;
import
org.apache.shardingsphere.database.protocol.firebird.packet.command.FirebirdCommandPacketType;
@@ -32,6 +33,7 @@ import org.mockito.Mock;
import org.mockito.MockedStatic;
import org.mockito.junit.jupiter.MockitoExtension;
+import java.nio.charset.StandardCharsets;
import java.util.Collections;
import static org.hamcrest.MatcherAssert.assertThat;
@@ -96,6 +98,18 @@ class FirebirdFetchResponsePacketTest {
}
}
+ @Test
+ void assertWriteWithBooleanCellData() {
+ ByteBuf byteBuf = Unpooled.buffer();
+ FirebirdPacketPayload payload = new FirebirdPacketPayload(byteBuf,
StandardCharsets.UTF_8);
+ FirebirdFetchResponsePacket.getFetchRowPacket(new
BinaryRow(Collections.singleton(new
BinaryCell(FirebirdBinaryColumnType.BOOLEAN, true)))).write(payload);
+ byteBuf.skipBytes(16);
+ assertThat(byteBuf.readByte(), is((byte) 1));
+ assertThat(byteBuf.readByte(), is((byte) 0));
+ assertThat(byteBuf.readByte(), is((byte) 0));
+ assertThat(byteBuf.readByte(), is((byte) 0));
+ }
+
@Test
void assertWriteWithNullCellData() {
when(payload.getByteBuf()).thenReturn(byteBuf);