Skip to content

[ZEPPELIN-4877]. text between 2 sql comment is mistaken as comment#3796

Closed
zjffdu wants to merge 3 commits intoapache:masterfrom
zjffdu:ZEPPELIN-4877
Closed

[ZEPPELIN-4877]. text between 2 sql comment is mistaken as comment#3796
zjffdu wants to merge 3 commits intoapache:masterfrom
zjffdu:ZEPPELIN-4877

Conversation

@zjffdu
Copy link
Contributor

@zjffdu zjffdu commented Jun 11, 2020

What is this PR for?

This PR fix the bug in Splitter that text between 2 sql comment is mistaken as comment. Unit test is added in this PR as well. Besides that, this PR also remove the comment in the middle of sql. e.g.

select a -- comment 1
from table_1

will be converted to

select a 
from table_1

What type of PR is it?

[Bug Fix]

Todos

  • - Task

What is the Jira issue?

How should this be tested?

  • CI pass

Screenshots (if appropriate)

Questions:

  • Does the licenses files need update? No
  • Is there breaking changes for older versions? No
  • Does this needs documentation? No


// end of multiple line comment
if (multiLineComment && character == '/' && text.charAt(index - 1) == '*') {
if (multiLineComment && (index - 1) >= 0 && text.charAt(index - 1) == '/'
Copy link
Contributor

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) >= 0 with (index - 2) >= 0 and just skip it later?

Copy link
Contributor Author

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 *

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) != '+') {
Copy link
Contributor

Choose a reason for hiding this comment

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

I would move text.length() > (index + 2) before text.charAt(index + 1) == '*'

Copy link
Contributor Author

Choose a reason for hiding this comment

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

fixed

Copy link
Contributor

Choose a reason for hiding this comment

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

sorry, I meant that we can write it as:

text.charAt(index) == '/' && text.length() > (index + 2) 
  && text.charAt(index + 1) == '*' && text.charAt(index + 2) != '+'

so we have range check for index+1 covered, just in case if index == lenght-1...

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 see, now it is fixed

Copy link
Contributor

@alexott alexott left a comment

Choose a reason for hiding this comment

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

lgtm

@asfgit asfgit closed this in badcaa0 Jun 17, 2020
asfgit pushed a commit that referenced this pull request Jun 17, 2020
### What is this PR for?

This PR fix the bug in Splitter that text between 2 sql comment is mistaken as comment. Unit test is added in this PR as well. Besides that, this PR also remove the comment in the middle of sql. e.g.
```
select a -- comment 1
from table_1
```
will be converted to
```
select a
from table_1
```

### What type of PR is it?
[Bug Fix]

### Todos
* [ ] - Task

### What is the Jira issue?
* https://issues.apache.org/jira/browse/ZEPPELIN-4877

### How should this be tested?
* CI pass

### Screenshots (if appropriate)

### Questions:
* Does the licenses files need update? No
* Is there breaking changes for older versions? No
* Does this needs documentation? No

Author: Jeff Zhang <zjffdu@apache.org>

Closes #3796 from zjffdu/ZEPPELIN-4877 and squashes the following commits:

0b0b728 [Jeff Zhang] address comment
6e9287e [Jeff Zhang] address comment
63afd6a [Jeff Zhang] [ZEPPELIN-4877]. text between 2 sql comment is mistaken as comment

(cherry picked from commit badcaa0)
Signed-off-by: Jeff Zhang <zjffdu@apache.org>
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