Search in sources :

Example 1 with TiKVDataSourceFactory

use of com.qlangtech.tis.plugin.ds.tidb.TiKVDataSourceFactory in project plugins by qlangtech.

the class TestDataXTiDBReader method testTemplateGenerate.

public void testTemplateGenerate() throws Exception {
    final String dataXName = "dataXName";
    GetColsMeta getColsMeta = new GetColsMeta().invoke();
    final TiKVDataSourceFactory dsFactory = getColsMeta.getDataSourceFactory();
    DataXTiDBReader dataxReader = new DataXTiDBReader() {

        @Override
        public TiKVDataSourceFactory getDataSourceFactory() {
            return dsFactory;
        }

        @Override
        public Class<?> getOwnerClass() {
            return DataXTiDBReader.class;
        }
    };
    dataxReader.template = DataXTiDBReader.getDftTemplate();
    dataxReader.setSelectedTabs(TestTiKVDataSourceFactory.createTabOfEmployees());
    ReaderTemplate.validateDataXReader("tidb-datax-reader-template-assert.json", dataXName, dataxReader);
}
Also used : TiKVDataSourceFactory(com.qlangtech.tis.plugin.ds.tidb.TiKVDataSourceFactory) TestTiKVDataSourceFactory(com.qlangtech.tis.plugin.ds.tidb.TestTiKVDataSourceFactory) GetColsMeta(com.qlangtech.tis.plugin.ds.tidb.GetColsMeta)

Example 2 with TiKVDataSourceFactory

use of com.qlangtech.tis.plugin.ds.tidb.TiKVDataSourceFactory in project plugins by qlangtech.

the class TisDataXTiDBReader method getTiKVDataSource.

private static final List<IDataSourceDumper> getTiKVDataSource(Configuration config, Optional<Long> regionId) {
    List<String> cols = config.getList("column", String.class);
    String tableName = config.getString("table");
    Configuration connection = config.getConfiguration("connection");
    TiKVDataSourceFactory sourceFactory = new TiKVDataSourceFactory();
    sourceFactory.pdAddrs = connection.getString("[0].pdAddrs");
    sourceFactory.dbName = connection.getString("[0].dbName");
    // sourceFactory.datetimeFormat = connection.getBool("datetimeFormat");
    if (StringUtils.isBlank(sourceFactory.pdAddrs) || StringUtils.isBlank(sourceFactory.dbName)) {
        throw new IllegalStateException("param 'pdAddrs' or 'dbName' can not be null,connection:" + connection.toJSON());
    }
    List<ColumnMetaData> tableMetadata = sourceFactory.getTableMetadata(tableName);
    TISTable table = new TISTable();
    table.setTableName(tableName);
    table.setReflectCols(tableMetadata.stream().filter((cmeta) -> cols.contains(cmeta.getKey())).collect(Collectors.toList()));
    DataDumpers dataDumpers = sourceFactory.getDataDumpers(table, regionId);
    List<IDataSourceDumper> dumpers = Lists.newArrayList(dataDumpers.dumpers);
    return dumpers;
}
Also used : TiKVDataSourceFactory(com.qlangtech.tis.plugin.ds.tidb.TiKVDataSourceFactory) DataDumpers(com.qlangtech.tis.plugin.ds.DataDumpers) Configuration(com.alibaba.datax.common.util.Configuration) IDataSourceDumper(com.qlangtech.tis.plugin.ds.IDataSourceDumper) TISTable(com.qlangtech.tis.plugin.ds.TISTable) ColumnMetaData(com.qlangtech.tis.plugin.ds.ColumnMetaData)

Aggregations

TiKVDataSourceFactory (com.qlangtech.tis.plugin.ds.tidb.TiKVDataSourceFactory)2 Configuration (com.alibaba.datax.common.util.Configuration)1 ColumnMetaData (com.qlangtech.tis.plugin.ds.ColumnMetaData)1 DataDumpers (com.qlangtech.tis.plugin.ds.DataDumpers)1 IDataSourceDumper (com.qlangtech.tis.plugin.ds.IDataSourceDumper)1 TISTable (com.qlangtech.tis.plugin.ds.TISTable)1 GetColsMeta (com.qlangtech.tis.plugin.ds.tidb.GetColsMeta)1 TestTiKVDataSourceFactory (com.qlangtech.tis.plugin.ds.tidb.TestTiKVDataSourceFactory)1