Search in sources :

Example 36 with ConfigSource

use of org.embulk.config.ConfigSource in project embulk by embulk.

the class TestCsvGuessPlugin method assertGuessByResource.

static void assertGuessByResource(TestingEmbulk embulk, String seedYamlResourceName, String sourceCsvResourceName, String resultResourceName) throws IOException {
    ConfigSource seed = embulk.loadYamlResource(RESOURCE_NAME_PREFIX + seedYamlResourceName);
    ConfigDiff guessed = embulk.parserBuilder().parser(seed).exec(embulk.newConfig().set("exclude_guess_plugins", ImmutableList.of("json"))).inputResource(RESOURCE_NAME_PREFIX + sourceCsvResourceName).guess();
    assertThat(guessed, is((DataSource) embulk.loadYamlResource(RESOURCE_NAME_PREFIX + resultResourceName)));
}
Also used : ConfigSource(org.embulk.config.ConfigSource) ConfigDiff(org.embulk.config.ConfigDiff) DataSource(org.embulk.config.DataSource)

Example 37 with ConfigSource

use of org.embulk.config.ConfigSource in project embulk by embulk.

the class TestRemoveColumnsFilterPlugin method assertRecordsByResource.

static void assertRecordsByResource(TestingEmbulk embulk, String inConfigYamlResourceName, String filterConfigYamlResourceName, 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 inConfig = embulk.loadYamlResource(RESOURCE_NAME_PREFIX + inConfigYamlResourceName).set("path_prefix", inputPath.toAbsolutePath().toString());
    // remove_columns filter config
    ConfigSource filterConfig = embulk.loadYamlResource(RESOURCE_NAME_PREFIX + filterConfigYamlResourceName);
    TestingEmbulk.RunResult result = embulk.inputBuilder().in(inConfig).filters(ImmutableList.of(filterConfig)).outputPath(outputPath).run();
    assertThat(readSortedFile(outputPath), is(readResource(RESOURCE_NAME_PREFIX + resultCsvResourceName)));
}
Also used : Path(java.nio.file.Path) ConfigSource(org.embulk.config.ConfigSource) TestingEmbulk(org.embulk.test.TestingEmbulk)

Example 38 with ConfigSource

use of org.embulk.config.ConfigSource in project embulk by embulk.

the class TestCsvAllStringsGuessPlugin method testSimple.

@Test
public void testSimple() throws Exception {
    ConfigSource exec = embulk.newConfig().set("guess_plugins", ImmutableList.of("csv_all_strings")).set("exclude_guess_plugins", ImmutableList.of("csv"));
    ConfigDiff guessed = embulk.parserBuilder().exec(exec).inputResource(RESOURCE_NAME_PREFIX + "test_simple.csv").guess();
    assertThat(guessed, is((DataSource) embulk.loadYamlResource(RESOURCE_NAME_PREFIX + "test_simple_guessed.yml")));
}
Also used : ConfigSource(org.embulk.config.ConfigSource) ConfigDiff(org.embulk.config.ConfigDiff) DataSource(org.embulk.config.DataSource) Test(org.junit.Test)

Example 39 with ConfigSource

use of org.embulk.config.ConfigSource in project embulk by embulk.

the class RenameFilterPlugin method transaction.

@Override
public void transaction(ConfigSource config, Schema inputSchema, FilterPlugin.Control control) {
    PluginTask task = config.loadConfig(PluginTask.class);
    Map<String, String> renameMap = task.getRenameMap();
    List<ConfigSource> rulesList = task.getRulesList();
    // Check if the given column in "columns" exists or not.
    for (String columnName : renameMap.keySet()) {
        // throws SchemaConfigException
        inputSchema.lookupColumn(columnName);
    }
    // Rename by "columns": to be applied before "rules".
    Schema.Builder builder = Schema.builder();
    for (Column column : inputSchema.getColumns()) {
        String name = column.getName();
        if (renameMap.containsKey(name)) {
            name = renameMap.get(name);
        }
        builder.add(name, column.getType());
    }
    Schema intermediateSchema = builder.build();
    // Rename by "rules".
    Schema outputSchema = intermediateSchema;
    for (ConfigSource rule : rulesList) {
        outputSchema = applyRule(rule, intermediateSchema);
        intermediateSchema = outputSchema;
    }
    control.run(task.dump(), outputSchema);
}
Also used : ConfigSource(org.embulk.config.ConfigSource) Column(org.embulk.spi.Column) Schema(org.embulk.spi.Schema)

Example 40 with ConfigSource

