Skip to content
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

[Feature] Add feature to send session variables to JDBC external table #53358

Open
wants to merge 4 commits into
base: main
Choose a base branch
from

Conversation

boosheen
Copy link

Why I'm doing:

I want to be able to send session variables to MySQL JDBC External tables.

This feature lets users send session variables to MySQL JDBC External Tables by setting a new session variable jdbc_external_table_session_variables.

For example, running this query against external table external_query_table

SELECT /*+ SET_VAR(jdbc_external_table_session_variables="@my_user_variable='abc',sql_select_limit=5") */ 
* from external_query_table;

Will get translated to this query sent to the external table

SELECT 
/*+ SET_USER_VARIABLE("@my_user_variable='abc') */ 
/*+ SET_VAR(sql_select_limit=5) */
* from external_table;

Also added new property DATABASE_TYPE to JDBC external table resource creation. This way, we can detect if DATABASE_TYPE is starrocks and set user defined variables as well to target starrocks cluster (MySQL does not support user defined variable query hint).


CREATE EXTERNAL RESOURCE external_resource_starrocks
PROPERTIES (
    "type" = "jdbc",
    "driver_class" = "com.mysql.cj.jdbc.Driver",
    "driver_url" = "mysql-connector-j-8.4.0.jar",
    "jdbc_uri" = "jdbc:mysql://127.0.0.1:9030/mydb",
    "user" = "user",
    "password" = "password",
    "database_type" = "starrocks"
);

What I'm doing:

Fixes #53356

What type of PR is this:

  • BugFix
  • Feature
  • Enhancement
  • Refactor
  • UT
  • Doc
  • Tool

Does this PR entail a change in behavior?

  • Yes, this PR will result in a change in behavior.
  • No, this PR will not result in a change in behavior.

If yes, please specify the type of change:

  • Interface/UI changes: syntax, type conversion, expression evaluation, display information
  • Parameter changes: default values, similar parameters but with different default values
  • Policy changes: use new policy to replace old one, functionality automatically enabled
  • Feature removed
  • Miscellaneous: upgrade & downgrade compatibility, etc.

Checklist:

  • I have added test cases for my bug fix or my new feature
  • This pr needs user documentation (for new or modified features or behaviors)
    • I have added documentation for my new feature or new function
  • This is a backport pr

Bugfix cherry-pick branch check:

  • I have checked the version labels which the pr will be auto-backported to the target branch
    • 3.4
    • 3.3
    • 3.2
    • 3.1
    • 3.0

@boosheen boosheen requested a review from a team as a code owner November 29, 2024 04:03
@CLAassistant
Copy link

CLAassistant commented Nov 29, 2024

CLA assistant check
All committers have signed the CLA.

@boosheen
Copy link
Author

I will raise a new PR with documentation if this is accepted 🙏

@boosheen boosheen force-pushed the boosheen/add-jdbc-external-table-session-variables branch from 9a3f772 to 58501cd Compare November 29, 2024 04:15
@boosheen boosheen changed the title [feature] Add feature to send session variables to JDBC external table [Feature] Add feature to send session variables to JDBC external table Nov 29, 2024
Copy link

sonarcloud bot commented Dec 2, 2024

Quality Gate Failed Quality Gate failed

Failed conditions
C Reliability Rating on New Code (required ≥ A)

See analysis details on SonarQube Cloud

Catch issues before they fail your Quality Gate with our IDE extension SonarQube for IDE

Copy link

github-actions bot commented Dec 2, 2024

[Java-Extensions Incremental Coverage Report]

pass : 0 / 0 (0%)

Copy link

github-actions bot commented Dec 2, 2024

[BE Incremental Coverage Report]

fail : 0 / 6 (00.00%)

file detail

path covered_line new_line coverage not_covered_line_detail
🔵 src/connector/jdbc_connector.cpp 0 6 00.00% [52, 55, 56, 58, 59, 60]

Copy link
Contributor

@zombee0 zombee0 left a comment

Choose a reason for hiding this comment

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

Question: if there are more than one starrocks table in a query, which one should take the session variable?

@boosheen
Copy link
Author

boosheen commented Dec 3, 2024

Question: if there are more than one starrocks table in a query, which one should take the session variable?

Hi @zombee0 good question. By default, the session variables will be sent to all external tables with MySQL protocol in a query (based on the external resource connection pool). It makes the implementation and query syntax simpler for the end user, e.g. if they want to set the same sql_select_limit to all possible external tables

I have considered adding support for user to specify specific resources to send session variables to, but that would be in a new feature/PR as the query input would be more complex.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[JDBC External Table] Support sending session variable to JDBC external table
5 participants