开发者社区> 问答> 正文

ClientAdapter HBase 手动ETL 类型转换失败

环境信息

JDK 1.8 Canal 1.1.3 ClientAdapter 1.1.3 mysql 5.5

问题描述

使用HBase模式

手动ETL: curl http://127.0.0.1:8081/etl/hbase/user.yml -X POST

抛错:com.mysql.jdbc.exceptions.jdbc4.MySQLDataException: '255' in column '49' is outside valid range for the datatype TINYINT.

column '49' 的类型:recommend tinyint(1) unsigned NOT NULL DEFAULT '0'

recommend 存储数据有3种值0, 1, 255

原因:

调用ClientAdapter类:public class HbaseEtlService 方法:207行 private static boolean executeSqlImport(DataSource ds, String sql, MappingConfig.HbaseMapping hbaseMapping, HbaseTemplate hbaseTemplate, AtomicLong successCount, List errMsg)

执行到251行: Object val = JdbcTypeUtil.getRSData(rs, columnName, jdbcTypes[j - 1]);

引用: JdbcTypeUtil.getRSData 方法 public static Object getRSData(ResultSet rs, String columnName, int jdbcType) throws SQLException { if (jdbcType == Types.BIT || jdbcType == Types.BOOLEAN) { return rs.getByte(columnName); } else { return rs.getObject(columnName); } }

Tinyint取到的类型为-7(Types.BIT) 所以走了 return rs.getByte(columnName); 这步,

public class ResultSetImpl implements ResultSetInternalMethods 这个类实现的rs.getByte(columnName)方法

调用到943行时: if (this.jdbcCompliantTruncationForReads && (valueAsLong < -128L || valueAsLong > 127L)) { this.throwRangeException(String.valueOf(valueAsLong), columnIndex, -6); }

因为是无符号类型,可存储整数值0-255, 所以抛出越界错误

原提问者GitHub用户elfc

展开
收起
数据大拿 2023-05-04 11:45:45 123 0
1 条回答
写回答
取消 提交回答
  • 已找到解决方案: https://dev.mysql.com/doc/connector-j/8.0/en/connector-j-reference-type-conversions.html

    java.lang.Boolean if the configuration property tinyInt1isBit is set to true (the default) and the storage size is 1, or java.lang.Integer if not.

    原回答者GitHub用户elfc

    2023-05-05 10:19:48
    赞同 展开评论 打赏
问答排行榜
最热
最新

相关电子书

更多
大数据时代的存储 ——HBase的实践与探索 立即下载
Hbase在滴滴出行的应用场景和最佳实践 立即下载
阿里云HBase主备双活 立即下载