Search in sources :

Example 1 with PreviewResult

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)));
}
Also used : Path(java.nio.file.Path) ConfigSource(org.embulk.config.ConfigSource) TestingEmbulk(org.embulk.test.TestingEmbulk) PreviewResult(org.embulk.exec.PreviewResult)

Example 2 with PreviewResult

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();
}
Also used : PreviewResult(org.embulk.exec.PreviewResult) VerticalPreviewPrinter(org.embulk.command.VerticalPreviewPrinter) TablePreviewPrinter(org.embulk.command.TablePreviewPrinter) VerticalPreviewPrinter(org.embulk.command.VerticalPreviewPrinter) PreviewPrinter(org.embulk.command.PreviewPrinter) TablePreviewPrinter(org.embulk.command.TablePreviewPrinter) ModelManager(org.embulk.config.ModelManager)

Aggregations

PreviewResult (org.embulk.exec.PreviewResult)2 Path (java.nio.file.Path)1 PreviewPrinter (org.embulk.command.PreviewPrinter)1 TablePreviewPrinter (org.embulk.command.TablePreviewPrinter)1 VerticalPreviewPrinter (org.embulk.command.VerticalPreviewPrinter)1 ConfigSource (org.embulk.config.ConfigSource)1 ModelManager (org.embulk.config.ModelManager)1 TestingEmbulk (org.embulk.test.TestingEmbulk)1