Search in sources :

Example 1 with SelectedTab

use of com.qlangtech.tis.plugin.datax.SelectedTab in project plugins by qlangtech.

the class TestStarRocksSinkFactory method testStartRocksWrite.

public void testStartRocksWrite() throws Exception {
    /**
     *         CREATE TABLE `totalpayinfo` (
     *         `id` varchar(32) NULL COMMENT "",
     *         `entity_id` varchar(10) NULL COMMENT "",
     *         `num` int(11) NULL COMMENT "",
     *         `create_time` bigint(20) NULL COMMENT "",
     *         `update_time` DATETIME   NULL,
     *         `update_date` DATE       NULL,
     *         `start_time`  DATETIME   NULL
     *         ) ENGINE=OLAP
     *         UNIQUE KEY(`id`)
     *         DISTRIBUTED BY HASH(`id`) BUCKETS 10
     *         PROPERTIES (
     *         "replication_num" = "1",
     *         "in_memory" = "false",
     *         "storage_format" = "DEFAULT"
     *         );
     */
    String tableName = "totalpayinfo";
    String colEntityId = "entity_id";
    String colNum = "num";
    String colId = "id";
    String colCreateTime = "create_time";
    String updateTime = "update_time";
    String updateDate = "update_date";
    String starTime = "start_time";
    IDataxProcessor dataxProcessor = mock("dataxProcessor", IDataxProcessor.class);
    IDataxReader dataxReader = mock("dataxReader", IDataxReader.class);
    List<ISelectedTab> selectedTabs = Lists.newArrayList();
    SelectedTab totalpayinfo = mock(tableName, SelectedTab.class);
    EasyMock.expect(totalpayinfo.getName()).andReturn(tableName).times(1);
    List<ISelectedTab.ColMeta> cols = Lists.newArrayList();
    ISelectedTab.ColMeta cm = new ISelectedTab.ColMeta();
    cm.setName(colEntityId);
    cm.setType(new DataType(Types.VARCHAR, 6));
    cols.add(cm);
    cm = new ISelectedTab.ColMeta();
    cm.setName(colNum);
    cm.setType(new DataType(Types.INTEGER));
    cols.add(cm);
    cm = new ISelectedTab.ColMeta();
    cm.setName(colId);
    cm.setType(new DataType(Types.VARCHAR, 32));
    cm.setPk(true);
    cols.add(cm);
    cm = new ISelectedTab.ColMeta();
    cm.setName(colCreateTime);
    cm.setType(new DataType(Types.BIGINT));
    cols.add(cm);
    cm = new ISelectedTab.ColMeta();
    cm.setName(updateTime);
    cm.setType(new DataType(Types.TIMESTAMP));
    cols.add(cm);
    cm = new ISelectedTab.ColMeta();
    cm.setName(updateDate);
    cm.setType(new DataType(Types.DATE));
    cols.add(cm);
    cm = new ISelectedTab.ColMeta();
    cm.setName(starTime);
    cm.setType(new DataType(Types.TIMESTAMP));
    cols.add(cm);
    EasyMock.expect(totalpayinfo.getCols()).andReturn(cols).times(2);
    selectedTabs.add(totalpayinfo);
    EasyMock.expect(dataxReader.getSelectedTabs()).andReturn(selectedTabs);
    EasyMock.expect(dataxProcessor.getReader(null)).andReturn(dataxReader);
    DataXDorisWriter dataXWriter = mock("dataXWriter", DataXDorisWriter.class);
    DorisSourceFactory sourceFactory = new DorisSourceFactory();
    sourceFactory.loadUrl = "[\"192.168.28.201:8030\"]";
    sourceFactory.userName = "root";
    sourceFactory.dbName = "tis";
    // sourceFactory.password = "";
    sourceFactory.port = 9030;
    sourceFactory.nodeDesc = "192.168.28.201";
    EasyMock.expect(dataXWriter.getDataSourceFactory()).andReturn(sourceFactory);
    dataXWriter.initWriterTable(tableName, Collections.singletonList("jdbc:mysql://192.168.28.201:9030/tis"));
    EasyMock.expect(dataxProcessor.getWriter(null)).andReturn(dataXWriter);
    StarRocksSinkFactory sinkFactory = new StarRocksSinkFactory();
    sinkFactory.columnSeparator = "x01";
    sinkFactory.rowDelimiter = "x02";
    sinkFactory.sinkSemantic = StarRocksSinkSemantic.AT_LEAST_ONCE.getName();
    sinkFactory.sinkBatchFlushInterval = 2000l;
    System.out.println("sinkFactory.sinkBatchFlushInterval:" + sinkFactory.sinkBatchFlushInterval);
    Map<String, IDataxProcessor.TableAlias> aliasMap = new HashMap<>();
    IDataxProcessor.TableAlias tab = new IDataxProcessor.TableAlias(tableName);
    aliasMap.put(tableName, tab);
    EasyMock.expect(dataxProcessor.getTabAlias()).andReturn(aliasMap);
    this.replay();
    Map<IDataxProcessor.TableAlias, SinkFunction<DTO>> sinkFunction = sinkFactory.createSinkFunction(dataxProcessor);
    StreamExecutionEnvironment env = StreamExecutionEnvironment.getExecutionEnvironment();
    DTO d = new DTO();
    d.setEventType(DTO.EventType.DELETE);
    d.setTableName(tableName);
    Map<String, Object> after = Maps.newHashMap();
    after.put(colEntityId, "334556");
    after.put(colNum, "5");
    after.put(colId, "88888888887");
    after.put(colCreateTime, "20211113115959");
    after.put(updateTime, "2021-12-17T09:21:20Z");
    after.put(starTime, "2021-12-18 09:21:20");
    after.put(updateDate, "2021-12-9");
    d.setAfter(after);
    assertEquals(1, sinkFunction.size());
    for (Map.Entry<IDataxProcessor.TableAlias, SinkFunction<DTO>> entry : sinkFunction.entrySet()) {
        env.fromElements(new DTO[] { d }).addSink(entry.getValue());
        break;
    }
    env.execute("testJob");
    Thread.sleep(14000);
    this.verifyAll();
}
Also used : HashMap(java.util.HashMap) ISelectedTab(com.qlangtech.tis.plugin.ds.ISelectedTab) DataXDorisWriter(com.qlangtech.tis.plugin.datax.doris.DataXDorisWriter) IDataxReader(com.qlangtech.tis.datax.IDataxReader) SinkFunction(org.apache.flink.streaming.api.functions.sink.SinkFunction) ISelectedTab(com.qlangtech.tis.plugin.ds.ISelectedTab) SelectedTab(com.qlangtech.tis.plugin.datax.SelectedTab) IDataxProcessor(com.qlangtech.tis.datax.IDataxProcessor) DorisSourceFactory(com.qlangtech.tis.plugin.ds.doris.DorisSourceFactory) StreamExecutionEnvironment(org.apache.flink.streaming.api.environment.StreamExecutionEnvironment) HashMap(java.util.HashMap) Map(java.util.Map) DTO(com.qlangtech.tis.realtime.transfer.DTO)

