Skip to content

[Enhancement] Support to specify warehouse for query_plan rest query#57930

Closed
zhangbutao wants to merge 3 commits into
StarRocks:mainfrom
zhangbutao:support_warehouse_for_rest_query
Closed

[Enhancement] Support to specify warehouse for query_plan rest query#57930
zhangbutao wants to merge 3 commits into
StarRocks:mainfrom
zhangbutao:support_warehouse_for_rest_query

Conversation

@zhangbutao
Copy link
Copy Markdown
Contributor

Why I'm doing:

Refert to the doc: https://github.com/StarRocks/starrocks-connector-for-apache-flink/blob/main/docs/content/connector-source.md
At present, we can not specify a warehouse when using flink to query the sr table. I propose to pass the warehouse info through http header.
This PR can be worked after StarRocks/starrocks-connector-for-apache-flink#423

What I'm doing:

Support to specify warehouse for rest query, like flink sr connector.

Fixes #issue

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.5
    • 3.4
    • 3.3
    • 3.2
    • 3.1

ctx.setCurrentUserIdentity(currentUser);
ctx.setCurrentRoleIds(currentUser);
ctx.setThreadLocalInfo();
if (request.getRequest().headers().contains(WAREHOUSE_KEY)) {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

please add some unit tests about the new parameters, and what's the response looks like if the specified warehouse doesn't exist.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Signed-off-by: zhangbutao <zhangbutao@cmss.chinamobile.com>
@zhangbutao zhangbutao force-pushed the support_warehouse_for_rest_query branch from 58df471 to 0432095 Compare April 17, 2025 06:08
Signed-off-by: zhangbutao <zhangbutao@cmss.chinamobile.com>
String respStr = Objects.requireNonNull(response.body()).string();
JSONObject jsonObject = new JSONObject(respStr);
System.out.println(respStr);
Assert.assertEquals(500, jsonObject.getInt("status"));
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

this is not expected, FE should respond HTTP 400 BAD request.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

The exception comes from here, which all exception wiil be 500

} catch (Exception e) {
LOG.error("Get query plan for sql[{}] error, queryId: {}", sql, context.getQueryId(), e);
throw new StarRocksHttpException(
HttpResponseStatus.INTERNAL_SERVER_ERROR,
"Invalid SQL: " + sql);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

should do input parameter check before execute the parameter, or do fine grain exception handling. It is the request's parameter invalidation, should not be considered as a HTTP 5XX error. Usually a HTTP 5XX error means the http client is not doing anything wrong, and can do endless retry without modification of the request as wish.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

@kevincai I changed the code to check and set warehouse before execute the query_plan, so that we can get the real error status and exception.
So this PR is for TableQueryPlanAction, which can solve the sr flink source connector warehouse issue.

For other http Action, i am not sure if need the warehouse. But we can also do similar check like this PR if other http Actions have any need.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

It is good enough to fix only in query_plan API in this PR.

@zhangbutao zhangbutao changed the title [Enhancement] Support to specify warehouse for rest query [Enhancement] Support to specify warehouse for query_plan rest query Apr 17, 2025
Signed-off-by: zhangbutao <zhangbutao@cmss.chinamobile.com>
@sonarqubecloud
Copy link
Copy Markdown

@github-actions
Copy link
Copy Markdown
Contributor

[Java-Extensions Incremental Coverage Report]

pass : 0 / 0 (0%)

@github-actions
Copy link
Copy Markdown
Contributor

[BE Incremental Coverage Report]

pass : 0 / 0 (0%)

@kevincai
Copy link
Copy Markdown
Contributor

the issue is fixed by #58387. This PR is not needed any more.

@kevincai kevincai closed this Jun 12, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants