Skip to content

GH-1552: Return exact unsigned integer values and report isSigned in Flight SQL JDBC - #1554

Closed
fredjoonpark wants to merge 1 commit into
apache:mainfrom
fredjoonpark:jdbc-unsigned-integers
Closed

fredjoonpark wants to merge 1 commit into
apache:mainfrom
fredjoonpark:jdbc-unsigned-integers

Conversation

@fredjoonpark

Copy link
Copy Markdown
Contributor

What's Changed

The Flight SQL JDBC driver sign-extended UInt8 and UInt32 values, wrapped UInt64 values above Long.MAX_VALUE in getters whose return type can hold them, threw ClassCastException from getObject(i, BigInteger.class), and reported isSigned() as false for every column.

The change is in flight/flight-sql-jdbc-core:

  • ArrowFlightJdbcNumericGetter: zero-extends the UInt8 and UInt32 holders, so getLong, getString, getBigDecimal, getDouble and getFloat (and getShort/getInt for UInt8) return the exact value.
  • ArrowFlightJdbcBaseIntVectorAccessor: getBigDecimal, getDouble and getFloat read UInt64 values above Long.MAX_VALUE as unsigned. The deprecated getBigDecimal(columnIndex, scale) is built on the exact getBigDecimal() instead of getDouble(). getObject(i, BigInteger.class) returns the value.
  • ConvertUtils: sets signed from the Arrow type, matching the parameter converters: Int follows its flag, FloatingPoint and Decimal are signed, everything else isn't.

Two behaviours change for signed columns. isSigned() becomes true for signed numeric columns, which changes the types callers derive from it; for example, Spark infers IntegerType and LongType for signed INTEGER and BIGINT columns instead of LongType and DecimalType(20,0). The deprecated scaled getBigDecimal becomes exact for values above 2^53.

This contains breaking changes.

Unchanged, and left for #1553 because fixing them means throwing or changing a returned class: narrowing getters still truncate values that don't fit, and getObject (all widths) and getLong (UInt64 above Long.MAX_VALUE) still return the same-width signed value.

Testing

  • ArrowFlightJdbcBaseIntVectorAccessorTest: for all eight integer vector types, getByte, getShort, getInt, getLong, getBigDecimal, getString, getFloat, getDouble and getObject(i, BigInteger.class) are checked against the value read from the vector, over values that include each type's maximum and sign bit.
  • ArrowFlightJdbcBaseIntVectorAccessorUnitTest: the scaled getBigDecimal for a BIGINT above 2^53, and getObject(i, BigInteger.class) for null.
  • ConvertUtilsTest: for 22 Arrow types, column signed is as expected and matches the parameter metadata.
  • ResultSetMetadataTest: isSigned() for signed, unsigned and non-numeric columns, from a prepared statement before execution and from its result set.
  • ResultSetTest: through the driver, UInt8, UInt16, UInt32 and UInt64 columns holding each type's maximum and its sign bit alone return the exact value from getString, getBigDecimal, the scaled getBigDecimal, getDouble, getObject(i, BigInteger.class), getObject(i, BigDecimal.class) and, where it fits, getLong.
  • mvn -pl flight/flight-sql-jdbc-core verify: 1461 tests, 0 failures, 0 errors; the 46 skipped are existing @Disabled or assumption-guarded tests in ArrowFlightConnectionPropertyTest, ArrowFlightJdbcTimeStampVectorAccessorTest and ArrowFlightPreparedStatementTest.
  • Not tested end to end against a real Flight SQL server.

Closes #1552.

…Flight SQL JDBC

Zero-extend UInt8 and UInt32 holders, read UInt64 values above
Long.MAX_VALUE as unsigned in getBigDecimal, getDouble and getFloat,
build the scaled getBigDecimal on the exact getBigDecimal, support
getObject(BigInteger.class) for integer columns, and set the column
signed flag from the Arrow type.
@fredjoonpark fredjoonpark closed this by deleting the head repository Dec 4, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[JDBC] Flight SQL JDBC driver returns wrong values for unsigned integers; isSigned() is false for signed columns

1 participant