Search in sources :

Example 11 with AbstractFormatterFactory

use of org.voltdb.importer.formatter.AbstractFormatterFactory 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 12 with AbstractFormatterFactory

use of org.voltdb.importer.formatter.AbstractFormatterFactory 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 13 with AbstractFormatterFactory

use of org.voltdb.importer.formatter.AbstractFormatterFactory 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 14 with AbstractFormatterFactory

use of org.voltdb.importer.formatter.AbstractFormatterFactory 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)

Example 15 with AbstractFormatterFactory

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

the class ImportManager method create.

/**
     * This creates a import connector from configuration provided.
     * @param myHostId
     * @param catalogContext
     */
private synchronized void create(int myHostId, CatalogContext catalogContext) {
    try {
        ImportType importElement = catalogContext.getDeployment().getImport();
        if (importElement == null || importElement.getConfiguration().isEmpty()) {
            return;
        }
        initializeChannelDistributer();
        final String clusterTag = m_distributer.getClusterTag();
        ImportDataProcessor newProcessor = new ImportProcessor(myHostId, m_distributer, m_statsCollector, clusterTag);
        m_processorConfig = CatalogUtil.getImportProcessorConfig(catalogContext.getDeployment().getImport());
        m_formatterFactories.clear();
        for (ImportConfiguration config : m_processorConfig.values()) {
            Properties prop = config.getformatterProperties();
            String module = prop.getProperty(ImportDataProcessor.IMPORT_FORMATTER);
            try {
                AbstractFormatterFactory formatterFactory = m_formatterFactories.get(module);
                if (formatterFactory == null) {
                    URI moduleURI = URI.create(module);
                    formatterFactory = m_moduleManager.getService(moduleURI, AbstractFormatterFactory.class);
                    if (formatterFactory == null) {
                        VoltDB.crashLocalVoltDB("Failed to initialize formatter from: " + module);
                    }
                    m_formatterFactories.put(module, formatterFactory);
                }
                config.setFormatterFactory(formatterFactory);
            } catch (Throwable t) {
                VoltDB.crashLocalVoltDB("Failed to configure import handler for " + module);
            }
        }
        discoverConfigsAndLoadBundles(catalogContext);
        if (!m_configsForProcessor.isEmpty()) {
            newProcessor.setProcessorConfig(m_configsForProcessor, m_loadedBundles);
            m_processor.set(newProcessor);
        } else {
            m_processor.set(null);
        }
    } catch (final Exception e) {
        VoltDB.crashLocalVoltDB("Error creating import processor", true, e);
    }
}
Also used : ImportType(org.voltdb.compiler.deploymentfile.ImportType) ImportConfiguration(org.voltdb.utils.CatalogUtil.ImportConfiguration) Properties(java.util.Properties) URI(java.net.URI) AbstractFormatterFactory(org.voltdb.importer.formatter.AbstractFormatterFactory) IOException(java.io.IOException) BundleException(org.osgi.framework.BundleException)

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