Переглянути джерело

HUE-9428 [editor] Fix issue where the syntax parsers fails parsing statements with UDFs

Johan Ahlen 5 роки тому
батько
коміт
8ba5f91a66
24 змінених файлів з 260 додано та 218 видалено
  1. 14 12
      desktop/core/src/desktop/js/parse/jison/sql/generic/sql_udf.jison
  2. 14 12
      desktop/core/src/desktop/js/parse/jison/sql/impala/sql_udf.jison
  3. 14 12
      desktop/core/src/desktop/js/parse/sql/calcite/calciteAutocompleteParser.js
  4. 14 12
      desktop/core/src/desktop/js/parse/sql/calcite/calciteSyntaxParser.js
  5. 14 12
      desktop/core/src/desktop/js/parse/sql/druid/druidAutocompleteParser.js
  6. 14 12
      desktop/core/src/desktop/js/parse/sql/druid/druidSyntaxParser.js
  7. 14 12
      desktop/core/src/desktop/js/parse/sql/elasticsearch/elasticsearchAutocompleteParser.js
  8. 14 12
      desktop/core/src/desktop/js/parse/sql/elasticsearch/elasticsearchSyntaxParser.js
  9. 14 12
      desktop/core/src/desktop/js/parse/sql/flink/flinkAutocompleteParser.js
  10. 14 12
      desktop/core/src/desktop/js/parse/sql/flink/flinkSyntaxParser.js
  11. 14 12
      desktop/core/src/desktop/js/parse/sql/generic/genericAutocompleteParser.js
  12. 14 12
      desktop/core/src/desktop/js/parse/sql/generic/genericSyntaxParser.js
  13. 0 0
      desktop/core/src/desktop/js/parse/sql/hive/hiveAutocompleteParser.js
  14. 0 0
      desktop/core/src/desktop/js/parse/sql/hive/hiveSyntaxParser.js
  15. 6 0
      desktop/core/src/desktop/js/parse/sql/hive/test/hiveSyntaxParser.test.js
  16. 14 12
      desktop/core/src/desktop/js/parse/sql/impala/impalaAutocompleteParser.js
  17. 14 12
      desktop/core/src/desktop/js/parse/sql/impala/impalaSyntaxParser.js
  18. 14 12
      desktop/core/src/desktop/js/parse/sql/ksql/ksqlAutocompleteParser.js
  19. 14 12
      desktop/core/src/desktop/js/parse/sql/ksql/ksqlSyntaxParser.js
  20. 14 12
      desktop/core/src/desktop/js/parse/sql/phoenix/phoenixAutocompleteParser.js
  21. 14 12
      desktop/core/src/desktop/js/parse/sql/phoenix/phoenixSyntaxParser.js
  22. 0 0
      desktop/core/src/desktop/js/parse/sql/presto/prestoAutocompleteParser.js
  23. 0 0
      desktop/core/src/desktop/js/parse/sql/presto/prestoSyntaxParser.js
  24. 2 2
      desktop/core/src/desktop/js/parse/sql/sqlParseUtils.js

+ 14 - 12
desktop/core/src/desktop/js/parse/jison/sql/generic/sql_udf.jison

@@ -21,18 +21,20 @@ NonParenthesizedValueExpressionPrimary
      // with columnReference for functions like: db.udf(foo)
      var fn = $1.chain[$1.chain.length - 1].name.toLowerCase();
      parser.addFunctionArgumentLocations(fn, $2.expressions, $1.chain);
