Repository navigation
feat(rust): implement getProcedures, getProcedureColumns - #366
Conversation
| )), | ||
| manifest: None, | ||
| }); | ||
| }; |
There was a problem hiding this comment.
i don't like this semantic that if we're unable to build sql then return empty result set. We're abstracting the empty catalog condition into the sql builder but this is semantically weird.
There was a problem hiding this comment.
This will be done in odbc layer now, fixed that. Our behavior would be:
catalog ->
null : system (all catalogs)
empty: empty (handled in odbc)
other: scoped to catalog
There was a problem hiding this comment.
title says getCrossReferences but don't see that
There was a problem hiding this comment.
Fixed that, initial thought about adding that, but it is covered under getForeignKeys anyways
| let reader: Box<dyn ResultReader + Send> = | ||
| Box::new(EmptyReader::new(sql::procedures_schema())); | ||
| return export_reader(reader, None, out); | ||
| } |
There was a problem hiding this comment.
this empty condition is also weirdly handled in the sql builder?
There was a problem hiding this comment.
This will be handled on caller side now, we will just return empty for empty catalog. For null, we will treat as all catalogs, and will be a valid scenario.
| Field::new("parameter_default", DataType::Utf8, true), | ||
| Field::new("comment", DataType::Utf8, true), | ||
| ])) | ||
| } |
There was a problem hiding this comment.
why are we doing this here? this should be in the odbc layer?
|
|
||
| println!("getProcedures (schema=default): {} rows", row_count); | ||
| println!(" PASS"); | ||
| } |
There was a problem hiding this comment.
why do a lot of these tests have ignore?
There was a problem hiding this comment.
Need to run on live connection, will fix
| assert_eq!(sql, "SHOW SCHEMAS IN ALL CATALOGS LIKE 'it''s'"); | ||
| } | ||
|
|
||
| #[cfg(feature = "metadata-ffi")] |
There was a problem hiding this comment.
why did we add this cfg to these tests but not to the new ones like test_get_procedures_null_catalog etc. imo these only test SqlCommandBuilder so don't need this cfg but we should atleast be consistent
vikrantpuppala
left a comment
There was a problem hiding this comment.
minor comment on test cfg, otherwise lgtm, thanks!
|
🚀 Integration tests triggered! View workflow run |
|
🔒 Integration test approval reset New commits were pushed to this PR. The A maintainer must re-review the changes and re-add the label to trigger tests again. Why is this necessary?
Latest commit: 54978c3 |
…sReferences Add three new metadata operations following the existing getTables/getColumns pattern: - getProcedures: queries information_schema.routines filtered by routine_type='PROCEDURE' - getProcedureColumns: queries information_schema.parameters joined with routines - getCrossReferences: uses SHOW FOREIGN KEYS (same as getForeignKeys), with all 6 params (pk_catalog/schema/table + fk_catalog/schema/table) passed through for ODBC-side filtering Each operation includes: - DatabricksClient trait method - SQL builder with catalog resolution (NULL→system, specific→catalog, empty→empty result) - SeaClient implementation - FFI function (extern "C") for the ODBC layer - C header declaration Also adds comprehensive E2E metadata tests (12 tests, all #[ignore]) covering every metadata operation: catalogs, schemas, tables, columns, primary keys, foreign keys, cross-references, procedures, and procedure columns. Co-authored-by: Isaac
- Empty catalog guard in SQL builders: build_get_procedures and build_get_procedure_columns now produce WHERE 1=0 queries for empty catalog instead of invalid SQL (FROM ``.information_schema) - Remove EmptyReader short-circuit in FFI: empty catalog now flows through to the SQL builder, preserving correct column schema for ODBC column-discovery (SQLDescribeCol) - Remove getCrossReferences: it was identical to getForeignKeys since we don't do PK-side filtering. The ODBC layer can call metadata_get_foreign_keys directly and filter by PK client-side, matching the JDBC pattern. Co-authored-by: Isaac
Databricks SQL treats backslash as an escape character in string literals. A trailing backslash in a pattern would produce a dangling escape causing a SQL parse error. escape_sql_string now escapes both \ and '. Co-authored-by: Isaac
Rewrite procedures E2E tests to use SqlCommandBuilder::build_get_procedures and build_get_procedure_columns instead of hardcoded SQL strings. This exercises the actual builder logic (catalog resolution, pattern escaping, WHERE 1=0 for empty catalog) through the Statement::execute path. Added two new tests for empty catalog (WHERE 1=0) to verify schema preservation for ODBC column discovery. Co-authored-by: Isaac
- Add resolve_catalog_prefix tests: None, empty string, specific, special chars - Add escape_sql_string tests: single quote, backslash, trailing backslash, combined, percent/underscore passthrough, empty string - Add procedure_columns column_pattern injection test (SQL injection + backslash) - Add foreign keys special character test (backticks in catalog/schema/table) - Add doc comments on escape_identifier, escape_sql_string, jdbc_pattern_to_hive explaining when to use each escaping strategy Co-authored-by: Isaac
Empty catalog now returns EmptyReader with a static schema instead of sending WHERE 1=0 to the server. This avoids: - Unnecessary server round-trip for a guaranteed-empty result - Permission errors if user lacks system.information_schema access Added procedures_schema() and procedure_columns_schema() functions that define the column structure matching the information_schema queries. Also: - Added ordering comment on escape_sql_string (backslash-first is critical) - Removed resolve_catalog_prefix empty-string case (handled by FFI caller) - Empty catalog schema tests are now local (no #[ignore], no server needed) Co-authored-by: Isaac
…i items - SqlCommandBuilder changed from pub to pub(crate) — it's an internal implementation detail, not part of the public API surface - procedures_schema, procedure_columns_schema, build_show_primary_keys, build_show_foreign_keys gated with #[cfg(feature = "metadata-ffi")] since they're only used from ffi/metadata.rs - E2E tests no longer import SqlCommandBuilder — use inline SQL constants instead (builder is already unit-tested separately) Co-authored-by: Isaac
…ure gating - Static schemas use Utf8 for all columns (safe for zero-row results, avoids type mismatches when actual server types differ from assumptions) - resolve_catalog_prefix returns Option — empty catalog returns None, callers (SeaClient + FFI) handle it with EmptyReader + static schema. No more debug_assert that's a no-op in release builds. - build_get_procedures/build_get_procedure_columns return Option<String> — None for empty catalog, Some(sql) otherwise - Feature gating: build_show_primary_keys/build_show_foreign_keys are cfg(metadata-ffi) since they're only called from ffi/metadata.rs. Schema functions and procedure builders are NOT gated since SeaClient calls them unconditionally. Co-authored-by: Isaac
Address vikrantpuppala's review comments: - SQL builder returns String directly (not Option) — no more semantic confusion about "None means empty result" - Empty catalog guard lives only in FFI layer with Schema::empty() — ODBC layer owns proper schema construction for empty results - Remove static schemas (procedures_schema, procedure_columns_schema) from sql.rs — not the Rust layer's responsibility - SeaClient just builds SQL and executes — no empty catalog handling - resolve_catalog_prefix returns String — None=system, Some=escaped Co-authored-by: Isaac
Per reviewer feedback: test_show_primary_keys, test_show_foreign_keys, and test_show_foreign_keys_special_chars_in_catalog were inconsistently gated with #[cfg(feature = "metadata-ffi")] while the new procedure builder tests were not. All these tests only exercise SqlCommandBuilder string building with no FFI dependencies. Replace #[cfg] on the functions with #[allow(dead_code)] since they're used when metadata-ffi feature is enabled but are just string builders. Co-authored-by: Isaac
54978c3 to
e822db0
Compare
|
🚀 Integration tests triggered! View workflow run |
Summary
getProcedures,getProcedureColumnsmetadata operationsgetTables/getColumnspattern with trait methods, SQL builders, SeaClient impl, FFI functions, and C header declarationsgetProcedures
information_schema.routinesfiltered byroutine_type = 'PROCEDURE'NULL→system(cross-catalog), specific value → that catalog, empty string → empty resultLIKEonroutine_schemaandroutine_namegetProcedureColumns
information_schema.parametersjoined withinformation_schema.routinesSQLProcedureColumns: parameter_name, parameter_mode, is_result, data_type, full_data_type, numeric_precision/scale, character_maximum/octet_length, ordinal_position, parameter_default, commentgetCrossReferences
SHOW FOREIGN KEYS(same query asgetForeignKeys)SQLCrossReferencesparameters (pk_catalog/schema/table + fk_catalog/schema/table)Design references
Test plan
#[ignore], require real Databricks connection) covering all operations: catalogs, schemas, tables, columns, primary keys, foreign keys, cross-references, procedures, procedure columnscargo test— 237 tests passcargo clippy --all-targets -- -D warnings— cleancargo +stable fmt --all— clean#[ignore]d)This pull request was AI-assisted by Isaac.