Browse Source

HUE-4031 [editor] Make sure the syntax parser has the same functions as the autocomplete parser

Johan Ahlen 8 years ago
parent
commit
3ac4014

+ 6 - 1
desktop/core/src/desktop/static/desktop/js/autocomplete/spec/sqlSyntaxParserSpec.js

@@ -69,13 +69,18 @@
       expect(result.loc.last_column).toEqual(11);
       expect(result.loc.last_column).toEqual(11);
     });
     });
 
 
-    it ('should find errors for "select *  form ', function () {
+    it('should find errors for "select *  form "', function () {
       var result = sqlSyntaxParser.parseSyntax('select *  form ', '');
       var result = sqlSyntaxParser.parseSyntax('select *  form ', '');
       expect(result).toBeTruthy();
       expect(result).toBeTruthy();
       expect(result.loc.first_column).toEqual(10);
       expect(result.loc.first_column).toEqual(10);
       expect(result.loc.last_column).toEqual(14);
       expect(result.loc.last_column).toEqual(14);
     });
     });
 
 
+    fit('should find errors for "select * from customers c cultster by awasd asd afd;"', function () {
+      var result = sqlSyntaxParser.parseSyntax('select * from customers c cultster by awasd asd afd;', '');
+      expect(result).toBeTruthy();
+    });
+
     it('should suggest expected words for "SLELECT "', function() {
     it('should suggest expected words for "SLELECT "', function() {
       var result = sqlSyntaxParser.parseSyntax('SLELECT ', '');
       var result = sqlSyntaxParser.parseSyntax('SLELECT ', '');
       expect(result).toBeTruthy();
       expect(result).toBeTruthy();

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

@@ -1543,10 +1543,26 @@ var SqlParseSupport = (function () {
     };
     };
   };
   };
 
 
+
+  var SYNTAX_PARSER_NOOP_FUNCTIONS = ['prepareNewStatement', 'addCommonTableExpressions', 'pushQueryState', 'popQueryState', 'suggestSelectListAliases',
+    'isHive', 'isImpala', 'mergeSuggestKeywords', 'suggestValueExpressionKeywords', 'getValueExpressionKeywords', 'getTypeKeywords',
+    'getColumnDataTypeKeywords', 'addColRefIfExists', 'selectListNoTableSuggest', 'suggestJoinConditions', 'suggestJoins', 'valueExpressionSuggest',
+    'applyTypeToSuggestions', 'findCaseType', 'findReturnTypes', 'applyArgumentTypesToSuggestions', 'commitLocations', 'expandImpalaIdentifierChain',
+    'identifyPartials', 'expandLateralViews', 'expandIdentifierChain', 'getSubQuery', 'addTablePrimary', 'suggestFileFormats', 'getKeywordsForOptionalsLR',
+    'suggestDdlAndDmlKeywords', 'checkForSelectListKeywords', 'checkForKeywords', 'createWeightedKeywords', 'suggestKeywords', 'suggestColRefKeywords',
+    'suggestTablesOrColumns', 'suggestFunctions', 'suggestAggregateFunctions', 'suggestAnalyticFunctions', 'suggestColumns', 'suggestGroupBys',
+    'suggestOrderBys', 'suggestFilters', 'suggestKeyValues', 'suggestTables', 'addFunctionLocation', 'addStatementLocation', 'addHdfsLocation',
+    'addDatabaseLocation', 'addTableLocation', 'addAsteriskLocation', 'addColumnLocation', 'addUnknownLocation', 'suggestDatabases', 'suggestHdfs',
+    'suggestValues', 'handleQuotedValueWithCursor'];
+
+  var SYNTAX_PARSER_NOOP = function () {};
+
   var initSyntaxParser = function (parser) {
   var initSyntaxParser = function (parser) {
-    parser.prepareNewStatement = function () {
-      // Empty for compatibility with the autocomplete parser
-    };
+
+    // Noop functions for compatibility with the autocomplete parser as the grammar is shared
+    SYNTAX_PARSER_NOOP_FUNCTIONS.forEach(function (noopFn) {
+      parser[noopFn] = SYNTAX_PARSER_NOOP
+    });
 
 
     parser.determineCase = function (text) {
     parser.determineCase = function (text) {
       if (!parser.yy.caseDetermined) {
       if (!parser.yy.caseDetermined) {