[ https://issues.apache.org/jira/browse/CALCITE-5094?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17522774#comment-17522774 ]
itxiangkui commented on CALCITE-5094: ------------------------------------- I think this problem can be fixed by changing the code of JdbcSchema {code:java} RelProtoDataType getRelDataType(DatabaseMetaData metaData, String catalogName, String schemaName, String tableName) throws SQLException { final ResultSet resultSet = metaData.getColumns(catalogName, schemaName, tableName, null); // Temporary type factory, just for the duration of this method. Allowable // because we're creating a proto-type, not a type; before being used, the // proto-type will be copied into a real type factory. final RelDataTypeFactory typeFactory = new SqlTypeFactoryImpl(RelDataTypeSystem.DEFAULT); final RelDataTypeFactory.Builder fieldInfo = typeFactory.builder(); while (resultSet.next()) { final String columnName = requireNonNull(resultSet.getString(4), "columnName"); final int dataType = resultSet.getInt(5); final String typeString = resultSet.getString(6); final int precision; final int scale; switch (SqlType.valueOf(dataType)) { case TIMESTAMP: case TIME: precision = resultSet.getInt(9); // SCALE scale = 0; break; default: precision = resultSet.getInt(7); // SIZE scale = resultSet.getInt(9); // SCALE break; } RelDataType sqlType = sqlType(typeFactory, dataType, precision, scale, typeString); boolean nullable = resultSet.getInt(11) != DatabaseMetaData.columnNoNulls; fieldInfo.add(columnName, sqlType).nullable(nullable); } resultSet.close(); return RelDataTypeImpl.proto(fieldInfo.build()); } {code} > JdbcAdapter will "NumberOutOfRange" when iterating over the datetime column > of mysql with function application > -------------------------------------------------------------------------------------------------------------- > > Key: CALCITE-5094 > URL: https://issues.apache.org/jira/browse/CALCITE-5094 > Project: Calcite > Issue Type: Bug > Components: core, jdbc-adapter > Affects Versions: 1.30.0 > Reporter: itxiangkui > Priority: Major > Labels: JDBC, adapters > > > When I have a mysql table, the example is as follows: > ||*aid:long*||*gettime:datetime*||*xip: int(10) unsigned*|| > |1|2021-08-11 14:38:01.0|3729727635| > > it will be OK: > {{select gettime from table}} > > it will occor some error: > {code:java} > select substring_index(cast(gettime as varchar),'.',1) from table {code} > {code:java} > Caused by: com.mysql.cj.exceptions.NumberOutOfRange: Value '3729727635' is > outside of valid range for type java.lang.Integer at > com.mysql.cj.result.IntegerValueFactory.createFromLong(IntegerValueFactory.java:62) > at > com.mysql.cj.result.IntegerValueFactory.createFromLong(IntegerValueFactory.java:44) > at > com.mysql.cj.protocol.a.MysqlTextValueDecoder.decodeUInt4(MysqlTextValueDecoder.java:99) > at > com.mysql.cj.protocol.result.AbstractResultsetRow.decodeAndCreateReturnValue(AbstractResultsetRow.java:105) > at > com.mysql.cj.protocol.result.AbstractResultsetRow.getValueFromBytes(AbstractResultsetRow.java:241) > at > com.mysql.cj.protocol.a.result.TextBufferRow.getValue(TextBufferRow.java:132) > at com.mysql.cj.jdbc.result.ResultSetImpl.getObject(ResultSetImpl.java:1285) > ... 34 more {code} > > It seems that *org.apache.calcite.linq4j.tree.Primitive.jdbcGet* > {code:java} > // code placeholder > public @Nullable Object jdbcGet(ResultSet resultSet, int i) throws > SQLException { > switch (this) { > case BOOLEAN: > return resultSet.getBoolean(i); > case BYTE: > return resultSet.getByte(i); > case CHAR: > return (char) resultSet.getShort(i); > case DOUBLE: > return resultSet.getDouble(i); > case FLOAT: > return resultSet.getFloat(i); > case INT: > return resultSet.getInt(i); > case LONG: > return resultSet.getLong(i); > case SHORT: > return resultSet.getShort(i); > default: > return resultSet.getObject(i); > } > } {code} > > resultSet.getObject(i) Triggered errors like Integer.parse(Long) -- This message was sent by Atlassian Jira (v8.20.1#820001)