课程链接: http://edu.51cto.com/course/15174.html
kudu对表数据进行读取操作
重要调优参数:
defaultAdminOperationTimeoutMs:用户对kudu的createTable,insertTable的操作连接超时数设置
String tableName = "wyh_main";
KuduClient client = new KuduClient.KuduClientBuilder("hadoop4,hadoop5,hadoop6").defaultAdminOperationTimeoutMs(600000).build();
// 获取需要查询数据的列
List<String> projectColumns = new ArrayList<String>();
projectColumns.add("id");
projectColumns.add("user_id");
projectColumns.add("start_time");
projectColumns.add("name");
// 简单的读取
// KuduScanner scanner = client.newScannerBuilder(table).setProjectedColumnNames(projectColumns).build();
// 根据主键设置读取的上限和下限
Schema schema = table.getSchema();
PartialRow lower = schema.newPartialRow();
lower.addLong("id", 10);
lower.addLong("user_id", 10);
lower.addLong("start_time", 50);
PartialRow upper = schema.newPartialRow();
upper.addLong("id", 50);
upper.addLong("user_id", 50);
upper.addLong("start_time", 50);
KuduScanner scanner = client.newScannerBuilder(table)
.setProjectedColumnNames(projectColumns)
.lowerBound(lower)
.exclusiveUpperBound(upper)
.build();
while (scanner.hasMoreRows()) {
RowResultIterator results = scanner.nextRows();
// 18个tablet,每次从tablet中获取的数据的行数
int numRows = results.getNumRows();
System.out.println("numRows is : " + numRows);
while (results.hasNext()) {
RowResult result = results.next();
long id = result.getLong(0);
long user_id = result.getLong(1);
long start_time = result.getLong(2);
String name = result.getString(3);
System.out.println("id is : " + id + "===user_id is : " + user_id + "===start_time" + start_time + "===name is : " + name);
}
System.out.println("--------------------------------------");
}