@Override public void operateOn(StructuredRecord record) { if (record.get(fieldName) != null) { count++; } }
@Override public int hashCode() { return record != null ? record.hashCode() : 0; } }
@Override public void groupBy(StructuredRecord record, Emitter<StructuredRecord> emitter) throws Exception { if (uniqueFields == null) { emitter.emit(record); return; } StructuredRecord.Builder builder = StructuredRecord.builder(getGroupKeySchema(record.getSchema())); for (String fieldName : uniqueFields) { builder.set(fieldName, record.get(fieldName)); } emitter.emit(builder.build()); }
/** * Get a builder for creating a record with the given schema. * * @param schema schema for the record to build. * @return builder for creating a record with the given schema. * @throws UnexpectedFormatException if the given schema is not a record with at least one field. */ public static Builder builder(Schema schema) throws UnexpectedFormatException { if (schema == null || schema.getType() != Schema.Type.RECORD || schema.getFields().size() < 1) { throw new UnexpectedFormatException("Schema must be a record with at least one field."); } return new Builder(schema); }
@Override public void groupBy(StructuredRecord record, Emitter<StructuredRecord> emitter) { if (fields == null) { emitter.emit(record); return; } Schema recordSchema = outputSchema == null ? getOutputSchema(record.getSchema(), fields) : outputSchema; StructuredRecord.Builder builder = StructuredRecord.builder(recordSchema); for (String fieldName : fields) { builder.set(fieldName, record.get(fieldName)); } emitter.emit(builder.build()); }
@Override public void operateOn(StructuredRecord record) { if (isFirst) { first = record.get(fieldName); firstRecord = record; isFirst = false; } }
/** * Get a builder for creating a record with the given schema. * * @param schema schema for the record to build. * @return builder for creating a record with the given schema. * @throws UnexpectedFormatException if the given schema is not a record with at least one field. */ public static Builder builder(Schema schema) throws UnexpectedFormatException { if (schema == null || schema.getType() != Schema.Type.RECORD || schema.getFields().size() < 1) { throw new UnexpectedFormatException("Schema must be a record with at least one field."); } return new Builder(schema); }
@Override public void operateOn(StructuredRecord record) { last = record.get(fieldName); lastRecord = record; }
@Override public void aggregate(Object groupKey, Iterator<StructuredRecord> groupValues, Emitter<StructuredRecord> emitter) throws Exception { long count = 0; while (groupValues.hasNext()) { groupValues.next(); count++; } emitter.emit(StructuredRecord.builder(schema) .set(config.fieldName, groupKey) .set("ct", count) .build()); }
@Override public void transform(StructuredRecord input, MultiOutputEmitter<StructuredRecord> emitter) throws Exception { String port = input.get(config.field) == null ? "null" : "non-null"; emitter.emit(port, input); }
@Override public void operateOn(StructuredRecord record) { Integer val = record.get(fieldName); if (val != null) { updateInt(val); } }
@Override public void operateOn(StructuredRecord record) { Long value = record.get(fieldName); if (value != null) { operateOnLong(value, record); } } };
@Override public void groupBy(StructuredRecord input, Emitter<String> emitter) throws Exception { String val = input.get(config.field); if (val != null) { emitter.emit(val); } }
@Override public void operateOn(StructuredRecord record) { Float val = record.get(fieldName); if (val != null) { updateFloat(val); } }