use of org.embulk.exec.PreviewResult in project embulk by embulk.
the class TestFilePreview method assertPreviewedRecords.
private static void assertPreviewedRecords(TestingEmbulk embulk, String loadYamlResourceName, String execYamlResourceName, String sourceCsvResourceName, String resultCsvResourceName) throws IOException {
Path inputPath = embulk.createTempFile("csv");
Path outputPath = embulk.createTempFile("csv");
// in: config
copyResource(RESOURCE_NAME_PREFIX + sourceCsvResourceName, inputPath);
ConfigSource load = embulk.loadYamlResource(RESOURCE_NAME_PREFIX + loadYamlResourceName).set("path_prefix", inputPath.toAbsolutePath().toString());
// exec: config
final TestingEmbulk.InputBuilder builder = embulk.inputBuilder();
if (execYamlResourceName != null) {
final ConfigSource execConfig = embulk.loadYamlResource(RESOURCE_NAME_PREFIX + execYamlResourceName);
builder.exec(execConfig);
}
// execute preview
final PreviewResult result = builder.in(load).outputPath(outputPath).preview();
assertThat(readFile(outputPath), is(readResource(RESOURCE_NAME_PREFIX + resultCsvResourceName)));
}
use of org.embulk.exec.PreviewResult in project embulk by embulk.
the class EmbulkRunner method previewInternal.
private void previewInternal(final ConfigSource configSource, final String format) throws IOException {
final PreviewResult previewResult = this.embed.preview(configSource);
final ModelManager modelManager = this.embed.getModelManager();
final PreviewPrinter printer;
switch(format != null ? format : "table") {
case "table":
printer = new TablePreviewPrinter(System.out, modelManager, previewResult.getSchema());
break;
case "vertical":
printer = new VerticalPreviewPrinter(System.out, modelManager, previewResult.getSchema());
break;
default:
throw new IllegalArgumentException("Unknown preview output format '" + format + "'. Supported formats: table, vertical");
}
printer.printAllPages(previewResult.getPages());
printer.finish();
}
Aggregations