借网上一个关于Driver的例子来说明一下:
import org.apache.hadoop.hive.conf.HiveConf;
import org.apache.hadoop.hive.ql.Driver;
import org.apache.hadoop.hive.ql.session.SessionState;
public class Test { public static void main(String args[]) {
Vector<String> res = new Vector<String>();
String sql = "SELECT * from test";
Driver driver = new Driver(new HiveConf(SessionState.class));
int ret = driver.run(sql);
try {
driver.getResults(res);
} catch(IOException e) {
e.printStackTrace();
}
driver.close();
System.out.println(driver.getMaxRows());
try {
System.out.println(driver.getSchema());
//System.out.println(driver.getThriftSchema());
} catch(Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
// System.out.println(res);
// System.out.println(ret);
}
}
Driver类没有象jdbc ResultSet一相提供next()遍历函数,若遇到类似select * from t;大量数据如何处理(假设大得足以若内存吃不消)
测试是它把结果集都放到里,感觉不太友好,有其它的解决办法吗?或能解释一下它为什么这么设计?
|