Skip to content

Commit

Permalink
使用JSON Splitter拆分记录中的JSON字段内容出错, modify for datavane/tis#390
Browse files Browse the repository at this point in the history
  • Loading branch information
baisui1981 committed Nov 5, 2024
1 parent ddd052d commit bacf0d4
Show file tree
Hide file tree
Showing 22 changed files with 450 additions and 181 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@
<parent>
<artifactId>tis-datax</artifactId>
<groupId>com.qlangtech.tis.plugins</groupId>
<version>4.1.0</version>
<version>4.1.0-SNAPSHOT</version>
<relativePath>../../pom.xml</relativePath>
</parent>
<modelVersion>4.0.0</modelVersion>
<groupId>com.qlangtech.tis.plugins</groupId>
<artifactId>dolphinscheduler-task-tis-datasync</artifactId>
<version>4.1.0</version>
<version>4.1.0-SNAPSHOT</version>
<licenses>
<license>
<name>GNU Affero General Public License</name>
Expand Down Expand Up @@ -68,7 +68,7 @@
<dependency>
<groupId>com.qlangtech.tis</groupId>
<artifactId>tis-base-test</artifactId>
<version>4.1.0</version>
<version>4.1.0-SNAPSHOT</version>
<scope>test</scope>
</dependency>
<dependency>
Expand All @@ -86,7 +86,7 @@
<dependency>
<groupId>com.alibaba.datax</groupId>
<artifactId>datax-common</artifactId>
<version>4.1.0</version>
<version>4.1.0-SNAPSHOT</version>
<scope>provided</scope>
</dependency>
<dependency>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@
<parent>
<artifactId>tis-aliyun-jindo-sdk-extends</artifactId>
<groupId>com.qlangtech.tis.plugins</groupId>
<version>4.1.0</version>
<version>4.1.0-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<groupId>com.qlangtech.tis.plugins</groupId>
<artifactId>tis-aliyun-jindo-sdk-extends-impl</artifactId>
<version>4.1.0</version>
<version>4.1.0-SNAPSHOT</version>
<licenses>
<license>
<name>GNU Affero General Public License</name>
Expand Down Expand Up @@ -46,7 +46,7 @@
<dependency>
<groupId>com.alibaba.datax</groupId>
<artifactId>datax-common</artifactId>
<version>4.1.0</version>
<version>4.1.0-SNAPSHOT</version>
<scope>provided</scope>
</dependency>
<dependency>
Expand All @@ -64,7 +64,7 @@
<dependency>
<groupId>com.qlangtech.tis</groupId>
<artifactId>tis-plugin</artifactId>
<version>4.1.0</version>
<version>4.1.0-SNAPSHOT</version>
<scope>provided</scope>
</dependency>
<dependency>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public CassandraWriterContext(DataXCassandraWriter writer, IDataxProcessor.Table
this.tabMapper = tabMapper;
this.dsFactory = writer.getDataSourceFactory();

this.cols = transformerRules.map((rule) -> rule.overwriteCols(tabMapper.getSourceCols()).getCols())
this.cols = transformerRules.map((rule) -> rule.overwriteCols(tabMapper.getSourceCols()).getColsWithoutVirtualInfo())
.orElseGet(() -> tabMapper.getSourceCols().stream().collect(Collectors.toList()));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public DataXDFSWriterContext(DataXDFSWriter writer, IDataxProcessor.TableMap tab
Objects.requireNonNull(writer.dfsLinker, "prop linker can not be null");
this.tableMapper = tableMapper;

this.cols = transformerRules.map((rule) -> rule.overwriteCols(tableMapper.getSourceCols()).getCols())
this.cols = transformerRules.map((rule) -> rule.overwriteCols(tableMapper.getSourceCols()).getColsWithoutVirtualInfo())
.orElseGet(() -> tableMapper.getSourceCols().stream().collect(Collectors.toList()));

// this.ftpServer = FTPServer.getServer(writer.linker);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ private static String getDftColumn(ISelectedTab tab, Optional<RecordTransformerR
try {
List<IColMetaGetter> cols = null;
if (transformerRules.isPresent()) {
cols = transformerRules.get().overwriteCols(tab.getCols()).getCols();
cols = transformerRules.get().overwriteCols(tab.getCols()).getColsWithoutVirtualInfo();
} else {
cols = tab.getCols().stream().collect(Collectors.toList());
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
/**
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
* <p>
* http://www.apache.org/licenses/LICENSE-2.0
* <p>
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package com.qlangtech.tis.plugin.ds.sqlserver;

import org.junit.Test;

import java.sql.Date;
import java.sql.PreparedStatement;
import java.sql.SQLType;
import java.sql.Types;

/**
* @author: 百岁([email protected]
* @create: 2024-11-02 15:05
**/
public class TestSqlServer2019DatasourceFactory {
@Test
public void testConnect() {
SqlServer2019DatasourceFactory sqlServer2019DatasourceFactory = new SqlServer2019DatasourceFactory();
sqlServer2019DatasourceFactory.name = "test";
sqlServer2019DatasourceFactory.dbName = "tis";
sqlServer2019DatasourceFactory.useSSL = false;
sqlServer2019DatasourceFactory.nodeDesc = "192.168.28.201";
sqlServer2019DatasourceFactory.port = 1433;
sqlServer2019DatasourceFactory.userName = "sa";
sqlServer2019DatasourceFactory.password = "Hello1234!";

sqlServer2019DatasourceFactory.visitFirstConnection((conn) -> {
try (PreparedStatement preparedStatement = conn.getConnection().prepareStatement("insert into base(base_id,update_date,col_blob) values( ?, ?, ? )")) {
preparedStatement.setInt(1, 24);
preparedStatement.setTimestamp(2, new java.sql.Timestamp(System.currentTimeMillis()));
preparedStatement.setObject(3, null, Types.NULL);
preparedStatement.execute();
}
});

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@
<parent>
<artifactId>tis-incr</artifactId>
<groupId>com.qlangtech.tis.plugins</groupId>
<version>4.1.0</version>
<version>4.1.0-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<groupId>com.qlangtech.tis.plugins</groupId>
<artifactId>tis-flink-cdc-shade-4-debezium-connector-mysql</artifactId>
<version>4.1.0</version>
<version>4.1.0-SNAPSHOT</version>
<licenses>
<license>
<name>GNU Affero General Public License</name>
Expand Down Expand Up @@ -66,7 +66,7 @@
<dependency>
<groupId>com.qlangtech.tis</groupId>
<artifactId>tis-plugin</artifactId>
<version>4.1.0</version>
<version>4.1.0-SNAPSHOT</version>
<scope>provided</scope>
</dependency>
<dependency>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@
<parent>
<artifactId>tis-incr</artifactId>
<groupId>com.qlangtech.tis.plugins</groupId>
<version>4.1.0</version>
<version>4.1.0-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<groupId>com.qlangtech.tis.plugins</groupId>
<artifactId>tis-flink-cdc-postgresql-shade-4-debezium-connector-postgresql</artifactId>
<version>4.1.0</version>
<version>4.1.0-SNAPSHOT</version>
<licenses>
<license>
<name>GNU Affero General Public License</name>
Expand Down Expand Up @@ -68,7 +68,7 @@
<dependency>
<groupId>com.qlangtech.tis</groupId>
<artifactId>tis-plugin</artifactId>
<version>4.1.0</version>
<version>4.1.0-SNAPSHOT</version>
<scope>provided</scope>
</dependency>
<dependency>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import com.qlangtech.tis.plugin.datax.dameng.ds.DaMengDataSourceFactory;
import com.qlangtech.tis.plugin.datax.dameng.writer.DataXDaMengWriter;
import com.qlangtech.tis.plugin.ds.BasicDataSourceFactory;
import com.qlangtech.tis.plugin.ds.CMeta;
import com.qlangtech.tis.plugin.ds.oracle.DamengDSFactoryContainer;
import com.qlangtech.tis.plugin.ds.oracle.TISDamengContainer;
import com.qlangtech.tis.plugins.incr.flink.connector.ChunjunSinkFactory;
Expand All @@ -34,6 +35,7 @@
import org.junit.Test;

import java.util.ArrayList;
import java.util.List;

/**
* @author: 百岁([email protected]
Expand Down Expand Up @@ -67,17 +69,18 @@ public static void stop() {

@Override
protected UpdateMode createIncrMode() {
// InsertType insertType = new InsertType();
// InsertType insertType = new InsertType();
UpsertType updateMode = new UpsertType();
// UpdateType updateMode = new UpdateType();
// UpdateType updateMode = new UpdateType();
// updateMode.updateKey = Lists.newArrayList(colId, updateTime);
return updateMode;
}

@Override
protected ArrayList<String> getUniqueKey() {
return Lists.newArrayList(colId, updateTime);
}
// @Override
// protected ArrayList<String> getUniqueKey(List<CMeta> metaCols) {
// // return Lists.newArrayList(colId, updateTime);
// return super.getUniqueKey(metaCols);
// }

@Override
protected BasicDataSourceFactory getDsFactory() {
Expand All @@ -87,6 +90,7 @@ protected BasicDataSourceFactory getDsFactory() {
@Test
@Override
public void testSinkSync() throws Exception {

super.testSinkSync();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
import com.qlangtech.tis.coredefine.module.action.TargetResName;
import com.qlangtech.tis.datax.IStreamTableMeataCreator;
import com.qlangtech.tis.datax.IStreamTableMeta;
import com.qlangtech.tis.datax.impl.DataxProcessor;
import com.qlangtech.tis.plugin.IEndTypeGetter;
import com.qlangtech.tis.plugin.common.PluginDesc;
import com.qlangtech.tis.plugin.datax.SelectedTab;
Expand All @@ -36,6 +37,7 @@
import com.qlangtech.tis.plugin.ds.BasicDataSourceFactory;
import com.qlangtech.tis.plugin.ds.DataSourceMeta;
import com.qlangtech.tis.plugin.ds.ISelectedTab;
import com.qlangtech.tis.plugin.ds.JDBCConnection;
import com.qlangtech.tis.plugin.ds.doris.DorisSourceFactory;
import com.qlangtech.tis.plugins.incr.flink.chunjun.script.ChunjunSqlType;
import com.qlangtech.tis.plugins.incr.flink.connector.ChunjunSinkFactory;
Expand All @@ -46,6 +48,7 @@
import com.qlangtech.tis.sql.parser.tuple.creator.IStreamIncrGenerateStrategy;
import org.apache.commons.lang.StringUtils;
import org.apache.commons.lang3.tuple.Pair;
import org.apache.flink.streaming.api.environment.StreamExecutionEnvironment;
import org.apache.http.HttpEntity;
import org.junit.After;
import org.junit.Assert;
Expand Down Expand Up @@ -246,50 +249,49 @@ private AtomicInteger getHttpPutCount() {
public void testSinkSyncWithSQL() throws Exception {

AtomicInteger httpPutCount = getHttpPutCount();
super.testSinkSync((dataxProcessor, sinkFactory, env, selectedTab) -> {
/**
* ==================================================
*/
TestTableRegisterFlinkSourceHandle tableRegisterHandle = new TotalpayRegisterFlinkSourceHandle(selectedTab);
tableRegisterHandle.setSinkFuncFactory(sinkFactory);

// (tab) -> {
// return () -> {
// return selectedTab.getCols().stream()
// .map((c) -> new HdfsColMeta(
// c.getName(), c.isNullable(), c.isPk(), c.getType())).collect(Collectors.toList());
// };
// }

tableRegisterHandle.setSourceStreamTableMeta(new IStreamTableMeataCreator.ISourceStreamMetaCreator() {
@Override
public ISelectedTab getSelectedTab(String tableName) {
throw new UnsupportedOperationException(tableName);
}
IStreamScriptRun streamScriptRun = new IStreamScriptRun() {
@Override
protected void runStream(DataxProcessor dataxProcessor
, ChunjunSinkFactory sinkFactory, StreamExecutionEnvironment env, SelectedTab selectedTab) throws Exception {
/**
* ==================================================
*/
TestTableRegisterFlinkSourceHandle tableRegisterHandle = new TotalpayRegisterFlinkSourceHandle(selectedTab);
tableRegisterHandle.setSinkFuncFactory(sinkFactory);

tableRegisterHandle.setSourceStreamTableMeta(new IStreamTableMeataCreator.ISourceStreamMetaCreator() {
@Override
public ISelectedTab getSelectedTab(String tableName) {
throw new UnsupportedOperationException(tableName);
}

@Override
public IStreamTableMeta getStreamTableMeta(String tableName) {
return () -> {
return selectedTab.getCols().stream()
.map((c) -> new HdfsColMeta(
c.getName(), c.isNullable(), c.isPk(), c.getType())).collect(Collectors.toList());
};
}
});

List<ReaderSource> sourceFuncts = Lists.newArrayList();
dataxProcessor.getTabAlias().forEach((key, val) -> {
Pair<DTOStream, ReaderSource<DTO>> sourceStream = createReaderSource(env, val);
sourceFuncts.add(sourceStream.getRight());
});

SourceChannel sourceChannel = new SourceChannel(sourceFuncts);
sourceChannel.setFocusTabs(Collections.singletonList(selectedTab), dataxProcessor.getTabAlias(), DTOStream::createDispatched);
tableRegisterHandle.consume(new TargetResName(dataXName), sourceChannel, dataxProcessor);
/**
* ===========================================
*/
});
@Override
public IStreamTableMeta getStreamTableMeta(String tableName) {
return () -> {
return selectedTab.getCols().stream()
.map((c) -> new HdfsColMeta(
c.getName(), c.isNullable(), c.isPk(), c.getType())).collect(Collectors.toList());
};
}
});

List<ReaderSource> sourceFuncts = Lists.newArrayList();
dataxProcessor.getTabAlias().forEach((key, val) -> {
Pair<DTOStream, ReaderSource<DTO>> sourceStream = createReaderSource(this, env, val);
sourceFuncts.add(sourceStream.getRight());
});

SourceChannel sourceChannel = new SourceChannel(sourceFuncts);
sourceChannel.setFocusTabs(Collections.singletonList(selectedTab), dataxProcessor.getTabAlias(), DTOStream::createDispatched);
tableRegisterHandle.consume(new TargetResName(dataXName), sourceChannel, dataxProcessor);
/**
* ===========================================
*/
}
};

super.testSinkSync(streamScriptRun);
Assert.assertEquals("httpPutCount must be 1", 1, httpPutCount.get());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,10 +73,10 @@ protected UpdateMode createIncrMode() {
return insertType;
}

@Override
protected ArrayList<String> getUniqueKey() {
return Lists.newArrayList(colId, updateTime);
}
// @Override
// protected ArrayList<String> getUniqueKey() {
// return Lists.newArrayList(colId, updateTime);
// }

@Override
protected BasicDataSourceFactory getDsFactory() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
import org.junit.Test;

import java.util.ArrayList;
import java.util.List;

/**
* @author: 百岁([email protected]
Expand Down Expand Up @@ -71,7 +72,7 @@ protected UpdateMode createIncrMode() {
}

@Override
protected ArrayList<String> getUniqueKey() {
protected List<String> getUniqueKey(List<CMeta> metaCols) {
return Lists.newArrayList(colId);
}

Expand Down
Loading

0 comments on commit bacf0d4

Please sign in to comment.