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 b3b9a4f84ed Fix firebird union parameters (#40209)
b3b9a4f84ed is described below
commit b3b9a4f84ed6cd4d650ff4228b253d55b728dbbd
Author: Maxim Igoshin <[email protected]>
AuthorDate: Wed Oct 21 11:11:56 2026 +0300
Fix firebird union parameters (#40209)
* Describe Firebird parameters of all branches of UNION in the order of the
statement
* fix conduct
* Fix lambda names and test helper order in Firebird union parameter
description
---
.../FirebirdPrepareStatementCommandExecutor.java | 28 +++++++++++++++-
...irebirdPrepareStatementCommandExecutorTest.java | 38 ++++++++++++++++++++++
2 files changed, 65 insertions(+), 1 deletion(-)
diff --git
a/proxy/frontend/dialect/firebird/src/main/java/org/apache/shardingsphere/proxy/frontend/firebird/command/query/statement/prepare/FirebirdPrepareStatementCommandExecutor.java
b/proxy/frontend/dialect/firebird/src/main/java/org/apache/shardingsphere/proxy/frontend/firebird/command/query/statement/prepare/FirebirdPrepareStatementCommandExecutor.java
index 3468a5dc376..5b61b327942 100644
---
a/proxy/frontend/dialect/firebird/src/main/java/org/apache/shardingsphere/proxy/frontend/firebird/command/query/statement/prepare/FirebirdPrepareStatementCommandExecutor.java
+++
b/proxy/frontend/dialect/firebird/src/main/java/org/apache/shardingsphere/proxy/frontend/firebird/command/query/statement/prepare/FirebirdPrepareStatementCommandExecutor.java
@@ -95,9 +95,12 @@ import org.jspecify.annotations.Nullable;
import java.sql.SQLException;
import java.sql.Types;
+import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
+import java.util.Comparator;
import java.util.LinkedList;
+import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.Optional;
@@ -398,7 +401,7 @@ public final class FirebirdPrepareStatementCommandExecutor
implements CommandExe
}
}
if (sqlStatementContext instanceof WhereContextAvailable) {
- Collection<WhereSegment> whereSegments = ((WhereContextAvailable)
sqlStatementContext).getWhereSegments();
+ Collection<WhereSegment> whereSegments =
getWhereSegments((WhereContextAvailable) sqlStatementContext);
for (WhereSegment each : whereSegments) {
processExpr(each.getExpr(), result);
}
@@ -406,6 +409,29 @@ public final class FirebirdPrepareStatementCommandExecutor
implements CommandExe
return result;
}
+ @HighFrequencyInvocation
+ private Collection<WhereSegment> getWhereSegments(final
WhereContextAvailable sqlStatementContext) {
+ if (!(sqlStatementContext instanceof SelectStatementContext) ||
!((SelectStatementContext) sqlStatementContext).isContainsCombine()) {
+ return sqlStatementContext.getWhereSegments();
+ }
+ List<WhereSegment> result = new
ArrayList<>(sqlStatementContext.getWhereSegments());
+ appendCombineWhereSegments(((SelectStatementContext)
sqlStatementContext).getSqlStatement(), result);
+ result.sort(Comparator.comparingInt(WhereSegment::getStartIndex));
+ return result;
+ }
+
+ private void appendCombineWhereSegments(final SelectStatement
selectStatement, final Collection<WhereSegment> whereSegments) {
+ selectStatement.getCombine().ifPresent(combine -> {
+ appendBranchWhereSegments(combine.getLeft().getSelect(),
whereSegments);
+ appendBranchWhereSegments(combine.getRight().getSelect(),
whereSegments);
+ });
+ }
+
+ private void appendBranchWhereSegments(final SelectStatement branch, final
Collection<WhereSegment> whereSegments) {
+ branch.getWhere().filter(whereSegment ->
!whereSegments.contains(whereSegment)).ifPresent(whereSegments::add);
+ appendCombineWhereSegments(branch, whereSegments);
+ }
+
private boolean processExpr(final ExpressionSegment expr, final
Collection<ColumnSegment> affectedColumns) {
if (!(expr instanceof BinaryOperationExpression)) {
return expr instanceof ParameterMarkerExpressionSegment;
diff --git
a/proxy/frontend/dialect/firebird/src/test/java/org/apache/shardingsphere/proxy/frontend/firebird/command/query/statement/prepare/FirebirdPrepareStatementCommandExecutorTest.java
b/proxy/frontend/dialect/firebird/src/test/java/org/apache/shardingsphere/proxy/frontend/firebird/command/query/statement/prepare/FirebirdPrepareStatementCommandExecutorTest.java
index dee52e8336d..ad387c11c18 100644
---
a/proxy/frontend/dialect/firebird/src/test/java/org/apache/shardingsphere/proxy/frontend/firebird/command/query/statement/prepare/FirebirdPrepareStatementCommandExecutorTest.java
+++
b/proxy/frontend/dialect/firebird/src/test/java/org/apache/shardingsphere/proxy/frontend/firebird/command/query/statement/prepare/FirebirdPrepareStatementCommandExecutorTest.java
@@ -193,6 +193,44 @@ class FirebirdPrepareStatementCommandExecutorTest {
assertThat(((DropDatabaseStatement)
preparedStatement.getSqlStatementContext().getSqlStatement()).getDatabaseName(),
is("foo_db"));
}
+ @Test
+ void assertDescribeParametersOfUnionWithTwoBranches() throws Exception {
+ FirebirdPrepareStatementReturnPacket actual = describeBind("SELECT id
FROM foo_tbl WHERE content = ? UNION ALL SELECT id FROM foo_tbl WHERE id = ?");
+ assertThat(actual.getDescribeBind().size(), is(2));
+ assertParameterType(actual.getDescribeBind().get(0),
FirebirdBinaryColumnType.BLOB);
+ assertParameterType(actual.getDescribeBind().get(1),
FirebirdBinaryColumnType.LONG);
+ }
+
+ private FirebirdPrepareStatementReturnPacket describeBind(final String
sql) throws Exception {
+ when(packet.getSQL()).thenReturn(sql);
+ when(packet.nextItem()).thenReturn(true, true, true, true, true,
false);
+ when(packet.getCurrentItem()).thenReturn(
+ FirebirdSQLInfoPacketType.STMT_TYPE,
+ FirebirdSQLInfoPacketType.BIND,
+ FirebirdSQLInfoPacketType.TYPE,
+ FirebirdSQLInfoPacketType.TYPE,
+ FirebirdSQLInfoPacketType.DESCRIBE_END,
+ FirebirdSQLInfoPacketType.DESCRIBE_END);
+ FirebirdPrepareStatementCommandExecutor executor = new
FirebirdPrepareStatementCommandExecutor(packet, connectionSession);
+ return (FirebirdPrepareStatementReturnPacket)
((FirebirdGenericResponsePacket)
executor.execute().iterator().next()).getData();
+ }
+
+ private void assertParameterType(final FirebirdReturnColumnPacket actual,
final FirebirdBinaryColumnType expected) {
+ FirebirdPacketPayload payload = mock(FirebirdPacketPayload.class);
+ actual.write(payload);
+ verify(payload).writeInt4LE(expected.getValue() + 1);
+ }
+
+ @Test
+ void assertDescribeParametersOfUnionWithThreeBranches() throws Exception {
+ String sql = "SELECT id FROM foo_tbl WHERE id = ? UNION ALL SELECT id
FROM foo_tbl WHERE content = ? UNION ALL SELECT id FROM foo_tbl WHERE id = ?";
+ FirebirdPrepareStatementReturnPacket actual = describeBind(sql);
+ assertThat(actual.getDescribeBind().size(), is(3));
+ assertParameterType(actual.getDescribeBind().get(0),
FirebirdBinaryColumnType.LONG);
+ assertParameterType(actual.getDescribeBind().get(1),
FirebirdBinaryColumnType.BLOB);
+ assertParameterType(actual.getDescribeBind().get(2),
FirebirdBinaryColumnType.LONG);
+ }
+
@Test
void assertExecuteDropDatabaseWithoutNameAndCurrentDatabase() {
when(packet.getSQL()).thenReturn("DROP DATABASE");