Example 2 with SelectedTab

use of com.qlangtech.tis.plugin.datax.SelectedTab in project plugins by qlangtech.

the class CUDCDCTestSuit method createDataxReader.

private BasicDataXRdbmsReader createDataxReader(TargetResName dataxName, String tabName) {
    BasicDataSourceFactory dataSourceFactory = createDataSourceFactory(dataxName);
    List<ColumnMetaData> tableMetadata = dataSourceFactory.getTableMetadata(tabName);
    BasicDataXRdbmsReader dataxReader = new BasicDataXRdbmsReader() {

        @Override
        protected RdbmsReaderContext createDataXReaderContext(String jobName, SelectedTab tab, IDataSourceDumper dumper) {
            return null;
        }

        @Override
        public DataSourceFactory getDataSourceFactory() {
            return dataSourceFactory;
        }
    };
    SelectedTab baseTab = new SelectedTab(tabName);
    baseTab.setCols(tableMetadata.stream().map((m) -> m.getName()).collect(Collectors.toList()));
    dataxReader.selectedTabs = Collections.singletonList(baseTab);
    return dataxReader;
}
Also used : SelectedTab(com.qlangtech.tis.plugin.datax.SelectedTab) BasicDataXRdbmsReader(com.qlangtech.tis.plugin.datax.common.BasicDataXRdbmsReader)

