Skip to content

feat(rust): implement getProcedures, getProcedureColumns - #366

Merged
gopalldb merged 10 commits into
mainfrom
feat/get-procedures
Mar 24, 2026
Merged

gopalldb merged 10 commits into
mainfrom
feat/get-procedures

Conversation

@gopalldb

@gopalldb gopalldb commented Mar 22, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

  • Implement getProcedures, getProcedureColumns metadata operations
  • Follow the existing getTables/getColumns pattern with trait methods, SQL builders, SeaClient impl, FFI functions, and C header declarations
  • Add comprehensive E2E metadata tests covering all metadata operations

getProcedures

  • Queries information_schema.routines filtered by routine_type = 'PROCEDURE'
  • Catalog resolution: NULL → system (cross-catalog), specific value → that catalog, empty string → empty result
  • Pattern filtering via SQL LIKE on routine_schema and routine_name

getProcedureColumns

  • Queries information_schema.parameters joined with information_schema.routines
  • Same catalog resolution and pattern filtering as getProcedures
  • Selects all columns needed for ODBC SQLProcedureColumns: parameter_name, parameter_mode, is_result, data_type, full_data_type, numeric_precision/scale, character_maximum/octet_length, ordinal_position, parameter_default, comment

getCrossReferences

  • Uses SHOW FOREIGN KEYS (same query as getForeignKeys)
  • Takes all 6 ODBC SQLCrossReferences parameters (pk_catalog/schema/table + fk_catalog/schema/table)
  • Parent table filtering is done client-side by the ODBC C++ layer

Design references

Test plan

  • 12 unit tests for SQL builders (catalog resolution, pattern filters, escaping, column selection)
  • 12 E2E metadata tests (#[ignore], require real Databricks connection) covering all operations: catalogs, schemas, tables, columns, primary keys, foreign keys, cross-references, procedures, procedure columns
  • cargo test — 237 tests pass
  • cargo clippy --all-targets -- -D warnings — clean
  • cargo +stable fmt --all — clean
  • E2E validation against live workspace (blocked on token — tests compile and are properly #[ignore]d)

This pull request was AI-assisted by Isaac.

@gopalldb
gopalldb requested a review from vikrantpuppala March 22, 2026 14:20
Comment thread rust/src/client/sea.rs Outdated
)),
manifest: None,
});
};

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

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.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

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

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

title says getCrossReferences but don't see that

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Fixed that, initial thought about adding that, but it is covered under getForeignKeys anyways

Comment thread rust/src/ffi/metadata.rs
let reader: Box<dyn ResultReader + Send> =
Box::new(EmptyReader::new(sql::procedures_schema()));
return export_reader(reader, None, out);
}

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

this empty condition is also weirdly handled in the sql builder?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

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.

Comment thread rust/src/metadata/sql.rs Outdated
Field::new("parameter_default", DataType::Utf8, true),
Field::new("comment", DataType::Utf8, true),
]))
}

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

why are we doing this here? this should be in the odbc layer?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Removed


println!("getProcedures (schema=default): {} rows", row_count);
println!(" PASS");
}

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

why do a lot of these tests have ignore?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Need to run on live connection, will fix

@gopalldb gopalldb changed the title feat(rust): implement getProcedures, getProcedureColumns, and getCrossReferences feat(rust): implement getProcedures, getProcedureColumns Mar 24, 2026
Comment thread rust/src/metadata/sql.rs Outdated
assert_eq!(sql, "SHOW SCHEMAS IN ALL CATALOGS LIKE 'it''s'");
}

#[cfg(feature = "metadata-ffi")]

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

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

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

removing the cfg

@vikrantpuppala vikrantpuppala left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

minor comment on test cfg, otherwise lgtm, thanks!

@vikrantpuppala vikrantpuppala added the integration-test Trigger integration tests in internal repo label Mar 24, 2026
@github-actions

Copy link
Copy Markdown
Contributor

🚀 Integration tests triggered! View workflow run

@github-actions github-actions Bot removed the integration-test Trigger integration tests in internal repo label Mar 24, 2026
@github-actions

Copy link
Copy Markdown
Contributor

🔒 Integration test approval reset

New commits were pushed to this PR. The integration-test label has been automatically removed for security.

A maintainer must re-review the changes and re-add the label to trigger tests again.

Why is this necessary?
  • New code requires fresh security review
  • Prevents approved PRs from adding malicious code later
  • Ensures all tested code has been explicitly approved

Latest commit: 54978c3

gopalldb added 10 commits March 24, 2026 10:23
…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
@gopalldb
gopalldb force-pushed the feat/get-procedures branch from 54978c3 to e822db0 Compare March 24, 2026 10:24
@gopalldb gopalldb added the integration-test Trigger integration tests in internal repo label Mar 24, 2026
@github-actions

Copy link
Copy Markdown
Contributor

🚀 Integration tests triggered! View workflow run

@gopalldb
gopalldb enabled auto-merge March 24, 2026 10:25
@gopalldb
gopalldb added this pull request to the merge queue Mar 24, 2026
Merged via the queue into main with commit f69804a Mar 24, 2026
30 checks passed
@gopalldb
gopalldb deleted the feat/get-procedures branch March 24, 2026 10:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

integration-test Trigger integration tests in internal repo

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants