Skip to content

Commit 3e9a2fb

Browse files
committed
Rename debug_record() Fix function to print_record(). (#238)
1 parent 1f5e47d commit 3e9a2fb

File tree

2 files changed

+78
-78
lines changed

2 files changed

+78
-78
lines changed

README.md

Lines changed: 31 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -242,37 +242,6 @@ Copies (or appends to) a field from an existing field.
242242
copy_field("<sourceField>", "<targetField>")
243243
```
244244

245-
##### `debug_record`
246-
247-
Prints the current record either to standard output or to a file.
248-
249-
Parameters:
250-
251-
- `prefix` (optional): Prefix to print before the record. (Default: Empty string)
252-
253-
Options:
254-
255-
- `compression` (file output only): Compression mode. (Default: `auto`)
256-
- `destination`: Destination to write the record to; may include [format directives](https://docs.oracle.com/javase/8/docs/api/java/util/Formatter.html#syntax) for counter and record ID (in that order). (Default: `stdout`)
257-
- `encoding` (file output only): Encoding used by the underlying writer. (Default: `UTF-8`)
258-
- `footer`: Footer which is output after the record. (Default: `\n`)
259-
- `header`: Header which is output before the record. (Default: Empty string)
260-
- `id`: Field name which contains the record ID; if found, will be included before the prefix. (Default: `_id`)
261-
- `json`: Whether to encode the record as JSON. (Default: `false`)
262-
- `pretty`: Whether to use pretty printing. (Default: `false`)
263-
264-
```perl
265-
debug_record(["<prefix>"][, <options>...])
266-
```
267-
268-
E.g.:
269-
270-
```perl
271-
debug_record("Before transformation")
272-
debug_record(destination: "record-%03d.gz", header: "After transformation: ")
273-
debug_record(destination: "record-%2$s.json", id: "001", json: "true", pretty: "true")
274-
```
275-
276245
##### `format`
277246

278247
Replaces the value with a formatted (`sprintf`-like) version.
@@ -336,6 +305,37 @@ paste("my.string", "~Hi", "a", "~how are you?")
336305
# "my.string": "Hi eeny how are you?"
337306
```
338307

308+
##### `print_record`
309+
310+
Prints the current record either to standard output or to a file.
311+
312+
Parameters:
313+
314+
- `prefix` (optional): Prefix to print before the record. (Default: Empty string)
315+
316+
Options:
317+
318+
- `compression` (file output only): Compression mode. (Default: `auto`)
319+
- `destination`: Destination to write the record to; may include [format directives](https://docs.oracle.com/javase/8/docs/api/java/util/Formatter.html#syntax) for counter and record ID (in that order). (Default: `stdout`)
320+
- `encoding` (file output only): Encoding used by the underlying writer. (Default: `UTF-8`)
321+
- `footer`: Footer which is output after the record. (Default: `\n`)
322+
- `header`: Header which is output before the record. (Default: Empty string)
323+
- `id`: Field name which contains the record ID; if found, will be included before the prefix. (Default: `_id`)
324+
- `json`: Whether to encode the record as JSON. (Default: `false`)
325+
- `pretty`: Whether to use pretty printing. (Default: `false`)
326+
327+
```perl
328+
print_record(["<prefix>"][, <options>...])
329+
```
330+
331+
E.g.:
332+
333+
```perl
334+
print_record("Before transformation")
335+
print_record(destination: "record-%03d.gz", header: "After transformation: ")
336+
print_record(destination: "record-%2$s.json", id: "001", json: "true", pretty: "true")
337+
```
338+
339339
##### `random`
340340

341341
Creates (or replaces) a field with a random number (less than the specified maximum).

metafix/src/main/java/org/metafacture/metafix/FixMethod.java

Lines changed: 47 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -131,53 +131,6 @@ public void apply(final Metafix metafix, final Record record, final List<String>
131131
}));
132132
}
133133
},
134-
debug_record {
135-
private final Map<Metafix, LongAdder> scopedCounter = new HashMap<>();
136-
137-
@Override
138-
public void apply(final Metafix metafix, final Record record, final List<String> params, final Map<String, String> options) {
139-
final String destination = options.getOrDefault("destination", ObjectWriter.STDOUT);
140-
final Value idValue = record.get(options.getOrDefault("id", StandardEventNames.ID));
141-
142-
final boolean json = getBoolean(options, "json");
143-
final boolean pretty = getBoolean(options, "pretty");
144-
145-
final String id = Value.isNull(idValue) ? "" : idValue.toString();
146-
final String prefix = (id.isEmpty() ? "" : "[" + id + "] ") + (params.isEmpty() ? "" : params.get(0) + ": ");
147-
148-
final LongAdder counter = scopedCounter.computeIfAbsent(metafix, k -> new LongAdder());
149-
counter.increment();
150-
151-
final ObjectWriter<String> writer = new ObjectWriter<>(String.format(destination, counter.sum(), id));
152-
153-
withOption(options, "compression", writer::setCompression);
154-
withOption(options, "encoding", writer::setEncoding);
155-
withOption(options, "footer", writer::setFooter);
156-
withOption(options, "header", writer::setHeader);
157-
158-
boolean written = false;
159-
160-
if (json) {
161-
try {
162-
writer.process(prefix + record.toJson(pretty));
163-
written = true;
164-
}
165-
catch (final IOException e) {
166-
}
167-
}
168-
169-
if (!written) {
170-
if (pretty) {
171-
record.forEach((f, v) -> writer.process(prefix + f + "=" + v));
172-
}
173-
else {
174-
writer.process(prefix + record);
175-
}
176-
}
177-
178-
writer.closeStream();
179-
}
180-
},
181134
format {
182135
@Override
183136
public void apply(final Metafix metafix, final Record record, final List<String> params, final Map<String, String> options) {
@@ -261,6 +214,53 @@ private boolean literalString(final String s) {
261214
return s.startsWith("~");
262215
}
263216
},
217+
print_record {
218+
private final Map<Metafix, LongAdder> scopedCounter = new HashMap<>();
219+
220+
@Override
221+
public void apply(final Metafix metafix, final Record record, final List<String> params, final Map<String, String> options) {
222+
final String destination = options.getOrDefault("destination", ObjectWriter.STDOUT);
223+
final Value idValue = record.get(options.getOrDefault("id", StandardEventNames.ID));
224+
225+
final boolean json = getBoolean(options, "json");
226+
final boolean pretty = getBoolean(options, "pretty");
227+
228+
final String id = Value.isNull(idValue) ? "" : idValue.toString();
229+
final String prefix = (id.isEmpty() ? "" : "[" + id + "] ") + (params.isEmpty() ? "" : params.get(0) + ": ");
230+
231+
final LongAdder counter = scopedCounter.computeIfAbsent(metafix, k -> new LongAdder());
232+
counter.increment();
233+
234+
final ObjectWriter<String> writer = new ObjectWriter<>(String.format(destination, counter.sum(), id));
235+
236+
withOption(options, "compression", writer::setCompression);
237+
withOption(options, "encoding", writer::setEncoding);
238+
withOption(options, "footer", writer::setFooter);
239+
withOption(options, "header", writer::setHeader);
240+
241+
boolean written = false;
242+
243+
if (json) {
244+
try {
245+
writer.process(prefix + record.toJson(pretty));
246+
written = true;
247+
}
248+
catch (final IOException e) {
249+
}
250+
}
251+
252+
if (!written) {
253+
if (pretty) {
254+
record.forEach((f, v) -> writer.process(prefix + f + "=" + v));
255+
}
256+
else {
257+
writer.process(prefix + record);
258+
}
259+
}
260+
261+
writer.closeStream();
262+
}
263+
},
264264
random {
265265
@Override
266266
public void apply(final Metafix metafix, final Record record, final List<String> params, final Map<String, String> options) {

0 commit comments

Comments
 (0)