Skip to content
Closed
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
38 changes: 36 additions & 2 deletions src/metadata/thrift_shape.rs
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,9 @@ pub(crate) static GET_FUNCTIONS_SCHEMA: LazyLock<SchemaRef> = LazyLock::new(|| {
Arc::new(Schema::new(vec![
Field::new("FUNCTION_CAT", DataType::Utf8, true),
Field::new("FUNCTION_SCHEM", DataType::Utf8, true),
Field::new("FUNCTION_NAME", DataType::Utf8, false),
// Classic SHOW FUNCTIONS can omit the modern `functionName` field.
// Keep this nullable so one malformed row does not discard the result.
Field::new("FUNCTION_NAME", DataType::Utf8, true),
Field::new("REMARKS", DataType::Utf8, true),
Field::new("FUNCTION_TYPE", DataType::Int16, true),
Field::new("SPECIFIC_NAME", DataType::Utf8, true),
Expand Down Expand Up @@ -844,7 +846,12 @@ pub(crate) fn reshape_functions(
) -> Result<RecordBatch> {
let function_cat = constant_utf8(batch.num_rows(), Some(resolved_catalog));
let function_schem = utf8_column(batch, "namespace")?;
let function_name = utf8_column(batch, "functionName")?;
let function_name = if column_index(batch.schema_ref(), "functionName").is_some() {
utf8_column(batch, "functionName")?
} else {
// Classic SHOW FUNCTIONS exposes a single column named `function`.

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔵 Low — Classic single-column SHOW FUNCTIONS fallback places the function column value directly into FUNCTION_NAME. Per the accompanying test, that column carries the fully-qualified name (e.g. system.builtin.abs) while FUNCTION_SCHEM/FUNCTION_CAT stay null (the namespace column is absent in this shape). JDBC/Thrift getFunctions normally splits catalog/schema/name across FUNCTION_CAT/FUNCTION_SCHEM/FUNCTION_NAME, so consumers filtering or joining on the unqualified name may not match. This is the fallback path only and the behavior is deliberately encoded by the test, so it's likely acceptable — but worth confirming it matches how the reference drivers surface the classic shape.

utf8_column(batch, "function")?

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔵 Low — The classic-shape fallback maps the single function column straight into FUNCTION_NAME while leaving FUNCTION_SCHEM/FUNCTION_CAT null. Classic SHOW FUNCTIONS typically returns fully-qualified names (e.g. system.builtin.abs, as your own test fixture shows), so FUNCTION_NAME ends up carrying the catalog/schema-qualified string rather than the bare function name that JDBC's getFunctions contract expects in that column. This is a rarely-hit legacy path and the row is preserved rather than discarded (the actual goal of this PR), so it's non-blocking — but consumers filtering/joining on FUNCTION_NAME may see qualified values here. Worth a comment noting the intentional non-decomposition, or a follow-up to split the qualified name.

};
let remarks = utf8_column(batch, "remarks")?;
let function_type = int16_column(batch, "functionType")?;

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔵 Low — Behavior change for the classic single-column SHOW FUNCTIONS shape: FUNCTION_TYPE is now derived from a functionType column that the classic shape does not carry, so int16_column returns an all-null Int16 array (falls into the None => branch that yields nulls). Previously reshape_functions hard-coded FUNCTION_TYPE = functionNoTable (1) for every row. So when the server returns the legacy single-function-column result, getFunctions now reports FUNCTION_TYPE = NULL instead of 1. The new test reshape_functions_supports_classic_single_column_shape covers this shape but deliberately does not assert on FUNCTION_TYPE, so the change is unverified. If JDBC parity for the classic path expects functionNoTable/functionResultUnknown rather than NULL, consider defaulting the column when functionType is absent; otherwise a short assertion/comment documenting the intended NULL would lock in the contract.

let specific_name = utf8_column(batch, "specificName")?;
Expand Down Expand Up @@ -2088,6 +2095,33 @@ mod tests {
assert_eq!(ftype.value(0), 1);
}

#[test]
fn reshape_functions_supports_classic_single_column_shape() {
let source = RecordBatch::try_new(
Arc::new(Schema::new(vec![Field::new(
"function",
DataType::Utf8,
true,
)])),
vec![Arc::new(StringArray::from(vec![
Some("system.builtin.abs"),
None,
]))],
)
.unwrap();

let out = reshape_functions(&source, "main").unwrap();
let names = out
.column(2)
.as_any()
.downcast_ref::<StringArray>()
.unwrap();
assert_eq!(names.value(0), "system.builtin.abs");
assert!(names.is_null(1));
assert!(out.column(1).is_null(0));
assert!(out.column(3).is_null(0));
}

/// `build_get_procedure_columns` raw server shape (information_schema
/// numeric metadata arrives as strings over the wire).
fn server_parameter_rows() -> RecordBatch {
Expand Down
6 changes: 6 additions & 0 deletions src/metadata_v0.rs
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,9 @@ fn normalize_native_metadata_batch(
)) as ArrayRef)
}
"ORDINAL_POSITION" => {
// JDBC treats native GetColumns rows as zero-based and
// increments them when copying native metadata. The SHOW
// fallback already reports ordinalPosition as one-based.
let values = column
.as_any()
.downcast_ref::<Int32Array>()
Expand Down Expand Up @@ -227,6 +230,9 @@ fn normalize_native_functions_batch(
) -> Result<arrow_array::RecordBatch> {
let normalized = normalize_native_metadata_batch(batch, GET_FUNCTIONS_SCHEMA.clone())?;
let mut columns = normalized.columns().to_vec();
// Match JDBC's native-only override: preserve the caller's original
// catalog argument, including null. The SHOW fallback uses the resolved
// catalog because it is a different result path.
columns[0] = Arc::new(StringArray::from(vec![
requested_catalog;
normalized.num_rows()
Expand Down
Loading
Loading