Example 3 with SelectedTab

use of com.qlangtech.tis.plugin.datax.SelectedTab in project plugins by qlangtech.

the class TestClickHouseSinkFactory method testCreateSinkFunction.

public void testCreateSinkFunction() throws Exception {
    String tableName = "totalpayinfo";
    String colEntityId = "entity_id";
    String colNum = "num";
    String colId = "id";
    String colCreateTime = "create_time";
    IDataxProcessor dataxProcessor = mock("dataxProcessor", IDataxProcessor.class);
    IDataxReader dataxReader = mock("dataxReader", IDataxReader.class);
    List<ISelectedTab> selectedTabs = Lists.newArrayList();
    SelectedTab totalpayinfo = mock(tableName, SelectedTab.class);
    EasyMock.expect(totalpayinfo.getName()).andReturn(tableName);
    List<ISelectedTab.ColMeta> cols = Lists.newArrayList();
    ISelectedTab.ColMeta cm = new ISelectedTab.ColMeta();
    cm.setName(colEntityId);
    cm.setType(new DataType(Types.VARCHAR, 6));
    cols.add(cm);
    cm = new ISelectedTab.ColMeta();
    cm.setName(colNum);
    cm.setType(new DataType(Types.INTEGER));
    cols.add(cm);
    cm = new ISelectedTab.ColMeta();
    cm.setName(colId);
    cm.setType(new DataType(Types.VARCHAR, 32));
    cm.setPk(true);
    cols.add(cm);
    cm = new ISelectedTab.ColMeta();
    cm.setName(colCreateTime);
    cm.setType(new DataType(Types.BIGINT));
    cols.add(cm);
    EasyMock.expect(totalpayinfo.getCols()).andReturn(cols).anyTimes();
    selectedTabs.add(totalpayinfo);
    EasyMock.expect(dataxReader.getSelectedTabs()).andReturn(selectedTabs);
    EasyMock.expect(dataxProcessor.getReader(null)).andReturn(dataxReader);
    DataXClickhouseWriter dataXWriter = mock("dataXWriter", DataXClickhouseWriter.class);
    dataXWriter.initWriterTable(tableName, Collections.singletonList("jdbc:clickhouse://192.168.28.201:8123/tis"));
    ClickHouseDataSourceFactory sourceFactory = new ClickHouseDataSourceFactory();
    sourceFactory.userName = "default";
    sourceFactory.dbName = "tis";
    sourceFactory.password = "123456";
    sourceFactory.port = 8123;
    sourceFactory.nodeDesc = "192.168.28.201";
    EasyMock.expect(dataXWriter.getDataSourceFactory()).andReturn(sourceFactory);
    EasyMock.expect(dataxProcessor.getWriter(null)).andReturn(dataXWriter);
    Map<String, IDataxProcessor.TableAlias> aliasMap = new HashMap<>();
    IDataxProcessor.TableAlias tab = new IDataxProcessor.TableAlias(tableName);
    aliasMap.put(tableName, tab);
    EasyMock.expect(dataxProcessor.getTabAlias()).andReturn(aliasMap);
    this.replay();
    ClickHouseSinkFactory clickHouseSinkFactory = new ClickHouseSinkFactory();
    clickHouseSinkFactory.ignoringSendingException = true;
    clickHouseSinkFactory.maxBufferSize = 1;
    clickHouseSinkFactory.numRetries = 5;
    clickHouseSinkFactory.numWriters = 1;
    clickHouseSinkFactory.queueMaxCapacity = 1;
    clickHouseSinkFactory.timeout = 30;
    Map<IDataxProcessor.TableAlias, SinkFunction<DTO>> sinkFuncs = clickHouseSinkFactory.createSinkFunction(dataxProcessor);
    assertTrue(sinkFuncs.size() > 0);
    StreamExecutionEnvironment env = StreamExecutionEnvironment.getExecutionEnvironment();
    env.setParallelism(1);
    DTO d = new DTO();
    d.setTableName(tableName);
    Map<String, Object> after = Maps.newHashMap();
    after.put(colEntityId, "334556");
    after.put(colNum, "5");
    after.put(colId, "123dsf124325253dsf123");
    after.put(colCreateTime, "20211113115959");
    d.setAfter(after);
    assertEquals(1, sinkFuncs.size());
    for (Map.Entry<IDataxProcessor.TableAlias, SinkFunction<DTO>> entry : sinkFuncs.entrySet()) {
        env.fromElements(new DTO[] { d }).addSink(entry.getValue()).name("clickhouse");
        break;
    }
    env.execute("testJob");
    Thread.sleep(5000);
    this.verifyAll();
}
Also used : HashMap(java.util.HashMap) ISelectedTab(com.qlangtech.tis.plugin.ds.ISelectedTab) IDataxReader(com.qlangtech.tis.datax.IDataxReader) SinkFunction(org.apache.flink.streaming.api.functions.sink.SinkFunction) ISelectedTab(com.qlangtech.tis.plugin.ds.ISelectedTab) SelectedTab(com.qlangtech.tis.plugin.datax.SelectedTab) IDataxProcessor(com.qlangtech.tis.datax.IDataxProcessor) StreamExecutionEnvironment(org.apache.flink.streaming.api.environment.StreamExecutionEnvironment) DataXClickhouseWriter(com.qlangtech.tis.plugin.datax.DataXClickhouseWriter) ClickHouseDataSourceFactory(com.qlangtech.tis.plugin.ds.clickhouse.ClickHouseDataSourceFactory) HashMap(java.util.HashMap) Map(java.util.Map) DTO(com.qlangtech.tis.realtime.transfer.DTO)

Example 4 with SelectedTab

use of com.qlangtech.tis.plugin.datax.SelectedTab in project plugins by qlangtech.

the class TestElasticSearchSinkFactory method testCreateSinkFunction.

/**
 * 参考:ElasticsearchSinkTestBase
 *
 * @throws Exception
 */
@Test
public void testCreateSinkFunction() throws Exception {
    String tableName = "totalpayinfo";
    String colEntityId = "entity_id";
    String colNum = "num";
    String colId = "id";
    String colCreateTime = "create_time";
    IDataxProcessor dataxProcessor = mock("dataxProcessor", IDataxProcessor.class);
    IDataxReader dataxReader = mock("dataxReader", IDataxReader.class);
    List<ISelectedTab> selectedTabs = Lists.newArrayList();
    SelectedTab totalpayinfo = mock(tableName, SelectedTab.class);
    EasyMock.expect(totalpayinfo.getName()).andReturn(tableName);
    List<ISelectedTab.ColMeta> cols = Lists.newArrayList();
    ISelectedTab.ColMeta cm = new ISelectedTab.ColMeta();
    cm.setName(colEntityId);
    cm.setType(new DataType(Types.VARCHAR, 6));
    cols.add(cm);
    cm = new ISelectedTab.ColMeta();
    cm.setName(colNum);
    cm.setType(new DataType(Types.INTEGER));
    cols.add(cm);
    cm = new ISelectedTab.ColMeta();
    cm.setName(colId);
    cm.setType(new DataType(Types.VARCHAR, 32));
    cm.setPk(true);
    cols.add(cm);
    cm = new ISelectedTab.ColMeta();
    cm.setName(colCreateTime);
    cm.setType(new DataType(Types.BIGINT));
    cols.add(cm);
    EasyMock.expect(totalpayinfo.getCols()).andReturn(cols).anyTimes();
    selectedTabs.add(totalpayinfo);
    EasyMock.expect(dataxReader.getSelectedTabs()).andReturn(selectedTabs);
    EasyMock.expect(dataxProcessor.getReader(null)).andReturn(dataxReader);
    DataXElasticsearchWriter dataXWriter = mock("dataXWriter", DataXElasticsearchWriter.class);
    ESTableAlias esTableAlias = new ESTableAlias();
    dataXWriter.initialIndex(esTableAlias);
    EasyMock.expect(dataxProcessor.getWriter(null)).andReturn(dataXWriter);
    Map<String, IDataxProcessor.TableAlias> aliasMap = new HashMap<>();
    IDataxProcessor.TableAlias tab = new IDataxProcessor.TableAlias(tableName);
    aliasMap.put(tableName, tab);
    EasyMock.expect(dataxProcessor.getTabAlias()).andReturn(aliasMap);
    this.replay();
    ElasticSearchSinkFactory clickHouseSinkFactory = new ElasticSearchSinkFactory();
    Map<IDataxProcessor.TableAlias, SinkFunction<DTO>> sinkFuncs = clickHouseSinkFactory.createSinkFunction(dataxProcessor);
    Assert.assertTrue("sinkFuncs must > 0", sinkFuncs.size() > 0);
    // StreamExecutionEnvironment env = StreamExecutionEnvironment.getExecutionEnvironment();
    // env.setParallelism(1);
    DTO d = new DTO();
    d.setTableName(tableName);
    d.setEventType(DTO.EventType.ADD);
    Map<String, Object> after = Maps.newHashMap();
    after.put(colEntityId, "334556");
    after.put(colNum, "5");
    after.put(colId, "123dsf124325253dsf123");
    after.put(colCreateTime, "20211113115959");
    d.setAfter(after);
    Assert.assertEquals(1, sinkFuncs.size());
    for (Map.Entry<IDataxProcessor.TableAlias, SinkFunction<DTO>> entry : sinkFuncs.entrySet()) {
        // env.fromElements(new DTO[]{d}).addSink(entry.getValue()).name("clickhouse");
        runElasticSearchSinkTest("elasticsearch-sink-test-json-index", entry.getValue());
        break;
    }
    // env.execute("testJob");
    Thread.sleep(5000);
    this.verifyAll();
    Client client = getClient();
}
Also used : HashMap(java.util.HashMap) ISelectedTab(com.qlangtech.tis.plugin.ds.ISelectedTab) DataXElasticsearchWriter(com.qlangtech.tis.plugin.datax.DataXElasticsearchWriter) IDataxReader(com.qlangtech.tis.datax.IDataxReader) SinkFunction(org.apache.flink.streaming.api.functions.sink.SinkFunction) ISelectedTab(com.qlangtech.tis.plugin.ds.ISelectedTab) SelectedTab(com.qlangtech.tis.plugin.datax.SelectedTab) DataType(com.qlangtech.tis.plugin.ds.DataType) Client(org.elasticsearch.client.Client) IDataxProcessor(com.qlangtech.tis.datax.IDataxProcessor) ESTableAlias(com.qlangtech.tis.datax.impl.ESTableAlias) ESTableAlias(com.qlangtech.tis.datax.impl.ESTableAlias) HashMap(java.util.HashMap) Map(java.util.Map) DTO(com.qlangtech.tis.realtime.transfer.DTO) Test(org.junit.Test)

