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

HUE-9464 [editor] Add Hive parser support for CREATE SCHEDULED QUERY

Johan Ahlen 5 жил өмнө
parent
commit
6356585cdc

+ 3 - 1
desktop/core/src/desktop/js/parse/jison/sql/hive/create/create_common.jison

@@ -23,7 +23,9 @@ DataDefinition_EDIT
        if ($2 && !$3) {
          parser.suggestKeywords(['EXTERNAL TABLE', 'FUNCTION', 'MACRO', 'TABLE']);
        } else if (!$2 && !$3) {
-         parser.suggestKeywords(['DATABASE', 'EXTERNAL TABLE', 'FUNCTION', 'INDEX', 'MATERIALIZED VIEW', 'ROLE', 'SCHEMA', 'TABLE', 'TEMPORARY EXTERNAL TABLE', 'TEMPORARY FUNCTION', 'TEMPORARY MACRO', 'TEMPORARY TABLE', 'TRANSACTIONAL TABLE', 'VIEW']);
+         parser.suggestKeywords(['DATABASE', 'EXTERNAL TABLE', 'FUNCTION', 'INDEX', 'MATERIALIZED VIEW', 'ROLE',
+           'SCHEDULED QUERY', 'SCHEMA', 'TABLE', 'TEMPORARY EXTERNAL TABLE', 'TEMPORARY FUNCTION', 'TEMPORARY MACRO',
+           'TEMPORARY TABLE', 'TRANSACTIONAL TABLE', 'VIEW']);
        } else if ($3) {
          parser.suggestKeywords(['TABLE']);
        }

+ 116 - 0
desktop/core/src/desktop/js/parse/jison/sql/hive/create/create_scheduled_query.jison

@@ -0,0 +1,116 @@
+// Licensed to Cloudera, Inc. under one
+// or more contributor license agreements.  See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership.  Cloudera, Inc. licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License.  You may obtain a copy of the License at
+//
+//     http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+// Depends on sql_extract.jison, sql_main.jison
+
+DataDefinition
+ : CreateScheduledQuery
+ ;
+
+DataDefinition_EDIT
+ : CreateScheduledQuery_EDIT
+   {
+     if ($1 && $1.suggestKeywords) {
+       parser.suggestKeywords($1.suggestKeywords);
+     }
+   }
+ ;
+
+CreateScheduledQuery
+ : 'CREATE' 'SCHEDULED' 'QUERY' RegularOrBacktickedIdentifier ScheduleSpecification OptionalExecutedAs OptionalEnabledOrDisabled DefinedAsSpecification
+ ;
+
+CreateScheduledQuery_EDIT
+ : 'CREATE' 'SCHEDULED' 'CURSOR' -> { suggestKeywords: ['QUERY'] }
+ | 'CREATE' 'SCHEDULED' 'QUERY' 'CURSOR'
+ | 'CREATE' 'SCHEDULED' 'QUERY' RegularOrBacktickedIdentifier 'CURSOR' -> { suggestKeywords: ['CRON', 'EVERY'] }
+ | 'CREATE' 'SCHEDULED' 'QUERY' RegularOrBacktickedIdentifier ScheduleSpecification_EDIT OptionalExecutedAs OptionalEnabledOrDisabled -> $5
+ | 'CREATE' 'SCHEDULED' 'QUERY' RegularOrBacktickedIdentifier ScheduleSpecification OptionalExecutedAs OptionalEnabledOrDisabled 'CURSOR'
+   {
+     var keywords = [{ value: 'DEFINED AS', weight: 1 }, { value: 'AS', weight: 1 }]
+     if (!$7) {
+       keywords = keywords.concat([{ value: 'ENABLE', weight: 2 }, { value: 'ENABLED', weight: 2 },
+         { value: 'DISABLE', weight: 2 }, { value: 'DISABLED', weight: 2 }]);
+     }
+     if (!$6 && !$7) {
+       keywords.push({value: 'EXECUTED AS', weight: 3 });
+       if ($5 && $5.suggestKeywords) {
+         keywords = keywords.concat($5.suggestKeywords);
+       }
+     }
+     $$ = { suggestKeywords: keywords };
+   }
+ | 'CREATE' 'SCHEDULED' 'QUERY' RegularOrBacktickedIdentifier ScheduleSpecification ExecutedAs_EDIT OptionalEnabledOrDisabled -> $6
+ | 'CREATE' 'SCHEDULED' 'QUERY' RegularOrBacktickedIdentifier ScheduleSpecification OptionalExecutedAs OptionalEnabledOrDisabled DefinedAsSpecification_EDIT -> $8
+ ;
+
+ScheduleSpecification
+ : 'CRON' QuotedValue
+ | 'EVERY' 'UNSIGNED_INTEGER' DateField OptionalOffset -> !$4 ? { suggestKeywords: [{ value: 'OFFSET', weight: 4 }] } : {}
+ ;
+
+ScheduleSpecification_EDIT
+ : 'EVERY' 'UNSIGNED_INTEGER' 'CURSOR' -> { suggestKeywords: ['DAY', 'DAYOFWEEK', 'HOUR', 'MINUTE', 'MONTH', 'QUARTER', 'SECOND', 'WEEK', 'YEAR'] }
+ | 'EVERY' 'UNSIGNED_INTEGER' DateField Offset_EDIT -> $4
+ ;
+
+OptionalExecutedAs
+ :
+ | 'EXECUTED' 'AS' QuotedValue
+ | 'EXECUTED' 'AS' RegularOrBacktickedIdentifier
+ ;
+
+ExecutedAs_EDIT
+ : 'EXECUTED' 'CURSOR' -> { suggestKeywords: ['AS'] }
+ ;
+
+OptionalEnabledOrDisabled
+ :
+ | 'ENABLE'
+ | 'ENABLED'
+ | 'DISABLE'
+ | 'DISABLED'
+ ;
+
+DefinedAsSpecification
+ : 'DEFINED' 'AS' QuerySpecification
+ | 'AS' QuerySpecification
+ ;
+
+DefinedAsSpecification_EDIT
+ : 'DEFINED' 'CURSOR' -> { suggestKeywords: ['AS'] }
+ | 'DEFINED' 'AS' 'CURSOR' -> { suggestKeywords: parser.DDL_AND_DML_KEYWORDS }
+ | 'DEFINED' 'AS' QuerySpecification_EDIT
+ | 'AS' 'CURSOR' -> { suggestKeywords: parser.DDL_AND_DML_KEYWORDS }
+ | 'AS' QuerySpecification_EDIT
+ ;
+
+OptionalOffset
+ :
+ | 'OFFSET' ByOrAt QuotedValue
+ ;
+
+Offset_EDIT
+ : 'OFFSET' 'CURSOR'
+   {
+     $$ = { suggestKeywords: ['AT', 'BY'] };
+   }
+ ;
+
+ByOrAt
+ : 'BY'
+ | 'AT'
+ ;

+ 9 - 0
desktop/core/src/desktop/js/parse/jison/sql/hive/sql.jisonlex

@@ -147,6 +147,7 @@
 'ARCHIVE'                            { return 'ARCHIVE'; }
 'ASC'                                { return 'ASC'; }
 'AST'                                { return 'AST'; }
+'AT'                                 { return 'AT'; }
 'AVRO'                               { return 'AVRO'; }
 'BUCKET'                             { return 'BUCKET'; }
 'BUCKETS'                            { return 'BUCKETS'; }
@@ -164,6 +165,7 @@
 'COMPUTE'                            { return 'COMPUTE'; }
 'CONCATENATE'                        { return 'CONCATENATE'; }
 'COST'                               { return 'COST'; }
+'CRON'                               { return 'CRON'; }
 'CURRENT_DATE'                       { return 'CURRENT_DATE'; }
 'CURRENT_TIMESTAMP'                  { return 'CURRENT_TIMESTAMP'; }
 'CURRENT_USER'                       { return 'CURRENT_USER'; }
@@ -181,12 +183,16 @@
 'DETAIL'                             { return 'DETAIL'; }
 'DIRECTORY'                          { this.begin('hdfs'); return 'DIRECTORY'; }
 'DISABLE'                            { return 'DISABLE'; }
+'DISABLED'                           { return 'DISABLED'; }
 'DISTRIBUTE'                         { return 'DISTRIBUTE'; }
 'DISTRIBUTED'                        { return 'DISTRIBUTED'; }
 DOUBLE\s+PRECISION                   { return 'DOUBLE_PRECISION'; }
 'ENABLE'                             { return 'ENABLE'; }
+'ENABLED'                            { return 'ENABLED'; }
 'ESCAPED'                            { return 'ESCAPED'; }
+'EVERY'                              { return 'EVERY'; }
 'EXCHANGE'                           { return 'EXCHANGE'; }
