Uploaded image for project: 'Hive'
  1. Hive
  2. HIVE-17312

Escaped qualified names in view are parsed incorrectly and result in broken views

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Open
    • Minor
    • Resolution: Unresolved
    • 2.1.0
    • None
    • Parser
    • None

    Description

      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:

      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
      

      Here's all the output of the test I've just done:

      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>
      

      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`

      Attachments

        Issue Links

          Activity

            People

              Unassigned Unassigned
              ddcprg Daniel del Castillo
              Votes:
              1 Vote for this issue
              Watchers:
              5 Start watching this issue

              Dates

                Created:
                Updated: