/** * Defines the HBase row key that will be used when writing the data from a * tuple to HBase. * * @param tuple The tuple to map to HBase. */ @Override public byte[] rowKey(Tuple tuple) { ProfileMeasurement measurement = (ProfileMeasurement) tuple.getValueByField("measurement"); return rowKeyBuilder.rowKey(measurement); }
List<Get> gets = new ArrayList<>(); for(ProfileMeasurement measurement: measurements) { byte[] rowKey = rowKeyBuilder.rowKey(measurement); Get get = new Get(rowKey).addColumn(columnFamily, columnQualifier); gets.add(get);
/** * Writes a set of measurements to HBase. * * @param iterator The measurements to write. * @return The number of measurements written to HBase. */ @Override public Iterator<Integer> call(Iterator<ProfileMeasurementAdapter> iterator) throws Exception { int count = 0; LOG.debug("About to write profile measurement(s) to HBase"); // do not open hbase connection, if nothing to write List<ProfileMeasurementAdapter> measurements = IteratorUtils.toList(iterator); if(measurements.size() > 0) { // open an HBase connection Configuration config = HBaseConfiguration.create(); try (HBaseClient client = new HBaseClient(tableProvider, config, tableName)) { for (ProfileMeasurementAdapter adapter : measurements) { ProfileMeasurement m = adapter.toProfileMeasurement(); client.addMutation(rowKeyBuilder.rowKey(m), columnBuilder.columns(m), durability); } count = client.mutate(); } catch (IOException e) { LOG.error("Unable to open connection to HBase", e); throw new RuntimeException(e); } } LOG.debug("{} profile measurement(s) written to HBase", count); return IteratorUtils.singletonIterator(count); }