Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix sql federation unknown type exception caused by calcite wrong result type with bigint #32730

Merged
merged 1 commit into from
Aug 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,11 @@

package org.apache.shardingsphere.sqlfederation.resultset;

import org.apache.calcite.avatica.SqlType;
import org.apache.calcite.jdbc.JavaTypeFactoryImpl;
import org.apache.calcite.rel.type.RelDataType;
import org.apache.calcite.rel.type.RelDataTypeFactory;
import org.apache.calcite.rel.type.RelDataTypeFactoryImpl.JavaType;
import org.apache.calcite.schema.Schema;
import org.apache.calcite.schema.Table;
import org.apache.calcite.sql.type.SqlTypeName;
Expand All @@ -29,6 +31,7 @@
import org.apache.shardingsphere.infra.database.core.DefaultDatabase;
import org.apache.shardingsphere.sqlfederation.resultset.converter.SQLFederationColumnTypeConverter;

import java.math.BigInteger;
import java.sql.ResultSetMetaData;
import java.util.List;
import java.util.Map;
Expand Down Expand Up @@ -148,7 +151,12 @@ public String getCatalogName(final int column) {

@Override
public int getColumnType(final int column) {
int jdbcType = resultColumnType.getFieldList().get(column - 1).getType().getSqlTypeName().getJdbcOrdinal();
RelDataType relDataType = resultColumnType.getFieldList().get(column - 1).getType();
// TODO remove this logic when calcite supports BigInteger type
if (relDataType instanceof JavaType && BigInteger.class.isAssignableFrom(((JavaType) relDataType).getJavaClass())) {
return SqlType.BIGINT.id;
}
int jdbcType = relDataType.getSqlTypeName().getJdbcOrdinal();
return columnTypeConverter.convertColumnType(jdbcType);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import lombok.AccessLevel;
import lombok.NoArgsConstructor;
import org.apache.shardingsphere.infra.database.core.type.DatabaseType;
import org.apache.shardingsphere.infra.exception.kernel.data.UnsupportedDataTypeConversionException;
import org.apache.shardingsphere.infra.executor.sql.execute.result.query.impl.driver.jdbc.type.util.ResultSetUtils;
import org.apache.shardingsphere.infra.metadata.database.schema.model.ShardingSphereColumn;
import org.apache.shardingsphere.sqlfederation.optimizer.metadata.util.SQLFederationDataTypeUtils;
Expand Down Expand Up @@ -80,7 +81,7 @@ public static Object[] convertToTargetType(final Map<Integer, Class<?>> columnTy
private static Object convertValue(final Object[] rows, final Map<Integer, Class<?>> columnTypes, final int index) {
try {
return ResultSetUtils.convertValue(rows[index], columnTypes.get(index));
} catch (final SQLFeatureNotSupportedException ex) {
} catch (final SQLFeatureNotSupportedException | UnsupportedDataTypeConversionException ex) {
return rows[index];
}
}
Expand Down