-     $1.lastLoc.type = 'function';
-     $1.lastLoc.function = fn;
-     $1.lastLoc.location = {
-       first_line: $1.lastLoc.location.first_line,
-       last_line: $1.lastLoc.location.last_line,
-       first_column: $1.lastLoc.location.first_column,
-       last_column: $1.lastLoc.location.last_column - 1
-     }
-     if ($1.lastLoc !== $1.firstLoc) {
-        $1.firstLoc.type = 'database';
-     } else {
-       delete $1.lastLoc.identifierChain;
+     if ($1.lastLoc && $1.lastLoc.location) {
+       $1.lastLoc.type = 'function';
+       $1.lastLoc.function = fn;
+       $1.lastLoc.location = {
+         first_line: $1.lastLoc.location.first_line,
+         last_line: $1.lastLoc.location.last_line,
+         first_column: $1.lastLoc.location.first_column,
+         last_column: $1.lastLoc.location.last_column - 1
+       }
+       if ($1.lastLoc !== $1.firstLoc) {
+          $1.firstLoc.type = 'database';
+       } else {
+         delete $1.lastLoc.identifierChain;
+       }
      }
      if ($2.expressions && $2.expressions.length) {
        $$ = { function: fn, expression: $2.expressions[$2.expressions.length - 1].expression, types: ['UDFREF'] }

+ 14 - 12
desktop/core/src/desktop/js/parse/jison/sql/impala/sql_udf.jison

@@ -21,18 +21,20 @@ NonParenthesizedValueExpressionPrimary
      // with columnReference for functions like: db.udf(foo)
      var fn = $1.chain[$1.chain.length - 1].name.toLowerCase();
      parser.addFunctionArgumentLocations(fn, $2.expressions, $1.chain);
-     $1.lastLoc.type = 'function';
-     $1.lastLoc.function = fn;
-     $1.lastLoc.location = {
-       first_line: $1.lastLoc.location.first_line,
-       last_line: $1.lastLoc.location.last_line,
-       first_column: $1.lastLoc.location.first_column,
-       last_column: $1.lastLoc.location.last_column - 1
-     }
-     if ($1.lastLoc !== $1.firstLoc) {
-        $1.firstLoc.type = 'database';
-     } else {
-       delete $1.lastLoc.identifierChain;
+     if ($1.lastLoc && $1.lastLoc.location) {
+       $1.lastLoc.type = 'function';
+       $1.lastLoc.function = fn;
+       $1.lastLoc.location = {
+         first_line: $1.lastLoc.location.first_line,
+         last_line: $1.lastLoc.location.last_line,
+         first_column: $1.lastLoc.location.first_column,
+         last_column: $1.lastLoc.location.last_column - 1
+       }
+       if ($1.lastLoc !== $1.firstLoc) {
+          $1.firstLoc.type = 'database';
+       } else {
+         delete $1.lastLoc.identifierChain;
+       }
      }
      if ($2.expressions && $2.expressions.length) {
        $$ = { function: fn, expression: $2.expressions[$2.expressions.length - 1].expression, types: ['UDFREF'] }

+ 14 - 12
desktop/core/src/desktop/js/parse/sql/calcite/calciteAutocompleteParser.js

@@ -1743,18 +1743,20 @@ case 870:
      // with columnReference for functions like: db.udf(foo)
      var fn = $$[$0-1].chain[$$[$0-1].chain.length - 1].name.toLowerCase();
      parser.addFunctionArgumentLocations(fn, $$[$0].expressions, $$[$0-1].chain);
-     $$[$0-1].lastLoc.type = 'function';
-     $$[$0-1].lastLoc.function = fn;
-     $$[$0-1].lastLoc.location = {
-       first_line: $$[$0-1].lastLoc.location.first_line,
-       last_line: $$[$0-1].lastLoc.location.last_line,
-       first_column: $$[$0-1].lastLoc.location.first_column,
-       last_column: $$[$0-1].lastLoc.location.last_column - 1
-     }
-     if ($$[$0-1].lastLoc !== $$[$0-1].firstLoc) {
-        $$[$0-1].firstLoc.type = 'database';
-     } else {
-       delete $$[$0-1].lastLoc.identifierChain;
+     if ($$[$0-1].lastLoc && $$[$0-1].lastLoc.location) {
+       $$[$0-1].lastLoc.type = 'function';
+       $$[$0-1].lastLoc.function = fn;
+       $$[$0-1].lastLoc.location = {
+         first_line: $$[$0-1].lastLoc.location.first_line,
+         last_line: $$[$0-1].lastLoc.location.last_line,
+         first_column: $$[$0-1].lastLoc.location.first_column,
+         last_column: $$[$0-1].lastLoc.location.last_column - 1
+       }
+       if ($$[$0-1].lastLoc !== $$[$0-1].firstLoc) {
+          $$[$0-1].firstLoc.type = 'database';
+       } else {
+         delete $$[$0-1].lastLoc.identifierChain;
+       }
      }
      if ($$[$0].expressions && $$[$0].expressions.length) {
        this.$ = { function: fn, expression: $$[$0].expressions[$$[$0].expressions.length - 1].expression, types: ['UDFREF'] }

+ 14 - 12
desktop/core/src/desktop/js/parse/sql/calcite/calciteSyntaxParser.js

@@ -1693,18 +1693,20 @@ case 815:
      // with columnReference for functions like: db.udf(foo)
      var fn = $$[$0-1].chain[$$[$0-1].chain.length - 1].name.toLowerCase();
      parser.addFunctionArgumentLocations(fn, $$[$0].expressions, $$[$0-1].chain);
-     $$[$0-1].lastLoc.type = 'function';
-     $$[$0-1].lastLoc.function = fn;
-     $$[$0-1].lastLoc.location = {
-       first_line: $$[$0-1].lastLoc.location.first_line,
-       last_line: $$[$0-1].lastLoc.location.last_line,
-       first_column: $$[$0-1].lastLoc.location.first_column,
-       last_column: $$[$0-1].lastLoc.location.last_column - 1
-     }
-     if ($$[$0-1].lastLoc !== $$[$0-1].firstLoc) {
-        $$[$0-1].firstLoc.type = 'database';
-     } else {
-       delete $$[$0-1].lastLoc.identifierChain;
+     if ($$[$0-1].lastLoc && $$[$0-1].lastLoc.location) {
+       $$[$0-1].lastLoc.type = 'function';
+       $$[$0-1].lastLoc.function = fn;
+       $$[$0-1].lastLoc.location = {
+         first_line: $$[$0-1].lastLoc.location.first_line,
+         last_line: $$[$0-1].lastLoc.location.last_line,
+         first_column: $$[$0-1].lastLoc.location.first_column,
+         last_column: $$[$0-1].lastLoc.location.last_column - 1
+       }
+       if ($$[$0-1].lastLoc !== $$[$0-1].firstLoc) {
+          $$[$0-1].firstLoc.type = 'database';
+       } else {
+         delete $$[$0-1].lastLoc.identifierChain;
+       }
      }
      if ($$[$0].expressions && $$[$0].expressions.length) {
        this.$ = { function: fn, expression: $$[$0].expressions[$$[$0].expressions.length - 1].expression, types: ['UDFREF'] }

+ 14 - 12
desktop/core/src/desktop/js/parse/sql/druid/druidAutocompleteParser.js

@@ -1731,18 +1731,20 @@ case 868:
      // with columnReference for functions like: db.udf(foo)
      var fn = $$[$0-1].chain[$$[$0-1].chain.length - 1].name.toLowerCase();
      parser.addFunctionArgumentLocations(fn, $$[$0].expressions, $$[$0-1].chain);
-     $$[$0-1].lastLoc.type = 'function';
-     $$[$0-1].lastLoc.function = fn;
-     $$[$0-1].lastLoc.location = {
-       first_line: $$[$0-1].lastLoc.location.first_line,
-       last_line: $$[$0-1].lastLoc.location.last_line,
-       first_column: $$[$0-1].lastLoc.location.first_column,
-       last_column: $$[$0-1].lastLoc.location.last_column - 1
-     }
-     if ($$[$0-1].lastLoc !== $$[$0-1].firstLoc) {
-        $$[$0-1].firstLoc.type = 'database';
-     } else {
-       delete $$[$0-1].lastLoc.identifierChain;
+     if ($$[$0-1].lastLoc && $$[$0-1].lastLoc.location) {
+       $$[$0-1].lastLoc.type = 'function';
+       $$[$0-1].lastLoc.function = fn;
+       $$[$0-1].lastLoc.location = {
+         first_line: $$[$0-1].lastLoc.location.first_line,
+         last_line: $$[$0-1].lastLoc.location.last_line,
+         first_column: $$[$0-1].lastLoc.location.first_column,
+         last_column: $$[$0-1].lastLoc.location.last_column - 1
+       }
+       if ($$[$0-1].lastLoc !== $$[$0-1].firstLoc) {
+          $$[$0-1].firstLoc.type = 'database';
+       } else {
+         delete $$[$0-1].lastLoc.identifierChain;
+       }
      }
      if ($$[$0].expressions && $$[$0].expressions.length) {
        this.$ = { function: fn, expression: $$[$0].expressions[$$[$0].expressions.length - 1].expression, types: ['UDFREF'] }

+ 14 - 12
desktop/core/src/desktop/js/parse/sql/druid/druidSyntaxParser.js

@@ -1681,18 +1681,20 @@ case 813:
      // with columnReference for functions like: db.udf(foo)
      var fn = $$[$0-1].chain[$$[$0-1].chain.length - 1].name.toLowerCase();
      parser.addFunctionArgumentLocations(fn, $$[$0].expressions, $$[$0-1].chain);
-     $$[$0-1].lastLoc.type = 'function';
-     $$[$0-1].lastLoc.function = fn;
-     $$[$0-1].lastLoc.location = {
-       first_line: $$[$0-1].lastLoc.location.first_line,
-       last_line: $$[$0-1].lastLoc.location.last_line,
-       first_column: $$[$0-1].lastLoc.location.first_column,
-       last_column: $$[$0-1].lastLoc.location.last_column - 1
-     }
-     if ($$[$0-1].lastLoc !== $$[$0-1].firstLoc) {
-        $$[$0-1].firstLoc.type = 'database';
-     } else {
-       delete $$[$0-1].lastLoc.identifierChain;
+     if ($$[$0-1].lastLoc && $$[$0-1].lastLoc.location) {
+       $$[$0-1].lastLoc.type = 'function';
+       $$[$0-1].lastLoc.function = fn;
+       $$[$0-1].lastLoc.location = {
+         first_line: $$[$0-1].lastLoc.location.first_line,
+         last_line: $$[$0-1].lastLoc.location.last_line,
+         first_column: $$[$0-1].lastLoc.location.first_column,
+         last_column: $$[$0-1].lastLoc.location.last_column - 1
+       }
+       if ($$[$0-1].lastLoc !== $$[$0-1].firstLoc) {
+          $$[$0-1].firstLoc.type = 'database';
+       } else {
+         delete $$[$0-1].lastLoc.identifierChain;
+       }
      }
      if ($$[$0].expressions && $$[$0].expressions.length) {
        this.$ = { function: fn, expression: $$[$0].expressions[$$[$0].expressions.length - 1].expression, types: ['UDFREF'] }

+ 14 - 12
desktop/core/src/desktop/js/parse/sql/elasticsearch/elasticsearchAutocompleteParser.js

@@ -1731,18 +1731,20 @@ case 868:
      // with columnReference for functions like: db.udf(foo)
      var fn = $$[$0-1].chain[$$[$0-1].chain.length - 1].name.toLowerCase();
      parser.addFunctionArgumentLocations(fn, $$[$0].expressions, $$[$0-1].chain);
-     $$[$0-1].lastLoc.type = 'function';
-     $$[$0-1].lastLoc.function = fn;
-     $$[$0-1].lastLoc.location = {
-       first_line: $$[$0-1].lastLoc.location.first_line,
-       last_line: $$[$0-1].lastLoc.location.last_line,
-       first_column: $$[$0-1].lastLoc.location.first_column,
-       last_column: $$[$0-1].lastLoc.location.last_column - 1
-     }
-     if ($$[$0-1].lastLoc !== $$[$0-1].firstLoc) {
-        $$[$0-1].firstLoc.type = 'database';
-     } else {
-       delete $$[$0-1].lastLoc.identifierChain;
+     if ($$[$0-1].lastLoc && $$[$0-1].lastLoc.location) {
+       $$[$0-1].lastLoc.type = 'function';
+       $$[$0-1].lastLoc.function = fn;
+       $$[$0-1].lastLoc.location = {
+         first_line: $$[$0-1].lastLoc.location.first_line,
+         last_line: $$[$0-1].lastLoc.location.last_line,
+         first_column: $$[$0-1].lastLoc.location.first_column,
+         last_column: $$[$0-1].lastLoc.location.last_column - 1
+       }
+       if ($$[$0-1].lastLoc !== $$[$0-1].firstLoc) {
+          $$[$0-1].firstLoc.type = 'database';
+       } else {
+         delete $$[$0-1].lastLoc.identifierChain;
+       }
      }
      if ($$[$0].expressions && $$[$0].expressions.length) {
        this.$ = { function: fn, expression: $$[$0].expressions[$$[$0].expressions.length - 1].expression, types: ['UDFREF'] }

+ 14 - 12
desktop/core/src/desktop/js/parse/sql/elasticsearch/elasticsearchSyntaxParser.js

@@ -1681,18 +1681,20 @@ case 813:
      // with columnReference for functions like: db.udf(foo)
      var fn = $$[$0-1].chain[$$[$0-1].chain.length - 1].name.toLowerCase();
      parser.addFunctionArgumentLocations(fn, $$[$0].expressions, $$[$0-1].chain);
-     $$[$0-1].lastLoc.type = 'function';
-     $$[$0-1].lastLoc.function = fn;
-     $$[$0-1].lastLoc.location = {
-       first_line: $$[$0-1].lastLoc.location.first_line,
-       last_line: $$[$0-1].lastLoc.location.last_line,
-       first_column: $$[$0-1].lastLoc.location.first_column,
-       last_column: $$[$0-1].lastLoc.location.last_column - 1
-     }
-     if ($$[$0-1].lastLoc !== $$[$0-1].firstLoc) {
-        $$[$0-1].firstLoc.type = 'database';
-     } else {
-       delete $$[$0-1].lastLoc.identifierChain;
+     if ($$[$0-1].lastLoc && $$[$0-1].lastLoc.location) {
+       $$[$0-1].lastLoc.type = 'function';
+       $$[$0-1].lastLoc.function = fn;
+       $$[$0-1].lastLoc.location = {
+         first_line: $$[$0-1].lastLoc.location.first_line,
+         last_line: $$[$0-1].lastLoc.location.last_line,
+         first_column: $$[$0-1].lastLoc.location.first_column,
+         last_column: $$[$0-1].lastLoc.location.last_column - 1
+       }
+       if ($$[$0-1].lastLoc !== $$[$0-1].firstLoc) {
+          $$[$0-1].firstLoc.type = 'database';
+       } else {
+         delete $$[$0-1].lastLoc.identifierChain;
+       }
      }
      if ($$[$0].expressions && $$[$0].expressions.length) {
        this.$ = { function: fn, expression: $$[$0].expressions[$$[$0].expressions.length - 1].expression, types: ['UDFREF'] }

+ 14 - 12
desktop/core/src/desktop/js/parse/sql/flink/flinkAutocompleteParser.js

@@ -1731,18 +1731,20 @@ case 868:
      // with columnReference for functions like: db.udf(foo)
      var fn = $$[$0-1].chain[$$[$0-1].chain.length - 1].name.toLowerCase();
      parser.addFunctionArgumentLocations(fn, $$[$0].expressions, $$[$0-1].chain);
-     $$[$0-1].lastLoc.type = 'function';
-     $$[$0-1].lastLoc.function = fn;
-     $$[$0-1].lastLoc.location = {
-       first_line: $$[$0-1].lastLoc.location.first_line,
-       last_line: $$[$0-1].lastLoc.location.last_line,
-       first_column: $$[$0-1].lastLoc.location.first_column,
-       last_column: $$[$0-1].lastLoc.location.last_column - 1
-     }
-     if ($$[$0-1].lastLoc !== $$[$0-1].firstLoc) {
-        $$[$0-1].firstLoc.type = 'database';
-     } else {
-       delete $$[$0-1].lastLoc.identifierChain;
+     if ($$[$0-1].lastLoc && $$[$0-1].lastLoc.location) {
+       $$[$0-1].lastLoc.type = 'function';
+       $$[$0-1].lastLoc.function = fn;
+       $$[$0-1].lastLoc.location = {
+         first_line: $$[$0-1].lastLoc.location.first_line,
+         last_line: $$[$0-1].lastLoc.location.last_line,
+         first_column: $$[$0-1].lastLoc.location.first_column,
+         last_column: $$[$0-1].lastLoc.location.last_column - 1
+       }
+       if ($$[$0-1].lastLoc !== $$[$0-1].firstLoc) {
+          $$[$0-1].firstLoc.type = 'database';
+       } else {
+         delete $$[$0-1].lastLoc.identifierChain;
+       }
      }
      if ($$[$0].expressions && $$[$0].expressions.length) {
        this.$ = { function: fn, expression: $$[$0].expressions[$$[$0].expressions.length - 1].expression, types: ['UDFREF'] }

+ 14 - 12
desktop/core/src/desktop/js/parse/sql/flink/flinkSyntaxParser.js

@@ -1681,18 +1681,20 @@ case 813:
      // with columnReference for functions like: db.udf(foo)
      var fn = $$[$0-1].chain[$$[$0-1].chain.length - 1].name.toLowerCase();
      parser.addFunctionArgumentLocations(fn, $$[$0].expressions, $$[$0-1].chain);
-     $$[$0-1].lastLoc.type = 'function';
-     $$[$0-1].lastLoc.function = fn;
-     $$[$0-1].lastLoc.location = {
-       first_line: $$[$0-1].lastLoc.location.first_line,
-       last_line: $$[$0-1].lastLoc.location.last_line,
-       first_column: $$[$0-1].lastLoc.location.first_column,
-       last_column: $$[$0-1].lastLoc.location.last_column - 1
-     }
-     if ($$[$0-1].lastLoc !== $$[$0-1].firstLoc) {
-        $$[$0-1].firstLoc.type = 'database';
-     } else {
-       delete $$[$0-1].lastLoc.identifierChain;
+     if ($$[$0-1].lastLoc && $$[$0-1].lastLoc.location) {
+       $$[$0-1].lastLoc.type = 'function';
+       $$[$0-1].lastLoc.function = fn;
+       $$[$0-1].lastLoc.location = {
+         first_line: $$[$0-1].lastLoc.location.first_line,
+         last_line: $$[$0-1].lastLoc.location.last_line,
+         first_column: $$[$0-1].lastLoc.location.first_column,
+         last_column: $$[$0-1].lastLoc.location.last_column - 1
+       }
+       if ($$[$0-1].lastLoc !== $$[$0-1].firstLoc) {
+          $$[$0-1].firstLoc.type = 'database';
+       } else {
+         delete $$[$0-1].lastLoc.identifierChain;
+       }
      }
      if ($$[$0].expressions && $$[$0].expressions.length) {
        this.$ = { function: fn, expression: $$[$0].expressions[$$[$0].expressions.length - 1].expression, types: ['UDFREF'] }

+ 14 - 12
desktop/core/src/desktop/js/parse/sql/generic/genericAutocompleteParser.js

@@ -1731,18 +1731,20 @@ case 868:
      // with columnReference for functions like: db.udf(foo)
      var fn = $$[$0-1].chain[$$[$0-1].chain.length - 1].name.toLowerCase();
      parser.addFunctionArgumentLocations(fn, $$[$0].expressions, $$[$0-1].chain);
-     $$[$0-1].lastLoc.type = 'function';
-     $$[$0-1].lastLoc.function = fn;
-     $$[$0-1].lastLoc.location = {
-       first_line: $$[$0-1].lastLoc.location.first_line,
-       last_line: $$[$0-1].lastLoc.location.last_line,
-       first_column: $$[$0-1].lastLoc.location.first_column,
-       last_column: $$[$0-1].lastLoc.location.last_column - 1
-     }
-     if ($$[$0-1].lastLoc !== $$[$0-1].firstLoc) {
-        $$[$0-1].firstLoc.type = 'database';
-     } else {
-       delete $$[$0-1].lastLoc.identifierChain;
+     if ($$[$0-1].lastLoc && $$[$0-1].lastLoc.location) {
+       $$[$0-1].lastLoc.type = 'function';
+       $$[$0-1].lastLoc.function = fn;
+       $$[$0-1].lastLoc.location = {
+         first_line: $$[$0-1].lastLoc.location.first_line,
+         last_line: $$[$0-1].lastLoc.location.last_line,
+         first_column: $$[$0-1].lastLoc.location.first_column,
+         last_column: $$[$0-1].lastLoc.location.last_column - 1
+       }
+       if ($$[$0-1].lastLoc !== $$[$0-1].firstLoc) {
+          $$[$0-1].firstLoc.type = 'database';
+       } else {
+         delete $$[$0-1].lastLoc.identifierChain;
+       }
      }
      if ($$[$0].expressions && $$[$0].expressions.length) {
        this.$ = { function: fn, expression: $$[$0].expressions[$$[$0].expressions.length - 1].expression, types: ['UDFREF'] }

+ 14 - 12
desktop/core/src/desktop/js/parse/sql/generic/genericSyntaxParser.js

@@ -1681,18 +1681,20 @@ case 813:
      // with columnReference for functions like: db.udf(foo)
      var fn = $$[$0-1].chain[$$[$0-1].chain.length - 1].name.toLowerCase();
      parser.addFunctionArgumentLocations(fn, $$[$0].expressions, $$[$0-1].chain);
-     $$[$0-1].lastLoc.type = 'function';
-     $$[$0-1].lastLoc.function = fn;
-     $$[$0-1].lastLoc.location = {
-       first_line: $$[$0-1].lastLoc.location.first_line,
-       last_line: $$[$0-1].lastLoc.location.last_line,
-       first_column: $$[$0-1].lastLoc.location.first_column,
-       last_column: $$[$0-1].lastLoc.location.last_column - 1
-     }
-     if ($$[$0-1].lastLoc !== $$[$0-1].firstLoc) {
-        $$[$0-1].firstLoc.type = 'database';
-     } else {
-       delete $$[$0-1].lastLoc.identifierChain;
+     if ($$[$0-1].lastLoc && $$[$0-1].lastLoc.location) {
+       $$[$0-1].lastLoc.type = 'function';
+       $$[$0-1].lastLoc.function = fn;
+       $$[$0-1].lastLoc.location = {
+         first_line: $$[$0-1].lastLoc.location.first_line,
+         last_line: $$[$0-1].lastLoc.location.last_line,
+         first_column: $$[$0-1].lastLoc.location.first_column,
+         last_column: $$[$0-1].lastLoc.location.last_column - 1
+       }
+       if ($$[$0-1].lastLoc !== $$[$0-1].firstLoc) {
+          $$[$0-1].firstLoc.type = 'database';
+       } else {
+         delete $$[$0-1].lastLoc.identifierChain;
+       }
      }
      if ($$[$0].expressions && $$[$0].expressions.length) {
        this.$ = { function: fn, expression: $$[$0].expressions[$$[$0].expressions.length - 1].expression, types: ['UDFREF'] }

Різницю між файлами не показано, бо вона завелика
+ 0 - 0
desktop/core/src/desktop/js/parse/sql/hive/hiveAutocompleteParser.js


Різницю між файлами не показано, бо вона завелика
+ 0 - 0
desktop/core/src/desktop/js/parse/sql/hive/hiveSyntaxParser.js


+ 6 - 0
desktop/core/src/desktop/js/parse/sql/hive/test/hiveSyntaxParser.test.js

@@ -75,6 +75,12 @@ describe('hiveSyntaxParser.js', () => {
     expect(result).toBeFalsy();
   });
 
+  it('should not throw exceptions for "SELECT cos(1) from test"', () => {
+    const result = hiveSyntaxParser.parseSyntax('SELECT cos(1) from test', '', true);
+
+    expect(result).toBeFalsy();
+  });
+
   it('should not report incomplete statement for "SELECT * FR"', () => {
     const result = hiveSyntaxParser.parseSyntax('SELECT * FR', '');
 

+ 14 - 12
desktop/core/src/desktop/js/parse/sql/impala/impalaAutocompleteParser.js

@@ -2607,18 +2607,20 @@ case 1804:
      // with columnReference for functions like: db.udf(foo)
      var fn = $$[$0-1].chain[$$[$0-1].chain.length - 1].name.toLowerCase();
      parser.addFunctionArgumentLocations(fn, $$[$0].expressions, $$[$0-1].chain);
-     $$[$0-1].lastLoc.type = 'function';
-     $$[$0-1].lastLoc.function = fn;
-     $$[$0-1].lastLoc.location = {
-       first_line: $$[$0-1].lastLoc.location.first_line,
-       last_line: $$[$0-1].lastLoc.location.last_line,
-       first_column: $$[$0-1].lastLoc.location.first_column,
-       last_column: $$[$0-1].lastLoc.location.last_column - 1
-     }
-     if ($$[$0-1].lastLoc !== $$[$0-1].firstLoc) {
-        $$[$0-1].firstLoc.type = 'database';
-     } else {
-       delete $$[$0-1].lastLoc.identifierChain;
+     if ($$[$0-1].lastLoc && $$[$0-1].lastLoc.location) {
+       $$[$0-1].lastLoc.type = 'function';
+       $$[$0-1].lastLoc.function = fn;
+       $$[$0-1].lastLoc.location = {
+         first_line: $$[$0-1].lastLoc.location.first_line,
+         last_line: $$[$0-1].lastLoc.location.last_line,
+         first_column: $$[$0-1].lastLoc.location.first_column,
+         last_column: $$[$0-1].lastLoc.location.last_column - 1
+       }
+       if ($$[$0-1].lastLoc !== $$[$0-1].firstLoc) {
+          $$[$0-1].firstLoc.type = 'database';
+       } else {
+         delete $$[$0-1].lastLoc.identifierChain;
+       }
      }
      if ($$[$0].expressions && $$[$0].expressions.length) {
        this.$ = { function: fn, expression: $$[$0].expressions[$$[$0].expressions.length - 1].expression, types: ['UDFREF'] }

+ 14 - 12
desktop/core/src/desktop/js/parse/sql/impala/impalaSyntaxParser.js

@@ -2541,18 +2541,20 @@ case 1742:
      // with columnReference for functions like: db.udf(foo)
      var fn = $$[$0-1].chain[$$[$0-1].chain.length - 1].name.toLowerCase();
      parser.addFunctionArgumentLocations(fn, $$[$0].expressions, $$[$0-1].chain);
-     $$[$0-1].lastLoc.type = 'function';
-     $$[$0-1].lastLoc.function = fn;
-     $$[$0-1].lastLoc.location = {
-       first_line: $$[$0-1].lastLoc.location.first_line,
-       last_line: $$[$0-1].lastLoc.location.last_line,
-       first_column: $$[$0-1].lastLoc.location.first_column,
-       last_column: $$[$0-1].lastLoc.location.last_column - 1
-     }
-     if ($$[$0-1].lastLoc !== $$[$0-1].firstLoc) {
-        $$[$0-1].firstLoc.type = 'database';
-     } else {
-       delete $$[$0-1].lastLoc.identifierChain;
+     if ($$[$0-1].lastLoc && $$[$0-1].lastLoc.location) {
+       $$[$0-1].lastLoc.type = 'function';
+       $$[$0-1].lastLoc.function = fn;
+       $$[$0-1].lastLoc.location = {
+         first_line: $$[$0-1].lastLoc.location.first_line,
+         last_line: $$[$0-1].lastLoc.location.last_line,
+         first_column: $$[$0-1].lastLoc.location.first_column,
+         last_column: $$[$0-1].lastLoc.location.last_column - 1
+       }
+       if ($$[$0-1].lastLoc !== $$[$0-1].firstLoc) {
+          $$[$0-1].firstLoc.type = 'database';
+       } else {
+         delete $$[$0-1].lastLoc.identifierChain;
+       }
      }
      if ($$[$0].expressions && $$[$0].expressions.length) {
        this.$ = { function: fn, expression: $$[$0].expressions[$$[$0].expressions.length - 1].expression, types: ['UDFREF'] }

+ 14 - 12
desktop/core/src/desktop/js/parse/sql/ksql/ksqlAutocompleteParser.js

@@ -1719,18 +1719,20 @@ case 848:
      // with columnReference for functions like: db.udf(foo)
      var fn = $$[$0-1].chain[$$[$0-1].chain.length - 1].name.toLowerCase();
      parser.addFunctionArgumentLocations(fn, $$[$0].expressions, $$[$0-1].chain);
-     $$[$0-1].lastLoc.type = 'function';
-     $$[$0-1].lastLoc.function = fn;
-     $$[$0-1].lastLoc.location = {
-       first_line: $$[$0-1].lastLoc.location.first_line,
-       last_line: $$[$0-1].lastLoc.location.last_line,
-       first_column: $$[$0-1].lastLoc.location.first_column,
-       last_column: $$[$0-1].lastLoc.location.last_column - 1
-     }
-     if ($$[$0-1].lastLoc !== $$[$0-1].firstLoc) {
-        $$[$0-1].firstLoc.type = 'database';
-     } else {
-       delete $$[$0-1].lastLoc.identifierChain;
+     if ($$[$0-1].lastLoc && $$[$0-1].lastLoc.location) {
+       $$[$0-1].lastLoc.type = 'function';
+       $$[$0-1].lastLoc.function = fn;
+       $$[$0-1].lastLoc.location = {
+         first_line: $$[$0-1].lastLoc.location.first_line,
+         last_line: $$[$0-1].lastLoc.location.last_line,
+         first_column: $$[$0-1].lastLoc.location.first_column,
+         last_column: $$[$0-1].lastLoc.location.last_column - 1
+       }
+       if ($$[$0-1].lastLoc !== $$[$0-1].firstLoc) {
+          $$[$0-1].firstLoc.type = 'database';
+       } else {
+         delete $$[$0-1].lastLoc.identifierChain;
+       }
      }
      if ($$[$0].expressions && $$[$0].expressions.length) {
        this.$ = { function: fn, expression: $$[$0].expressions[$$[$0].expressions.length - 1].expression, types: ['UDFREF'] }

+ 14 - 12
desktop/core/src/desktop/js/parse/sql/ksql/ksqlSyntaxParser.js

@@ -1669,18 +1669,20 @@ case 793:
      // with columnReference for functions like: db.udf(foo)
      var fn = $$[$0-1].chain[$$[$0-1].chain.length - 1].name.toLowerCase();
      parser.addFunctionArgumentLocations(fn, $$[$0].expressions, $$[$0-1].chain);
-     $$[$0-1].lastLoc.type = 'function';
-     $$[$0-1].lastLoc.function = fn;
-     $$[$0-1].lastLoc.location = {
-       first_line: $$[$0-1].lastLoc.location.first_line,
-       last_line: $$[$0-1].lastLoc.location.last_line,
-       first_column: $$[$0-1].lastLoc.location.first_column,
-       last_column: $$[$0-1].lastLoc.location.last_column - 1
-     }
-     if ($$[$0-1].lastLoc !== $$[$0-1].firstLoc) {
-        $$[$0-1].firstLoc.type = 'database';
-     } else {
-       delete $$[$0-1].lastLoc.identifierChain;
+     if ($$[$0-1].lastLoc && $$[$0-1].lastLoc.location) {
+       $$[$0-1].lastLoc.type = 'function';
+       $$[$0-1].lastLoc.function = fn;
+       $$[$0-1].lastLoc.location = {
+         first_line: $$[$0-1].lastLoc.location.first_line,
+         last_line: $$[$0-1].lastLoc.location.last_line,
+         first_column: $$[$0-1].lastLoc.location.first_column,
+         last_column: $$[$0-1].lastLoc.location.last_column - 1
+       }
+       if ($$[$0-1].lastLoc !== $$[$0-1].firstLoc) {
+          $$[$0-1].firstLoc.type = 'database';
+       } else {
+         delete $$[$0-1].lastLoc.identifierChain;
+       }
      }
      if ($$[$0].expressions && $$[$0].expressions.length) {
        this.$ = { function: fn, expression: $$[$0].expressions[$$[$0].expressions.length - 1].expression, types: ['UDFREF'] }

+ 14 - 12
desktop/core/src/desktop/js/parse/sql/phoenix/phoenixAutocompleteParser.js

@@ -1731,18 +1731,20 @@ case 868:
      // with columnReference for functions like: db.udf(foo)
      var fn = $$[$0-1].chain[$$[$0-1].chain.length - 1].name.toLowerCase();
      parser.addFunctionArgumentLocations(fn, $$[$0].expressions, $$[$0-1].chain);
-     $$[$0-1].lastLoc.type = 'function';
-     $$[$0-1].lastLoc.function = fn;
-     $$[$0-1].lastLoc.location = {
-       first_line: $$[$0-1].lastLoc.location.first_line,
-       last_line: $$[$0-1].lastLoc.location.last_line,
-       first_column: $$[$0-1].lastLoc.location.first_column,
-       last_column: $$[$0-1].lastLoc.location.last_column - 1
-     }
-     if ($$[$0-1].lastLoc !== $$[$0-1].firstLoc) {
-        $$[$0-1].firstLoc.type = 'database';
-     } else {
-       delete $$[$0-1].lastLoc.identifierChain;
+     if ($$[$0-1].lastLoc && $$[$0-1].lastLoc.location) {
+       $$[$0-1].lastLoc.type = 'function';
+       $$[$0-1].lastLoc.function = fn;
+       $$[$0-1].lastLoc.location = {
+         first_line: $$[$0-1].lastLoc.location.first_line,
+         last_line: $$[$0-1].lastLoc.location.last_line,
+         first_column: $$[$0-1].lastLoc.location.first_column,
+         last_column: $$[$0-1].lastLoc.location.last_column - 1
+       }
+       if ($$[$0-1].lastLoc !== $$[$0-1].firstLoc) {
+          $$[$0-1].firstLoc.type = 'database';
+       } else {
+         delete $$[$0-1].lastLoc.identifierChain;
+       }
      }
      if ($$[$0].expressions && $$[$0].expressions.length) {
        this.$ = { function: fn, expression: $$[$0].expressions[$$[$0].expressions.length - 1].expression, types: ['UDFREF'] }

+ 14 - 12
desktop/core/src/desktop/js/parse/sql/phoenix/phoenixSyntaxParser.js

@@ -1681,18 +1681,20 @@ case 813:
      // with columnReference for functions like: db.udf(foo)
      var fn = $$[$0-1].chain[$$[$0-1].chain.length - 1].name.toLowerCase();
      parser.addFunctionArgumentLocations(fn, $$[$0].expressions, $$[$0-1].chain);
-     $$[$0-1].lastLoc.type = 'function';
-     $$[$0-1].lastLoc.function = fn;
-     $$[$0-1].lastLoc.location = {
-       first_line: $$[$0-1].lastLoc.location.first_line,
-       last_line: $$[$0-1].lastLoc.location.last_line,
-       first_column: $$[$0-1].lastLoc.location.first_column,
-       last_column: $$[$0-1].lastLoc.location.last_column - 1
-     }
-     if ($$[$0-1].lastLoc !== $$[$0-1].firstLoc) {
-        $$[$0-1].firstLoc.type = 'database';
-     } else {
-       delete $$[$0-1].lastLoc.identifierChain;
+     if ($$[$0-1].lastLoc && $$[$0-1].lastLoc.location) {
+       $$[$0-1].lastLoc.type = 'function';
+       $$[$0-1].lastLoc.function = fn;
+       $$[$0-1].lastLoc.location = {
+         first_line: $$[$0-1].lastLoc.location.first_line,
+         last_line: $$[$0-1].lastLoc.location.last_line,
+         first_column: $$[$0-1].lastLoc.location.first_column,
+         last_column: $$[$0-1].lastLoc.location.last_column - 1
+       }
+       if ($$[$0-1].lastLoc !== $$[$0-1].firstLoc) {
+          $$[$0-1].firstLoc.type = 'database';
+       } else {
+         delete $$[$0-1].lastLoc.identifierChain;
+       }
      }
      if ($$[$0].expressions && $$[$0].expressions.length) {
        this.$ = { function: fn, expression: $$[$0].expressions[$$[$0].expressions.length - 1].expression, types: ['UDFREF'] }

Різницю між файлами не показано, бо вона завелика
+ 0 - 0
desktop/core/src/desktop/js/parse/sql/presto/prestoAutocompleteParser.js


Різницю між файлами не показано, бо вона завелика
+ 0 - 0
desktop/core/src/desktop/js/parse/sql/presto/prestoSyntaxParser.js


+ 2 - 2
desktop/core/src/desktop/js/parse/sql/sqlParseUtils.js

@@ -602,6 +602,7 @@ const SYNTAX_PARSER_NOOP_FUNCTIONS = [
   'addCteAliasLocation',
   'addDatabaseLocation',
   'addFileLocation',
+  'addFunctionArgumentLocations',
   'addFunctionLocation',
   'addNewDatabaseLocation',
   'addNewTableLocation',
@@ -763,9 +764,8 @@ export const initSyntaxParser = parser => {
       parser.parse(beforeCursor + afterCursor);
     } catch (err) {
       if (debug) {
-        console.warn(err);
-        console.warn(err.stack);
         console.warn(parser.yy.error);
+        throw err;
       }
     }
 

Деякі файли не було показано, через те що забагато файлів було змінено