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
DRILL-5868: Support SQL syntax highlighting of queries #1084
Conversation
@arina-ielchiieva / @cgivre , would you care to review this? Let me know if you are unable to build and need screenshots. |
8f41c4e
to
8c396d6
Compare
"when|else|end|type|left|right|join|on|outer|desc|asc|union|create|table|key|if|" + | ||
"not|default|null|inner|database|drop|" + | ||
"flatten|kvgen|columns" |
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.
We have more keywords which would be nice to highlight and which are in https://drill.apache.org/docs/reserved-keywords/ list, for example: alter, function, explain, session, system etc. maybe we can add them in this PR?
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.
This list I could add. Adding everything else is a bit harder. I'll update the list in an add-on comit and attach to this PR. Thnx!
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.
There is a small challenge with this list. The 300+ keywords are a mix of reserved SQL keywords, functions and other words. I could be wrong, but I think some of these are not even supported (e.g. TRIGGER).
I would need to separate the functions and SQL keywords for the colour highlighting to appear correctly.
Let me walk through the list and at least identify the SQL keywords. Functions were already covered separately.
* Drill SQL Syntax Snippets | ||
*/ | ||
|
||
ace.define("ace/snippets/sql",["require","exports","module"], function(require, exports, module) { |
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.
-
Could you please add information about snippets to Jira description. We might what to add it to Drill documentation later so user knows which snippets can be used. Let's say, it's hard to guess the snippers without looking into the code :)
-
When using snippets, I saw the following warning.
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.
+1
I did see this initially, but ignored it as I made progress. Guess I got trained to ignoring the contents in the end :)
Will fix this.
var builtinFunctions = ( | ||
//Math and Trignometric | ||
"abs|cbrt|ceil|ceiling|degrees|e|exp|floor|log|log|log10|lshift|mod|negative|pi|pow|radians|rand|round|round|rshift|sign|sqrt|trunc|trunc|" + |
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.
I believe n future we'll have system table with Drill functions. Will be there a possibility to pass list of functions to the js script instead of hard-coding them?
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.
I tried looking at that option, but it is quite difficult to figure out how the libraries read these files. We could do a dynamic generation of this list, when the sys.functions
table does get implemented.
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.
Sounds good, could you please then just file a Jira for this improvement?
|
||
exports.snippetText = "snippet info\n\ | ||
select * from INFORMATION_SCHEMA.${1:<tableName>};\n\ | ||
snippet sysmem\n\ |
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.
Also snippets are case-sensitive. Is it common practice?
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.
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.
Turns out that my Chrome, it works when using -> Ctrl + space.
Could you please update Jira with list of available snippets and ways how to enable them?
f4635ce
to
9dabd5f
Compare
|
||
exports.snippetText = "snippet info\n\ | ||
select * from INFORMATION_SCHEMA.${1:<tableName>};\n\ | ||
snippet sysmem\n\ |
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.
Turns out that my Chrome, it works when using -> Ctrl + space.
Could you please update Jira with list of available snippets and ways how to enable them?
select * from sys.conn;\n\ | ||
snippet sysprof\n\ | ||
select * from sys.prof;\n\ | ||
snippet cview\n\ |
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.
I am not sure that snippets for sys tables are correct. Please see below list of current tables present in sys schema:
0: jdbc:drill:drillbit=localhost> show tables;
+---------------+-----------------------+
| TABLE_SCHEMA | TABLE_NAME |
+---------------+-----------------------+
| sys | profiles_json |
| sys | drillbits |
| sys | boot |
| sys | internal_options |
| sys | threads |
| sys | options_val |
| sys | profiles |
| sys | connections |
| sys | internal_options_val |
| sys | memory |
| sys | version |
| sys | options |
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.
Good catch.
I was generating the code for the snippets script, so I missed these (they went into a recent commit). I'll fix these.
create table ${1:<tableName>} ( ${2:<columnName>} ) as \n\ | ||
${3:<query>};\n\ | ||
snippet ctemp\n\ | ||
create temporary table ${1:<tableName>} ( ${2:<columnName>} ) as \n\ |
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.
Could you please also add snippet for create function: CREATE FUNCTION USING JAR '<jar_name>.jar';
?
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.
Done.
a76002b
to
b19d901
Compare
@arina-ielchiieva updated the changes based on your review. Please have a look. |
<textarea class="form-control" id="query" name="query" style="font-family: Courier;">${model.getProfile().query}</textarea> | ||
</div> | ||
<div id="query-editor" class="form-group">${model.getProfile().query}</div> | ||
<input class="form-control" id="query" name="query" type="hidden" value="${model.getProfile().query}"/> |
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.
It looks like you have the same code on lines 87-88. These code lines are included when only impersonation is enabled. So if I am not mistaken, you'll end up with two query editors when only impersonation is enabled. Please check.
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.
Let me take a look. This might have slipped past during a merge conflict.
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.
Patched and Verified that with Impersonation enabled, there is only one editor for the profile page.
+1, LGTM. |
@kkhatua I saw some check style errors when applying the patch : .git/rebase-apply/patch:215: trailing whitespace. Can you rebase on latest master and fixup ? |
Based on the commit for DRILL-5981 (PR apache#1043), this commit further leverages the Ace JavaScript library with customizations specific to Drill. This commit introduces the following to the Query Editor (including the Edit Query tab within an existing profile to rerunning the query). 1. Syntax highlighting (This is supported for submitted query profiles 2. Autocomplete supported in editors 3. Specifying Drill specific keywords and functions in visible autocomplete 4. Key snippets (template SQLs) allowing for rapid writing of syntax: i. Query System Tables ii. CView, CTAS and CTempTAS iii. Alter Session iv. Explain and Select * queries NOTE: The lists for #3 and #4 are not exhaustive. As more features are added to Drill, these lists can be expanded. Updates based on review comments 1. Disabled warning message 2. Extended reserved keyword list 3. Fixed bugs List: Update 1: Bug fix for when Impersonation is enabled Update 2: Remove the duplicate editor that might get injected Update 3: Removed trailing whitespaces in Javascripts
Found some Javascript files with trailing white spaces. Removed these spaces and squashed after a rebase. |
Based on the commit for DRILL-5981 (PR apache#1043), this commit further leverages the Ace JavaScript library with customizations specific to Drill. This commit introduces the following to the Query Editor (including the Edit Query tab within an existing profile to rerunning the query). 1. Syntax highlighting (This is supported for submitted query profiles 2. Autocomplete supported in editors 3. Specifying Drill specific keywords and functions in visible autocomplete 4. Key snippets (template SQLs) allowing for rapid writing of syntax: i. Query System Tables ii. CView, CTAS and CTempTAS iii. Alter Session iv. Explain and Select * queries NOTE: The lists for apache#3 and apache#4 are not exhaustive. As more features are added to Drill, these lists can be expanded. Updates based on review comments 1. Disabled warning message 2. Extended reserved keyword list 3. Fixed bugs List: Update 1: Bug fix for when Impersonation is enabled Update 2: Remove the duplicate editor that might get injected Update 3: Removed trailing whitespaces in Javascripts close apache#1084
Based on the commit for DRILL-5981 ([PR #1043), this commit further leverages the Ace JavaScript library with customizations specific to Drill.
This introduces the following to Drill:
For browsers like Chrome, you should be able to type
Ctrl+Space
to show a drop down list for use. Arrow keys are used for navigating to the desired option.i. Query System Tables
ii. CView, CTAS, CTempTAS and CFuncJar
iii. Alter Session
iv. Explain and Select * queries
This is done by leveraging the Snippets feature in the Ace library, which allows for writing SQL code from templates. Like auto-complete, this will insert a template for you. The required/optional fields are then selected (in order) for you to populate, as you complete each and navigate to the next using
Tab
.NOTE: The lists for items 3 and 4 are not exhaustive. As more features are added to Drill, these lists can be expanded.