Преглед изворни кода

HUE-9706 [Phoenix] Right assist does not list current table

ayush.goyal пре 4 година
родитељ
комит
929ce11960

+ 29 - 0
desktop/core/src/desktop/js/parse/jison/sql/phoenix/quoted_table_identifier.jison

@@ -0,0 +1,29 @@
+// 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.
+
+SchemaQualifiedTableIdentifier
+ : DoubleQuotedValue
+   {
+     parser.addTableLocation(@1, [ { name: $1 } ]);
+     $$ = { identifierChain: [ { name: $1 } ] };
+   }
+ | DoubleQuotedValue '.' DoubleQuotedValue
+   {
+     parser.addDatabaseLocation(@1, [ { name: $1 } ]);
+     parser.addTableLocation(@3, [ { name: $1 }, { name: $3 } ]);
+     $$ = { identifierChain: [ { name: $1 }, { name: $3 } ] };
+   }
+ ;

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

@@ -53,6 +53,7 @@
     "../generic/use/use.jison",
     "../generic/sql_error.jison",
     "../generic/sql_main.jison",
+    "quoted_table_identifier.jison",
     "../generic/sql_valueExpression.jison",
     "../generic/autocomplete_footer.jison"
   ],
@@ -108,6 +109,7 @@
     "../generic/update/update_table.jison",
     "../generic/use/use.jison",
     "../generic/sql_main.jison",
+    "quoted_table_identifier.jison",
     "../generic/sql_valueExpression.jison",
     "../generic/syntax_footer.jison"
   ]

Разлика између датотеке није приказан због своје велике величине
+ 0 - 0
desktop/core/src/desktop/js/parse/sql/phoenix/phoenixAutocompleteParser.js


Разлика између датотеке није приказан због своје велике величине
+ 0 - 0
desktop/core/src/desktop/js/parse/sql/phoenix/phoenixSyntaxParser.js


+ 59 - 0
desktop/core/src/desktop/js/parse/sql/phoenix/test/phoenixAutocompleteParser.Locations.test.js

@@ -105,6 +105,65 @@ describe('phoenixAutocompleteParser.js locations', () => {
     });
   });
 
+  it('should report locations for "select cos(1) as foo from customers order by foo;"', () => {
+    assertLocations({
+      beforeCursor: 'select cos(1) as foo from "customers" order by foo; ',
+      expectedLocations: [
+        {
+          type: 'statement',
+          location: { first_line: 1, last_line: 1, first_column: 1, last_column: 49 }
+        },
+        {
+          type: 'selectList',
+          missing: false,
+          location: { first_line: 1, last_line: 1, first_column: 8, last_column: 21 }
+        },
+        {
+          type: 'function',
+          location: { first_line: 1, last_line: 1, first_column: 8, last_column: 10 },
+          function: 'cos'
+        },
+        {
+          type: 'functionArgument',
+          location: { first_line: 1, last_line: 1, first_column: 12, last_column: 13 },
+          function: 'cos',
+          argumentPosition: 0,
+          identifierChain: [{ name: 'cos' }],
+          expression: { types: ['NUMBER'], text: '1' }
+        },
+        {
+          type: 'alias',
+          source: 'column',
+          alias: 'foo',
+          location: { first_line: 1, last_line: 1, first_column: 18, last_column: 21 },
+          parentLocation: { first_line: 1, last_line: 1, first_column: 8, last_column: 14 }
+        },
+        {
+          type: 'table',
+          location: { first_line: 1, last_line: 1, first_column: 27, last_column: 36 },
+          identifierChain: [{ name: 'customers' }]
+        },
+        {
+          type: 'whereClause',
+          missing: true,
+          location: { first_line: 1, last_line: 1, first_column: 36, last_column: 36 }
+        },
+        {
+          type: 'alias',
+          location: { first_line: 1, last_line: 1, first_column: 46, last_column: 49 },
+          alias: 'foo',
+          source: 'column',
+          parentLocation: { first_line: 1, last_line: 1, first_column: 8, last_column: 14 }
+        },
+        {
+          type: 'limitClause',
+          missing: true,
+          location: { first_line: 1, last_line: 1, first_column: 49, last_column: 49 }
+        }
+      ]
+    });
+  });
+
   it('should report locations for "WITH boo AS (SELECT * FROM tbl) SELECT * FROM boo; |"', () => {
     assertLocations({
       beforeCursor: 'WITH boo AS (SELECT * FROM tbl) SELECT * FROM boo; ',

+ 5 - 0
desktop/libs/notebook/src/notebook/connectors/sql_alchemy.py

@@ -419,6 +419,11 @@ class SqlAlchemyApi(Api):
 
   @query_error_handler
   def autocomplete(self, snippet, database=None, table=None, column=None, nested=None, operation=None):
+    if snippet['type'] == 'phoenix':
+      if database:
+        database = database.upper()
+      if table:
+        table = table.upper()
     engine = self._get_engine()
     inspector = inspect(engine)
 

+ 2 - 2
desktop/libs/notebook/src/notebook/connectors/sql_alchemy_tests.py

@@ -367,7 +367,7 @@ class TestAutocomplete(object):
       'options': {'url': 'phoenix://'}
     }
 
-    snippet = Mock()
+    snippet = MagicMock()
     with patch('notebook.connectors.sql_alchemy.create_engine') as create_engine:
       with patch('notebook.connectors.sql_alchemy.inspect') as inspect:
         with patch('notebook.connectors.sql_alchemy.Assist') as Assist:
@@ -383,7 +383,7 @@ class TestAutocomplete(object):
       'options': {'url': 'phoenix://'}
     }
 
-    snippet = Mock()
+    snippet = MagicMock()
     with patch('notebook.connectors.sql_alchemy.create_engine') as create_engine:
       with patch('notebook.connectors.sql_alchemy.inspect') as inspect:
         with patch('notebook.connectors.sql_alchemy.Assist') as Assist:

Неке датотеке нису приказане због велике количине промена