[ZEPPELIN-2279] excluded comments from SQL#2158
Conversation
|
biggest job is interrupted because of the limit in travis-ci (50 minutes) -> CI red |
|
@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? |
|
@Leemoonsoo |
|
Looks like somehow this branch includes commits not part of this contribution. If you rebase / merge correctly, they'll not be seen as commit of this PR. Could you reset to 6db3c46 |
1295a74 to
6db3c46
Compare
|
@Leemoonsoo |
|
I fixed Jenkins build command the problem taking wrong commit hash when it's got merge commit. |
|
could you elaborate on what errors would come from comment in SQL? |
|
@felixcheung |
|
@Leemoonsoo |
|
LGTM |
|
Actually I want to clarify...
Do you know why the specific example fails? The Postgres spec is pretty clear that it is an accept form of comment.
https://www.postgresql.org/docs/8.0/static/sql-syntax.html#SQL-SYNTAX-COMMENTS
Again my point is we can't possibly know what is and is not supported by all the possible JDBC sources - we should avoid hardcoding the logic here.
#2158 (comment)
|
|
@felixcheung 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). |
|
that's the thing, each of these implementation handles comments differently. |
| if (StringUtils.isNotBlank(precode)) { | ||
| precode = StringUtils.trim(precode); | ||
| logger.info("Run SQL precode '{}'", precode); | ||
| List<String> precodeQueries = splitSqlQueries(precode); |
There was a problem hiding this comment.
why do we need to split this up?
There was a problem hiding this comment.
Yes, there is no need to
| t.open(); | ||
|
|
||
| String sqlQuery = "/* ; */\n" + | ||
| "--select * from test_table\n" + |
|
@felixcheung
|
|
Ready to review |
|
LGTM \cc @felixcheung |
|
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) == '*')) { |
There was a problem hiding this comment.
should check if item == 0, for example
/* multi line
/
*/
this is going to call sql.charAt(0 - 1)?
There was a problem hiding this comment.
why sometimes character.equals() and sometimes charAt() ==?
There was a problem hiding this comment.
item > 0 because first condition should be multiLineComment == true
There was a problem hiding this comment.
conditions fixed
| if (character.equals('/') && sql.charAt(item + 1) == '*') { | ||
| multiLineComment = true; | ||
| continue; | ||
| } |
There was a problem hiding this comment.
what about
-- /* comment
select ...
is that a single line or multiline?
There was a problem hiding this comment.
single because singleLineComment == true
if (singleLineComment || multiLineComment) { continue; }
### 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
### 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
### 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>
### 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
### 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

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?
Questions: