Search in sources :

Example 1 with DataxReader

use of com.qlangtech.tis.datax.impl.DataxReader in project plugins by qlangtech.

the class TestDataxMySQLReader method testGetPluginFormPropertyTypes.

public void testGetPluginFormPropertyTypes() {
    DataxMySQLReader mySQLReader = new DataxMySQLReader();
    Descriptor<DataxReader> descriptor = mySQLReader.getDescriptor();
    assertNotNull(descriptor);
    PluginFormProperties propertyTypes = descriptor.getPluginFormPropertyTypes();
    assertEquals(4, propertyTypes.getKVTuples().size());
}
Also used : DataxReader(com.qlangtech.tis.datax.impl.DataxReader) PluginFormProperties(com.qlangtech.tis.extension.PluginFormProperties)

Example 2 with DataxReader

use of com.qlangtech.tis.datax.impl.DataxReader in project plugins by qlangtech.

the class TestDataXMongodbWriter method testDescriptorsJSONGenerate.

public void testDescriptorsJSONGenerate() {
    DataxReader dataxReader = EasyMock.createMock("dataxReader", DataxReader.class);
    List<ISelectedTab> selectedTabs = TestSelectedTabs.createSelectedTabs(1).stream().map((t) -> t).collect(Collectors.toList());
    for (ISelectedTab tab : selectedTabs) {
        for (ISelectedTab.ColMeta cm : tab.getCols()) {
            cm.setType(DataXReaderColType.STRING.dataType);
        }
    }
    EasyMock.expect(dataxReader.getSelectedTabs()).andReturn(selectedTabs).times(4);
    DataxReader.dataxReaderThreadLocal.set(dataxReader);
    EasyMock.replay(dataxReader);
    DataXMongodbWriter writer = new DataXMongodbWriter();
    assertTrue(writer instanceof IDataSourceFactoryGetter);
    DescriptorsJSON descJson = new DescriptorsJSON(writer.getDescriptor());
    JsonUtil.assertJSONEqual(DataXMongodbWriter.class, "mongdodb-datax-writer-descriptor.json", descJson.getDescriptorsJSON(), (m, e, a) -> {
        assertEquals(m, e, a);
    });
    JsonUtil.assertJSONEqual(DataXMongodbWriter.class, "mongdodb-datax-writer-descriptor.json", descJson.getDescriptorsJSON(), (m, e, a) -> {
        assertEquals(m, e, a);
    });
    EasyMock.verify(dataxReader);
}
Also used : PluginExtraProps(com.qlangtech.tis.extension.util.PluginExtraProps) ISelectedTab(com.qlangtech.tis.plugin.ds.ISelectedTab) MangoDBDataSourceFactory(com.qlangtech.tis.plugin.ds.mangodb.MangoDBDataSourceFactory) EasyMock(org.easymock.EasyMock) TestSelectedTabs(com.qlangtech.tis.plugin.datax.test.TestSelectedTabs) Collectors(java.util.stream.Collectors) DescriptorsJSON(com.qlangtech.tis.util.DescriptorsJSON) JsonUtil(com.qlangtech.tis.trigger.util.JsonUtil) DataXReaderColType(com.qlangtech.tis.plugin.ds.DataXReaderColType) IDataSourceFactoryGetter(com.qlangtech.tis.plugin.ds.IDataSourceFactoryGetter) List(java.util.List) DataxReader(com.qlangtech.tis.datax.impl.DataxReader) IOUtils(com.qlangtech.tis.extension.impl.IOUtils) Optional(java.util.Optional) TestCase(junit.framework.TestCase) WriterTemplate(com.qlangtech.tis.plugin.common.WriterTemplate) ISelectedTab(com.qlangtech.tis.plugin.ds.ISelectedTab) DescriptorsJSON(com.qlangtech.tis.util.DescriptorsJSON) DataxReader(com.qlangtech.tis.datax.impl.DataxReader) IDataSourceFactoryGetter(com.qlangtech.tis.plugin.ds.IDataSourceFactoryGetter)

Example 3 with DataxReader