use of org.embulk.config.ConfigSource in project embulk by embulk.

the class TestFileOutputRunner method testMockFormatterIteration.

@Test
public void testMockFormatterIteration() {
    MockFileOutputPlugin fileOutputPlugin = new MockFileOutputPlugin();
    final FileOutputRunner runner = new FileOutputRunner(fileOutputPlugin);
    ImmutableList<ImmutableMap<String, Object>> columns = ImmutableList.of(ImmutableMap.<String, Object>of("name", "col1", "type", "boolean", "option", ImmutableMap.of()), ImmutableMap.<String, Object>of("name", "col2", "type", "long", "option", ImmutableMap.of()), ImmutableMap.<String, Object>of("name", "col3", "type", "double", "option", ImmutableMap.of()), ImmutableMap.<String, Object>of("name", "col4", "type", "string", "option", ImmutableMap.of()), ImmutableMap.<String, Object>of("name", "col5", "type", "timestamp", "option", ImmutableMap.of()), ImmutableMap.<String, Object>of("name", "col6", "type", "json", "option", ImmutableMap.of()));
    ConfigSource config = Exec.newConfigSource().set("type", "unused?").set("formatter", ImmutableMap.of("type", "mock", "columns", columns));
    final Schema schema = config.getNested("formatter").loadConfig(MockParserPlugin.PluginTask.class).getSchemaConfig().toSchema();
    runner.transaction(config, schema, 1, new OutputPlugin.Control() {

        public List<TaskReport> run(final TaskSource outputTask) {
            TransactionalPageOutput tran = runner.open(outputTask, schema, 1);
            boolean committed = false;
            try {
                ImmutableMapValue jsonValue = newMap(newString("_c1"), newBoolean(true), newString("_c2"), newInteger(10), newString("_c3"), newString("embulk"), newString("_c4"), newMap(newString("k"), newString("v")));
                for (Page page : PageTestUtils.buildPage(runtime.getBufferAllocator(), schema, true, 2L, 3.0D, "45", Timestamp.ofEpochMilli(678L), jsonValue, true, 2L, 3.0D, "45", Timestamp.ofEpochMilli(678L), jsonValue)) {
                    tran.add(page);
                }
                tran.commit();
                committed = true;
            } finally {
                if (!committed) {
                    tran.abort();
                }
                tran.close();
            }
            return new ArrayList<TaskReport>();
        }
    });
    assertEquals(true, fileOutputPlugin.transactionCompleted);
    assertEquals(2, MockFormatterPlugin.records.size());
    for (List<Object> record : MockFormatterPlugin.records) {
        assertEquals(Boolean.TRUE, record.get(0));
        assertEquals(2L, record.get(1));
        assertEquals(3.0D, (Double) record.get(2), 0.1D);
        assertEquals("45", record.get(3));
        assertEquals(678L, ((Timestamp) record.get(4)).toEpochMilli());
        assertEquals("{\"_c1\":true,\"_c2\":10,\"_c3\":\"embulk\",\"_c4\":{\"k\":\"v\"}}", record.get(5).toString());
    }
}
Also used : TaskReport(org.embulk.config.TaskReport) ImmutableMap(com.google.common.collect.ImmutableMap) ConfigSource(org.embulk.config.ConfigSource) ArrayList(java.util.ArrayList) List(java.util.List) ImmutableList(com.google.common.collect.ImmutableList) ImmutableMapValue(org.msgpack.value.ImmutableMapValue) TaskSource(org.embulk.config.TaskSource) Test(org.junit.Test)

Aggregations

ConfigSource (org.embulk.config.ConfigSource)50 Test (org.junit.Test)33 TaskSource (org.embulk.config.TaskSource)12 Schema (org.embulk.spi.Schema)9 HashMap (java.util.HashMap)8 ArrayList (java.util.ArrayList)6 List (java.util.List)6 ConfigDiff (org.embulk.config.ConfigDiff)6 FilterPlugin (org.embulk.spi.FilterPlugin)6 ImmutableList (com.google.common.collect.ImmutableList)5 SchemaConfigException (org.embulk.spi.SchemaConfigException)4 ConfigException (org.embulk.config.ConfigException)3 Column (org.embulk.spi.Column)3 InputPlugin (org.embulk.spi.InputPlugin)3 ImmutableMap (com.google.common.collect.ImmutableMap)2 IOException (java.io.IOException)2 Path (java.nio.file.Path)2 LinkedList (java.util.LinkedList)2 DataSource (org.embulk.config.DataSource)2 TaskReport (org.embulk.config.TaskReport)2