Skip to content
Closed
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,9 @@ public void execute(BaseRequest request, BaseResponse response) throws DdlExcept
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.

ctx.setCurrentWarehouse(request.getRequest().headers().get(WAREHOUSE_KEY));
}
executeWithoutPassword(request, response);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -182,4 +182,27 @@ public void testQueryPlanActionPruneEmpty() throws Exception {
Assert.assertEquals("{\"partitions\":{},\"opaqued_query_plan\":\"\",\"status\":200}", respStr);
}
}

@Test
public void testQueryPlanActionWithInvalidWarehouse() throws Exception {
super.setUpWithCatalog();
RequestBody body =
RequestBody.create(JSON, "{ \"sql\" : \" select k1 from " + DB_NAME + "." + TABLE_NAME + " \" }");
Request request = new Request.Builder()
.post(body)
.addHeader("Authorization", rootAuth)
.addHeader("warehouse", "invalid_warehouse")
.url(URI + PATH_URI)
.build();
try (Response response = networkClient.newCall(request).execute()) {
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.

String exception = jsonObject.getString("exception");
Assert.assertNotNull(exception);
Assert.assertTrue(
exception.startsWith("Invalid SQL: select k1 from testDb.testTbl "));
}
}
}