use of com.qlangtech.tis.datax.impl.DataxReader in project plugins by qlangtech.

the class TisDataXHdfsReader method getHdfsReaderPlugin.

private static DataXHdfsReader getHdfsReaderPlugin(Configuration cfg) {
    String dataxName = cfg.getNecessaryValue(DataxUtils.DATAX_NAME, HdfsWriterErrorCode.REQUIRED_VALUE);
    DataxReader dataxReader = DataxReader.load(null, dataxName);
    if (!(dataxReader instanceof DataXHdfsReader)) {
        throw new BasicHdfsWriterJob.JobPropInitializeException("datax reader must be type of 'DataXHdfsReader',but now is:" + dataxReader.getClass());
    }
    return (DataXHdfsReader) dataxReader;
}
Also used : DataxReader(com.qlangtech.tis.datax.impl.DataxReader)

Example 4 with DataxReader

use of com.qlangtech.tis.datax.impl.DataxReader in project plugins by qlangtech.

the class DataXMongodbWriter method getDftColumn.

/**
 * 取得默认的列内容
 *
 * @return
 */
public static String getDftColumn() {
    // [{"name":"user_id","type":"string"},{"name":"user_name","type":"array","splitter":","}]
    JSONArray fields = new JSONArray();
    DataxReader dataReader = DataxReader.getThreadBingDataXReader();
    if (dataReader == null) {
        return "[]";
    }
    try {
        List<ISelectedTab> selectedTabs = dataReader.getSelectedTabs();
        if (CollectionUtils.isEmpty(selectedTabs)) {
            return "[]";
        }
        for (ISelectedTab tab : selectedTabs) {
            tab.getCols().forEach((col) -> {
                JSONObject field = new JSONObject();
                field.put("name", col.getName());
                field.put("type", col.getType().getCollapse().getLiteria());
                fields.add(field);
            });
            break;
        }
    } catch (Exception e) {
        logger.warn(e.getMessage(), e);
        return "[]";
    }
    return JsonUtil.toString(fields);
}
Also used : JSONObject(com.alibaba.fastjson.JSONObject) JSONArray(com.alibaba.fastjson.JSONArray) DataxReader(com.qlangtech.tis.datax.impl.DataxReader)

Example 5 with DataxReader

use of com.qlangtech.tis.datax.impl.DataxReader in project tis by qlangtech.

the class IDataxProcessor method getDataXWorkDir.

static File getDataXWorkDir(IPluginContext pluginContext, String appName) {
    KeyedPluginStore<DataxReader> readerStore = DataxReader.getPluginStore(pluginContext, appName);
    File targetFile = readerStore.getTargetFile();
    return targetFile.getParentFile();
}
Also used : DataxReader(com.qlangtech.tis.datax.impl.DataxReader) File(java.io.File)

Aggregations

DataxReader (com.qlangtech.tis.datax.impl.DataxReader)22 ISelectedTab (com.qlangtech.tis.plugin.ds.ISelectedTab)7 File (java.io.File)7 DescriptorsJSON (com.qlangtech.tis.util.DescriptorsJSON)6 Collectors (java.util.stream.Collectors)6 Lists (com.google.common.collect.Lists)5 PluginFormProperties (com.qlangtech.tis.extension.PluginFormProperties)5 SuFormProperties (com.qlangtech.tis.extension.impl.SuFormProperties)5 JsonUtil (com.qlangtech.tis.trigger.util.JsonUtil)5 JSONObject (com.alibaba.fastjson.JSONObject)4 IDataxProcessor (com.qlangtech.tis.datax.IDataxProcessor)4 DataxProcessor (com.qlangtech.tis.datax.impl.DataxProcessor)4 DataxWriter (com.qlangtech.tis.datax.impl.DataxWriter)4 Descriptor (com.qlangtech.tis.extension.Descriptor)4 IOException (java.io.IOException)4 List (java.util.List)4 Optional (java.util.Optional)4 TestCase (junit.framework.TestCase)4 FileUtils (org.apache.commons.io.FileUtils)4 EasyMock (org.easymock.EasyMock)4