Daniel del Castillo created HIVE-17312:
------------------------------------------
Summary: Escaped qualified names in view are parsed incorrectly
and result in broken views
Key: HIVE-17312
URL: https://issues.apache.org/jira/browse/HIVE-17312
Project: Hive
Issue Type: Bug
Components: Parser
Affects Versions: 2.1.0
Reporter: Daniel del Castillo
Priority: Minor
The parser gets confused when a view is created with escaped qualified table
name. The resulting view can't be used as any attempt to access the view
results in _"SemanticException [Error 10255]: Invalid table name ..."_
Steps to reproduce using the default database:
{code}
hive> create table table_a (col1 string, col2 string);
OK
Time taken: 0.142 seconds
hive> CREATE VIEW dummy_view_3 AS SELECT * FROM `default.table_a`;
OK
Time taken: 0.137 seconds
hive> SELECT * FROM dummy_view_3;
FAILED: SemanticException [Error 10255]: Invalid table name
default.default.table_a
hive> CREATE VIEW dummy_view_2 AS SELECT * FROM default.table_a;
OK
Time taken: 1.165 seconds
{code}
Here's all the output of the test I've just done:
{code}
hive> create table table_a (col1 string, col2 string);
OK
Time taken: 0.142 seconds
hive> CREATE VIEW dummy_view_3 AS SELECT * FROM `default.table_a`;
OK
Time taken: 0.137 seconds
hive> SELECT * FROM dummy_view_3;
FAILED: SemanticException [Error 10255]: Invalid table name
default.default.table_a
hive> CREATE VIEW dummy_view_2 AS SELECT * FROM default.table_a;
OK
Time taken: 1.165 seconds
hive> SELECT * FROM dummy_view_2;
OK
Time taken: 1.202 seconds
hive> CREATE VIEW dummy_view_1 AS SELECT * FROM `default`.`table_a`;
OK
Time taken: 1.182 seconds
hive> SELECT * FROM dummy_view_1;
OK
Time taken: 1.084 seconds
hive>
[hadoop@:) ~]$
[hadoop@:) ~]$ mysql -h localhost -D hive -u hive -p
Enter password:
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 41152
Server version: 5.5.54 MySQL Community Server (GPL)
Copyright (c) 2000, 2016, Oracle and/or its affiliates. All rights reserved.
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
mysql> select * from TBLS;
+--------+-------------+-------+------------------+--------+-----------+-------+--------------+---------------+--------------------------------------------------------------------------------------------+-------------------------------+
| TBL_ID | CREATE_TIME | DB_ID | LAST_ACCESS_TIME | OWNER | RETENTION | SD_ID
| TBL_NAME | TBL_TYPE | VIEW_EXPANDED_TEXT
| VIEW_ORIGINAL_TEXT |
+--------+-------------+-------+------------------+--------+-----------+-------+--------------+---------------+--------------------------------------------------------------------------------------------+-------------------------------+
| 9 | 1502707228 | 1 | 0 | hadoop | 0 | 10
| table_a | MANAGED_TABLE | NULL
| NULL |
| 10 | 1502707256 | 1 | 0 | hadoop | 0 | 11
| dummy_view_3 | VIRTUAL_VIEW | SELECT `default.table_a`.`col1`,
`default.table_a`.`col2` FROM `default`.`default.table_a` | SELECT * FROM
default.table_a |
| 11 | 1502707765 | 1 | 0 | hadoop | 0 | 12
| dummy_view_2 | VIRTUAL_VIEW | SELECT `table_a`.`col1`, `table_a`.`col2` FROM
`default`.`table_a` | SELECT * FROM default.table_a |
| 12 | 1502708095 | 1 | 0 | hadoop | 0 | 13
| dummy_view_1 | VIRTUAL_VIEW | SELECT `table_a`.`col1`, `table_a`.`col2` FROM
`default`.`table_a` | SELECT * FROM default.table_a |
+--------+-------------+-------+------------------+--------+-----------+-------+--------------+---------------+--------------------------------------------------------------------------------------------+-------------------------------+
4 rows in set (0.00 sec)
mysql>
{code}
Note the expanded text of the faulty view is interpreting the escaped
characters as a non-qualified table name:
_SELECT `default.table_a`.`col1`, `default.table_a`.`col2` FROM
*`default`.`default.table_a`*_
The parser should either reject the creation of the view or expand the query as
_SELECT `default.table_a`.`col1`, `default.table_a`.`col2` FROM
*`default`.`table_a`*_
--
This message was sent by Atlassian JIRA
(v6.4.14#64029)