Skip to content

Conversation

danielgerlag
Copy link
Contributor

This pull request refactors the way tables and schemas are handled in the SQL proxy by introducing a new TableRegistry class and updating the table cursor logic to support schema-qualified table names. The changes improve robustness when dealing with tables from multiple schemas and ensure that only registered tables are processed, and fixes a bug where tables in the non-default schema could not be bootstrapped.

Schema and Table Registry Improvements:

  • Added a new TableRegistry class to manage table-to-schema mappings, parsing the tables config and providing lookup methods for table existence and schema name. (sources/relational/sql-proxy/src/main/java/io/drasi/TableRegistry.java)
  • Updated ResultStream to instantiate and use TableRegistry, checking if each requested table exists and retrieving its schema before creating TableCursor instances. Unregistered tables are logged and skipped. (sources/relational/sql-proxy/src/main/java/io/drasi/ResultStream.java) [1] [2]

Table Cursor and Query Handling:

  • Refactored TableCursor to accept both schemaName and tableName in its constructor, and to use these values when building SQL queries and reading table mappings. (sources/relational/sql-proxy/src/main/java/io/drasi/TableCursor.java)
  • Updated SQL query construction in TableCursor to use fully qualified table names (including schema when present), ensuring correct querying in multi-schema environments. (sources/relational/sql-proxy/src/main/java/io/drasi/TableCursor.java)
  • Simplified and clarified the logic for reading table mappings and primary keys, passing schema and table names directly and improving error messages for missing primary keys. (sources/relational/sql-proxy/src/main/java/io/drasi/TableCursor.java)

@danielgerlag danielgerlag requested a review from a team as a code owner September 3, 2025 22:05
Copy link
Member

@amansinghoriginal amansinghoriginal left a comment

Choose a reason for hiding this comment

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

LGTM

var rs = metadata.getPrimaryKeys(null, schemaName, tableName);
if (!rs.next())
throw new SQLException("No primary key found for " + table);
throw new SQLException("No primary key found for " + (schemaName != null ? schemaName + "." + tableName : tableName));
Copy link
Member

Choose a reason for hiding this comment

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

Should we make this into a function schemaName != null ? schemaName + "." + tableName : tableName ? Since it is repeated a couple of times.

@agentofreality
Copy link
Member

@danielgerlag are there no changes required to the releation reactivator to distinguish between tables with the same name but from different schema?

throw new SQLException("No primary key found for " + (schemaName != null ? schemaName + "." + tableName : tableName));
var mapping = new NodeMapping();
mapping.tableName = rs.getString("TABLE_SCHEM") + "." + tableName;
String actualSchema = rs.getString("TABLE_SCHEM");
Copy link
Member

@agentofreality agentofreality Sep 4, 2025

Choose a reason for hiding this comment

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

Is TABLE_SCHEM a typo that we are perpetuating?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@danielgerlag
Copy link
Contributor Author

@danielgerlag are there no changes required to the releation reactivator to distinguish between tables with the same name but from different schema?

The reactivator does not have this issue, because we are not manually constructing a query string, the debezium library handles things.

@danielgerlag danielgerlag merged commit 7eb5084 into drasi-project:main Sep 4, 2025
136 of 138 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants