Skip to content

Commit 49a84ba

Browse files
authored
Fixed column length resolution for sharded tables (#37425)
* fix column length resolution for sharded tables * ci trigger
1 parent 5dcd1a9 commit 49a84ba

2 files changed

Lines changed: 28 additions & 2 deletions

File tree

database/connector/dialect/firebird/src/main/java/org/apache/shardingsphere/database/connector/firebird/metadata/data/FirebirdSizeRegistry.java

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,16 @@ public static OptionalInt findColumnSize(final String schemaName, final String t
8787

8888
private static String buildTableKey(final String schemaName, final String tableName) {
8989
String schemaKey = null == schemaName ? "" : toKey(schemaName);
90-
return schemaKey + "." + toKey(tableName);
90+
String logicTable = trimToLogicTableName(tableName);
91+
return schemaKey + "." + toKey(logicTable);
92+
}
93+
94+
private static String trimToLogicTableName(final String tableName) {
95+
int end = tableName.length() - 1;
96+
while (end >= 0 && !Character.isLetter(tableName.charAt(end))) {
97+
end--;
98+
}
99+
return end < 0 ? tableName : tableName.substring(0, end + 1);
91100
}
92101

93102
private static String toKey(final String value) {

proxy/frontend/dialect/firebird/src/main/java/org/apache/shardingsphere/proxy/frontend/firebird/command/query/statement/prepare/FirebirdPrepareStatementCommandExecutor.java

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -458,7 +458,7 @@ private void processColumn(final Collection<FirebirdReturnColumnPacket> describe
458458
String tableAliasString = null == tableAlias ? table.getName() : tableAlias.getValue();
459459
String columnAliasString = null == columnAlias ? column.getName() : columnAlias.getValue();
460460
String owner = connectionSession.getConnectionContext().getGrantee().getUsername();
461-
Integer columnLength = resolveColumnLength(table, column);
461+
Integer columnLength = (null != column && isDynamicLengthType(column.getDataType())) ? resolveColumnLength(table, column) : null;
462462
describeColumns.add(new FirebirdReturnColumnPacket(requestedItems, idx, table, column, tableAliasString, columnAliasString, owner, columnLength));
463463
}
464464

@@ -469,4 +469,21 @@ private Integer resolveColumnLength(final ShardingSphereTable table, final Shard
469469
OptionalInt columnSize = FirebirdSizeRegistry.findColumnSize(connectionSession.getCurrentDatabaseName(), table.getName(), column.getName());
470470
return columnSize.isPresent() ? columnSize.getAsInt() : null;
471471
}
472+
473+
private boolean isDynamicLengthType(final int dataType) {
474+
switch (dataType) {
475+
case Types.CHAR:
476+
case Types.NCHAR:
477+
case Types.VARCHAR:
478+
case Types.NVARCHAR:
479+
case Types.LONGVARCHAR:
480+
case Types.LONGNVARCHAR:
481+
case Types.BINARY:
482+
case Types.VARBINARY:
483+
case Types.LONGVARBINARY:
484+
return true;
485+
default:
486+
return false;
487+
}
488+
}
472489
}

0 commit comments

Comments
 (0)