+'EXECUTED'                           { return 'EXECUTED'; }
 'EXPLAIN'                            { parser.determineCase(yytext); return 'EXPLAIN'; }
 'EXPORT'                             { parser.determineCase(yytext); return 'EXPORT'; }
 'EXPRESSION'                         { return 'EXPRESSION'; }
@@ -229,6 +235,7 @@ DOUBLE\s+PRECISION                   { return 'DOUBLE_PRECISION'; }
 'NOSCAN'                             { return 'NOSCAN'; }
 'NOVALIDATE'                         { return 'NOVALIDATE'; }
 'OFFLINE'                            { return 'OFFLINE'; }
+'OFFSET'                             { return 'OFFSET'; }
 'ONLY'                               { return 'ONLY'; }
 'OPERATOR'                           { return 'OPERATOR'; }
 'OPTION'                             { return 'OPTION'; }
@@ -245,6 +252,7 @@ OVERWRITE\s+DIRECTORY                { this.begin('hdfs'); return 'OVERWRITE_DIR
 'PRIVILEGES'                         { return 'PRIVILEGES'; }
 'PURGE'                              { return 'PURGE'; }
 'QUARTER'                            { return 'QUARTER'; }
+'QUERY'                              { return 'QUERY'; }
 'RCFILE'                             { return 'RCFILE'; }
 'REBUILD'                            { return 'REBUILD'; }
 'RECOVER'                            { return 'RECOVER'; }
@@ -258,6 +266,7 @@ OVERWRITE\s+DIRECTORY                { this.begin('hdfs'); return 'OVERWRITE_DIR
 'REWRITE'                            { return 'REWRITE'; }
 'ROLE'                               { return 'ROLE'; }
 'ROLES'                              { return 'ROLES'; }
+'SCHEDULED'                          { return 'SCHEDULED'; }
 'SCHEMA'                             { return 'SCHEMA'; }
 'SCHEMAS'                            { return 'SCHEMAS'; }
 'SECOND'                             { return 'SECOND'; }

+ 18 - 0
desktop/core/src/desktop/js/parse/jison/sql/hive/sql_main.jison

@@ -93,6 +93,7 @@ NonReservedKeyword
  | 'ANALYZE'
  | 'ARCHIVE'
  | 'AST'
+ | 'AT'
  | 'AVRO'
  | 'BUCKET'
  | 'BUCKETS'
@@ -109,6 +110,7 @@ NonReservedKeyword
  | 'COMPUTE'
  | 'CONCATENATE'
  | 'COST'
+ | 'CRON'
  | 'CURRENT_DATE'
  | 'CURRENT_TIMESTAMP'
  | 'CURRENT_USER'
@@ -125,11 +127,15 @@ NonReservedKeyword
  | 'DETAIL'
  | 'DIRECTORY'
  | 'DISABLE'
+ | 'DISABLED'
  | 'DISTRIBUTED'
  | 'DOUBLE_PRECISION'
  | 'ENABLE'
+ | 'ENABLED'
  | 'ESCAPED'
+ | 'EVERY'
  | 'EXCHANGE'
+ | 'EXECUTED'
  | 'EXPLAIN'
  | 'EXPORT'
  | 'EXPRESSION'
@@ -168,6 +174,7 @@ NonReservedKeyword
  | 'NOSCAN'
  | 'NOVALIDATE'
  | 'OFFLINE'
+ | 'OFFSET'
  | 'ONLY'
  | 'OPERATOR'
  | 'OPTION'
@@ -183,6 +190,7 @@ NonReservedKeyword
  | 'PRIVILEGES'
  | 'PURGE'
  | 'QUARTER'
+ | 'QUERY'
  | 'RCFILE'
  | 'REBUILD'
  | 'RECOVER'
@@ -196,6 +204,7 @@ NonReservedKeyword
  | 'REWRITE'
  | 'ROLE'
  | 'ROLES'
+ | 'SCHEDULED'
  | 'SCHEMAS'
  | 'SECOND'
  | 'SEQUENCEFILE'
@@ -276,6 +285,7 @@ NonStartingToken
  | 'ARRAY'
  | 'AS'
  | 'ASC'
+ | 'AT'
  | 'AUTHORIZATION'
  | 'AVG'
  | 'AVRO'
@@ -307,6 +317,7 @@ NonStartingToken
  | 'COUNT'
  | 'COVAR_POP'
  | 'COVAR_SAMP'
+ | 'CRON'
  | 'CROSS'
  | 'CUBE'
  | 'CURRENT'
@@ -324,6 +335,7 @@ NonStartingToken
  | 'DEPENDENCY'
  | 'DESC'
  | 'DIRECTORY'
+ | 'DISABLED'
  | 'DISTINCT'
  | 'DISTRIBUTE'
  | 'DISTRIBUTED'
@@ -331,8 +343,11 @@ NonStartingToken
  | 'DOUBLE_PRECISION'
  | 'DOUBLE_QUOTE'
  | 'ELSE'
+ | 'ENABLED'
  | 'END'
  | 'ESCAPED'
+ | 'EVERY'
+ | 'EXECUTED'
  | 'EXISTS'
  | 'EXTENDED'
  | 'EXTERNAL'
@@ -401,6 +416,7 @@ NonStartingToken
  | 'NULL'
  | 'NULLS'
  | 'OF'
+ | 'OFFSET'
  | 'ON'
  | 'OPTION'
  | 'OR'
@@ -424,6 +440,7 @@ NonStartingToken
  | 'PRIVILEGES'
  | 'PURGE'
  | 'QUARTER'
+ | 'QUERY'
  | 'RANGE'
  | 'RCFILE'
  | 'REBUILD'
@@ -440,6 +457,7 @@ NonStartingToken
  | 'ROLLUP'
  | 'ROW'
  | 'ROWS'
+ | 'SCHEDULED'
  | 'SCHEMA'
  | 'SCHEMAS'
  | 'SECOND'

+ 2 - 0
desktop/core/src/desktop/js/parse/jison/sql/hive/structure.json

@@ -17,6 +17,7 @@
     "create/create_index.jison",
     "create/create_materialized_view.jison",
     "create/create_role.jison",
+    "create/create_scheduled_query.jison",
     "create/create_table.jison",
     "create/create_temporary_function.jison",
     "create/create_temporary_macro.jison",
@@ -127,6 +128,7 @@
     "create/create_index.jison",
     "create/create_materialized_view.jison",
     "create/create_role.jison",
+    "create/create_scheduled_query.jison",
     "create/create_table.jison",
     "create/create_temporary_function.jison",
     "create/create_temporary_macro.jison",

Файлын зөрүү хэтэрхий том тул дарагдсан байна
+ 0 - 0
desktop/core/src/desktop/js/parse/sql/hive/hiveAutocompleteParser.js


Файлын зөрүү хэтэрхий том тул дарагдсан байна
+ 0 - 0
desktop/core/src/desktop/js/parse/sql/hive/hiveSyntaxParser.js


+ 28 - 29
desktop/core/src/desktop/js/parse/sql/hive/sqlParseSupport.js

@@ -27,6 +27,33 @@ import {
 const initSqlParser = function (parser) {
   initSharedAutocomplete(parser);
 
+  parser.DDL_AND_DML_KEYWORDS = [
+    'ABORT',
+    'ALTER',
+    'ANALYZE TABLE',
+    'CREATE',
+    'DELETE',
+    'DESCRIBE',
+    'DROP',
+    'EXPORT',
+    'GRANT',
+    'IMPORT',
+    'INSERT',
+    'LOAD',
+    'MERGE',
+    'MSCK',
+    'RELOAD FUNCTION',
+    'RESET',
+    'REVOKE',
+    'SELECT',
+    'SET',
+    'SHOW',
+    'TRUNCATE',
+    'UPDATE',
+    'USE',
+    'WITH'
+  ];
+
   parser.prepareNewStatement = function () {
     linkTablePrimaries();
     parser.commitLocations();
@@ -1168,40 +1195,12 @@ const initSqlParser = function (parser) {
   };
 
   parser.suggestDdlAndDmlKeywords = function (extraKeywords) {
-    let keywords = [
-      'ALTER',
-      'CREATE',
-      'DESCRIBE',
-      'DROP',
-      'GRANT',
-      'INSERT',
-      'REVOKE',
-      'SELECT',
-      'SET',
-      'SHOW',
-      'TRUNCATE',
-      'UPDATE',
-      'USE',
-      'WITH'
-    ];
+    let keywords = parser.DDL_AND_DML_KEYWORDS;
 
     if (extraKeywords) {
       keywords = keywords.concat(extraKeywords);
     }
 
-    keywords = keywords.concat([
-      'ABORT',
-      'ANALYZE TABLE',
-      'DELETE',
-      'EXPORT',
-      'IMPORT',
-      'LOAD',
-      'MERGE',
-      'MSCK',
-      'RELOAD FUNCTION',
-      'RESET'
-    ]);
-
     parser.suggestKeywords(keywords);
   };
 

+ 220 - 0
desktop/core/src/desktop/js/parse/sql/hive/test/alter/alterScheduledQuery.test.js

@@ -0,0 +1,220 @@
+// Licensed to Cloudera, Inc. under one
+// or more contributor license agreements.  See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership.  Cloudera, Inc. licenses this file
+// to you under the Apache License, Version 2.0 (the
+// 'License'); you may not use this file except in compliance
+// with the License.  You may obtain a copy of the License at
+//
+//     http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an 'AS IS' BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+import hiveAutocompleteParser from '../../hiveAutocompleteParser';
+
+describe('hiveAutocompleteParser.js CREATE SCHEDULED QUERY statements', () => {
+  beforeAll(() => {
+    hiveAutocompleteParser.yy.parseError = function (msg) {
+      throw Error(msg);
+    };
+  });
+
+  const assertAutoComplete = testDefinition => {
+    const debug = false;
+    expect(
+      hiveAutocompleteParser.parseSql(
+        testDefinition.beforeCursor,
+        testDefinition.afterCursor,
+        debug
+      )
+    ).toEqualDefinition(testDefinition);
+  };
+
+  it('should handle "CREATE SCHEDULED QUERY sc1 CRON \'0 */10 * * * ? *\' AS INSERT INTO t VALUES (1); |"', () => {
+    assertAutoComplete({
+      beforeCursor:
+        "CREATE SCHEDULED QUERY sc1 CRON '0 */10 * * * ? *' AS INSERT INTO t VALUES (1); ",
+      afterCursor: '',
+      containsKeywords: ['SELECT'],
+      expectedResult: {
+        lowerCase: false
+      }
+    });
+  });
+
+  it('should handle "CREATE SCHEDULED QUERY test EVERY 10 MINUTES EXECUTED AS bar DISABLED DEFINED AS SELECT * FROM foo; |', () => {
+    assertAutoComplete({
+      beforeCursor:
+        'CREATE SCHEDULED QUERY test EVERY 10 MINUTES EXECUTED AS bar DISABLED DEFINED AS SELECT * FROM foo; ',
+      afterCursor: '',
+      containsKeywords: ['SELECT'],
+      expectedResult: {
+        lowerCase: false
+      }
+    });
+  });
+
+  it('should suggest keywords for "CREATE |"', () => {
+    assertAutoComplete({
+      beforeCursor: 'CREATE ',
+      afterCursor: '',
+      containsKeywords: ['SCHEDULED QUERY'],
+      expectedResult: {
+        lowerCase: false
+      }
+    });
+  });
+
+  it('should suggest keywords for "CREATE SCHEDULED |"', () => {
+    assertAutoComplete({
+      beforeCursor: 'CREATE SCHEDULED ',
+      afterCursor: '',
+      expectedResult: {
+        lowerCase: false,
+        suggestKeywords: ['QUERY']
+      }
+    });
+  });
+
+  it('should suggest keywords for "CREATE SCHEDULED QUERY foo |"', () => {
+    assertAutoComplete({
+      beforeCursor: 'CREATE SCHEDULED QUERY foo ',
+      afterCursor: '',
+      expectedResult: {
+        lowerCase: false,
+        suggestKeywords: ['CRON', 'EVERY']
+      }
+    });
+  });
+
+  it('should suggest keywords for "CREATE SCHEDULED QUERY foo EVERY 10 |"', () => {
+    assertAutoComplete({
+      beforeCursor: 'CREATE SCHEDULED QUERY foo EVERY 10 ',
+      afterCursor: '',
+      containsKeywords: ['MINUTE', 'DAY'],
+      expectedResult: {
+        lowerCase: false
+      }
+    });
+  });
+
+  it('should suggest keywords for "CREATE SCHEDULED QUERY foo EVERY 10 DAY |"', () => {
+    assertAutoComplete({
+      beforeCursor: 'CREATE SCHEDULED QUERY foo EVERY 10 DAY ',
+      afterCursor: '',
+      containsKeywords: ['EXECUTED AS', 'ENABLED', 'DISABLE', 'DEFINED AS', 'AS'],
+      expectedResult: {
+        lowerCase: false
+      }
+    });
+  });
+
+  it('should suggest keywords for "CREATE SCHEDULED QUERY foo CRON \'Some cron\' |"', () => {
+    assertAutoComplete({
+      beforeCursor: "CREATE SCHEDULED QUERY foo CRON 'Some cron' ",
+      afterCursor: '',
+      containsKeywords: ['EXECUTED AS', 'ENABLED', 'DISABLE', 'DEFINED AS', 'AS'],
+      expectedResult: {
+        lowerCase: false
+      }
+    });
+  });
+
+  it('should suggest keywords for "CREATE SCHEDULED QUERY foo CRON \'Some cron\' EXECUTED |"', () => {
+    assertAutoComplete({
+      beforeCursor: "CREATE SCHEDULED QUERY foo CRON 'Some cron' EXECUTED ",
+      afterCursor: '',
+      expectedResult: {
+        lowerCase: false,
+        suggestKeywords: ['AS']
+      }
+    });
+  });
+
+  it('should suggest keywords for "CREATE SCHEDULED QUERY foo EVERY 1 MINUTE EXECUTED AS bar |"', () => {
+    assertAutoComplete({
+      beforeCursor: 'CREATE SCHEDULED QUERY foo EVERY 1 MINUTE EXECUTED AS bar ',
+      afterCursor: '',
+      containsKeywords: ['ENABLED', 'DISABLE', 'DEFINED AS', 'AS'],
+      doesNotContainKeywords: ['EXECUTED AS'],
+      expectedResult: {
+        lowerCase: false
+      }
+    });
+  });
+
+  it('should suggest keywords for "CREATE SCHEDULED QUERY foo EVERY 1 MINUTE EXECUTED AS bar DISABLE |"', () => {
+    assertAutoComplete({
+      beforeCursor: 'CREATE SCHEDULED QUERY foo EVERY 1 MINUTE EXECUTED AS bar DISABLE ',
+      afterCursor: '',
+      expectedResult: {
+        lowerCase: false,
+        suggestKeywords: ['AS', 'DEFINED AS']
+      }
+    });
+  });
+
+  it('should suggest keywords for "CREATE SCHEDULED QUERY foo EVERY 1 MINUTE ENABLED |"', () => {
+    assertAutoComplete({
+      beforeCursor: 'CREATE SCHEDULED QUERY foo EVERY 1 MINUTE ENABLED ',
+      afterCursor: '',
+      expectedResult: {
+        lowerCase: false,
+        suggestKeywords: ['AS', 'DEFINED AS']
+      }
+    });
+  });
+
+  it('should suggest keywords for "CREATE SCHEDULED QUERY foo EVERY 1 MINUTE ENABLED DEFINED |"', () => {
+    assertAutoComplete({
+      beforeCursor: 'CREATE SCHEDULED QUERY foo EVERY 1 MINUTE ENABLED DEFINED ',
+      afterCursor: '',
+      expectedResult: {
+        lowerCase: false,
+        suggestKeywords: ['AS']
+      }
+    });
+  });
+
+  it('should suggest keywords for "CREATE SCHEDULED QUERY foo EVERY 1 MINUTE ENABLED DEFINED AS |"', () => {
+    assertAutoComplete({
+      beforeCursor: 'CREATE SCHEDULED QUERY foo EVERY 1 MINUTE ENABLED DEFINED AS ',
+      afterCursor: '',
+      containsKeywords: ['SELECT', 'INSERT'],
+      expectedResult: {
+        lowerCase: false
+      }
+    });
+  });
+
+  it('should suggest keywords for "CREATE SCHEDULED QUERY foo EVERY 1 MINUTE ENABLED AS |"', () => {
+    assertAutoComplete({
+      beforeCursor: 'CREATE SCHEDULED QUERY foo EVERY 1 MINUTE ENABLED AS ',
+      afterCursor: '',
+      containsKeywords: ['SELECT', 'INSERT'],
+      expectedResult: {
+        lowerCase: false
+      }
+    });
+  });
+
+  it('should suggest keywords for "CREATE SCHEDULED QUERY foo EVERY 1 MINUTE ENABLED AS SELECT |"', () => {
+    assertAutoComplete({
+      beforeCursor: 'CREATE SCHEDULED QUERY foo EVERY 1 MINUTE ENABLED AS SELECT ',
+      afterCursor: '',
+      containsKeywords: ['*'],
+      expectedResult: {
+        lowerCase: false,
+        suggestAggregateFunctions: { tables: [] },
+        suggestAnalyticFunctions: true,
+        suggestFunctions: {},
+        suggestTables: { prependQuestionMark: true, prependFrom: true },
+        suggestDatabases: { prependQuestionMark: true, prependFrom: true, appendDot: true }
+      }
+    });
+  });
+});

+ 220 - 0
desktop/core/src/desktop/js/parse/sql/hive/test/create/createScheduledQuery.test.js

@@ -0,0 +1,220 @@
+// Licensed to Cloudera, Inc. under one
+// or more contributor license agreements.  See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership.  Cloudera, Inc. licenses this file
+// to you under the Apache License, Version 2.0 (the
+// 'License'); you may not use this file except in compliance
+// with the License.  You may obtain a copy of the License at
+//
+//     http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an 'AS IS' BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+import hiveAutocompleteParser from '../../hiveAutocompleteParser';
+
+describe('hiveAutocompleteParser.js CREATE SCHEDULED QUERY statements', () => {
+  beforeAll(() => {
+    hiveAutocompleteParser.yy.parseError = function (msg) {
+      throw Error(msg);
+    };
+  });
+
+  const assertAutoComplete = testDefinition => {
+    const debug = false;
+    expect(
+      hiveAutocompleteParser.parseSql(
+        testDefinition.beforeCursor,
+        testDefinition.afterCursor,
+        debug
+      )
+    ).toEqualDefinition(testDefinition);
+  };
+
+  it('should handle "CREATE SCHEDULED QUERY sc1 CRON \'0 */10 * * * ? *\' AS INSERT INTO t VALUES (1); |"', () => {
+    assertAutoComplete({
+      beforeCursor:
+        "CREATE SCHEDULED QUERY sc1 CRON '0 */10 * * * ? *' AS INSERT INTO t VALUES (1); ",
+      afterCursor: '',
+      containsKeywords: ['SELECT'],
+      expectedResult: {
+        lowerCase: false
+      }
+    });
+  });
+
+  it('should handle "CREATE SCHEDULED QUERY test EVERY 10 MINUTES EXECUTED AS bar DISABLED DEFINED AS SELECT * FROM foo; |', () => {
+    assertAutoComplete({
+      beforeCursor:
+        'CREATE SCHEDULED QUERY test EVERY 10 MINUTES EXECUTED AS bar DISABLED DEFINED AS SELECT * FROM foo; ',
+      afterCursor: '',
+      containsKeywords: ['SELECT'],
+      expectedResult: {
+        lowerCase: false
+      }
+    });
+  });
+
+  it('should suggest keywords for "CREATE |"', () => {
+    assertAutoComplete({
+      beforeCursor: 'CREATE ',
+      afterCursor: '',
+      containsKeywords: ['SCHEDULED QUERY'],
+      expectedResult: {
+        lowerCase: false
+      }
+    });
+  });
+
+  it('should suggest keywords for "CREATE SCHEDULED |"', () => {
+    assertAutoComplete({
+      beforeCursor: 'CREATE SCHEDULED ',
+      afterCursor: '',
+      expectedResult: {
+        lowerCase: false,
+        suggestKeywords: ['QUERY']
+      }
+    });
+  });
+
+  it('should suggest keywords for "CREATE SCHEDULED QUERY foo |"', () => {
+    assertAutoComplete({
+      beforeCursor: 'CREATE SCHEDULED QUERY foo ',
+      afterCursor: '',
+      expectedResult: {
+        lowerCase: false,
+        suggestKeywords: ['CRON', 'EVERY']
+      }
+    });
+  });
+
+  it('should suggest keywords for "CREATE SCHEDULED QUERY foo EVERY 10 |"', () => {
+    assertAutoComplete({
+      beforeCursor: 'CREATE SCHEDULED QUERY foo EVERY 10 ',
+      afterCursor: '',
+      containsKeywords: ['MINUTE', 'DAY'],
+      expectedResult: {
+        lowerCase: false
+      }
+    });
+  });
+
+  it('should suggest keywords for "CREATE SCHEDULED QUERY foo EVERY 10 DAY |"', () => {
+    assertAutoComplete({
+      beforeCursor: 'CREATE SCHEDULED QUERY foo EVERY 10 DAY ',
+      afterCursor: '',
+      containsKeywords: ['EXECUTED AS', 'ENABLED', 'DISABLE', 'DEFINED AS', 'AS'],
+      expectedResult: {
+        lowerCase: false
+      }
+    });
+  });
+
+  it('should suggest keywords for "CREATE SCHEDULED QUERY foo CRON \'Some cron\' |"', () => {
+    assertAutoComplete({
+      beforeCursor: "CREATE SCHEDULED QUERY foo CRON 'Some cron' ",
+      afterCursor: '',
+      containsKeywords: ['EXECUTED AS', 'ENABLED', 'DISABLE', 'DEFINED AS', 'AS'],
+      expectedResult: {
+        lowerCase: false
+      }
+    });
+  });
+
+  it('should suggest keywords for "CREATE SCHEDULED QUERY foo CRON \'Some cron\' EXECUTED |"', () => {
+    assertAutoComplete({
+      beforeCursor: "CREATE SCHEDULED QUERY foo CRON 'Some cron' EXECUTED ",
+      afterCursor: '',
+      expectedResult: {
+        lowerCase: false,
+        suggestKeywords: ['AS']
+      }
+    });
+  });
+
+  it('should suggest keywords for "CREATE SCHEDULED QUERY foo EVERY 1 MINUTE EXECUTED AS bar |"', () => {
+    assertAutoComplete({
+      beforeCursor: 'CREATE SCHEDULED QUERY foo EVERY 1 MINUTE EXECUTED AS bar ',
+      afterCursor: '',
+      containsKeywords: ['ENABLED', 'DISABLE', 'DEFINED AS', 'AS'],
+      doesNotContainKeywords: ['EXECUTED AS'],
+      expectedResult: {
+        lowerCase: false
+      }
+    });
+  });
+
+  it('should suggest keywords for "CREATE SCHEDULED QUERY foo EVERY 1 MINUTE EXECUTED AS bar DISABLE |"', () => {
+    assertAutoComplete({
+      beforeCursor: 'CREATE SCHEDULED QUERY foo EVERY 1 MINUTE EXECUTED AS bar DISABLE ',
+      afterCursor: '',
+      expectedResult: {
+        lowerCase: false,
+        suggestKeywords: ['AS', 'DEFINED AS']
+      }
+    });
+  });
+
+  it('should suggest keywords for "CREATE SCHEDULED QUERY foo EVERY 1 MINUTE ENABLED |"', () => {
+    assertAutoComplete({
+      beforeCursor: 'CREATE SCHEDULED QUERY foo EVERY 1 MINUTE ENABLED ',
+      afterCursor: '',
+      expectedResult: {
+        lowerCase: false,
+        suggestKeywords: ['AS', 'DEFINED AS']
+      }
+    });
+  });
+
+  it('should suggest keywords for "CREATE SCHEDULED QUERY foo EVERY 1 MINUTE ENABLED DEFINED |"', () => {
+    assertAutoComplete({
+      beforeCursor: 'CREATE SCHEDULED QUERY foo EVERY 1 MINUTE ENABLED DEFINED ',
+      afterCursor: '',
+      expectedResult: {
+        lowerCase: false,
+        suggestKeywords: ['AS']
+      }
+    });
+  });
+
+  it('should suggest keywords for "CREATE SCHEDULED QUERY foo EVERY 1 MINUTE ENABLED DEFINED AS |"', () => {
+    assertAutoComplete({
+      beforeCursor: 'CREATE SCHEDULED QUERY foo EVERY 1 MINUTE ENABLED DEFINED AS ',
+      afterCursor: '',
+      containsKeywords: ['SELECT', 'INSERT'],
+      expectedResult: {
+        lowerCase: false
+      }
+    });
+  });
+
+  it('should suggest keywords for "CREATE SCHEDULED QUERY foo EVERY 1 MINUTE ENABLED AS |"', () => {
+    assertAutoComplete({
+      beforeCursor: 'CREATE SCHEDULED QUERY foo EVERY 1 MINUTE ENABLED AS ',
+      afterCursor: '',
+      containsKeywords: ['SELECT', 'INSERT'],
+      expectedResult: {
+        lowerCase: false
+      }
+    });
+  });
+
+  it('should suggest keywords for "CREATE SCHEDULED QUERY foo EVERY 1 MINUTE ENABLED AS SELECT |"', () => {
+    assertAutoComplete({
+      beforeCursor: 'CREATE SCHEDULED QUERY foo EVERY 1 MINUTE ENABLED AS SELECT ',
+      afterCursor: '',
+      containsKeywords: ['*'],
+      expectedResult: {
+        lowerCase: false,
+        suggestAggregateFunctions: { tables: [] },
+        suggestAnalyticFunctions: true,
+        suggestFunctions: {},
+        suggestTables: { prependQuestionMark: true, prependFrom: true },
+        suggestDatabases: { prependQuestionMark: true, prependFrom: true, appendDot: true }
+      }
+    });
+  });
+});

Энэ ялгаанд хэт олон файл өөрчлөгдсөн тул зарим файлыг харуулаагүй болно