【问题标题】:Hive to Hbase comparision of data in tablesHive 到 Hbase 比较表中的数据
【发布时间】:2017-08-24 05:33:37
【问题描述】:

我正在进行 DW 测试,需要比较源数据和目标数据。源数据存储在 hive/RDBMS 中,而目标数据加载到 Hbase 中。我是 Hbase 的新手。任何人都可以帮助我采用我可以采取的方法。我正在寻找的是与 "MINUS" 类似的功能。是否可以 ?

【问题讨论】:

    标签: hadoop hive hbase etl bigdata


    【解决方案1】:

    您应该编写可以组合的 java 文件:

    HBase:
    import java.io.IOException;
    
    // HBASE
    import org.apache.hadoop.conf.Configuration;
    
    import org.apache.hadoop.hbase.HBaseConfiguration;
    import org.apache.hadoop.hbase.client.Get;
    import org.apache.hadoop.hbase.client.HTable;
    import org.apache.hadoop.hbase.client.Result;
    import org.apache.hadoop.hbase.util.Bytes;
    
    
    
    public class RetriveData{
    
       public static void main(String[] args) throws IOException, Exception{
    
          // Instantiating Configuration class
          Configuration config = HBaseConfiguration.create();
    
          // Instantiating HTable class
          HTable table = new HTable(config, "emp");
    
          // Instantiating Get class
          Get g = new Get(Bytes.toBytes("row1"));
    
          // Reading the data
          Result result = table.get(g);
    
          // Reading values from Result class object
          byte [] value = result.getValue(Bytes.toBytes("personal"),Bytes.toBytes("name"));
    
          byte [] value1 = result.getValue(Bytes.toBytes("personal"),Bytes.toBytes("city"));
    
          // Printing the values
          String name = Bytes.toString(value);
          String city = Bytes.toString(value1);
    
    **// CALL THE HIVE CLASS(HiveQLOrderBy)...YOU CAN COMPARE**
    
          System.out.println("name: " + name + " city: " + city);
       }
    }
    
    
    //HIVE
    
    import java.sql.SQLException;
    import java.sql.Connection;
    import java.sql.ResultSet;
    import java.sql.Statement;
    import java.sql.DriverManager;
    
    public class HiveQLOrderBy {
       private static String driverName = "org.apache.hadoop.hive.jdbc.HiveDriver";
    
       public static void main(String[] args) throws SQLException {
    
          // Register driver and create driver instance
          Class.forName(driverName);
    
          // get connection
          Connection con = DriverManager.getConnection("jdbc:hive://localhost:10000/userdb", "", "");
    
          // create statement 
          Statement stmt = con.createStatement();
    
          // execute statement
          Resultset res = stmt.executeQuery("SELECT * FROM employee ORDER BY DEPT;");
          System.out.println(" ID \t Name \t Salary \t Designation \t Dept ");
    
          while (res.next()) {
             System.out.println(res.getInt(1) + " " + res.getString(2) + " " + res.getDouble(3) + " " + res.getString(4) + " " + res.getString(5));
          }
    
          con.close();
       }
    }
    

    【讨论】:

    • 感谢@R Palanivel,但我从上面的 Java 文件中了解到,它将单独打印 Hbase 表中的结果,然后 Hive 必须手动比较它。如果我错了,请纠正我。到目前为止,我还无法实现它。请提出建议。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2020-12-15
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-02-17
    • 1970-01-01
    相关资源
    最近更新 更多