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

#2550 Allowing joins when index names start with a period #2948

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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 @@ -90,12 +90,26 @@ public static String unquoteSingleField(String text) {
* @return A string whose each dot-separated field has been unquoted from back-ticks (if any)
*/
public static String unquoteFullColumn(String text, String quote) {
boolean startsWithPeriod = false;
if (text.startsWith(quote + ".")) {
startsWithPeriod = true;
text = quote + text.substring(2);
}
String[] strs = text.split("\\.");
Copy link
Collaborator

Choose a reason for hiding this comment

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

Just wonder if any easier way to do this. Essentially, we just want to split from the second dot if text starts with . or `. ?

for (int i = 0; i < strs.length; i++) {
String unquotedSubstr = unquoteSingleField(strs[i], quote);
strs[i] = unquotedSubstr;
}
return String.join(".", strs);
if (startsWithPeriod) {
String s = String.join(".", strs);
if (s.startsWith(quote)) {
return new StringBuilder(s).insert(1, ".").toString();
} else {
return "." + s;
}
} else {
return String.join(".", strs);
}
}

public static String unquoteFullColumn(String text) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,20 +23,25 @@ public class BackticksUnquoterTest {
public void assertNotQuotedStringShouldKeepTheSame() {
assertThat(unquoteSingleField("identifier"), equalTo("identifier"));
assertThat(unquoteFullColumn("identifier"), equalTo("identifier"));
assertThat(unquoteFullColumn(".identifier"), equalTo(".identifier"));
}

@Test
public void assertStringWithOneBackTickShouldKeepTheSame() {
assertThat(unquoteSingleField("`identifier"), equalTo("`identifier"));
assertThat(unquoteFullColumn("`identifier"), equalTo("`identifier"));
assertThat(unquoteFullColumn("`.identifier"), equalTo("`.identifier"));
}

@Test
public void assertBackticksQuotedStringShouldBeUnquoted() {
assertThat("identifier", equalTo(unquoteSingleField("`identifier`")));
assertThat(".identifier", equalTo(unquoteSingleField("`.identifier`")));

assertThat(
"identifier1.identifier2", equalTo(unquoteFullColumn("`identifier1`.`identifier2`")));
assertThat("identifier1.identifier2", equalTo(unquoteFullColumn("`identifier1`.identifier2")));
assertThat(
".identifier1.identifier2", equalTo(unquoteFullColumn("`.identifier1`.`identifier2`")));
Copy link
Member

Choose a reason for hiding this comment

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

Does the queries (without join) work before this fixing?

select q.query_id 
from .ubi_log_queries q

select q.query_id 
from `.ubi_log_queries` q

Could you add some tests to verify the objective issue is fixed:

select q.query_id 
from .ubi_log_queries q join .ubi_log_events e
on q.query_id = e.query_id

select q.query_id 
from `.ubi_log_queries` q join `.ubi_log_events` e
on q.query_id = e.query_id

Copy link
Author

Choose a reason for hiding this comment

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

Yes, those queries work fine.

I'm open to testing suggestions, but the issue is the presence of the period inside the backticks. When an index starts with a ., the period is not included in the backticks.

}
}
Loading