From feac322ee58c854682ed40a60ffbd42593441db9 Mon Sep 17 00:00:00 2001 From: Vikrant Puppala Date: Tue, 19 May 2026 10:18:15 +0000 Subject: [PATCH] fix(metadata): match Thrift wire types for BUFFER_LENGTH and SOURCE_DATA_TYPE The Thrift backend's `GetColumns` RPC ships two of the JDBC `getColumns` integer columns with narrower types than the JDBC spec: BUFFER_LENGTH: Thrift TINYINT vs JDBC Types.INTEGER SOURCE_DATA_TYPE: Thrift SMALLINT vs JDBC Types.SMALLINT JDBC spec says `Types.INTEGER` for BUFFER_LENGTH and `Types.SMALLINT` for SOURCE_DATA_TYPE. We previously emitted Int32 for both to keep the schema uniform; that left an unnecessary diff with Thrift's wire format (`tinyint` and `smallint`) when running the comparator. Switch to Int8 / Int16 to match Thrift exactly. The values are always null (no server-side source), so the narrower range has no practical effect. Closes 1 comparator case (the `list_columns(catalog='nonexistent')` schema check). Signed-off-by: Vikrant Puppala --- src/metadata/thrift_shape.rs | 27 +++++++++++++++++++++++---- 1 file changed, 23 insertions(+), 4 deletions(-) diff --git a/src/metadata/thrift_shape.rs b/src/metadata/thrift_shape.rs index 21411f6e..7723ee36 100644 --- a/src/metadata/thrift_shape.rs +++ b/src/metadata/thrift_shape.rs @@ -130,7 +130,13 @@ pub(crate) static GET_COLUMNS_SCHEMA: LazyLock = LazyLock::new(|| { Field::new("DATA_TYPE", DataType::Int32, false), Field::new("TYPE_NAME", DataType::Utf8, false), Field::new("COLUMN_SIZE", DataType::Int32, true), - Field::new("BUFFER_LENGTH", DataType::Int32, true), + // JDBC spec says `Types.INTEGER` (Int32) for BUFFER_LENGTH, + // but Thrift's `GetColumns` RPC ships it as TINYINT — that's + // what existing PySQL/JDBC users see today. Match Thrift's + // wire type so the kernel backend is a drop-in replacement. + // The value is always null (no server-side source), so the + // narrower range has no practical effect. + Field::new("BUFFER_LENGTH", DataType::Int8, true), Field::new("DECIMAL_DIGITS", DataType::Int32, true), Field::new("NUM_PREC_RADIX", DataType::Int32, true), Field::new("NULLABLE", DataType::Int32, false), @@ -148,7 +154,12 @@ pub(crate) static GET_COLUMNS_SCHEMA: LazyLock = LazyLock::new(|| { Field::new("SCOPE_CATALOG", DataType::Utf8, true), Field::new("SCOPE_SCHEMA", DataType::Utf8, true), Field::new("SCOPE_TABLE", DataType::Utf8, true), - Field::new("SOURCE_DATA_TYPE", DataType::Int32, true), + // JDBC spec says `Types.SMALLINT` (Int16) for SOURCE_DATA_TYPE. + // Thrift's `GetColumns` ships it as SMALLINT and that's what + // PySQL/JDBC users see today; we previously emitted Int32 to + // align with Int32 elsewhere in the schema, but Thrift's + // narrower type is the user-facing contract. + Field::new("SOURCE_DATA_TYPE", DataType::Int16, true), // JDBC `DatabaseMetaData.getColumns` Javadoc names this // `IS_AUTOINCREMENT` (one word). Thrift's wire response uses // `IS_AUTO_INCREMENT` (with the underscore), and that's what @@ -248,6 +259,14 @@ fn null_int32(len: usize) -> ArrayRef { Arc::new(Int32Array::from(vec![None::; len])) } +fn null_int16(len: usize) -> ArrayRef { + Arc::new(arrow_array::Int16Array::from(vec![None::; len])) +} + +fn null_int8(len: usize) -> ArrayRef { + Arc::new(arrow_array::Int8Array::from(vec![None::; len])) +} + /// Map a server-side `"true"` / `"false"` string column to JDBC's /// `"YES"` / `"NO"` / `""` convention. Used for `IS_NULLABLE` and /// `IS_AUTO_INCREMENT` in `reshape_columns`; both follow the same @@ -527,7 +546,7 @@ pub(crate) fn reshape_columns( data_type_arr, type_name, column_size, - null_int32(n), // BUFFER_LENGTH + null_int8(n), // BUFFER_LENGTH (Thrift wire type: TINYINT) decimal_digits, num_prec_radix, nullable, @@ -541,7 +560,7 @@ pub(crate) fn reshape_columns( null_utf8(n), // SCOPE_CATALOG null_utf8(n), // SCOPE_SCHEMA null_utf8(n), // SCOPE_TABLE - null_int32(n), // SOURCE_DATA_TYPE + null_int16(n), // SOURCE_DATA_TYPE (Thrift wire type: SMALLINT) is_autoincrement, ], )