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

White spaces characters in view creation via JDBC cause problems with show create.

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Open
    • Minor
    • Resolution: Unresolved
    • 1.1.1
    • None
    • JDBC
    • None

    Description

      When view is created via JDBC, white spaces are included in the view creation. This is not the same behavior if we use beeline to create the view.

      For the JDBC issue, consider the below tables setup.

      create table t0 (id int, name string, address string, dob timestamp);
      create table t1 (id int, activity string, timedone timestamp);
      create table t2 (id int, history string);
      

      And, the Java code to create the view:

      public class ViewCreationThroughJDBC{
      public static void main(String[] args) throws SQLException{
      try {
      Class.forName("org.apache.hive.jdbc.HiveDriver");
      } catch (ClassNotFoundException e) {
      e.printStackTrace();
      System.exit(1);
      }
      String hostName = null;
      try {
      InetAddress ipAddress = InetAddress.getLocalHost();
      hostName = ipAddress.getHostName();
      System.out.println("Current IP: <" + ipAddress + ">");
      System.out.println("Hostname is: <" + hostName + ">");
      
      } catch (UnknownHostException e) {
      e.printStackTrace();
      }
      
      String sql = null;
      try {
      sql = new String(Files.readAllBytes(Paths.get("view_create.txt")), StandardCharsets.UTF_8);
      } catch (Exception e) {
      e.printStackTrace();
      }
      
      Connection conn = DriverManager.getConnection("jdbc:hive2://" + hostName + ":10000/default;", "username", "password");
      
      Statement stmt = conn.createStatement();
      System.out.println("Running: " + sql);
      //ResultSet res = stmt.executeQuery(sql);
      stmt.execute(sql);
      try {
      //res.close();
      stmt.close();
      conn.close();
      }
      catch (Exception e) {
      e.printStackTrace();
      }
      }
      }
      

      And, the contents of view_create.txt referenced in the above code is as shown below:

      (Note: Please insert tabs {at least 4 tabs} before each line below. When I used the

      {code\} tag, I think it cleared the tabs. Hence, I request you to manually insert spacesĀ in front of each line below.}
      create view v0 as
      select
       -- get the id from t0 table
      
      a.id
       -- Do not get
       --, any other
       --, details
      
      -- lets gather name address and dob
       ,
       a.name ,
       a.address ,
       a.dob ,
       b.activity ,
       b.timedone
       -- The column name should be timezone and not timedone
       ,
       c.history
       from t0 a, t1 b, t2 c
       where
       a.id = b.id
       and c.id = a.id
      

      When this code is run and a 'show create table v0' is run from beeline, it shows empty lines.

      Essentially, when: 'show create table v0' is run from beeline, below is the output I see:

      +------------------------------------------+--+
      | createtab_stmt |
      +------------------------------------------+--+
      | CREATE VIEW `v0` AS select |
      | |
      | |
      | |
      | |
      | |
      | |
      | |
      | |
      | |
      | |
      | |
      | |
      | |
      | |
      | |
      | |
      | |
      | |
      | |
      | |
      | |
      +------------------------------------------+--+
      22 rows selected (0.188 seconds)

      Attachments

        Activity

          People

            Unassigned Unassigned
            venu.yanamandra@live.com Venu Yanamandra
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

              Created:
              Updated: