-
Notifications
You must be signed in to change notification settings - Fork 2.8k
[ZEPPELIN-4877]. text between 2 sql comment is mistaken as comment #3796
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
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -19,6 +19,8 @@ | |
| package org.apache.zeppelin.interpreter.util; | ||
|
|
||
|
|
||
| import org.apache.commons.lang3.StringUtils; | ||
|
|
||
| import java.util.ArrayList; | ||
| import java.util.HashSet; | ||
| import java.util.List; | ||
|
|
@@ -79,11 +81,9 @@ public List<String> splitSql(String text) { | |
| } | ||
|
|
||
| // end of multiple line comment | ||
| if (multiLineComment && character == '/' && text.charAt(index - 1) == '*') { | ||
| if (multiLineComment && (index - 1) >= 0 && text.charAt(index - 1) == '/' | ||
| && (index - 2) >= 0 && text.charAt(index - 2) == '*') { | ||
| multiLineComment = false; | ||
| if (query.toString().trim().isEmpty()) { | ||
| continue; | ||
| } | ||
| } | ||
|
|
||
| if (character == '\'') { | ||
|
|
@@ -106,39 +106,30 @@ public List<String> splitSql(String text) { | |
| && text.length() > (index + 1)) { | ||
| if (isSingleLineComment(text.charAt(index), text.charAt(index + 1))) { | ||
| singleLineComment = true; | ||
| } else if (text.charAt(index) == '/' && text.charAt(index + 1) == '*') { | ||
| } else if (text.charAt(index) == '/' && text.charAt(index + 1) == '*' | ||
| && text.length() > (index + 2) && text.charAt(index + 2) != '+') { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I would move
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. fixed
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. sorry, I meant that we can write it as: so we have range check for
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I see, now it is fixed |
||
| multiLineComment = true; | ||
| } | ||
| } | ||
|
|
||
| if (character == ';' && !singleQuoteString && !doubleQuoteString && !multiLineComment | ||
| && !singleLineComment) { | ||
| // meet semicolon | ||
| queries.add(query.toString().trim()); | ||
| query = new StringBuilder(); | ||
| if (character == ';' && !singleQuoteString && !doubleQuoteString && !multiLineComment && !singleLineComment) { | ||
| // meet the end of semicolon | ||
| if (!query.toString().trim().isEmpty()) { | ||
| queries.add(query.toString().trim()); | ||
| query = new StringBuilder(); | ||
| } | ||
| } else if (index == (text.length() - 1)) { | ||
| // meet the last character | ||
| if (!singleLineComment && !multiLineComment) { | ||
| query.append(character); | ||
| } | ||
| if (!query.toString().trim().isEmpty()) { | ||
| queries.add(query.toString().trim()); | ||
| query = new StringBuilder(); | ||
| } | ||
| } else if (!singleLineComment && !multiLineComment) { | ||
| // normal case, not in single line comment and not in multiple line comment | ||
| query.append(character); | ||
| } else if (singleLineComment && !query.toString().trim().isEmpty()) { | ||
| // in single line comment, only add it to query when the single line comment is | ||
| // in the middle of sql statement | ||
| // e.g. | ||
| // select a -- comment | ||
| // from table_1 | ||
| query.append(character); | ||
| } else if (multiLineComment && !query.toString().trim().isEmpty()) { | ||
| // in multiple line comment, only add it to query when the multiple line comment | ||
| // is in the middle of sql statement. | ||
| // e.g. | ||
| // select a /* comment */ | ||
| // from table_1 | ||
| query.append(character); | ||
| } | ||
| } | ||
|
|
||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we replace
(index - 1) >= 0with(index - 2) >= 0and just skip it later?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry, I don't get it. Here I just check whether it is the end of multiple comment via checking whether (index-1) is
/and (index-2) is*