问题描述:

I was able to create a table into hbase using hive now I'm trying to load data into a hive table then overwrite the data into the hbase table :

public class HiveJdbcClient {

private static String driverName = "org.apache.hadoop.hive.jdbc.HiveDriver";

/**

* @param args

* @throws SQLException

**/

public static void main(String[] args) throws SQLException {

try {

Class.forName(driverName);

} catch (ClassNotFoundException e){

// TODO Auto-generated catch block

e.printStackTrace();

System.exit(1);

}

Connection con = DriverManager.getConnection("jdbc:hive://localhost:10000/default", "", "");

Statement stmt = con.createStatement();

String tableNameHive = "hbase_trades";

String tableNameHbase= "trades";

stmt.executeQuery("drop table " + tableNameHive);

ResultSet res = stmt.executeQuery("create table " + tableNameHive + " (key string, value string) STORED BY 'org.apache.hadoop.hive.hbase.HBaseStorageHandler' WITH SERDEPROPERTIES (\"hbase.columns.mapping\" = \":key,cf1:val\") TBLPROPERTIES (\"hbase.table.name\" = \"trades\")");

String sql = "show tables '" + tableNameHive + "'";

System.out.println("Running: " + sql);

res = stmt.executeQuery(sql);

if (res.next()) {

System.out.println(res.getString(1));

}

sql = "describe " + tableNameHive;

System.out.println("Running: " + sql);

res = stmt.executeQuery(sql);

while (res.next()) {

System.out.println(res.getString(1) + "\t" + res.getString(2));

}

String filepath = "/tmp/test_hive_server.txt";

sql = "load data local inpath '" + filepath + "' into table " + tableNameHive;

System.out.println("Running: " + sql);

res = stmt.executeQuery(sql);

stmt.executeQuery("insert overwrite " + tableNameHbase+"select * from"+tableNameHive);

}

}

and I get the following error:

Running: load data local inpath '/tmp/test_hive_server.txt' into table hbase_trades

Exception in thread "main" java.sql.SQLException: Query returned non-zero code: 10101, cause: FAILED: SemanticException [Error 10101]: A non-native table cannot be used as target for LOAD

at org.apache.hadoop.hive.jdbc.HiveStatement.executeQuery(HiveStatement.java:194)

at com.palmyra.nosql.HiveJdbcClient.main(HiveJdbcClient.java:53)

could someone tell me what's the problem??

相关阅读:
Top