Example 5 with SelectedTab

use of com.qlangtech.tis.plugin.datax.SelectedTab in project plugins by qlangtech.

the class CUDCDCTestSuit method startTest.

public void startTest(MQListenerFactory cdcFactory, String tabName) throws Exception {
    BasicDataXRdbmsReader dataxReader = createDataxReader(dataxName, tabName);
    // replay();
    List<SelectedTab> selectedTabs = dataxReader.getSelectedTabs();
    Optional<SelectedTab> firstSelectedTab = selectedTabs.stream().filter((t) -> tabName.equals(t.name)).findFirst();
    Assert.assertTrue("firstSelectedTab:" + tabName + " must be present", firstSelectedTab.isPresent());
    ISelectedTab tab = firstSelectedTab.get();
    this.cols = Lists.newArrayList();
    HdfsColMeta cMeta = null;
    for (ISelectedTab.ColMeta c : tab.getCols()) {
        cMeta = new HdfsColMeta(c.getName(), c.isNullable(), c.isPk(), c.getType());
        cols.add(cMeta);
    }
    IResultRows consumerHandle = getTestBasicFlinkSourceHandle(tabName);
    cdcFactory.setConsumerHandle(consumerHandle.getConsumerHandle());
    IMQListener<JobExecutionResult> imqListener = cdcFactory.create();
    this.verfiyTableCrudProcess(tabName, dataxReader, tab, consumerHandle, imqListener);
    consumerHandle.cancel();
}
Also used : LineIterator(org.apache.commons.io.LineIterator) java.sql(java.sql) StringUtils(org.apache.commons.lang.StringUtils) java.util(java.util) TargetResName(com.qlangtech.tis.coredefine.module.action.TargetResName) Date(java.util.Date) SimpleDateFormat(java.text.SimpleDateFormat) DTO(com.qlangtech.tis.realtime.transfer.DTO) BigDecimal(java.math.BigDecimal) Lists(com.google.common.collect.Lists) ByteArrayInputStream(java.io.ByteArrayInputStream) TisUTF8(com.qlangtech.tis.manage.common.TisUTF8) MQListenerFactory(com.qlangtech.tis.async.message.client.consumer.impl.MQListenerFactory) IDataxProcessor(com.qlangtech.tis.datax.IDataxProcessor) ParseException(java.text.ParseException) TISSinkFactory(com.qlangtech.tis.plugin.incr.TISSinkFactory) SinkFunction(org.apache.flink.streaming.api.functions.sink.SinkFunction) BasicDataXRdbmsReader(com.qlangtech.tis.plugin.datax.common.BasicDataXRdbmsReader) RdbmsReaderContext(com.qlangtech.tis.plugin.datax.common.RdbmsReaderContext) com.qlangtech.tis.plugin.ds(com.qlangtech.tis.plugin.ds) Maps(com.google.common.collect.Maps) Collectors(java.util.stream.Collectors) JobExecutionResult(org.apache.flink.api.common.JobExecutionResult) HdfsColMeta(com.alibaba.datax.plugin.writer.hdfswriter.HdfsColMeta) IOUtils(org.apache.commons.io.IOUtils) TestBasicFlinkSourceHandle(com.qlangtech.plugins.incr.flink.cdc.source.TestBasicFlinkSourceHandle) SelectedTab(com.qlangtech.tis.plugin.datax.SelectedTab) CloseableIterator(org.apache.flink.util.CloseableIterator) RowKind(org.apache.flink.types.RowKind) Row(org.apache.flink.types.Row) Assert(org.junit.Assert) IMQListener(com.qlangtech.tis.async.message.client.consumer.IMQListener) JobExecutionResult(org.apache.flink.api.common.JobExecutionResult) HdfsColMeta(com.alibaba.datax.plugin.writer.hdfswriter.HdfsColMeta) SelectedTab(com.qlangtech.tis.plugin.datax.SelectedTab) BasicDataXRdbmsReader(com.qlangtech.tis.plugin.datax.common.BasicDataXRdbmsReader)

