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: make stream and column names case-insensitive in /inserts-stream #5591

Merged
merged 7 commits into from
Jun 10, 2020

Conversation

vcrfxia
Copy link
Contributor

@vcrfxia vcrfxia commented Jun 10, 2020

Description

The stream name and column names provided to the /inserts-stream endpoint are both currently case-sensitive, meaning an attempted insert into a stream with name foo will fail if the stream actually has name FOO in the metastore (e.g., if the stream were created with create stream foo ...). The same holds for column names as well. This PR updates the /inserts-stream endpoint to be case-insensitive by default, in order to be consistent with the rest of ksqlDB.

BREAKING CHANGE: Stream name and column names provided to the /inserts-stream endpoint are no longer case-sensitive. Instead, they will be upper-cased by default. To preserve case-sensitivity, surround the names with double-quotes or backticks.

Testing done

Added integration tests.

Reviewer checklist

  • Ensure docs are updated if necessary. (eg. if a user visible feature is being added or changed).
  • Ensure relevant issues are linked (description should include text like "Fixes #")

@vcrfxia vcrfxia requested a review from a team as a code owner June 10, 2020 07:58
@@ -97,6 +97,20 @@ public static String convertCommaSeparatedWilcardsToRegex(final String csv) {
return out.toString();
}

// See ParserUtil#getIdentifierText()
public static String getIdentifierText(final String text) {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

It's not great that this logic is repeated here and also in the method of the same name in ParserUtil.java. I couldn't think of a way to combine them, though, since the ParserUtil method is specific to the AST.

@vcrfxia vcrfxia requested a review from purplefox June 10, 2020 08:00
Copy link
Contributor

@purplefox purplefox left a comment

Choose a reason for hiding this comment

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

Just a few comments

@@ -69,6 +71,28 @@ public static GenericRow extractValues(final JsonObject values, final LogicalSch
return GenericRow.fromList(vals);
}

static JsonObject convertColumnNameCase(final JsonObject jsonObjectWithCaseInsensitiveFields) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Instead of iterating through the entries again in here and having an extra method, it would be simpler to call ServerUtils.getIdentifierText in the existing extractValues method.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Then we'd also have to do the conversion in extractKey() too, right? I think it's better to do it once upfront, rather than making both extractValues() and extractKey() responsible for converting.

I'm going to merge this for now; can open a follow-up with the requested changes if I've misunderstood.

}

final char firstChar = text.charAt(0);
if (firstChar == '`' || firstChar == '"') {
Copy link
Contributor

Choose a reason for hiding this comment

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

Do we really also support double quotes for escaping? Thought it was just backtick.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

We also support double quotes. Here's the relevant code:

if (context instanceof SqlBaseParser.QuotedIdentifierAlternativeContext) {
return unquote(context.getText(), "\"");
} else if (context instanceof SqlBaseParser.BackQuotedIdentifierContext) {
return unquote(context.getText(), "`");

I also sanity checked manually.

public void shouldTreatInsertColumnNamesAsCaseSensitiveIfQuoted() {
// Given:
JsonObject row = new JsonObject()
.put("\"str\"", "HELLO")
Copy link
Contributor

Choose a reason for hiding this comment

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

What about backtick?

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.

@vcrfxia
Copy link
Contributor Author

vcrfxia commented Jun 10, 2020

As discussed in #5588 (review), I'm going to intentionally leave out the breaking note change in this PR description from the final commit message (so it won't appear in the auto-generated changelog).

@vcrfxia vcrfxia merged commit e9e3042 into confluentinc:6.0.x Jun 10, 2020
@vcrfxia vcrfxia deleted the inserts-stream-case branch June 10, 2020 20:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants