瀏覽代碼

HUE-6835 [autocomplete] Add support for integer division with DIV

Johan Ahlen 8 年之前
父節點
當前提交
096f8ebb53

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

@@ -320,6 +320,7 @@
 'DATABASE'                                 { return 'DATABASE'; }
 'DECIMAL'                                  { return 'DECIMAL'; }
 'DISTINCT'                                 { return 'DISTINCT'; }
+'DIV'                                      { return 'ARITHMETIC_OPERATOR'; }
 'DOUBLE'                                   { return 'DOUBLE'; }
 'DESC'                                     { return 'DESC'; }
 'DROP'                                     { parser.determineCase(yytext); return 'DROP'; }
@@ -465,15 +466,6 @@ ROW_NUMBER\s*\(                            { yy.lexer.unput('('); yytext = 'row_
 '^'                                        { return 'ARITHMETIC_OPERATOR'; }
 '&'                                        { return 'ARITHMETIC_OPERATOR'; }
 
-'-'                                        { return '-'; }
-'*'                                        { return '*'; }
-'+'                                        { return 'ARITHMETIC_OPERATOR'; }
-'/'                                        { return 'ARITHMETIC_OPERATOR'; }
-'%'                                        { return 'ARITHMETIC_OPERATOR'; }
-'|'                                        { return 'ARITHMETIC_OPERATOR'; }
-'^'                                        { return 'ARITHMETIC_OPERATOR'; }
-'&'                                        { return 'ARITHMETIC_OPERATOR'; }
-
 ','                                        { return ','; }
 '.'                                        { return '.'; }
 ':'                                        { return ':'; }

+ 28 - 1
desktop/core/src/desktop/static/desktop/js/autocomplete/spec/sqlSpecSelect.js

@@ -87,7 +87,7 @@
       assertAutoComplete({
         beforeCursor: 'SELECT foo, bar ',
         afterCursor: '',
-        containsKeywords: ['AS', '+', 'FROM'],
+        containsKeywords: ['AS', '+', 'FROM', 'DIV'],
         expectedResult: {
           lowerCase: false,
           suggestTables:{
@@ -264,10 +264,35 @@
     });
 
     describe('Complete Statements', function () {
+      it('should handle "SELECT 4 / 2; |"', function () {
+        assertAutoComplete({
+          beforeCursor: 'SELECT 4 / 2; ',
+          afterCursor: '',
+          noErrors: true,
+          containsKeywords: ['SELECT'],
+          expectedResult: {
+            lowerCase: false
+          }
+        });
+      });
+
+      it('should handle "SELECT 4 DIV 2; |"', function () {
+        assertAutoComplete({
+          beforeCursor: 'SELECT 4 DIV 2; ',
+          afterCursor: '',
+          noErrors: true,
+          containsKeywords: ['SELECT'],
+          expectedResult: {
+            lowerCase: false
+          }
+        });
+      });
+
       it ('should handle "SELECT bla NOT RLIKE \'ble\', ble NOT REGEXP \'b\' FROM tbl; |"', function () {
         assertAutoComplete({
           beforeCursor: 'SELECT bla NOT RLIKE \'ble\', ble NOT REGEXP \'b\' FROM tbl; ',
           afterCursor: '',
+          noErrors: true,
           containsKeywords: ['SELECT'],
           expectedResult: {
             lowerCase: false
@@ -1086,6 +1111,7 @@
         assertAutoComplete({
           beforeCursor: 'SELECT row_number() OVER (PARTITION BY a) FROM testTable;',
           afterCursor: '',
+          noErrors: true,
           containsKeywords: ['SELECT'],
           expectedResult: {
             lowerCase: false
@@ -1097,6 +1123,7 @@
         assertAutoComplete({
           beforeCursor: 'SELECT COUNT(DISTINCT a) OVER (PARTITION by c) FROM testTable;',
           afterCursor: '',
+          noErrors: true,
           containsKeywords: ['SELECT'],
           expectedResult: {
             lowerCase: false

文件差異過大導致無法顯示
+ 0 - 0
desktop/core/src/desktop/static/desktop/js/autocomplete/sqlAutocompleteParser.js


+ 2 - 2
desktop/core/src/desktop/static/desktop/js/autocomplete/sqlParseSupport.js

@@ -217,7 +217,7 @@ var SqlParseSupport = (function () {
           suggestKeywords: keywords,
           suggestColRefKeywords: {
             BOOLEAN: ['AND', 'OR'],
-            NUMBER: ['+', '-', '*', '/', '%'],
+            NUMBER: ['+', '-', '*', '/', '%', 'DIV'],
             STRING: ['LIKE', 'NOT LIKE', 'REGEX', 'RLIKE']
           }
         }
@@ -226,7 +226,7 @@ var SqlParseSupport = (function () {
         keywords = keywords.concat(['AND', 'OR']);
       }
       if (SqlFunctions.matchesType(parser.yy.activeDialect, ['NUMBER'], types)) {
-        keywords = keywords.concat(['+', '-', '*', '/', '%']);
+        keywords = keywords.concat(['+', '-', '*', '/', '%', 'DIV']);
       }
       if (SqlFunctions.matchesType(parser.yy.activeDialect, ['STRING'], types)) {
         keywords = keywords.concat(['LIKE', 'NOT LIKE', 'REGEX', 'RLIKE']);

文件差異過大導致無法顯示
+ 0 - 0
desktop/core/src/desktop/static/desktop/js/autocomplete/sqlSyntaxParser.js


+ 4 - 4
desktop/core/src/desktop/static/desktop/js/sqlUtils.js

@@ -20,7 +20,7 @@ var SqlUtils = (function () {
   var hiveReservedKeywords = {
     ALL: true, ALTER: true, AND: true, ARRAY: true, AS: true, AUTHORIZATION: true, BETWEEN: true, BIGINT: true, BINARY: true, BOOLEAN: true, BOTH: true, BY: true, CASE: true, CAST: true,
     CHAR: true, COLUMN: true, CONF: true, CREATE: true, CROSS: true, CUBE: true, CURRENT: true, CURRENT_DATE: true, CURRENT_TIMESTAMP: true, CURSOR: true,
-    DATABASE: true, DATE: true, DECIMAL: true, DELETE: true, DESCRIBE: true, DISTINCT: true, DOUBLE: true, DROP: true, ELSE: true, END: true, EXCHANGE: true, EXISTS: true,
+    DATABASE: true, DATE: true, DECIMAL: true, DELETE: true, DESCRIBE: true, DISTINCT: true, DIV: true, DOUBLE: true, DROP: true, ELSE: true, END: true, EXCHANGE: true, EXISTS: true,
     EXTENDED: true, EXTERNAL: true, FALSE: true, FETCH: true, FLOAT: true, FOLLOWING: true, FOR: true, FROM: true, FULL: true, FUNCTION: true, GRANT: true, GROUP: true,
     GROUPING: true, HAVING: true, IF: true, IMPORT: true, IN: true, INNER: true, INSERT: true, INT: true, INTERSECT: true, INTERVAL: true, INTO: true, IS: true, JOIN: true, LATERAL: true,
     LEFT: true, LESS: true, LIKE: true, LOCAL: true, MACRO: true, MAP: true, MORE: true, NONE: true, NOT: true, NULL: true, OF: true, ON: true, OR: true, ORDER: true, OUT: true, OUTER: true, OVER: true,
@@ -36,12 +36,12 @@ var SqlUtils = (function () {
   };
 
   var impalaReservedKeywords = {
-    ADD: true, AGGREGATE: true, ALL: true, ALTER: true, AND: true, API_VERSION: true, AS: true, ASC: true, AVRO: true, BETWEEN: true, BIGINT: true, BINARY: true, BOOLEAN: true, BY: true, CACHED: true, CASE: true, CAST: true, CHANGE: true, CHAR: true, CLASS: true, CLOSE_FN: true,
+    ADD: true, AGGREGATE: true, ALL: true, ALTER: true, AND: true, API_VERSION: true, ARRAY: true, AS: true, ASC: true, AVRO: true, BETWEEN: true, BIGINT: true, BINARY: true, BOOLEAN: true, BY: true, CACHED: true, CASE: true, CAST: true, CHANGE: true, CHAR: true, CLASS: true, CLOSE_FN: true,
     COLUMN: true, COLUMNS: true, COMMENT: true, COMPUTE: true, CREATE: true, CROSS: true, DATA: true, DATABASE: true, DATABASES: true, DATE: true, DATETIME: true, DECIMAL: true, DELIMITED: true, DESC: true, DESCRIBE: true, DISTINCT: true, DIV: true, DOUBLE: true, DROP: true, ELSE: true, END: true,
     ESCAPED: true, EXISTS: true, EXPLAIN: true, EXTERNAL: true, FALSE: true, FIELDS: true, FILEFORMAT: true, FINALIZE_FN: true, FIRST: true, FLOAT: true, FORMAT: true, FORMATTED: true, FROM: true, FULL: true, FUNCTION: true, FUNCTIONS: true, GROUP: true, HAVING: true, IF: true, IN: true, INCREMENTAL: true,
-    INIT_FN: true, INNER: true, INPATH: true, INSERT: true, INT: true, INTEGER: true, INTERMEDIATE: true, INTERVAL: true, INTO: true, INVALIDATE: true, IS: true, JOIN: true, KEY: true, KUDU: true, LAST: true, LEFT: true, LIKE: true, LIMIT: true, LINES: true, LOAD: true, LOCATION: true, MERGE_FN: true, METADATA: true,
+    INIT_FN: true, INNER: true, INPATH: true, INSERT: true, INT: true, INTEGER: true, INTERMEDIATE: true, INTERVAL: true, INTO: true, INVALIDATE: true, IS: true, JOIN: true, KEY: true, KUDU: true, LAST: true, LEFT: true, LIKE: true, LIMIT: true, LINES: true, LOAD: true, LOCATION: true, MAP: true, MERGE_FN: true, METADATA: true,
     NOT: true, NULL: true, NULLS: true, OFFSET: true, ON: true, OR: true, ORDER: true, OUTER: true, OVERWRITE: true, PARQUET: true, PARQUETFILE: true, PARTITION: true, PARTITIONED: true, PARTITIONS: true, PREPARE_FN: true, PRIMARY: true, PRODUCED: true, RCFILE: true, REAL: true, REFRESH: true, REGEXP: true, RENAME: true,
-    REPLACE: true, RETURNS: true, RIGHT: true, RLIKE: true, ROW: true, SCHEMA: true, SCHEMAS: true, SELECT: true, SEMI: true, SEQUENCEFILE: true, SERDEPROPERTIES: true, SERIALIZE_FN: true, SET: true, SHOW: true, SMALLINT: true, STATS: true, STORED: true, STRAIGHT_JOIN: true, STRING: true, SYMBOL: true, TABLE: true,
+    REPLACE: true, RETURNS: true, RIGHT: true, RLIKE: true, ROW: true, SCHEMA: true, SCHEMAS: true, SELECT: true, SEMI: true, SEQUENCEFILE: true, SERDEPROPERTIES: true, SERIALIZE_FN: true, SET: true, SHOW: true, SMALLINT: true, STATS: true, STORED: true, STRAIGHT_JOIN: true, STRING: true, STRUCT: true, SYMBOL: true, TABLE: true,
     TABLES: true, TBLPROPERTIES: true, TERMINATED: true, TEXTFILE: true, THEN: true, TIMESTAMP: true, TINYINT: true, TO: true, TRUE: true, UNCACHED: true, UNION: true, UPDATE_FN: true, USE: true, USING: true, VALUES: true, VIEW: true, WHEN: true, WHERE: true, WITH: true
   };
 

部分文件因文件數量過多而無法顯示