Search in sources :

Example 11 with FormatterBuilder

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

the class TestVoltCSVFormatter method testCSVBundle.

@Test
public void testCSVBundle() 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("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 12 with FormatterBuilder

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

the class TestVoltCSVFormatter method testTrimunquotedTrim.

@Test
public void testTrimunquotedTrim() 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", "true");
    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 13 with FormatterBuilder

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

the class TestVoltCSVFormatter method testBlankEmpty.

@Test
public void testBlankEmpty() 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", "empty");
    FormatterBuilder builder = new FormatterBuilder("csv", prop);
    builder.setFormatterFactory(o);
    Formatter formatter = builder.create();
    Object[] results = formatter.transform(ByteBuffer.wrap("12,,test".getBytes(StandardCharsets.UTF_8)));
    assertEquals(results.length, 3);
    assertEquals(results[0], "12");
    assertEquals(results[1], null);
    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 14 with FormatterBuilder

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

the class TestVoltCSVFormatter method testNullTransform.

@Test
public void testNullTransform() 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("csv", prop);
    builder.setFormatterFactory(o);
    Formatter formatter = builder.create();
    Object[] results = formatter.transform(null);
    assertNull(results);
}
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 15 with FormatterBuilder

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

the class TestVoltCSVFormatter method testJapaneseCharacterSeperator.

@Test
public void testJapaneseCharacterSeperator() 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", "の");
    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)

Aggregations

Properties (java.util.Properties)16 FormatterBuilder (org.voltdb.importer.formatter.FormatterBuilder)16 Test (org.junit.Test)14 ServiceReference (org.osgi.framework.ServiceReference)14 AbstractFormatterFactory (org.voltdb.importer.formatter.AbstractFormatterFactory)14 Formatter (org.voltdb.importer.formatter.Formatter)13 File (java.io.File)1 FileInputStream (java.io.FileInputStream)1 InputStream (java.io.InputStream)1 URI (java.net.URI)1 CountDownLatch (java.util.concurrent.CountDownLatch)1 ImporterConfig (org.voltdb.importer.ImporterConfig)1 VoltCSVFormatterFactory (org.voltdb.importer.formatter.builtin.VoltCSVFormatterFactory)1