Repository navigation
feat(metadata): enable native list functions #369
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
3973320
9256734
cb41a57
0fe47c8
d511b8f
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -837,26 +837,14 @@ pub(crate) fn reshape_procedures(batch: &RecordBatch) -> Result<RecordBatch> { | |
| .map_err(|e| Error::data_loss().message(format!("reshape procedures: {e}"))) | ||
| } | ||
|
|
||
| /// Reshape the `build_get_functions` result (same server columns as | ||
| /// `build_get_procedures`) into the JDBC `getFunctions` shape. | ||
| /// | ||
| /// `FUNCTION_TYPE` is constant `functionNoTable` (1) — Databricks functions | ||
| /// are scalar / return a value, not a table. (JDBC: `functionResultUnknown`=0, | ||
| /// `functionNoTable`=1, `functionReturnsTable`=2.) | ||
| /// Reshape the `SHOW FUNCTIONS` result into the JDBC `getFunctions` shape. | ||
| pub(crate) fn reshape_functions(batch: &RecordBatch) -> Result<RecordBatch> { | ||
| let n = batch.num_rows(); | ||
| let function_cat = utf8_column(batch, "routine_catalog")?; | ||
| let function_schem = utf8_column(batch, "routine_schema")?; | ||
| let function_name = utf8_column(batch, "routine_name")?; | ||
| let remarks = utf8_column(batch, "comment")?; | ||
| let specific_name = utf8_column(batch, "specific_name")?; | ||
| // FUNCTION_TYPE is reported functionNoTable(1) for every row. Databricks | ||
| // supports table-valued functions, which JDBC would report as | ||
| // functionReturnsTable(2), but build_get_functions does not select a column | ||
| // that distinguishes scalar from table functions, so the reshape cannot tell | ||
| // them apart. Known parity gap; distinguishing TVFs would require selecting | ||
| // additional information_schema.routines columns in the builder. | ||
| let function_type = Arc::new(Int16Array::from(vec![Some(1_i16); n])) as ArrayRef; | ||
| let function_cat = utf8_column(batch, "catalogName")?; | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🟡 Medium — In the Consequence: |
||
| let function_schem = utf8_column(batch, "namespace")?; | ||
| let function_name = utf8_column(batch, "functionName")?; | ||
| let remarks = utf8_column(batch, "remarks")?; | ||
| let function_type = int16_column(batch, "functionType")?; | ||
| let specific_name = utf8_column(batch, "specificName")?; | ||
| RecordBatch::try_new( | ||
| GET_FUNCTIONS_SCHEMA.clone(), | ||
| vec![ | ||
|
|
@@ -1245,6 +1233,7 @@ impl ResultReader for ThriftReshapingReader { | |
| #[cfg(test)] | ||
| mod tests { | ||
| use super::*; | ||
| use arrow_array::cast::AsArray; | ||
| use arrow_array::{BooleanArray, RecordBatch}; | ||
|
|
||
| // ─── is_object_not_found tests ───────────────────────────────── | ||
|
|
@@ -1991,7 +1980,7 @@ mod tests { | |
|
|
||
| // ─── procedures / functions / procedure-columns reshape ─────────── | ||
|
|
||
| /// One-row `build_get_procedures` / `build_get_functions` server shape. | ||
| /// One-row `build_get_procedures` server shape. | ||
| fn server_routine_row(comment: Option<&str>) -> RecordBatch { | ||
| let schema = Arc::new(Schema::new(vec![ | ||
| Field::new("routine_catalog", DataType::Utf8, true), | ||
|
|
@@ -2013,6 +2002,29 @@ mod tests { | |
| .unwrap() | ||
| } | ||
|
|
||
| fn server_function_row() -> RecordBatch { | ||
| let schema = Arc::new(Schema::new(vec![ | ||
| Field::new("functionName", DataType::Utf8, false), | ||
| Field::new("namespace", DataType::Utf8, false), | ||
| Field::new("catalogName", DataType::Utf8, true), | ||
| Field::new("remarks", DataType::Utf8, true), | ||
| Field::new("functionType", DataType::Int32, true), | ||
| Field::new("specificName", DataType::Utf8, true), | ||
| ])); | ||
| RecordBatch::try_new( | ||
| schema, | ||
| vec![ | ||
| Arc::new(StringArray::from(vec![Some("sp_report")])), | ||
| Arc::new(StringArray::from(vec![Some("sales")])), | ||
| Arc::new(StringArray::from(vec![Some("main")])), | ||
| Arc::new(StringArray::from(vec![Some("nightly report")])), | ||
| Arc::new(Int32Array::from(vec![Some(0)])), | ||
| Arc::new(StringArray::from(vec![Some("sp_report")])), | ||
| ], | ||
| ) | ||
| .unwrap() | ||
| } | ||
|
|
||
| fn col_names(batch: &RecordBatch) -> Vec<String> { | ||
| batch | ||
| .schema() | ||
|
|
@@ -2049,7 +2061,7 @@ mod tests { | |
|
|
||
| #[test] | ||
| fn reshape_functions_produces_jdbc_get_functions_shape() { | ||
| let out = reshape_functions(&server_routine_row(None)).unwrap(); | ||
| let out = reshape_functions(&server_function_row()).unwrap(); | ||
| assert_eq!( | ||
| col_names(&out), | ||
| vec![ | ||
|
|
@@ -2061,9 +2073,19 @@ mod tests { | |
| "SPECIFIC_NAME", | ||
| ] | ||
| ); | ||
| // FUNCTION_TYPE = functionNoTable (1). | ||
| let ftype = out.column(4).as_any().downcast_ref::<Int16Array>().unwrap(); | ||
| assert_eq!(ftype.value(0), 1); | ||
| assert_eq!(out.column(0).as_string::<i32>().value(0), "main"); | ||
| assert_eq!(out.column(1).as_string::<i32>().value(0), "sales"); | ||
| assert_eq!(out.column(2).as_string::<i32>().value(0), "sp_report"); | ||
| assert_eq!(out.column(3).as_string::<i32>().value(0), "nightly report"); | ||
| assert_eq!( | ||
| out.column(4) | ||
| .as_any() | ||
| .downcast_ref::<Int16Array>() | ||
| .unwrap() | ||
| .value(0), | ||
| 0 | ||
| ); | ||
| assert_eq!(out.column(5).as_string::<i32>().value(0), "sp_report"); | ||
| } | ||
|
|
||
| /// `build_get_procedure_columns` raw server shape (information_schema | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.