public static void main(String[] args) throws Exception { if (args.length < 2) { throw new Exception("Table name not specified."); } Configuration conf = HBaseConfiguration.create(); HTable table = new HTable(conf, args[0]); String startKey = args[1]; TimeCounter executeTimer = new TimeCounter(); executeTimer.begin(); executeTimer.enter(); Expression exp = ExpressionFactory.eq( ExpressionFactory.toLong( ExpressionFactory.toString(ExpressionFactory.columnValue("family", "longStr2"))), ExpressionFactory.constant(Long.parseLong("99"))); ExpressionFilter expressionFilter = new ExpressionFilter(exp); Scan scan = new Scan(Bytes.toBytes(startKey), expressionFilter); int count = 0; ResultScanner scanner = table.getScanner(scan); Result r = scanner.next(); while (r != null) { count++; r = scanner.next(); } System.out.println("++ Scanning finished with count : " + count + " ++"); scanner.close(); executeTimer.leave(); executeTimer.end(); System.out.println("++ Time cost for scanning: " + executeTimer.getTimeString() + " ++"); }
public static void main(String[] args) { Configuration conf = HBaseConfiguration.create(); conf.setInt("hbase.client.retries.number", 1); conf.setInt("ipc.client.connect.max.retries", 1); byte[] table = Bytes.toBytes("t"); try { GroupByClient groupByClient = new GroupByClient(conf); Scan[] scans = {new Scan()}; List<Expression> groupByExpresstions = new ArrayList<Expression>(); List<Expression> selectExpresstions = new ArrayList<Expression>(); groupByExpresstions.add(ExpressionFactory.columnValue("f", "id")); selectExpresstions.add( ExpressionFactory.groupByKey(ExpressionFactory.columnValue("f", "id"))); List<EvaluationResult[]> groupByResultList = groupByClient.groupBy(table, scans, groupByExpresstions, selectExpresstions, null); for (EvaluationResult[] res : groupByResultList) { String resultString = ""; for (int i = 0; i < res.length; i++) { EvaluationResult er = res[i]; resultString += "\t\t" + er.toString(); if (0 == ((i + 1) % selectExpresstions.size())) { System.out.println(resultString); resultString = ""; } } } } catch (Throwable e) { e.printStackTrace(); } }