Aggregations

SelectedTab (com.qlangtech.tis.plugin.datax.SelectedTab)8 IDataxProcessor (com.qlangtech.tis.datax.IDataxProcessor)4 ISelectedTab (com.qlangtech.tis.plugin.ds.ISelectedTab)4 DTO (com.qlangtech.tis.realtime.transfer.DTO)4 SinkFunction (org.apache.flink.streaming.api.functions.sink.SinkFunction)4 IDataxReader (com.qlangtech.tis.datax.IDataxReader)3 HashMap (java.util.HashMap)3 Map (java.util.Map)3 BasicDataXRdbmsReader (com.qlangtech.tis.plugin.datax.common.BasicDataXRdbmsReader)2 StreamExecutionEnvironment (org.apache.flink.streaming.api.environment.StreamExecutionEnvironment)2 HdfsColMeta (com.alibaba.datax.plugin.writer.hdfswriter.HdfsColMeta)1 Lists (com.google.common.collect.Lists)1 Maps (com.google.common.collect.Maps)1 TestBasicFlinkSourceHandle (com.qlangtech.plugins.incr.flink.cdc.source.TestBasicFlinkSourceHandle)1 IMQListener (com.qlangtech.tis.async.message.client.consumer.IMQListener)1 MQListenerFactory (com.qlangtech.tis.async.message.client.consumer.impl.MQListenerFactory)1 TargetResName (com.qlangtech.tis.coredefine.module.action.TargetResName)1 IGroupChildTaskIterator (com.qlangtech.tis.datax.IGroupChildTaskIterator)1 ESTableAlias (com.qlangtech.tis.datax.impl.ESTableAlias)1 TisUTF8 (com.qlangtech.tis.manage.common.TisUTF8)1