Search in sources :

Example 1 with IDataSourceDumper

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

the class TestTiKVDataSourceFactory method testGetPlugin.

public void testGetPlugin() {
    GetColsMeta getColsMeta = new GetColsMeta().invoke();
    TiKVDataSourceFactory dataSourceFactory = getColsMeta.getDataSourceFactory();
    List<ColumnMetaData> employeesCols = getColsMeta.getEmployeesCols();
    TISTable dumpTable = new TISTable();
    dumpTable.setDbName(DB_NAME);
    dumpTable.setTableName(TABLE_NAME);
    dumpTable.setReflectCols(employeesCols);
    DataDumpers dataDumpers = dataSourceFactory.getDataDumpers(dumpTable);
    assertEquals(1, dataDumpers.splitCount);
    Iterator<IDataSourceDumper> dumpers = dataDumpers.dumpers;
    Map<String, Object> row = null;
    StringBuffer rowContent = null;
    int rowCount = 0;
    while (dumpers.hasNext()) {
        IDataSourceDumper dumper = dumpers.next();
        // assertEquals(300024, );
        assertTrue(dumper.getRowSize() > 0);
        try {
            Iterator<Map<String, Object>> rowIterator = dumper.startDump();
            while (rowIterator.hasNext()) {
                rowContent = new StringBuffer();
                row = rowIterator.next();
                // }
                for (Map.Entry<String, Object> entry : row.entrySet()) {
                    rowContent.append(entry.getKey()).append(":").append(entry.getValue()).append(",");
                }
                rowCount++;
                System.out.println(rowContent);
            }
        } finally {
            dumper.closeResource();
        }
    }
    assertEquals(300024, rowCount);
}
Also used : DataDumpers(com.qlangtech.tis.plugin.ds.DataDumpers) TISTable(com.qlangtech.tis.plugin.ds.TISTable) IDataSourceDumper(com.qlangtech.tis.plugin.ds.IDataSourceDumper) ColumnMetaData(com.qlangtech.tis.plugin.ds.ColumnMetaData) Map(java.util.Map)

Example 2 with IDataSourceDumper

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

the class TestDorisSourceFactory method testDataDumpers.

public void testDataDumpers() throws Exception {
    DorisSourceFactory dataSourceFactory = getDorisSourceFactory();
    TISTable dumpTable = new TISTable();
    dumpTable.setSelectSql("SELECT emp_no,birth_date,first_name,last_name,gender,hire_date FROM employees");
    dumpTable.setTableName("employees");
    DataDumpers dataDumpers = dataSourceFactory.getDataDumpers(dumpTable);
    assertNotNull("dataDumpers can not be null", dataDumpers);
    assertEquals(1, dataDumpers.splitCount);
    Iterator<IDataSourceDumper> dumpers = dataDumpers.dumpers;
    Map<String, String> row = null;
    assertTrue("must contain a dumper", dumpers.hasNext());
    IDataSourceDumper dumper = dumpers.next();
    assertNotNull(dumper);
    assertEquals("jdbc:mysql://192.168.28.202:9030/", dumper.getDbHost());
// dumper.closeResource();
}
Also used : DataDumpers(com.qlangtech.tis.plugin.ds.DataDumpers) IDataSourceDumper(com.qlangtech.tis.plugin.ds.IDataSourceDumper) TISTable(com.qlangtech.tis.plugin.ds.TISTable)

Example 3 with IDataSourceDumper

use of com.qlangtech.tis.plugin.ds.IDataSourceDumper 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

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