Search in sources :

Example 1 with AbstractFormatterFactory

use of org.voltdb.importer.formatter.AbstractFormatterFactory in project voltdb by VoltDB.

the class TestVoltCSVFormatter method testBlankError.

@Test
public void testBlankError() throws Exception {
    ServiceReference[] refs = m_bundle.getRegisteredServices();
    ServiceReference<AbstractFormatterFactory> reference = refs[0];
    AbstractFormatterFactory o = m_bundle.getBundleContext().getService(reference);
    Properties prop = new Properties();
    prop.setProperty("separator", ",");
    prop.setProperty("blank", "error");
    FormatterBuilder builder = new FormatterBuilder("csv", prop);
    builder.setFormatterFactory(o);
    Formatter formatter = builder.create();
    try {
        Object[] results = formatter.transform(ByteBuffer.wrap("12,,test".getBytes(StandardCharsets.UTF_8)));
        fail();
    } catch (RuntimeException e) {
    }
}
Also used : Formatter(org.voltdb.importer.formatter.Formatter) Properties(java.util.Properties) FormatterBuilder(org.voltdb.importer.formatter.FormatterBuilder) AbstractFormatterFactory(org.voltdb.importer.formatter.AbstractFormatterFactory) ServiceReference(org.osgi.framework.ServiceReference) Test(org.junit.Test)

Example 2 with AbstractFormatterFactory

use of org.voltdb.importer.formatter.AbstractFormatterFactory in project voltdb by VoltDB.

the class TestVoltCSVFormatter method testQuoteChar.

//char separator, char quotechar, char escape, boolean strictQuotes, boolean ignoreLeadingWhiteSpace
@Test
public void testQuoteChar() throws Exception {
    ServiceReference[] refs = m_bundle.getRegisteredServices();
    ServiceReference<AbstractFormatterFactory> reference = refs[0];
    AbstractFormatterFactory o = m_bundle.getBundleContext().getService(reference);
    Properties prop = new Properties();
    prop.setProperty("quotechar", "'");
    FormatterBuilder builder = new FormatterBuilder("csv", prop);
    builder.setFormatterFactory(o);
    Formatter formatter = builder.create();
    Object[] results = formatter.transform(ByteBuffer.wrap("12,'10.05,test'".getBytes(StandardCharsets.UTF_8)));
    assertEquals(results.length, 2);
    assertEquals(results[0], "12");
    assertEquals(results[1], "10.05,test");
}
Also used : Formatter(org.voltdb.importer.formatter.Formatter) Properties(java.util.Properties) FormatterBuilder(org.voltdb.importer.formatter.FormatterBuilder) AbstractFormatterFactory(org.voltdb.importer.formatter.AbstractFormatterFactory) ServiceReference(org.osgi.framework.ServiceReference) Test(org.junit.Test)

Example 3 with AbstractFormatterFactory

use of org.voltdb.importer.formatter.AbstractFormatterFactory in project voltdb by VoltDB.

the class TestVoltCSVFormatter method testBadFormat.

@Test
public void testBadFormat() throws Exception {
    ServiceReference[] refs = m_bundle.getRegisteredServices();
    ServiceReference<AbstractFormatterFactory> reference = refs[0];
    AbstractFormatterFactory o = m_bundle.getBundleContext().getService(reference);
    Properties prop = new Properties();
    FormatterBuilder builder = new FormatterBuilder("badformat", prop);
    builder.setFormatterFactory(o);
    try {
        builder.create();
        fail();
    } catch (RuntimeException e) {
    }
}
Also used : Properties(java.util.Properties) FormatterBuilder(org.voltdb.importer.formatter.FormatterBuilder) AbstractFormatterFactory(org.voltdb.importer.formatter.AbstractFormatterFactory) ServiceReference(org.osgi.framework.ServiceReference) Test(org.junit.Test)

Example 4 with AbstractFormatterFactory

use of org.voltdb.importer.formatter.AbstractFormatterFactory in project voltdb by VoltDB.

the class TestVoltCSVFormatter method testTrimunquoted.

@Test
public void testTrimunquoted() throws Exception {
    ServiceReference[] refs = m_bundle.getRegisteredServices();
    ServiceReference<AbstractFormatterFactory> reference = refs[0];
    AbstractFormatterFactory o = m_bundle.getBundleContext().getService(reference);
    Properties prop = new Properties();
    prop.setProperty("trimunquoted", "false");
    FormatterBuilder builder = new FormatterBuilder("csv", prop);
    builder.setFormatterFactory(o);
    Formatter formatter = builder.create();
    Object[] results = formatter.transform(ByteBuffer.wrap("12,10.05,  test".getBytes(StandardCharsets.UTF_8)));
    assertEquals(results.length, 3);
    assertEquals(results[0], "12");
    assertEquals(results[1], "10.05");
    assertEquals(results[2], "  test");
}
Also used : Formatter(org.voltdb.importer.formatter.Formatter) Properties(java.util.Properties) FormatterBuilder(org.voltdb.importer.formatter.FormatterBuilder) AbstractFormatterFactory(org.voltdb.importer.formatter.AbstractFormatterFactory) ServiceReference(org.osgi.framework.ServiceReference) Test(org.junit.Test)

Example 5 with AbstractFormatterFactory

use of org.voltdb.importer.formatter.AbstractFormatterFactory in project voltdb by VoltDB.

the class TestVoltCSVFormatter method testStrictQuotes.

@Test
public void testStrictQuotes() throws Exception {
    ServiceReference[] refs = m_bundle.getRegisteredServices();
    ServiceReference<AbstractFormatterFactory> reference = refs[0];
    AbstractFormatterFactory o = m_bundle.getBundleContext().getService(reference);
    Properties prop = new Properties();
    prop.setProperty("strictquotes", "true");
    FormatterBuilder builder = new FormatterBuilder("csv", prop);
    builder.setFormatterFactory(o);
    Formatter formatter = builder.create();
    Object[] results = formatter.transform(ByteBuffer.wrap("\"12\",\"10.05\",\"es\"".getBytes(StandardCharsets.UTF_8)));
    assertEquals(results.length, 3);
    assertEquals(results[0], "12");
    assertEquals(results[1], "10.05");
    assertEquals(results[2], "es");
}
Also used : Formatter(org.voltdb.importer.formatter.Formatter) Properties(java.util.Properties) FormatterBuilder(org.voltdb.importer.formatter.FormatterBuilder) AbstractFormatterFactory(org.voltdb.importer.formatter.AbstractFormatterFactory) ServiceReference(org.osgi.framework.ServiceReference) Test(org.junit.Test)

Aggregations

Properties (java.util.Properties)15 AbstractFormatterFactory (org.voltdb.importer.formatter.AbstractFormatterFactory)15 Test (org.junit.Test)14 ServiceReference (org.osgi.framework.ServiceReference)14 FormatterBuilder (org.voltdb.importer.formatter.FormatterBuilder)14 Formatter (org.voltdb.importer.formatter.Formatter)13 IOException (java.io.IOException)1 URI (java.net.URI)1 BundleException (org.osgi.framework.BundleException)1 ImportType (org.voltdb.compiler.deploymentfile.ImportType)1 ImportConfiguration (org.voltdb.utils.CatalogUtil.ImportConfiguration)1