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 all 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 @@ -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 @@ -1626,6 +1626,18 @@ public void testInsertWithInvalidSelectStatement()
.verify();
}

@Test
public void testInsertWithLongIdentifer()
{
// This test fails because an identifer is specified of length 200, which exceeds the length limit of 128
// characters.
String longIdentifer = new String(new char[200]).replace('\0', 'a');
testIngestionQuery()
.sql(StringUtils.format("INSERT INTO t SELECT %s FROM foo PARTITIONED BY ALL", longIdentifer)) // count is a keyword
.expectValidationError(invalidSqlContains(StringUtils.format("Length of identifier '%s' must be less than or equal to 128 characters", longIdentifer)))
.verify();
}

@Test
public void testInsertWithUnnamedColumnInSelectStatement()
{
Expand Down
Loading