Skip to content

[ZEPPELIN-2279] excluded comments from SQL#2158

Closed
tinkoff-dwh wants to merge 4 commits into
apache:masterfrom
tinkoff-dwh:ZEPPELIN-2279
Closed

[ZEPPELIN-2279] excluded comments from SQL#2158
tinkoff-dwh wants to merge 4 commits into
apache:masterfrom
tinkoff-dwh:ZEPPELIN-2279

Conversation

@tinkoff-dwh
Copy link
Copy Markdown
Contributor

@tinkoff-dwh tinkoff-dwh commented Mar 19, 2017

What is this PR for?

Exclusion comments (single-, multiline) from queries before execution. Comments don't need to execute query and sometimes there are errors.

What type of PR is it?

Bug Fix | Improvement

What is the Jira issue?

https://issues.apache.org/jira/browse/ZEPPELIN-2279

How should this be tested?

/* ; */
select 1;
-- text select 1
/* bla 
bla
bla*/
select 1; -- text

Questions:

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

@tinkoff-dwh
Copy link
Copy Markdown
Contributor Author

tinkoff-dwh commented Mar 19, 2017

biggest job is interrupted because of the limit in travis-ci (50 minutes) -> CI red

@Leemoonsoo
Copy link
Copy Markdown
Member

@tinkoff-dwh Thanks for contribution.

CI failure on exceeding timelimit has fixed on master branch. Can you try rebase this branch and see if CI becomes green?

@tinkoff-dwh
Copy link
Copy Markdown
Contributor Author

@Leemoonsoo
done

@Leemoonsoo
Copy link
Copy Markdown
Member

Looks like somehow this branch includes commits not part of this contribution.
image

If you rebase / merge correctly, they'll not be seen as commit of this PR. Could you reset to 6db3c46
and try again?

@tinkoff-dwh
Copy link
Copy Markdown
Contributor Author

@Leemoonsoo
Copy link
Copy Markdown
Member

I fixed Jenkins build command the problem taking wrong commit hash when it's got merge commit.
Now Jenkins will take correct commits. @tinkoff-dwh Could you try close / re-open this PR and see if Jenkins check the travis correctly?

@felixcheung
Copy link
Copy Markdown
Member

could you elaborate on what errors would come from comment in SQL?
generally we should avoid trying to pre-parse the paragraph text since we don't necessarily know the SQL dialect the interpreter can handle, or not

@tinkoff-dwh
Copy link
Copy Markdown
Contributor Author

@felixcheung
example in jira

@tinkoff-dwh tinkoff-dwh reopened this Mar 21, 2017
@tinkoff-dwh
Copy link
Copy Markdown
Contributor Author

@Leemoonsoo
it works, thx!

@Leemoonsoo
Copy link
Copy Markdown
Member

LGTM
Merge to master if no further comments.

@felixcheung
Copy link
Copy Markdown
Member

felixcheung commented Mar 23, 2017 via email

@tinkoff-dwh
Copy link
Copy Markdown
Contributor Author

@felixcheung
falls because ";" is delimiter query and after split generated two queries ("/* ", "*/ select ...")

I relied on the standards for SQL89, 92 ... if you're talking about nosql databases, the jdbc driver are implemented in the form of wrappers (SQL queries, mongodb, aerospike).

@felixcheung
Copy link
Copy Markdown
Member

that's the thing, each of these implementation handles comments differently.
for instance, solr JDBC shares the same spec as presto (which is very common) - but it doesn't support empty comment /**/ or multiline comment /*\n*/

