Search in sources :

Example 6 with TextFormatConfig

use of org.apache.drill.exec.store.easy.text.TextFormatPlugin.TextFormatConfig in project drill by apache.

the class BaseCsvTest method setup.

protected static void setup(boolean skipFirstLine, boolean extractHeader, int maxParallelization) throws Exception {
    startCluster(ClusterFixture.builder(dirTestWatcher).maxParallelization(maxParallelization));
    // Set up CSV storage plugin using headers.
    TextFormatConfig csvFormat = new TextFormatConfig(null, // line delimiter
    null, // field delimiter
    null, // quote
    null, // escape
    null, // comment
    null, skipFirstLine, extractHeader);
    testDir = cluster.makeDataDir("data", "csv", csvFormat);
}
Also used : TextFormatConfig(org.apache.drill.exec.store.easy.text.TextFormatPlugin.TextFormatConfig)

Example 7 with TextFormatConfig

use of org.apache.drill.exec.store.easy.text.TextFormatPlugin.TextFormatConfig in project drill by apache.

the class TestTextWriter method setup.

@BeforeClass
public static void setup() throws Exception {
    ClusterFixtureBuilder builder = ClusterFixture.builder(dirTestWatcher);
    startCluster(builder);
    Map<String, FormatPluginConfig> formats = new HashMap<>();
    formats.put("csv", new TextFormatConfig(Collections.singletonList("csv"), // line delimiter
    "\n", // field delimiter
    ",", // quote
    "\"", // escape
    "\"", // comment
    null, // skip first line
    false, // extract header
    true));
    formats.put("tsv", new TextFormatConfig(Collections.singletonList("tsv"), // line delimiter
    "\n", // field delimiter
    "\t", // quote
    "\"", // escape
    "\"", // comment
    null, // skip first line
    false, // extract header
    true));
    formats.put("custom", new TextFormatConfig(Collections.singletonList("custom"), // line delimiter
    "!", // field delimiter
    "_", // quote
    "$", // escape
    "^", // comment
    null, // skip first line
    false, // extract header
    true));
    cluster.defineFormats("dfs", formats);
}
Also used : HashMap(java.util.HashMap) FormatPluginConfig(org.apache.drill.common.logical.FormatPluginConfig) TextFormatConfig(org.apache.drill.exec.store.easy.text.TextFormatPlugin.TextFormatConfig) ClusterFixtureBuilder(org.apache.drill.test.ClusterFixtureBuilder) BeforeClass(org.junit.BeforeClass)

Example 8 with TextFormatConfig

use of org.apache.drill.exec.store.easy.text.TextFormatPlugin.TextFormatConfig in project drill by apache.

the class StoragePluginTestUtils method configureFormatPlugins.

public static void configureFormatPlugins(StoragePluginRegistry pluginRegistry, String storagePlugin) throws PluginException {
    FileSystemConfig fileSystemConfig = (FileSystemConfig) pluginRegistry.getStoredConfig(storagePlugin);
    Map<String, FormatPluginConfig> newFormats = new HashMap<>();
    Optional.ofNullable(fileSystemConfig.getFormats()).ifPresent(newFormats::putAll);
    newFormats.put("txt", new TextFormatConfig(ImmutableList.of("txt"), null, "\u0000", null, null, null, null, null));
    newFormats.put("ssv", new TextFormatConfig(ImmutableList.of("ssv"), null, " ", null, null, null, null, null));
    newFormats.put("psv", new TextFormatConfig(ImmutableList.of("tbl"), null, "|", null, null, null, null, null));
    SequenceFileFormatConfig seqConfig = new SequenceFileFormatConfig(ImmutableList.of("seq"));
    newFormats.put("sequencefile", seqConfig);
    newFormats.put("csvh-test", new TextFormatConfig(ImmutableList.of("csvh-test"), null, ",", null, null, null, true, true));
    FileSystemConfig newFileSystemConfig = new FileSystemConfig(fileSystemConfig.getConnection(), fileSystemConfig.getConfig(), fileSystemConfig.getWorkspaces(), newFormats, PlainCredentialsProvider.EMPTY_CREDENTIALS_PROVIDER);
    newFileSystemConfig.setEnabled(fileSystemConfig.isEnabled());
    pluginRegistry.put(storagePlugin, newFileSystemConfig);
}
Also used : SequenceFileFormatConfig(org.apache.drill.exec.store.easy.sequencefile.SequenceFileFormatConfig) HashMap(java.util.HashMap) FormatPluginConfig(org.apache.drill.common.logical.FormatPluginConfig) TextFormatConfig(org.apache.drill.exec.store.easy.text.TextFormatPlugin.TextFormatConfig) FileSystemConfig(org.apache.drill.exec.store.dfs.FileSystemConfig)

Example 9 with TextFormatConfig

use of org.apache.drill.exec.store.easy.text.TextFormatPlugin.TextFormatConfig in project drill by apache.

the class TestTextWriter method testLineDelimiterLengthLimit.

@Test
public void testLineDelimiterLengthLimit() throws Exception {
    TextFormatConfig incorrect = new TextFormatConfig(null, // line delimiter
    "end", // field delimiter
    null, // quote
    null, // escape
    null, // comment
    null, // skip first line
    false, // extract header
    false);
    cluster.defineFormat("dfs", "incorrect", incorrect);
    client.alterSession(ExecConstants.OUTPUT_FORMAT_OPTION, "incorrect");
    String tableName = "incorrect_line_delimiter_table";
    String fullTableName = String.format("dfs.tmp.`%s`", tableName);
    tablesToDrop.add(fullTableName);
    // univocity-parsers allow only 1 - 2 characters line separators
    thrown.expect(UserException.class);
    thrown.expectMessage("Invalid line separator");
    queryBuilder().sql("create table %s as select 1 as id from (values(1))", fullTableName).run();
}
Also used : TextFormatConfig(org.apache.drill.exec.store.easy.text.TextFormatPlugin.TextFormatConfig) ClusterTest(org.apache.drill.test.ClusterTest) Test(org.junit.Test)

Aggregations

TextFormatConfig (org.apache.drill.exec.store.easy.text.TextFormatPlugin.TextFormatConfig)9 BeforeClass (org.junit.BeforeClass)5 HashMap (java.util.HashMap)3 FormatPluginConfig (org.apache.drill.common.logical.FormatPluginConfig)3 FileSystemConfig (org.apache.drill.exec.store.dfs.FileSystemConfig)3 ClusterFixtureBuilder (org.apache.drill.test.ClusterFixtureBuilder)3 StoragePluginConfig (org.apache.drill.common.logical.StoragePluginConfig)2 Test (org.junit.Test)2 ArrayList (java.util.ArrayList)1 PluginException (org.apache.drill.exec.store.StoragePluginRegistry.PluginException)1 WorkspaceConfig (org.apache.drill.exec.store.dfs.WorkspaceConfig)1 JSONFormatConfig (org.apache.drill.exec.store.easy.json.JSONFormatPlugin.JSONFormatConfig)1 SequenceFileFormatConfig (org.apache.drill.exec.store.easy.sequencefile.SequenceFileFormatConfig)1 BaseTest (org.apache.drill.test.BaseTest)1 ClusterFixture (org.apache.drill.test.ClusterFixture)1 ClusterTest (org.apache.drill.test.ClusterTest)1