Эх сурвалжийг харах

HUE-8576 [editor] Add backticked suggestion to the syntax checked for reserved keywords

Johan Ahlen 7 жил өмнө
parent
commit
961a3574c1

+ 8 - 0
desktop/core/src/desktop/static/desktop/js/autocomplete/spec/sqlSyntaxParserSpec.js

@@ -107,6 +107,14 @@
       expect(result).toBeTruthy();
     });
 
+    it('should find errors for "select * from using where a = 1;"', function () {
+      var result = sqlSyntaxParser.parseSyntax('select * from using where a = 1;', '', 'hive');
+      expect(result).toBeTruthy();
+      expect(result.expected.some(function (expected) { return expected.text === '`using`' })).toBeTruthy();
+      expect(result.expectedIdentifier).toBeTruthy();
+      expect(result.possibleReserved).toBeTruthy();
+    });
+
     it('should suggest expected words for "SLELECT "', function() {
       var result = sqlSyntaxParser.parseSyntax('SLELECT ', '');
       expect(result).toBeTruthy();

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

@@ -2066,7 +2066,7 @@ var SqlParseSupport = (function () {
       'EOF': true,
       'UNSIGNED_INTEGER': true,
       'UNSIGNED_INTEGER_E': true,
-      'REGULAR_IDENTIFIER': true, // TODO: Indicate that an identifier was expected
+      'REGULAR_IDENTIFIER': true,
       'CURSOR': true,
       'PARTIAL_CURSOR': true,
       'HDFS_START_QUOTE': true,
@@ -2144,7 +2144,17 @@ var SqlParseSupport = (function () {
           // Strip away the surrounding ' chars
           expected = expected.substring(1, expected.length - 1);
           // TODO: Only suggest alphanumeric?
-          if (!IGNORED_EXPECTED[expected] && /[a-z_]+/i.test(expected)) {
+          if (expected === 'REGULAR_IDENTIFIER') {
+            parser.yy.error.expectedIdentifier = true;
+            if (/^<[a-z]+>/.test(parser.yy.error.token)) {
+              var text = '`' + parser.yy.error.text + '`';
+              weightedExpected.push({
+                text: text,
+                distance: stringDistance(parser.yy.error.text, text, true)
+              });
+              parser.yy.error.possibleReserved = true;
+            }
+          } else if (!IGNORED_EXPECTED[expected] && /[a-z_]+/i.test(expected)) {
             if (dialect && expected.indexOf('<' + dialect + '>') == 0) {
               expected = expected.substring(dialect.length + 2);
             } else if (/^<[a-z]+>/.test(expected)) {