if (StringUtils.isNotBlank(precode)) {
precode = StringUtils.trim(precode);
logger.info("Run SQL precode '{}'", precode);
List<String> precodeQueries = splitSqlQueries(precode);
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

why do we need to split this up?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Yes, there is no need to

t.open();

String sqlQuery = "/* ; */\n" +
"--select * from test_table\n" +
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

add a test for -- a ; b?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

added

@tinkoff-dwh
Copy link
Copy Markdown
Contributor Author

@felixcheung
I don't see a problem.

  1. /**/ will not be processed
  2. /\n/ will not be processed

@tinkoff-dwh
Copy link
Copy Markdown
Contributor Author

Ready to review

@Leemoonsoo
Copy link
Copy Markdown
Member

LGTM \cc @felixcheung

@Leemoonsoo
Copy link
Copy Markdown
Member

Merge to master if no further discussions.

character = sql.charAt(item);

if ((singleLineComment && (character.equals('\n') || item == sql.length() - 1))
|| (multiLineComment && character.equals('/') && sql.charAt(item - 1) == '*')) {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

should check if item == 0, for example

/* multi line
/
*/

this is going to call sql.charAt(0 - 1)?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

why sometimes character.equals() and sometimes charAt() ==?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

item > 0 because first condition should be multiLineComment == true

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

conditions fixed

if (character.equals('/') && sql.charAt(item + 1) == '*') {
multiLineComment = true;
continue;
}
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

what about

-- /* comment
select ...

is that a single line or multiline?

Copy link
Copy Markdown
Contributor Author

@tinkoff-dwh tinkoff-dwh Apr 5, 2017

Choose a reason for hiding this comment

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

single because singleLineComment == true

if (singleLineComment || multiLineComment) { continue; }

@asfgit asfgit closed this in f9830a7 Apr 8, 2017
@tinkoff-dwh tinkoff-dwh deleted the ZEPPELIN-2279 branch April 17, 2017 09:47
prabhjyotsingh pushed a commit to prabhjyotsingh/zeppelin that referenced this pull request Sep 1, 2017
### What is this PR for?
Exclusion comments (single-, multiline) from queries before execution. Comments don't need to execute  query and sometimes there are errors.

### What type of PR is it?
Bug Fix | Improvement

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

### How should this be tested?
```
/* ; */
select 1;
-- text select 1
/* bla
bla
bla*/
select 1; -- text
```

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

Author: Tinkoff DWH <tinkoff.dwh@gmail.com>

Closes apache#2158 from tinkoff-dwh/ZEPPELIN-2279 and squashes the following commits:

3f7496e [Tinkoff DWH] [ZEPPELIN-2279] fix conditions, common format
f48f7d6 [Tinkoff DWH] [ZEPPELIN-2279] improve test, revert  precode execution
2cb94fa [Tinkoff DWH] Merge remote-tracking branch 'origin/master' into ZEPPELIN-2279
6db3c46 [Tinkoff DWH] [ZEPPELIN-2279] excluded comments from SQL
prabhjyotsingh pushed a commit to prabhjyotsingh/zeppelin that referenced this pull request Oct 23, 2017
### What is this PR for?
Exclusion comments (single-, multiline) from queries before execution. Comments don't need to execute  query and sometimes there are errors.

### What type of PR is it?
Bug Fix | Improvement

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

### How should this be tested?
```
/* ; */
select 1;
-- text select 1
/* bla
bla
bla*/
select 1; -- text
```

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

Author: Tinkoff DWH <tinkoff.dwh@gmail.com>

Closes apache#2158 from tinkoff-dwh/ZEPPELIN-2279 and squashes the following commits:

3f7496e [Tinkoff DWH] [ZEPPELIN-2279] fix conditions, common format
f48f7d6 [Tinkoff DWH] [ZEPPELIN-2279] improve test, revert  precode execution
2cb94fa [Tinkoff DWH] Merge remote-tracking branch 'origin/master' into ZEPPELIN-2279
6db3c46 [Tinkoff DWH] [ZEPPELIN-2279] excluded comments from SQL
asfgit pushed a commit that referenced this pull request Apr 1, 2018
### What is this PR for?
The original purpose of #2158 was correct processing of ';'. This was done via full removing comments from code.
Unfortunately Apache Phoenix uses hooks in comments https://forcedotcom.github.io/phoenix/#hintml.
Thus we should not delete comments in scripts.
There was discussion about comment rules for different databases (solr). The right way is keep style. Thus analysts can copy queries to another tool and can get same results and errors.

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

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

### How should this be tested?
* Unit tests pass: testSplitSqlQueryWithComments and testSplitSqlQuery

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

Author: mebelousov <mebelousov@ya.ru>

Closes #2876 from mebelousov/ZEPPELIN-3344 and squashes the following commits:

6980400 [mebelousov] ZEPPELIN-3344 Fix checkstyle, add tests for comments
83c8e8f [mebelousov] ZEPPELIN-3344 Rename test
eed54c8 [mebelousov] ZEPPELIN-3344 Revert comments in JDBC interpreter

(cherry picked from commit 8238b71)
Signed-off-by: Jeff Zhang <zjffdu@apache.org>
asfgit pushed a commit that referenced this pull request Apr 1, 2018
### What is this PR for?
The original purpose of #2158 was correct processing of ';'. This was done via full removing comments from code.
Unfortunately Apache Phoenix uses hooks in comments https://forcedotcom.github.io/phoenix/#hintml.
Thus we should not delete comments in scripts.
There was discussion about comment rules for different databases (solr). The right way is keep style. Thus analysts can copy queries to another tool and can get same results and errors.

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

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

### How should this be tested?
* Unit tests pass: testSplitSqlQueryWithComments and testSplitSqlQuery

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

Author: mebelousov <mebelousov@ya.ru>

Closes #2876 from mebelousov/ZEPPELIN-3344 and squashes the following commits:

6980400 [mebelousov] ZEPPELIN-3344 Fix checkstyle, add tests for comments
83c8e8f [mebelousov] ZEPPELIN-3344 Rename test
eed54c8 [mebelousov] ZEPPELIN-3344 Revert comments in JDBC interpreter
jwagun pushed a commit to jwagun/zeppelin that referenced this pull request Apr 23, 2018
### What is this PR for?
The original purpose of apache#2158 was correct processing of ';'. This was done via full removing comments from code.
Unfortunately Apache Phoenix uses hooks in comments https://forcedotcom.github.io/phoenix/#hintml.
Thus we should not delete comments in scripts.
There was discussion about comment rules for different databases (solr). The right way is keep style. Thus analysts can copy queries to another tool and can get same results and errors.

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

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

### How should this be tested?
* Unit tests pass: testSplitSqlQueryWithComments and testSplitSqlQuery

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

Author: mebelousov <mebelousov@ya.ru>

Closes apache#2876 from mebelousov/ZEPPELIN-3344 and squashes the following commits:

6980400 [mebelousov] ZEPPELIN-3344 Fix checkstyle, add tests for comments
83c8e8f [mebelousov] ZEPPELIN-3344 Rename test
eed54c8 [mebelousov] ZEPPELIN-3344 Revert comments in JDBC interpreter
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.

3 participants