Browse Source

HUE-4577 [editor] The new autocompleter should support CREATE, DROP and SET ROLE

Johan Ahlen 9 years ago
parent
commit
991b482

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

@@ -48,6 +48,7 @@
 <hive>'LATERAL'                            { return '<hive>LATERAL'; }
 <hive>'MACRO'                              { return '<hive>MACRO'; }
 <hive>'MAP'                                { return '<hive>MAP'; }
+<hive>'NONE'                               { return '<hive>NONE'; }
 <hive>'OF'                                 { return '<hive>OF'; }
 <hive>'OUT'                                { return '<hive>OUT'; }
 <hive>'ROLLUP'                             { return '<hive>ROLLUP'; }
@@ -302,7 +303,7 @@
 'SCHEMA'                                   { return 'SCHEMA'; }
 'SELECT'                                   { determineCase(yytext); return 'SELECT'; }
 'SEMI'                                     { return 'SEMI'; }
-'SET'                                      { return 'SET'; }
+'SET'                                      { determineCase(yytext); return 'SET'; }
 'SHOW'                                     { determineCase(yytext); return 'SHOW'; }
 'SMALLINT'                                 { return 'SMALLINT'; }
 'STRING'                                   { return 'STRING'; }

+ 1 - 0
desktop/core/src/desktop/static/desktop/js/autocomplete/jison/sql_create.jison

@@ -1352,6 +1352,7 @@ RoleDefinition
 
 AnyRole
  : '<hive>ROLE'
+ | '<impala>ROLE'
  | 'ROLE'
  ;
 

+ 5 - 0
desktop/core/src/desktop/static/desktop/js/autocomplete/jison/sql_drop.jison

@@ -25,6 +25,7 @@ DataDefinition_EDIT
 DropStatement
  : DropDatabaseStatement
  | DropFunctionStatement
+ | DropRoleStatement
  | DropTableStatement
  | DropIndexStatement
  | DropMacroStatement
@@ -159,6 +160,10 @@ DropHiveFunction_EDIT
  | 'DROP' '<hive>FUNCTION' OptionalIfExists_EDIT SchemaQualifiedTableIdentifier
  ;
 
