Przeglądaj źródła

HUE-6869 [editor] Show language reference when right clicking statement starting keywords in the editor

Johan Ahlen 7 lat temu
rodzic
commit
e0033d88ae

Plik diff jest za duży
+ 0 - 0
desktop/core/src/desktop/static/desktop/css/hue-embedded.css


Plik diff jest za duży
+ 0 - 0
desktop/core/src/desktop/static/desktop/css/hue.css


Plik diff jest za duży
+ 0 - 0
desktop/core/src/desktop/static/desktop/css/hue3-extra.css


+ 17 - 17
desktop/core/src/desktop/static/desktop/js/autocomplete/jison/sql.jisonlex

@@ -219,14 +219,14 @@
 <impala>'COLUMNS'                          { return '<impala>COLUMNS'; }
 <impala>'COMMENT'                          { parser.determineCase(yytext); return '<impala>COMMENT'; }
 <impala>'COMPUTE'                          { parser.determineCase(yytext); return '<impala>COMPUTE'; }
-<impala>'CREATE'                           { parser.determineCase(yytext); return '<impala>CREATE'; }
+<impala>'CREATE'                           { parser.determineCase(yytext); parser.addStatementTypeLocation('CREATE', yylloc, yy.lexer.upcomingInput()); return '<impala>CREATE'; }
 <impala>'DATA'                             { return '<impala>DATA'; }
 <impala>'DATABASES'                        { return '<impala>DATABASES'; }
 <impala>'DELETE'                           { return '<impala>DELETE'; }
 <impala>'DELIMITED'                        { return '<impala>DELIMITED'; }
-<impala>'DESCRIBE'                         { parser.determineCase(yytext); return '<impala>DESCRIBE'; }
+<impala>'DESCRIBE'                         { parser.determineCase(yytext); parser.addStatementTypeLocation('DESCRIBE', yylloc); return '<impala>DESCRIBE'; }
 <impala>'ESCAPED'                          { return '<impala>ESCAPED'; }
-<impala>'EXPLAIN'                          { parser.determineCase(yytext); return '<impala>EXPLAIN'; }
+<impala>'EXPLAIN'                          { parser.determineCase(yytext); parser.addStatementTypeLocation('EXPLAIN', yylloc); return '<impala>EXPLAIN'; }
 <impala>'EXTERNAL'                         { return '<impala>EXTERNAL'; }
 <impala>'EXTENDED'                         { return '<impala>EXTENDED'; }
 <impala>'FIELDS'                           { return '<impala>FIELDS'; }
@@ -242,11 +242,11 @@
 <impala>'HASH'                             { return '<impala>HASH'; }
 <impala>'ILIKE'                            { return '<impala>ILIKE'; }
 <impala>'INCREMENTAL'                      { return '<impala>INCREMENTAL'; }
-<impala>'INSERT'                           { parser.determineCase(yytext); return '<impala>INSERT'; }
+<impala>'INSERT'                           { parser.determineCase(yytext); parser.addStatementTypeLocation('INSERT', yylloc); return '<impala>INSERT'; }
 <impala>'INTERVAL'                         { return '<impala>INTERVAL'; }
 <impala>'INTERMEDIATE'                     { return '<impala>INTERMEDIATE'; }
 <impala>'INIT_FN'                          { return '<impala>INIT_FN'; }
-<impala>'INVALIDATE'                       { parser.determineCase(yytext); return '<impala>INVALIDATE'; }
+<impala>'INVALIDATE'                       { parser.determineCase(yytext); parser.addStatementTypeLocation('INVALIDATE', yylloc, yy.lexer.upcomingInput()); return '<impala>INVALIDATE'; }
 <impala>'INPATH'                           { this.begin('hdfs'); return '<impala>INPATH'; }
 <impala>'IREGEXP'                          { return '<impala>IREGEXP'; }
 <impala>'KEY'                              { return '<impala>KEY'; }
@@ -255,7 +255,7 @@
 <impala>LIKE\s+PARQUET                     { this.begin('hdfs'); return '<impala>LIKE_PARQUET'; }
 <impala>'LIMIT'                            { return '<impala>LIMIT'; }
 <impala>'LINES'                            { return '<impala>LINES'; }
-<impala>'LOAD'                             { parser.determineCase(yytext); return '<impala>LOAD'; }
+<impala>'LOAD'                             { parser.determineCase(yytext); parser.addStatementTypeLocation('LOAD', yylloc, yy.lexer.upcomingInput()); return '<impala>LOAD'; }
 <impala>'LOCATION'                         { this.begin('hdfs'); return '<impala>LOCATION'; }
 <impala>'MERGE_FN'                         { return '<impala>MERGE_FN'; }
 <impala>'METADATA'                         { return '<impala>METADATA'; }
@@ -271,14 +271,14 @@
 <impala>'RCFILE'                           { return '<impala>RCFILE'; }
 <impala>'RANGE'                            { return '<impala>RANGE'; }
 <impala>'REAL'                             { return '<impala>REAL'; }
-<impala>'REFRESH'                          { parser.determineCase(yytext); return '<impala>REFRESH'; }
+<impala>'REFRESH'                          { parser.determineCase(yytext); parser.addStatementTypeLocation('REFRESH', yylloc); return '<impala>REFRESH'; }
 <impala>'RENAME'                           { return '<impala>RENAME'; }
 <impala>'REPEATABLE'                       { return '<impala>REPEATABLE'; }
 <impala>'REPLACE'                          { return '<impala>REPLACE'; }
 <impala>'REPLICATION'                      { return '<impala>REPLICATION'; }
 <impala>'RESTRICT'                         { return '<impala>RESTRICT'; }
 <impala>'RETURNS'                          { return '<impala>RETURNS'; }
-<impala>'REVOKE'                           { return '<impala>REVOKE'; }
+<impala>'REVOKE'                           { parser.determineCase(yytext); parser.addStatementTypeLocation('REVOKE', yylloc); return '<impala>REVOKE'; }
 <impala>'SEQUENCEFILE'                     { return '<impala>SEQUENCEFILE'; }
 <impala>'SERDEPROPERTIES'                  { return '<impala>SERDEPROPERTIES'; }
 <impala>'SCHEMAS'                          { return '<impala>SCHEMAS'; }
@@ -297,7 +297,7 @@
 <impala>'TEXTFILE'                         { return '<impala>TEXTFILE'; }
 <impala>'UNCACHED'                         { return '<impala>UNCACHED'; }
 <impala>'UPDATE_FN'                        { return '<impala>UPDATE_FN'; }
-<impala>'UPSERT'                           { parser.determineCase(yytext); return '<impala>UPSERT'; }
+<impala>'UPSERT'                           { parser.determineCase(yytext); parser.addStatementTypeLocation('UPSERT', yylloc); return '<impala>UPSERT'; }
 <impala>'URI'                              { return '<impala>URI'; }
 <impala>'USING'                            { return '<impala>USING'; }
 <impala>PARTITION\s+VALUE\s                { return '<impala>PARTITION_VALUE'; }
@@ -331,7 +331,7 @@
 
 // Reserved Keywords
 'ALL'                                      { return 'ALL'; }
-'ALTER'                                    { parser.determineCase(yytext); return 'ALTER'; }
+'ALTER'                                    { parser.determineCase(yytext); parser.addStatementTypeLocation('ALTER', yylloc, yy.lexer.upcomingInput()); return 'ALTER'; }
 'AND'                                      { return 'AND'; }
 'AS'                                       { return 'AS'; }
 'ASC'                                      { return 'ASC'; }
@@ -350,7 +350,7 @@
 'DIV'                                      { return 'ARITHMETIC_OPERATOR'; }
 'DOUBLE'                                   { return 'DOUBLE'; }
 'DESC'                                     { return 'DESC'; }
-'DROP'                                     { parser.determineCase(yytext); return 'DROP'; }
+'DROP'                                     { parser.determineCase(yytext); parser.addStatementTypeLocation('DROP', yylloc, yy.lexer.upcomingInput()); return 'DROP'; }
 'ELSE'                                     { return 'ELSE'; }
 'END'                                      { return 'END'; }
 'EXISTS'                                   { parser.yy.correlatedSubQuery = true; return 'EXISTS'; }
@@ -389,10 +389,10 @@
 'ROW'                                      { return 'ROW'; }
 'ROWS'                                     { return 'ROWS'; }
 'SCHEMA'                                   { return 'SCHEMA'; }
-'SELECT'                                   { parser.determineCase(yytext); return 'SELECT'; }
+'SELECT'                                   { parser.determineCase(yytext); parser.addStatementTypeLocation('SELECT', yylloc); return 'SELECT'; }
 'SEMI'                                     { return 'SEMI'; }
-'SET'                                      { parser.determineCase(yytext); return 'SET'; }
-'SHOW'                                     { parser.determineCase(yytext); return 'SHOW'; }
+'SET'                                      { parser.determineCase(yytext); parser.addStatementTypeLocation('SET', yylloc); return 'SET'; }
+'SHOW'                                     { parser.determineCase(yytext); parser.addStatementTypeLocation('SHOW', yylloc); return 'SHOW'; }
 'SMALLINT'                                 { return 'SMALLINT'; }
 'STRING'                                   { return 'STRING'; }
 'TABLE'                                    { return 'TABLE'; }
@@ -401,17 +401,17 @@
 'TINYINT'                                  { return 'TINYINT'; }
 'TO'                                       { return 'TO'; }
 'TRUE'                                     { return 'TRUE'; }
-'TRUNCATE'                                 { parser.determineCase(yytext); return 'TRUNCATE'; }
+'TRUNCATE'                                 { parser.determineCase(yytext); parser.addStatementTypeLocation('TRUNCATE', yylloc, yy.lexer.upcomingInput()); return 'TRUNCATE'; }
 'UNBOUNDED'                                { return 'UNBOUNDED'; }
 'UPDATE'                                   { parser.determineCase(yytext); return 'UPDATE'; }
-'USE'                                      { parser.determineCase(yytext); return 'USE'; }
+'USE'                                      { parser.determineCase(yytext); parser.addStatementTypeLocation('USE', yylloc); return 'USE'; }
 'UNION'                                    { return 'UNION'; }
 'VIEW'                                     { return 'VIEW'; }
 'VARCHAR'                                  { return 'VARCHAR'; } // Not in Impala
 'VALUES'                                   { return 'VALUES'; }
 'WHEN'                                     { return 'WHEN'; }
 'WHERE'                                    { return 'WHERE'; }
-'WITH'                                     { parser.determineCase(yytext); return 'WITH'; }
+'WITH'                                     { parser.determineCase(yytext); parser.addStatementTypeLocation('WITH', yylloc); return 'WITH'; }
 
 // Non-reserved Keywords
 'OVER'                                     { return 'OVER'; }

+ 3 - 0
desktop/core/src/desktop/static/desktop/js/autocomplete/spec/sqlSpec.js

@@ -435,10 +435,12 @@
       assertAutoComplete({
         beforeCursor: '-- line comment\nSELECT * from testTable1;\n',
         afterCursor: '\n-- other line comment',
+        dialect: 'impala',
         containsKeywords: ['SELECT'],
         expectedResult: {
           locations: [
             { type: 'statement', location: { first_line: 1, last_line: 2, first_column: 1, last_column: 25 } },
+            { type: 'statementType', location: { first_line: 2, last_line: 2, first_column: 1, last_column: 7 }, identifier: 'SELECT' },
             { type: 'selectList', missing: false, location: { first_line: 2, last_line: 2, first_column: 8, last_column: 9 } },
             { type: 'asterisk', location: { first_line: 2, last_line: 2, first_column: 8, last_column: 9 }, tables: [{ identifierChain: [{ name: 'testTable1' }] }] },
             { type: 'table', location: { first_line:2, last_line:2, first_column:15, last_column:25 }, identifierChain: [{ name: 'testTable1' }] },
@@ -454,6 +456,7 @@
       assertAutoComplete({
         beforeCursor: '/* line 1\nline 2\n*/\nSELECT * from testTable1;\n',
         afterCursor: '',
+        dialect: 'hive',
         containsKeywords: ['SELECT'],
         expectedResult: {
           locations: [

+ 2 - 0
desktop/core/src/desktop/static/desktop/js/autocomplete/spec/sqlSpecDescribe_impala.js

@@ -38,6 +38,7 @@
           lowerCase: false,
           locations: [
             { type: 'statement', location: { 'first_line': 1, 'last_line': 1, 'first_column': 1, 'last_column': 13 } },
+            { type: 'statementType', location: { first_line: 1, last_line: 1, first_column: 1, last_column: 9 }, identifier: 'DESCRIBE' },
             { type: 'table', location: { first_line: 1, last_line: 1, first_column: 10, last_column: 13}, identifierChain: [{ name: 'tbl' }] }
           ]
         }
@@ -53,6 +54,7 @@
           lowerCase: false,
           locations: [
             { type: 'statement', location: { 'first_line': 1, 'last_line': 1, 'first_column': 1, 'last_column': 16 } },
+            { type: 'statementType', location: { first_line: 1, last_line: 1, first_column: 1, last_column: 9 }, identifier: 'DESCRIBE' },
             { type: 'database', location: { first_line: 1, last_line: 1, first_column: 10, last_column: 12 }, identifierChain: [{ name: 'db' }]},
             { type: 'table', location: { first_line: 1, last_line: 1, first_column: 13, last_column: 16}, identifierChain: [{ name: 'db' }, { name: 'tbl' }] }
           ]

+ 2 - 0
desktop/core/src/desktop/static/desktop/js/autocomplete/spec/sqlSpecDrop.js

@@ -980,11 +980,13 @@
         assertAutoComplete({
           beforeCursor: 'DROP TABLE foo ',
           afterCursor: '',
+          dialect: 'impala',
           expectedResult: {
             lowerCase: false,
             suggestKeywords: ['PURGE'],
             locations: [
               { type: 'statement', location: { first_line: 1, last_line: 1, first_column: 1, last_column: 15 } },
+              { type: 'statementType', location: { first_line: 1, last_line: 1, first_column: 1, last_column: 5 }, identifier: 'DROP TABLE' },
               {type: 'table', location: { first_line: 1, last_line: 1, first_column: 12, last_column: 15}, identifierChain: [{ name: 'foo' }]}
             ]
           }

+ 17 - 0
desktop/core/src/desktop/static/desktop/js/autocomplete/spec/sqlSpecLocations.js

@@ -41,6 +41,7 @@
         dialect: 'impala',
         expectedLocations: [
           { type: 'statement', location: { first_line: 1, last_line: 1, first_column: 1, last_column: 38 } },
+          { type: 'statementType', location: { first_line: 1, last_line: 1, first_column: 1, last_column: 7 }, identifier: 'SELECT' },
           { type: 'selectList', missing: false, location: { first_line: 1, last_line: 1, first_column: 8, last_column: 9 } },
           { type: 'asterisk', location: { first_line: 1, last_line: 1, first_column: 8, last_column: 9 }, tables: [{ alias: 'c', identifierChain: [{ name: 'customers' }] }, { alias: 'o', identifierChain: [{ name: 'customers' }, { name: 'orders' }] }] },
           { type: 'table', location: { first_line: 1, last_line: 1, first_column: 15, last_column: 24 }, identifierChain: [{ name: 'customers' }] },
@@ -60,6 +61,7 @@
         dialect: 'impala',
         expectedLocations: [
           { type: 'statement', location: { first_line: 1, last_line: 1, first_column: 1, last_column: 47 } },
+          { type: 'statementType', location: { first_line: 1, last_line: 1, first_column: 1, last_column: 7 }, identifier: 'SELECT' },
           { type: 'selectList', missing: false, location: { first_line: 1, last_line: 1, first_column: 8, last_column: 18 } },
           { type: 'complex', location: { first_line: 1, last_line: 1, first_column: 8, last_column: 9 }, identifierChain: [{ name: 'customers' }, { name: 'orders' }], qualified: false },
           { type: 'complex', location: { first_line: 1, last_line: 1, first_column: 10, last_column: 18 }, identifierChain: [{ name: 'order_id' }], qualified: true, tables: [{ identifierChain: [{ name: 'customers' }, { name: 'orders' }], alias: 'o' }] },
@@ -81,6 +83,7 @@
         dialect: 'impala',
         expectedLocations: [
           { type: 'statement', location: { first_line: 1, last_line: 1, first_column: 1, last_column: 42 } },
+          { type: 'statementType', location: { first_line: 1, last_line: 1, first_column: 1, last_column: 7 }, identifier: 'SELECT' },
           { type: 'selectList', missing: false, location: { first_line: 1, last_line: 1, first_column: 8, last_column: 12 } },
           // TODO: Does it matter if we mark following as complex or column?
           { type: 'complex', location: { first_line: 1, last_line: 1, first_column: 8, last_column: 10 }, identifierChain: [{ name: 'testTable' }, { name: 'testMap' }], qualified: false },
@@ -101,6 +104,7 @@
         dialect: 'impala',
         expectedLocations: [
           { type: 'statement', location: { first_line: 1, last_line: 1, first_column: 1, last_column: 69 } },
+          { type: 'statementType', location: { first_line: 1, last_line: 1, first_column: 1, last_column: 7 }, identifier: 'SELECT' },
           { type: 'selectList', missing: false, location: { first_line: 1, last_line: 1, first_column: 8, last_column: 9 } },
           { type: 'asterisk', location: { first_line: 1, last_line: 1, first_column: 8, last_column: 9 }, tables: [{ alias: 'c', identifierChain: [{ name: 'customers' }] }, { alias: 'o', identifierChain: [{ name: 'customers' }, { name: 'orders' }] }, { identifierChain: [{ subQuery: 'v' }] }] },
           { type: 'table', location: { first_line: 1, last_line: 1, first_column: 15, last_column: 24 }, identifierChain: [{ name: 'customers' }] },
@@ -108,6 +112,7 @@
           { type: 'table', location: { first_line: 1, last_line: 1, first_column: 28, last_column: 29 }, identifierChain: [{ name: 'customers' }] },
           { type: 'column', location: { first_line: 1, last_line: 1, first_column: 30, last_column: 36 }, identifierChain: [{ name: 'orders' }], tables: [{ identifierChain: [{ name: 'customers' }], alias: 'c' }], qualified: false },
           { type: 'alias', source: 'table', alias: 'o', location: { first_line: 1, last_line: 1, first_column: 37, last_column: 38 }, identifierChain: [{ name: 'c' }, { name: 'orders' }] },
+          { type: 'statementType', location: { first_line: 1, last_line: 1, first_column: 41, last_column: 47 }, identifier: 'SELECT' },
           { type: 'selectList', missing: false, location: { first_line: 1, last_line: 1, first_column: 48, last_column: 53 }, subquery: true },
           { type: 'column', location: { first_line: 1, last_line: 1, first_column: 48, last_column: 53 }, identifierChain: [{ name: 'price' }], qualified: false, tables: [{ identifierChain: [{ name: 'customers' }, { name: 'orders' }, { name: 'items' }] }] },
           { type: 'complex', location: { first_line: 1, last_line: 1, first_column: 59, last_column: 60 }, identifierChain: [{ name: 'customers' }, { name: 'orders' }] },
@@ -197,6 +202,7 @@
         beforeCursor: 'SELECT db.tbl.col FROM db.tbl; ',
         expectedLocations: [
           { type: 'statement', location: { first_line: 1, last_line: 1, first_column: 1, last_column: 30 } },
+          { type: 'statementType', location: { first_line: 1, last_line: 1, first_column: 1, last_column: 7 }, identifier: 'SELECT' },
           { type: 'selectList', missing: false, location: { first_line: 1, last_line: 1, first_column: 8, last_column: 18 } },
           { type: 'database', location: { first_line: 1, last_line: 1, first_column: 8, last_column: 10 }, identifierChain: [{ name: 'db' }]},
           { type: 'table', location: { first_line: 1, last_line: 1, first_column: 11, last_column: 14 }, identifierChain: [{ name: 'db' }, { name: 'tbl' }]},
@@ -215,6 +221,7 @@
         dialect: 'impala',
         expectedLocations: [
           { type: 'statement', location: { first_line: 1, last_line: 1, first_column: 1, last_column: 23 } },
+          { type: 'statementType', location: { first_line: 1, last_line: 1, first_column: 1, last_column: 7 }, identifier: 'SELECT' },
           { type: 'selectList', missing: false, location: { first_line: 1, last_line: 1, first_column: 8, last_column: 11 } },
           { type: 'column', location: { first_line: 1, last_line: 1, first_column: 8, last_column: 11 }, identifierChain: [ { name: 'tbl' }], tables: [{ identifierChain: [{ name: 'db' }, { name: 'tbl' }] }], qualified: false },
           { type: 'database', location: { first_line: 1, last_line: 1, first_column: 17, last_column: 19 }, identifierChain: [{ name: 'db' }] },
@@ -231,6 +238,7 @@
         dialect: 'impala',
         expectedLocations: [
           { type: 'statement', location: { first_line: 1, last_line: 1, first_column: 1, last_column: 27 } },
+          { type: 'statementType', location: { first_line: 1, last_line: 1, first_column: 1, last_column: 7 }, identifier: 'SELECT' },
           { type: 'selectList', missing: false, location: { first_line: 1, last_line: 1, first_column: 8, last_column: 15 } },
           { type: 'table', location: { first_line: 1, last_line: 1, first_column: 8, last_column: 11 }, identifierChain: [{ name: 'db' }, { name: 'tbl' }] },
           { type: 'column', location: { first_line: 1, last_line: 1, first_column: 12, last_column: 15 }, identifierChain: [{ name: 'col' }], tables: [{ identifierChain: [{ name: 'db' }, { name: 'tbl' }] }], qualified: true },
@@ -565,6 +573,7 @@
           beforeCursor: 'CREATE TABLE bla (id INT) LOCATION \'/bla/bla/\';',
           expectedLocations: [
             { type: 'statement', location: { first_line: 1, last_line: 1, first_column: 1, last_column: 47 } },
+            { type: 'statementType', location: { first_line: 1, last_line: 1, first_column: 1, last_column: 7 }, identifier: 'CREATE TABLE' },
             { type: 'file', location: {first_line: 1, last_line: 1, first_column: 37, last_column: 46}, path: '/bla/bla/' }
           ]
         });
@@ -888,6 +897,7 @@
           afterCursor: '',
           expectedLocations: [
             { type: 'statement', location: { first_line: 1, last_line: 1, first_column: 1, last_column: 271 } },
+            { type: 'statementType', location: { first_line: 1, last_line: 1, first_column: 1, last_column: 7 }, identifier: 'SELECT' },
             { type: 'selectList', missing: false, location: { first_line: 1, last_line: 1, first_column: 8, last_column: 36 } },
             { type: 'subQuery', location: { first_line: 1, last_line: 1, first_column: 8, last_column: 11 }, identifierChain: [{ subQuery: 'tmp' }]},
             { type: 'column', location: { first_line: 1, last_line: 1, first_column: 12, last_column: 14 }, identifierChain: [{ name: 'bc' }], tables: [{ subQuery: 'tmp' }], qualified: true },
@@ -895,6 +905,7 @@
             { type: 'subQuery', location: { first_line: 1, last_line: 1, first_column: 22, last_column: 25 }, identifierChain: [{ subQuery: 'tmp' }]},
             { type: 'column', location: { first_line: 1, last_line: 1, first_column: 26, last_column: 27 }, identifierChain: [{ name: 'r' }], tables: [{ subQuery: 'tmp' }], qualified: true },
             { type: 'alias', source: 'column', alias: 'r', location: { first_line: 1, last_line: 1, first_column: 35, last_column: 36 }, parentLocation: { first_line: 1, last_line: 1, first_column: 16, last_column: 31 } },
+            { type: 'statementType', location: { first_line: 1, last_line: 1, first_column: 44, last_column: 50 }, identifier: 'SELECT' },
             { type: 'selectList', missing: false, location: { first_line: 1, last_line: 1, first_column: 51, last_column: 108 }, subquery: true },
             { type: 'database', location: { first_line: 1, last_line: 1, first_column: 51, last_column: 57 }, identifierChain: [{ name: 'tstDb1' }]},
             { type: 'table', location: { first_line: 1, last_line: 1, first_column: 58, last_column: 60 }, identifierChain: [{ name:'tstDb1' }, { name: 'b1' }]},
@@ -938,6 +949,7 @@
           afterCursor: '',
           expectedLocations: [
             { type: 'statement', location: { first_line: 1, last_line: 1, first_column: 1, last_column: 53 } },
+            { type: 'statementType', location: { first_line: 1, last_line: 1, first_column: 1, last_column: 7 }, identifier: 'SELECT' },
             { type: 'selectList', missing: false, location: { first_line: 1, last_line: 1, first_column: 8, last_column: 9 } },
             { type: 'asterisk', location: { first_line: 1, last_line: 1, first_column: 8, last_column: 9 }, tables: [{ identifierChain: [{ name: 'testTable' }] }] },
             { type: 'table', location: { first_line: 1, last_line: 1, first_column: 15, last_column: 24 }, identifierChain: [{ name: 'testTable' }]},
@@ -959,6 +971,7 @@
             beforeCursor: 'select a as b from tbl where b = ${var_name=10}; ',
             expectedLocations: [
               { type: 'statement', location: { first_line: 1, last_line: 1, first_column: 1, last_column: 48 } },
+              { type: 'statementType', location: { first_line: 1, last_line: 1, first_column: 1, last_column: 7 }, identifier: 'SELECT' },
               { type: 'selectList', missing: false, location: { first_line: 1, last_line: 1, first_column: 8, last_column: 14 } },
               { type: 'column', location: { first_line: 1, last_line: 1, first_column: 8, last_column: 9 }, identifierChain: [{ name: 'a' }], qualified: false, alias: 'b', tables: [{ identifierChain: [{ name: 'tbl' }] }] },
               { type: 'alias', source: 'column', alias: 'b', location: { first_line: 1, last_line: 1, first_column: 13, last_column: 14 }, parentLocation: { first_line: 1, last_line: 1, first_column: 8, last_column: 9 } },
@@ -994,6 +1007,7 @@
             afterCursor: '',
             expectedLocations: [
               { type: 'statement', location: { first_line: 1, last_line: 1, first_column: 1, last_column: 48 } },
+              { type: 'statementType', location: { first_line: 1, last_line: 1, first_column: 1, last_column: 7 }, identifier: 'SELECT' },
               { type: 'selectList', missing: false, location: { first_line: 1, last_line: 1, first_column: 8, last_column: 9 } },
               { type: 'asterisk', location: { first_line: 1, last_line: 1, first_column: 8, last_column: 9 }, tables: [{ identifierChain: [{ name: 'testTable' }] }] },
               { type: 'table', location: { first_line: 1, last_line: 1, first_column: 15, last_column: 24 }, identifierChain: [{ name: 'testTable' }] },
@@ -1012,6 +1026,7 @@
             afterCursor: '',
             expectedLocations: [
               { type: 'statement', location: { first_line: 1, last_line: 1, first_column: 1, last_column: 49 } },
+              { type: 'statementType', location: { first_line: 1, last_line: 1, first_column: 1, last_column: 7 }, identifier: 'SELECT' },
               { type: 'selectList', missing: false, location: { first_line: 1, last_line: 1, first_column: 8, last_column: 9 } },
               { type: 'asterisk', location: { first_line: 1, last_line: 1, first_column: 8, last_column: 9 }, tables: [{ identifierChain: [{ name: 'tbl1' }] }, { identifierChain: [{ name: 'tbl2' }] }] },
               { type: 'table', location: { first_line: 1, last_line: 1, first_column: 15, last_column: 19 }, identifierChain: [{ name: 'tbl1' }] },
@@ -1031,6 +1046,7 @@
             afterCursor: '',
             expectedLocations: [
               { type: 'statement', location: { first_line: 1, last_line: 1, first_column: 1, last_column: 54 } },
+              { type: 'statementType', location: { first_line: 1, last_line: 1, first_column: 1, last_column: 7 }, identifier: 'SELECT' },
               { type: 'selectList', missing: false, location: { first_line: 1, last_line: 1, first_column: 8, last_column: 9 } },
               { type: 'asterisk', location: { first_line: 1, last_line: 1, first_column: 8, last_column: 9 }, tables: [{ identifierChain: [{ name: 'tbl1' }] }, { identifierChain: [{ name: 'tbl2' }] }] },
               { type: 'table', location: { first_line: 1, last_line: 1, first_column: 15, last_column: 19 }, identifierChain: [{ name: 'tbl1' }] },
@@ -1051,6 +1067,7 @@
             afterCursor: '',
             expectedLocations: [
               { type: 'statement', location: { first_line: 1, last_line: 1, first_column: 1, last_column: 60 } },
+              { type: 'statementType', location: { first_line: 1, last_line: 1, first_column: 1, last_column: 7 }, identifier: 'SELECT' },
               { type: 'selectList', missing: false, location: { first_line: 1, last_line: 1, first_column: 8, last_column: 9 } },
               { type: 'asterisk', location: { first_line: 1, last_line: 1, first_column: 8, last_column: 9 }, tables: [{ identifierChain: [{ name: 'tbl1' }] }, { identifierChain: [{ name: 'somedb' }, { name: 'tbl2' }] }] },
               { type: 'table', location: { first_line: 1, last_line: 1, first_column: 15, last_column: 19 }, identifierChain: [{ name: 'tbl1' }] },

Plik diff jest za duży
+ 0 - 0
desktop/core/src/desktop/static/desktop/js/autocomplete/sqlAutocompleteParser.js


+ 71 - 3
desktop/core/src/desktop/static/desktop/js/autocomplete/sqlParseSupport.js

@@ -1479,6 +1479,74 @@ var SqlParseSupport = (function () {
       parser.yy.locations.push(location)
     };
 
+    parser.addStatementTypeLocation = function (identifier, location, additionalText) {
+      if (!parser.isImpala()) {
+        return;
+      }
+      var loc = {
+        type: 'statementType',
+        location: adjustLocationForCursor(location),
+        identifier: identifier
+      };
+      if (typeof additionalText !== 'undefined') {
+        switch (identifier) {
+          case 'ALTER':
+            if (/ALTER\s+VIEW/i.test(additionalText)) {
+              loc.identifier = 'ALTER VIEW';
+            } else {
+              loc.identifier = 'ALTER TABLE';
+            }
+            break;
+          case 'COMPUTE':
+            loc.identifier = 'COMPUTE STATS';
+            break;
+          case 'CREATE':
+            if (/CREATE\s+VIEW/i.test(additionalText)) {
+              loc.identifier = 'CREATE VIEW';
+            } else if (/CREATE\s+TABLE/i.test(additionalText)) {
+              loc.identifier = 'CREATE TABLE';
+            } else if (/CREATE\s+DATABASE/i.test(additionalText)) {
+              loc.identifier = 'CREATE DATABASE';
+            } else if (/CREATE\s+ROLE/i.test(additionalText)) {
+              loc.identifier = 'CREATE ROLE';
+            } else if (/CREATE\s+FUNCTION/i.test(additionalText)) {
+              loc.identifier = 'CREATE FUNCTION';
+            } else {
+              loc.identifier = 'CREATE TABLE';
+            }
+            break;
+          case 'DROP':
+            if (/DROP\s+VIEW/i.test(additionalText)) {
+              loc.identifier = 'DROP VIEW';
+            } else if (/DROP\s+TABLE/i.test(additionalText)) {
+              loc.identifier = 'DROP TABLE';
+            } else if (/DROP\s+DATABASE/i.test(additionalText)) {
+              loc.identifier = 'DROP DATABASE';
+            } else if (/DROP\s+ROLE/i.test(additionalText)) {
+              loc.identifier = 'DROP ROLE';
+            } else if (/DROP\s+STATS/i.test(additionalText)) {
+              loc.identifier = 'DROP STATS';
+            } else if (/DROP\s+FUNCTION/i.test(additionalText)) {
+              loc.identifier = 'DROP FUNCTION';
+            } else {
+              loc.identifier = 'DROP TABLE';
+            }
+            break;
+          case 'INVALIDATE':
+            loc.identifier = 'INVALIDATE METADATA';
+            break;
+          case 'LOAD':
+            loc.identifier = 'LOAD DATA';
+            break;
+          case 'TRUNCATE':
+            loc.identifier = 'TRUNCATE TABLE';
+            break;
+          default:
+        }
+      }
+      parser.yy.locations.push(loc);
+    };
+
     parser.addFileLocation = function (location, path) {
       parser.yy.locations.push({
         type: 'file',
@@ -1876,9 +1944,9 @@ var SqlParseSupport = (function () {
     'getSubQuery', 'addTablePrimary', 'suggestFileFormats', 'suggestDdlAndDmlKeywords', 'checkForSelectListKeywords', 'checkForKeywords',
     'suggestKeywords', 'suggestColRefKeywords', 'suggestTablesOrColumns', 'suggestFunctions', 'suggestAggregateFunctions', 'suggestAnalyticFunctions',
     'suggestColumns', 'suggestGroupBys', 'suggestIdentifiers', 'suggestOrderBys', 'suggestFilters', 'suggestKeyValues', 'suggestTables', 'addFunctionLocation',
-    'addStatementLocation', 'firstDefined', 'addClauseLocation', 'addFileLocation', 'addDatabaseLocation', 'addColumnAliasLocation', 'addTableAliasLocation',
-    'addSubqueryAliasLocation', 'addTableLocation', 'addAsteriskLocation', 'addVariableLocation', 'addColumnLocation', 'addCteAliasLocation', 'addUnknownLocation',
-    'addColRefToVariableIfExists', 'suggestDatabases', 'suggestHdfs', 'suggestValues'];
+    'addStatementLocation', 'firstDefined', 'addClauseLocation', 'addStatementTypeLocation', 'addFileLocation', 'addDatabaseLocation', 'addColumnAliasLocation',
+    'addTableAliasLocation', 'addSubqueryAliasLocation', 'addTableLocation', 'addAsteriskLocation', 'addVariableLocation', 'addColumnLocation', 'addCteAliasLocation',
+    'addUnknownLocation', 'addColRefToVariableIfExists', 'suggestDatabases', 'suggestHdfs', 'suggestValues'];
 
   var SYNTAX_PARSER_NOOP = function () {};
 

Plik diff jest za duży
+ 0 - 0
desktop/core/src/desktop/static/desktop/js/autocomplete/sqlSyntaxParser.js


+ 14 - 18
desktop/core/src/desktop/static/desktop/less/hue-assist.less

@@ -649,27 +649,23 @@
   padding: 10px;
   white-space: normal;
   overflow-x: auto;
+}
 
-  .sql-docs-inline-code {
-    font-family: @font-family-monospace;
-  }
-
-  .sql-docs-code-block {
-    display: block;
-    font-family: @font-family-monospace;
-    white-space: pre-wrap;
-    margin-bottom: 10px;
-    color: @cui-gray-700;
-  }
-
-  .sql-docs-variable {
-    font-family: @font-family-monospace;
-    color: @cui-steel;
-  }
+.sql-docs-inline-code {
+  font-family: @font-family-monospace;
+}
 
-  .sql-docs-note {
+.sql-docs-code-block {
+  display: block;
+  font-family: @font-family-monospace;
+  white-space: pre-wrap;
+  margin-bottom: 10px;
+  color: @cui-gray-700;
+}
 
-  }
+.sql-docs-variable {
+  font-family: @font-family-monospace;
+  color: @cui-steel;
 }
 
 .assist-function-signature {

+ 11 - 5
desktop/core/src/desktop/static/desktop/spec/autocompleterTestUtils.js

@@ -467,6 +467,14 @@ var SqlTestUtils = (function() {
               }
             }
 
+            if (testDefinition.dialect !== 'impala' && actualResponse.locations) {
+              actualResponse.locations = actualResponse.locations.filter(function (location) {
+                if (location.type !== 'statementType') {
+                  return location;
+                }
+              })
+            }
+
             if (testDefinition.locationsOnly) {
               return {
                 pass: resultEquals(actualResponse.locations, testDefinition.expectedLocations),
@@ -587,11 +595,9 @@ var SqlTestUtils = (function() {
     assertAutocomplete: function(testDefinition) {
       var debug = false;
       if (typeof testDefinition.dialect === 'undefined') {
-        expect(sqlAutocompleteParser.parseSql(testDefinition.beforeCursor, testDefinition.afterCursor, testDefinition.dialect, debug)).toEqualDefinition(testDefinition);
-        testDefinition.dialect = 'hive';
-        expect(sqlAutocompleteParser.parseSql(testDefinition.beforeCursor, testDefinition.afterCursor,  testDefinition.dialect, debug)).toEqualDefinition(testDefinition);
-        testDefinition.dialect = 'impala';
-        expect(sqlAutocompleteParser.parseSql(testDefinition.beforeCursor, testDefinition.afterCursor,  testDefinition.dialect, debug)).toEqualDefinition(testDefinition);
+        expect(sqlAutocompleteParser.parseSql(testDefinition.beforeCursor, testDefinition.afterCursor, undefined, debug)).toEqualDefinition(testDefinition);
+        expect(sqlAutocompleteParser.parseSql(testDefinition.beforeCursor, testDefinition.afterCursor, 'hive', debug)).toEqualDefinition(testDefinition);
+        expect(sqlAutocompleteParser.parseSql(testDefinition.beforeCursor, testDefinition.afterCursor, 'impala', debug)).toEqualDefinition(testDefinition);
       } else {
         expect(sqlAutocompleteParser.parseSql(testDefinition.beforeCursor, testDefinition.afterCursor, testDefinition.dialect, debug)).toEqualDefinition(testDefinition);
       }

+ 9 - 0
desktop/core/src/desktop/static/desktop/spec/sqlAutocompleter3Spec.js

@@ -28,6 +28,9 @@
           },
           namespace: function () {
             return { id: 'defaultNamespace' }
+          },
+          compute: function () {
+            return { id: 'defaultCompute' }
           }
         },
         editor: function () {
@@ -416,6 +419,12 @@
             database: function () {
               return 'default';
             },
+            namespace: function () {
+              return { id: 'defaultNamespace' }
+            },
+            compute: function () {
+              return { id: 'defaultCompute' }
+            },
             positionStatement: ko.observable(positionStatement)
           },
           editor: function () {

+ 59 - 9
desktop/core/src/desktop/templates/ko_components/ko_context_popover.mako

@@ -285,6 +285,29 @@ from metadata.conf import has_navigator
   <script type="text/html" id="context-catalog-doc-title">
   </script>
 
+  <script type="text/html" id="context-lang-ref-title">
+    <div class="hue-popover-title" style="white-space: nowrap; overflow: hidden; text-overflow: ellipsis; margin-right: 20px;">
+      <i class="fa fa-question muted" style="margin-top: 3px"></i> <span style="padding-left: 4px;" data-bind="text: title"></span>
+      <div class="hue-popover-title-actions">
+        <a class="pointer inactive-action" title="${ _('Pin') }" data-bind="visible: popover.pinEnabled, click: popover.pin"><i class="fa fa-fw fa-thumb-tack"></i></a>
+        <a class="pointer inactive-action" title="${ _('Close') }" data-bind="visible: !popover.closeDisabled, click: popover.close"><i class="fa fa-fw fa-times"></i></a>
+      </div>
+    </div>
+  </script>
+
+  <script type="text/html" id="context-lang-ref-contents">
+    <div class="context-popover-content">
+      <div class="context-popover-flex-fill" data-bind="html: body"></div>
+      <div class="context-popover-flex-bottom-links">
+        <div class="context-popover-link-row">
+          <a class="inactive-action pointer" data-bind="click: $parent.openInRightAssist">
+            <i style="font-size: 11px;" title="${ _("Show in Assist...") }" class="fa fa-search"></i> ${ _("Assist") }
+          </a>
+        </div>
+      </div>
+    </div>
+  </script>
+
   <script type="text/html" id="context-catalog-entry-title">
     <div class="hue-popover-title">
       <i class="hue-popover-title-icon fa muted" data-bind="css: catalogEntry() && catalogEntry().isView() ? 'fa-eye' : 'fa-table'"></i>
@@ -824,13 +847,35 @@ from metadata.conf import has_navigator
         self.activeTab = ko.observable('details');
       }
 
-      function HueAppContext(data) {
+      function LangRefContext(options) {
         var self = this;
-        self.data = data;
-        self.hasErrors = ko.observable(false);
-        self.loading = ko.observable(false);
-        self.template = 'context-hue-app-details';
-      }
+        self.popover = options.popover;
+        self.title = ko.observable();
+        self.body = ko.observable();
+
+        var topicId = 'topics/impala_' + options.data.identifier.toLowerCase().replace(/ /g, '_') + '.xml';
+
+        console.log(topicId);
+        var findTopic = function (topics) {
+          topics.some(function (topic) {
+            if (topic.id === topicId) {
+              self.title(topic.title);
+              self.body(topic.body);
+              return true;
+            }
+            if (findTopic(topic.children)) {
+              return true;
+            }
+          });
+        };
+
+        findTopic(impalaLangRefTopics);
+      };
+
+      LangRefContext.prototype.openInRightAssist = function () {
+        var self = this;
+        // TODO: implement
+      };
 
       function DocumentContext(data) {
         var self = this;
@@ -872,7 +917,7 @@ from metadata.conf import has_navigator
         huePubSub.publish('open.link', entry.details.link);
         huePubSub.publish('context.popover.hide');
         huePubSub.publish('global.search.close');
-      }
+      };
 
       DocumentContext.prototype.dispose = function () {
         var self = this;
@@ -1282,6 +1327,7 @@ from metadata.conf import has_navigator
         self.isDocument = params.data.type.toLowerCase() === 'hue';
         self.isCollection = params.data.type === 'collection';
         self.isCatalogEntry = !!params.data.catalogEntry;
+        self.isLangRef = params.data.type === 'statementType';
 
         if (self.isCatalogEntry && params.data.catalogEntry.getSourceType() === 'solr' && params.data.catalogEntry.isField()) {
           self.isCollection = true;
@@ -1321,6 +1367,10 @@ from metadata.conf import has_navigator
           self.contents = new CollectionContextTabs(self.data);
           self.title = self.data.catalogEntry.path.slice(1).join('.');
           self.iconClass = 'fa-search';
+        } else if (self.isLangRef) {
+          self.contents = new LangRefContext({ popover: self, data: params.data });
+          self.titleTemplate = 'context-lang-ref-title';
+          self.contentsTemplate = 'context-lang-ref-contents';
         } else {
           self.title = '';
           self.iconClass = 'fa-info';
@@ -1397,11 +1447,11 @@ from metadata.conf import has_navigator
       ContextPopoverViewModel.prototype.pin = function () {
         var self = this;
         hidePopover();
-        if (typeof self.contents.sample !== 'undefined') {
+        if (self.contents && typeof self.contents.sample !== 'undefined') {
           self.contents.sample.fetchedData(undefined);
         }
         huePubSub.publish('sql.context.pin', self);
-        if (self.contents.activeTab() === 'sample') {
+        if (self.contents && self.contents.activeTab() === 'sample') {
           self.contents.refetchSamples();
         }
       };

Niektóre pliki nie zostały wyświetlone z powodu dużej ilości zmienionych plików