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

Fix sql syntax error user #16583

Merged
merged 4 commits into from
Jun 11, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Next Next commit
SQL syntax error should target USER persona
  • Loading branch information
zachjsh committed Jun 10, 2024
commit ccdbc746c1ff2690f94f0b6f15ed1a7b041a1a19
Original file line number Diff line number Diff line change
Expand Up @@ -380,13 +380,7 @@ public static DruidException translateException(Exception e)
}
}

return DruidException.forPersona(DruidException.Persona.DEVELOPER)
Copy link
Contributor

@abhishekrb19 abhishekrb19 Jun 10, 2024

Choose a reason for hiding this comment

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

This makes sense to me since this is still a case of SqlParseException.

@zachjsh, do you mind adding a test with a bad SQL that would cause the exception to be targeted towards a user?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Added.

.ofCategory(DruidException.Category.UNCATEGORIZED)
.build(
inner,
"Unable to parse the SQL, unrecognized error from calcite: [%s]",
inner.getMessage()
);
return InvalidSqlInput.exception(inner.getMessage());
Copy link
Member

Choose a reason for hiding this comment

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

this exception creation clips the stacktrace - it only retains the source exceptions message

}
catch (RelOptPlanner.CannotPlanException inner) {
return DruidException.forPersona(DruidException.Persona.USER)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -684,16 +684,7 @@ private DruidException buildSQLPlanningError(RelOptPlanner.CannotPlanException e
.ofCategory(DruidException.Category.UNSUPPORTED)
.build(exception, "Unhandled Query Planning Failure, see broker logs for details");
} else {
// Planning errors are more like hints: it isn't guaranteed that the planning error is actually what went wrong.
// For this reason, we consider these as targetting a more expert persona, i.e. the admin instead of the actual
// user.
Copy link
Member

Choose a reason for hiding this comment

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

The removed comment provides the reason why it was not target to the USER ; I think we should leave the uncategorized ones to ADMIN or something

if there is a particular set of exceptions which should be hardened; maybe those should be targeted directly

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I reverted this part of the change, thanks for taking a look!

throw DruidException.forPersona(DruidException.Persona.ADMIN)
.ofCategory(DruidException.Category.INVALID_INPUT)
.build(
exception,
"Query could not be planned. A possible reason is [%s]",
errorMessage
);
throw InvalidSqlInput.exception("Query could not be planned. A possible reason is [%s]", errorMessage);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -664,11 +664,7 @@ public void assertQueryIsUnplannable(final PlannerConfig plannerConfig, final St

private DruidExceptionMatcher buildUnplannableExceptionMatcher()
{
if (testBuilder().isDecoupledMode()) {
return new DruidExceptionMatcher(Persona.USER, Category.INVALID_INPUT, "invalidInput");
} else {
return new DruidExceptionMatcher(Persona.ADMIN, Category.INVALID_INPUT, "general");
}
return new DruidExceptionMatcher(Persona.USER, Category.INVALID_INPUT, "invalidInput");
}

/**
Expand Down