+DropRoleStatement
+ : 'DROP' AnyRole RegularIdentifier
+ ;
+
 DropTableStatement
  : 'DROP' AnyTable OptionalIfExists SchemaQualifiedTableIdentifier
    {

+ 1 - 1
desktop/core/src/desktop/static/desktop/js/autocomplete/jison/sql_main.jison

@@ -195,7 +195,7 @@ SqlStatement_EDIT
 // This is a work-around for error handling when a statement starts with some token that the parser can understand but
 // it's not a valid statement (see ErrorStatement). It contains everything except valid starting tokens ('SELECT', 'USE' etc.)
 NonStartingToken
- : '<hive>ALL' | '<hive>ARRAY' | '<hive>AS' | '<hive>AVRO' | '<hive>BINARY' | '<hive>BUCKET' | '<hive>BUCKETS' | '<hive>CACHE' | '<hive>CLUSTER' | '<hive>CLUSTERED' | '<hive>COLLECTION' | '<hive>COMPUTE' | '<hive>CONF' | '<hive>CROSS' | '<hive>CUBE' | '<hive>CURRENT' | '<hive>DATE' | '<hive>DEFERRED' | '<hive>DELIMITED' | '<hive>DISTRIBUTE' | '<hive>DISTRIBUTED' | '<hive>ESCAPED' | '<hive>EXTENDED' | '<hive>EXTERNAL' | '<hive>FIELDS' | '<hive>FILE' | '<hive>FOR' | '<hive>FORMAT' | '<hive>FUNCTION' | '<hive>GRANT' | '<hive>GROUPING' | '<hive>IDXPROPERTIES' | '<hive>LATERAL' | '<hive>MACRO' | '<hive>PARTITION' | '<hive>REBUILD' | '<hive>REPAIR' | '<hive>ROLLUP' | '<hive>SETS' | '<hive>STATISTICS' | '<hive>TABLE' | '<hive>USER' | '<hive>ASC' | '<hive>COLUMNS' | '<hive>COMMENT' | '<hive>COMPACTIONS' | '<hive>DATA' | '<hive>DATABASES' | '<hive>DEFINED' | '<hive>DESC' |  '<hive>FORMATTED' | '<hive>FUNCTIONS' | '<hive>INDEX' | '<hive>INDEXES' | '<hive>INPATH' | '<hive>INPUTFORMAT' | '<hive>ITEMS' | '<hive>JAR' | '<hive>KEYS' | '<hive>LINES' | '<hive>LIMIT' | '<hive>LOCATION' | '<hive>LOCKS' | '<hive>MAP' | '<hive>METADATA' | '<hive>NOSCAN' | '<hive>OF' | '<hive>ORC' | '<hive>OUT' | '<hive>OUTPUTFORMAT' | '<hive>PARQUET' | '<hive>PARTITIONED' | '<hive>PARTITIONS' | '<hive>RCFILE' | '<hive>ROLE' | '<hive>ROLES' | '<hive>SCHEMA' | '<hive>SCHEMAS' | '<hive>SEQUENCEFILE' | '<hive>SERDE' | '<hive>SERDEPROPERTIES' | '<hive>SKEWED' | '<hive>SORTED' | '<hive>STORED' | '<hive>STORED_AS_DIRECTORIES' | '<hive>STRING' | '<hive>STRUCT' | '<hive>TABLES' | '<hive>TABLESAMPLE' | '<hive>TBLPROPERTIES' | '<hive>TEMPORARY' | '<hive>TERMINATED' | '<hive>TEXTFILE' | '<hive>TINYINT' | '<hive>TRANSACTIONS' | '<hive>UNIONTYPE' | '<hive>USING' | '<hive>VIEW' | '<hive>WINDOW' | '<hive>.' | '<hive>[' | '<hive>]'
+ : '<hive>ALL' | '<hive>ARRAY' | '<hive>AS' | '<hive>AVRO' | '<hive>BINARY' | '<hive>BUCKET' | '<hive>BUCKETS' | '<hive>CACHE' | '<hive>CLUSTER' | '<hive>CLUSTERED' | '<hive>COLLECTION' | '<hive>COMPUTE' | '<hive>CONF' | '<hive>CROSS' | '<hive>CUBE' | '<hive>CURRENT' | '<hive>DATE' | '<hive>DEFERRED' | '<hive>DELIMITED' | '<hive>DISTRIBUTE' | '<hive>DISTRIBUTED' | '<hive>ESCAPED' | '<hive>EXTENDED' | '<hive>EXTERNAL' | '<hive>FIELDS' | '<hive>FILE' | '<hive>FOR' | '<hive>FORMAT' | '<hive>FUNCTION' | '<hive>GRANT' | '<hive>GROUPING' | '<hive>IDXPROPERTIES' | '<hive>LATERAL' | '<hive>MACRO' | '<hive>PARTITION' | '<hive>REBUILD' | '<hive>REPAIR' | '<hive>ROLLUP' | '<hive>SETS' | '<hive>STATISTICS' | '<hive>TABLE' | '<hive>USER' | '<hive>ASC' | '<hive>COLUMNS' | '<hive>COMMENT' | '<hive>COMPACTIONS' | '<hive>DATA' | '<hive>DATABASES' | '<hive>DEFINED' | '<hive>DESC' |  '<hive>FORMATTED' | '<hive>FUNCTIONS' | '<hive>INDEX' | '<hive>INDEXES' | '<hive>INPATH' | '<hive>INPUTFORMAT' | '<hive>ITEMS' | '<hive>JAR' | '<hive>KEYS' | '<hive>LINES' | '<hive>LIMIT' | '<hive>LOCATION' | '<hive>LOCKS' | '<hive>MAP' | '<hive>METADATA' | '<hive>NONE' | '<hive>NOSCAN' | '<hive>OF' | '<hive>ORC' | '<hive>OUT' | '<hive>OUTPUTFORMAT' | '<hive>PARQUET' | '<hive>PARTITIONED' | '<hive>PARTITIONS' | '<hive>RCFILE' | '<hive>ROLE' | '<hive>ROLES' | '<hive>SCHEMA' | '<hive>SCHEMAS' | '<hive>SEQUENCEFILE' | '<hive>SERDE' | '<hive>SERDEPROPERTIES' | '<hive>SKEWED' | '<hive>SORTED' | '<hive>STORED' | '<hive>STORED_AS_DIRECTORIES' | '<hive>STRING' | '<hive>STRUCT' | '<hive>TABLES' | '<hive>TABLESAMPLE' | '<hive>TBLPROPERTIES' | '<hive>TEMPORARY' | '<hive>TERMINATED' | '<hive>TEXTFILE' | '<hive>TINYINT' | '<hive>TRANSACTIONS' | '<hive>UNIONTYPE' | '<hive>USING' | '<hive>VIEW' | '<hive>WINDOW' | '<hive>.' | '<hive>[' | '<hive>]'
  | '<impala>AGGREGATE' | '<impala>AVRO' | '<impala>CACHED' | '<impala>CLOSE_FN' | '<impala>COLUMN' | '<impala>COMMENT' | '<impala>DATA' | '<impala>DATABASES' | '<impala>DELIMITED' | '<impala>ESCAPED' | '<impala>EXTERNAL' | '<impala>FIELDS' | '<impala>FINALIZE_FN' | '<impala>FIRST' | '<impala>FORMAT' | '<impala>FORMATTED' | '<impala>FUNCTION' | '<impala>FUNCTIONS' | '<impala>GROUP' | '<impala>INCREMENTAL' | '<impala>INTERVAL' | '<impala>INIT_FN' | '<impala>INPATH' | '<impala>LAST' | '<impala>LINES' | '<impala>LOCATION' | '<impala>MERGE_FN' | '<impala>NULLS' | '<impala>PARTITIONS' | '<impala>PREPARE_FN' | '<impala>REAL' | '<impala>RETURNS' | '<impala>SCHEMAS' | '<impala>SERIALIZE_FN' | '<impala>STATS' | '<impala>STRAIGHT_JOIN' | '<impala>SYMBOL' | '<impala>TABLE' | '<impala>TABLES' | '<impala>USING' | '<impala>ANALYTIC' | '<impala>ANTI' | '<impala>CURRENT' | '<impala>GRANT' | '<impala>PARQUET' | '<impala>PARTITIONED' | '<impala>RCFILE' | '<impala>ROLE' | '<impala>ROLES' | '<impala>SEQUENCEFILE' | '<impala>SERDEPROPERTIES' | '<impala>SHUFFLE' | '<impala>STORED' | '<impala>TBLPROPERTIES' | '<impala>TERMINATED' | '<impala>TEXTFILE' | '<impala>UPDATE_FN' | '<impala>BROADCAST' | '<impala>...' | '<impala>.' | '<impala>[' | '<impala>]'
  | 'ALL' | 'AS' | 'ASC' | 'BETWEEN' | 'BIGINT' | 'BOOLEAN' | 'BY' | 'CASE' | 'CHAR' | 'CURRENT' | 'DATABASE' | 'DECIMAL' | 'DISTINCT' | 'DOUBLE' | 'DESC' | 'ELSE' | 'END' | 'EXISTS' | 'FALSE' | 'FLOAT' | 'FOLLOWING' | 'FROM' | 'FULL' | 'GROUP' | 'HAVING' | 'IF' | 'IN' | 'INNER' | 'INT' | 'INTO' | 'IS' | 'JOIN' | 'LEFT' | 'LIKE' | 'LIMIT' | 'NOT' | 'NULL' | 'ON' | 'ORDER' | 'OUTER' | 'OVER' | 'PARTITION' | 'PRECEDING' | 'RANGE' | 'REGEXP' | 'RIGHT' | 'RLIKE' | 'ROW' | 'ROWS' | 'SCHEMA' | 'SEMI' | 'SET' | 'SMALLINT' | 'STRING' | 'TABLE' | 'THEN' | 'TIMESTAMP' | 'TINYINT' | 'TRUE' | 'UNION' | 'VARCHAR' | 'WHEN' | 'WHERE' | 'WITH' | 'ROLE'
  | 'AVG' | 'CAST' | 'COUNT' | 'MAX' | 'MIN' | 'STDDEV_POP' | 'STDDEV_SAMP' | 'SUM' | 'VARIANCE' | 'VAR_POP' | 'VAR_SAMP'

+ 42 - 0
desktop/core/src/desktop/static/desktop/js/autocomplete/jison/sql_set.jison

@@ -0,0 +1,42 @@
+// 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.
+
+DataDefinition
+ : SetRoleStatement
+ ;
+
+DataDefinition_EDIT
+ : SetRoleStatement_EDIT
+ | 'SET' 'CURSOR'
+   {
+     if (isHive()) {
+       suggestKeywords(['ROLE']);
+     }
+   }
+ ;
+
+SetRoleStatement
+ : 'SET' '<hive>ROLE' RegularIdentifier
+ | 'SET' '<hive>ROLE' '<hive>ALL'
+ | 'SET' '<hive>ROLE' '<hive>NONE'
+ ;
+
+SetRoleStatement_EDIT
+ : 'SET' '<hive>ROLE' 'CURSOR'
+   {
+     suggestKeywords(['ALL', 'NONE']);
+   }
+ ;

File diff suppressed because it is too large
+ 0 - 0
desktop/core/src/desktop/static/desktop/js/autocomplete/sql.js


+ 5 - 1
desktop/core/src/desktop/static/desktop/js/autocomplete/sql_support.js

@@ -18,6 +18,7 @@ var prepareNewStatement = function () {
   linkTablePrimaries();
   commitLocations();
 
+  delete parser.yy.caseDetermined;
   delete parser.yy.latestTablePrimaries;
   delete parser.yy.latestCommonTableExpressions;
   delete parser.yy.correlatedSubQuery;
@@ -833,7 +834,10 @@ var suggestValues = function (details) {
 };
 
 var determineCase = function (text) {
-  parser.yy.lowerCase = text.toLowerCase() === text;
+  if (!parser.yy.caseDetermined) {
+    parser.yy.lowerCase = text.toLowerCase() === text;
+    parser.yy.caseDetermined = true;
+  }
 };
 
 var lexerModified = false;

+ 1 - 0
desktop/core/src/desktop/static/desktop/spec/autocomplete/sqlSpec.js

@@ -25,6 +25,7 @@ define([
   'desktop/spec/autocomplete/sqlSpecError',
   'desktop/spec/autocomplete/sqlSpecLoad',
   'desktop/spec/autocomplete/sqlSpecSelect',
+  'desktop/spec/autocomplete/sqlSpecSet',
   'desktop/spec/autocomplete/sqlSpecShow',
   'desktop/spec/autocomplete/sqlSpecUpdate',
   'desktop/spec/autocomplete/sqlSpecUse'

+ 12 - 0
desktop/core/src/desktop/static/desktop/spec/autocomplete/sqlSpecCreate.js

@@ -53,6 +53,18 @@ define([
       });
     });
 
+    it('should handle "CREATE ROLE baaa;|', function () {
+      assertAutoComplete({
+        beforeCursor: 'CREATE ROLE baaa;',
+        afterCursor: '',
+        noError: true,
+        containsKeywords: ['SELECT'],
+        expectedResult: {
+          lowerCase: false
+        }
+      });
+    });
+
     describe('Hive specific', function () {
       it('should suggest keywords for "CREATE |"', function () {
         assertAutoComplete({

+ 14 - 0
desktop/core/src/desktop/static/desktop/spec/autocomplete/sqlSpecDrop.js

@@ -392,6 +392,20 @@ define([
       });
     });
 
+    describe('DROP ROLE', function () {
+      it('should handle "DROP ROLE boo;|"', function() {
+        assertAutoComplete({
+          beforeCursor: 'DROP ROLE boo;',
+          afterCursor: '',
+          noErrors: true,
+          containsKeywords: ['SELECT'],
+          expectedResult: {
+            lowerCase: false
+          }
+        });
+      });
+    });
+
     describe('DROP TABLE', function () {
       it('should suggest tables for "DROP TABLE |"', function() {
         assertAutoComplete({

+ 110 - 0
desktop/core/src/desktop/static/desktop/spec/autocomplete/sqlSpecSet.js

@@ -0,0 +1,110 @@
+// 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.
+define([
+  'knockout',
+  'desktop/js/autocomplete/sql',
+  'desktop/spec/autocompleterTestUtils'
+], function(ko, sql, testUtils) {
+
+  describe('sql.js SET statements', function() {
+
+    beforeAll(function () {
+      sql.yy.parseError = function (msg) {
+        throw Error(msg);
+      };
+      jasmine.addMatchers(testUtils.testDefinitionMatcher);
+    });
+
+    var assertAutoComplete = testUtils.assertAutocomplete;
+
+    it('should suggest keywords for "|"', function () {
+      assertAutoComplete({
+        beforeCursor: '',
+        afterCursor: '',
+        containsKeywords: ['SET'],
+        expectedResult: {
+          lowerCase: false
+        }
+      });
+    });
+
+    describe('SET ROLE', function () {
+
+      it('should handle "SET ROLE baaa;', function () {
+        assertAutoComplete({
+          beforeCursor: 'SET ROLE baaa;',
+          afterCursor: '',
+          dialect: 'hive',
+          noErrors: true,
+          containsKeywords: ['SELECT'],
+          expectedResult: {
+            lowerCase: false
+          }
+        });
+      });
+
+      it('should handle "SET ROLE ALL;', function () {
+        assertAutoComplete({
+          beforeCursor: 'SET ROLE ALL;',
+          afterCursor: '',
+          dialect: 'hive',
+          noErrors: true,
+          containsKeywords: ['SELECT'],
+          expectedResult: {
+            lowerCase: false
+          }
+        });
+      });
+
+      it('should handle "SET ROLE NONE;', function () {
+        assertAutoComplete({
+          beforeCursor: 'SET ROLE NONE;',
+          afterCursor: '',
+          dialect: 'hive',
+          noErrors: true,
+          containsKeywords: ['SELECT'],
+          expectedResult: {
+            lowerCase: false
+          }
+        });
+      });
+
+      it('should suggest keywords for "SET |"', function() {
+        assertAutoComplete({
+          beforeCursor: 'SET ',
+          afterCursor: '',
+          dialect: 'hive',
+          expectedResult: {
+            lowerCase: false,
+            suggestKeywords: ['ROLE']
+          }
+        });
+      });
+
+      it('should suggest keywords for "set role |"', function() {
+        assertAutoComplete({
+          beforeCursor: 'set role ',
+          afterCursor: '',
+          dialect: 'hive',
+          expectedResult: {
+            lowerCase: true,
+            suggestKeywords: ['ALL', 'NONE']
+          }
+        });
+      });
+    });
+  });
+});

+ 16 - 0
desktop/core/src/desktop/static/desktop/spec/autocomplete/sqlSpecShow.js

@@ -72,6 +72,7 @@ define([
           beforeCursor: 'SHOW COMPACTIONS;',
           afterCursor: '',
           dialect: 'hive',
+          noErrors: true,
           containsKeywords: ['SELECT'],
           expectedResult: {
             lowerCase: false
@@ -84,6 +85,20 @@ define([
           beforeCursor: 'SHOW CONF a.b.c;',
           afterCursor: '',
           dialect: 'hive',
+          noErrors: true,
+          containsKeywords: ['SELECT'],
+          expectedResult: {
+            lowerCase: false
+          }
+        });
+      });
+
+      it('should handle "SHOW CURRENT ROLES;|"', function() {
+        assertAutoComplete({
+          beforeCursor: 'SHOW CURRENT ROLES;',
+          afterCursor: '',
+          dialect: 'hive',
+          noErrors: true,
           containsKeywords: ['SELECT'],
           expectedResult: {
             lowerCase: false
@@ -1309,6 +1324,7 @@ define([
           beforeCursor: 'SHOW CURRENT ROLES;',
           afterCursor: '',
           dialect: 'impala',
+          noErrors: true,
           containsKeywords: ['SELECT'],
           expectedResult: {
             lowerCase: false

+ 1 - 1
tools/jison/hue-jison.sh

@@ -30,7 +30,7 @@ echo "%%" > sql_end.jison
 # With this all create tests will pass
 # cat sql_main.jison sql_create.jison sql_end.jison ../sql_support.js > sql.jison
 
-cat sql_main.jison sql_valueExpression.jison sql_error.jison sql_alter.jison sql_analyze.jison sql_create.jison sql_drop.jison sql_show.jison sql_update.jison sql_use.jison sql_end.jison ../sql_support.js > sql.jison
+cat sql_main.jison sql_valueExpression.jison sql_error.jison sql_alter.jison sql_analyze.jison sql_create.jison sql_drop.jison sql_set.jison sql_show.jison sql_update.jison sql_use.jison sql_end.jison ../sql_support.js > sql.jison
 
 jison sql.jison sql.jisonlex -m amd
 cat license.txt sql.js > ../sql.js

Some files were not shown because too many files changed in this diff