@Override public StructuredRecord getCurrentRecord() throws InterruptedException { Row row = tableSplitReader.getCurrentValue(); try { return rowReader.read(row, tableSchema); } catch (IOException e) { LOG.error("Unable to read row.", e); throw Throwables.propagate(e); } }
private StructuredRecordScanner(SplitReader<byte[], Row> tableSplitReader) { this.tableSplitReader = tableSplitReader; this.rowReader = new ReflectionRowRecordReader(tableSchema, rowFieldName); }
@Override public StructuredRecord read(Row row, Schema sourceSchema) throws IOException { Preconditions.checkArgument(sourceSchema.getType() == Schema.Type.RECORD, "Source schema must be a record."); initializeRead(sourceSchema); StructuredRecord.Builder builder = StructuredRecord.builder(schema); // if one of the fields should come from the row key, add it. if (rowFieldName != null) { builder.set(rowFieldName, rowKeyFunction.convert(row.getRow())); } // go through the Row columns and add their values to the record try { for (Schema.Field sourceField : sourceSchema.getFields()) { String sourceFieldName = sourceField.getName(); Schema.Field targetField = schema.getField(sourceFieldName); // the Row may contain more fields than our target schema. Skip those fields that are not in the target schema, // as well as the row key field since it comes from the row key and not the columns. if (targetField == null || targetField.getName().equals(rowFieldName)) { advanceField(); continue; } builder.set(sourceFieldName, read(row, sourceField.getSchema(), targetField.getSchema(), type)); } return builder.build(); } catch (Exception e) { throw propagate(e); } }
@Override public void apply() throws Exception { Put put = new Put(rowKey); ReflectionPutWriter<User> putWriter = new ReflectionPutWriter<>(schema); putWriter.write(SAMUEL, put); usersTable.put(put); Row row = usersTable.get(rowKey); ReflectionRowRecordReader rowReader = new ReflectionRowRecordReader(schema, null); StructuredRecord actual = rowReader.read(row, schema); assertRecordEqualsUser(SAMUEL, actual); } });
@Override public StructuredRecord read(Row row, Schema sourceSchema) throws IOException { Preconditions.checkArgument(sourceSchema.getType() == Schema.Type.RECORD, "Source schema must be a record."); initializeRead(sourceSchema); StructuredRecord.Builder builder = StructuredRecord.builder(schema); // if one of the fields should come from the row key, add it. if (rowFieldName != null) { builder.set(rowFieldName, rowKeyFunction.convert(row.getRow())); } // go through the Row columns and add their values to the record try { for (Schema.Field sourceField : sourceSchema.getFields()) { String sourceFieldName = sourceField.getName(); Schema.Field targetField = schema.getField(sourceFieldName); // the Row may contain more fields than our target schema. Skip those fields that are not in the target schema, // as well as the row key field since it comes from the row key and not the columns. if (targetField == null || targetField.getName().equals(rowFieldName)) { advanceField(); continue; } builder.set(sourceFieldName, read(row, sourceField.getSchema(), targetField.getSchema(), type)); } return builder.build(); } catch (Exception e) { throw propagate(e); } }
@Override public void apply() throws Exception { Put put = new Put(rowKey); ReflectionPutWriter<User> putWriter = new ReflectionPutWriter<>(fullSchema); putWriter.write(SAMUEL, put); usersTable.put(put); Row row = usersTable.get(rowKey); ReflectionRowRecordReader rowReader = new ReflectionRowRecordReader(projSchema, null); StructuredRecord actual = rowReader.read(row, fullSchema); assertRecordEqualsUser(projected, actual); } });
@Override public StructuredRecord getCurrentRecord() throws InterruptedException { Row row = tableSplitReader.getCurrentValue(); try { return rowReader.read(row, tableSchema); } catch (IOException e) { LOG.error("Unable to read row.", e); throw Throwables.propagate(e); } }
private StructuredRecordScanner(SplitReader<byte[], Row> tableSplitReader) { this.tableSplitReader = tableSplitReader; this.rowReader = new ReflectionRowRecordReader(tableSchema, rowFieldName); }