Row getRowDataTypeForSelect(ParserRuleContext ctx, String conn, String select) {
    Row row = null;
    Conn.Type connType = exec.getConnectionType(conn); 
    // Hive does not support ResultSetMetaData on PreparedStatement, and Hive DESCRIBE
    // does not support queries, so we have to execute the query with LIMIT 1
    if (connType == Conn.Type.HIVE) {
      String sql = "SELECT * FROM (" + select + ") t LIMIT 1";
      QueryResult query = queryExecutor.executeQuery(sql, ctx);
      if (!query.error()) {
        try {
          int cols = query.columnCount();
          row = new Row();
          for (int i = 0; i < cols; i++) {
            String name = query.metadata().columnName(i);
            if (name.startsWith("t.")) {
              name = name.substring(2);
            }
            row.addColumnDefinition(name, query.metadata().columnTypeName(i));
          }
        } 
        catch (Exception e) {
          exec.signal(e);
        }
      }
      else {
        exec.signal(query.exception());
      }
      query.close();
    }
    else {
      QueryResult query = queryExecutor.executeQuery(select, ctx);
      if (!query.error()) {
        try {
          Metadata rm = query.metadata();
          int cols = rm.columnCount();
          for (int i = 1; i <= cols; i++) {
            String col = rm.columnName(i);
            String typ = rm.columnTypeName(i);
            if (row == null) {
              row = new Row();
            }
            row.addColumnDefinition(col.toUpperCase(), typ);
          }
        }
        catch (Exception e) {
          exec.signal(e);
        }
      }
      query.close();
    }
    return row;
  }
Get data types for all columns of the SELECT statement
hplsql/src/main/java/org/apache/hive/hplsql/Meta.java