Skip to content

Commit

Permalink
Flink reserved key led to error 源数据库的表中存在flink保留字段,导致创建增量同步时异常 datav…
Browse files Browse the repository at this point in the history
  • Loading branch information
baisui1981 committed Jul 31, 2023
1 parent 6f43fbe commit 2a62202
Show file tree
Hide file tree
Showing 20 changed files with 472 additions and 201 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -147,22 +147,23 @@ protected void appendTabMeta(List<ColWrapper> pks) {
script.append(")\n");
script.append("BUCKETS 10\n");

StringBuffer seqBuffer = new StringBuffer();
if (StringUtils.isNotEmpty(dorisTab.seqKey)) {

List<CMeta> cols = this.tableMapper.getSourceCols();
Optional<CMeta> p = cols.stream().filter((c) -> dorisTab.seqKey.equals(c.getName())).findFirst();
if (!p.isPresent()) {
throw new IllegalStateException("can not find col:" + dorisTab.seqKey);
}

// seqBuffer.append("\n\t, \"function_column.sequence_col\" = '").append(dorisTab.seqKey)
// .append("'\n\t, \"function_column.sequence_type\"='").append(createColWrapper(p.get()).getMapperType()).append("'");

seqBuffer.append("\n\t, \"function_column.sequence_col\" = '").append(dorisTab.seqKey);
// .append("'\n\t, \"function_column.sequence_type\"='").append(createColWrapper(p.get()).getMapperType()).append("'");

}
StringBuffer seqBuffer = dorisTab.seqKey.createDDLScript(this.tableMapper);// new StringBuffer();
// if (StringUtils.isNotEmpty(dorisTab.seqKey)) {
//
// List<CMeta> cols = this.tableMapper.getSourceCols();
// Optional<CMeta> p = cols.stream().filter((c) -> dorisTab.seqKey.equals(c.getName())).findFirst();
// if (!p.isPresent()) {
// throw new IllegalStateException("can not find col:" + dorisTab.seqKey);
// }
//
//// seqBuffer.append("\n\t, \"function_column.sequence_col\" = '").append(dorisTab.seqKey)
//// .append("'\n\t, \"function_column.sequence_type\"='").append(createColWrapper(p.get()).getMapperType()).append("'");
//
// seqBuffer.append("\n\t, \"function_column.sequence_col\" = '").append(dorisTab.seqKey);
// // .append("'\n\t, \"function_column.sequence_type\"='").append(createColWrapper(p.get()).getMapperType()).append("'");
//
// }

script.append("PROPERTIES(\"replication_num\" = \"1\" " + seqBuffer + " )");

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,39 +20,20 @@

import com.alibaba.citrus.turbine.Context;
import com.qlangtech.tis.extension.TISExtension;
import com.qlangtech.tis.manage.common.Option;
import com.qlangtech.tis.plugin.annotation.FormField;
import com.qlangtech.tis.plugin.annotation.FormFieldType;
import com.qlangtech.tis.plugin.datax.SelectedTab;
import com.qlangtech.tis.plugin.ds.DataXReaderColType;
import com.qlangtech.tis.plugin.datax.seq.SeqKey;
import com.qlangtech.tis.runtime.module.misc.IControlMsgHandler;

import java.util.List;

/**
* @author: 百岁([email protected]
* @create: 2023-05-21 15:00
**/
public class DorisSelectedTab extends SelectedTab {

@FormField(ordinal = 4, type = FormFieldType.ENUM, validate = {})
public String seqKey;


/**
* seq cols候选列
*
* @return
*/
public static List<Option> getSeqKeys() {
List<Option> result = SelectedTab.getContextTableCols((cols) -> {
return cols.stream().filter((c) -> {
DataXReaderColType t = c.getType().getCollapse();
return t == DataXReaderColType.INT || t == DataXReaderColType.Long || t == DataXReaderColType.Date;
});
});
return result;
}
@FormField(ordinal = 4, validate = {})
public SeqKey seqKey;

@TISExtension
public static class DefaultDescriptor extends SelectedTab.DefaultDescriptor {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@

package com.qlangtech.tis.plugin.datax.doris;

import com.alibaba.datax.plugin.writer.doriswriter.Keys;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.qlangtech.tis.datax.IDataxProcessor;
Expand Down Expand Up @@ -57,13 +56,14 @@ public boolean isContainLoadProps() {

public String getLoadProps() {

if (StringUtils.isNotEmpty(dorisTab.seqKey)) {
JSONObject props = JSON.parseObject(this.plugin.loadProps);
props.put(Keys.COL_SEQUENCE_NAME, dorisTab.seqKey);
return JsonUtil.toString(props);
}
// if (StringUtils.isNotEmpty(dorisTab.seqKey)) {
JSONObject props = JSON.parseObject(this.plugin.loadProps);
dorisTab.seqKey.appendBatchCfgs(props);
return JsonUtil.toString(props);
//}

return this.plugin.loadProps;

// return this.plugin.loadProps;
}

public boolean isContainMaxBatchRows() {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
/**
* 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.datax.seq;

import com.alibaba.fastjson.JSONObject;
import com.qlangtech.tis.extension.Descriptor;
import com.qlangtech.tis.extension.TISExtension;

/**
* @author: 百岁([email protected]
* @create: 2023-07-31 15:09
**/
public class OffSeqKey extends SeqKey {

@Override
public void appendBatchCfgs(JSONObject props) {

}

@Override
public boolean isOn() {
return false;
}

@TISExtension
public static class DftDescriptor extends Descriptor<SeqKey> {
public DftDescriptor() {
}

@Override
public String getDisplayName() {
return SWITCH_OFF;
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,114 @@
/**
* 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.datax.seq;

import com.alibaba.datax.plugin.writer.doriswriter.Keys;
import com.alibaba.fastjson.JSONObject;
import com.qlangtech.tis.datax.IDataxProcessor;
import com.qlangtech.tis.extension.Descriptor;
import com.qlangtech.tis.extension.TISExtension;
import com.qlangtech.tis.manage.common.Option;
import com.qlangtech.tis.plugin.annotation.FormField;
import com.qlangtech.tis.plugin.annotation.FormFieldType;
import com.qlangtech.tis.plugin.annotation.Validator;
import com.qlangtech.tis.plugin.datax.SelectedTab;
import com.qlangtech.tis.plugin.ds.CMeta;
import com.qlangtech.tis.plugin.ds.DataXReaderColType;
import org.apache.commons.lang3.StringUtils;

import java.util.List;
import java.util.Optional;

/**
* @author: 百岁([email protected]
* @create: 2023-07-31 15:12
**/
public class OnSeqKey extends SeqKey {

@FormField(ordinal = 4, type = FormFieldType.ENUM, validate = {Validator.require})
public String seqKey;

@Override
public void appendBatchCfgs(JSONObject props) {
props.put(Keys.COL_SEQUENCE_NAME, this.seqKey);
}

@Override
public boolean isOn() {
return true;
}

@Override
public String getSeqColName() {
return this.seqKey;
}

@Override
public StringBuffer createDDLScript(IDataxProcessor.TableMap tableMapper) {
// if (StringUtils.isNotEmpty(this.seqKey)) {
if (tableMapper == null) {
throw new IllegalArgumentException("param tableMapper can not be null");
}
if (StringUtils.isEmpty(seqKey)) {
throw new IllegalArgumentException("param seqKey can not be null");
}
StringBuffer seqBuffer = new StringBuffer();
List<CMeta> cols = tableMapper.getSourceCols();
Optional<CMeta> p = cols.stream().filter((c) -> seqKey.equals(c.getName())).findFirst();
if (!p.isPresent()) {
throw new IllegalStateException("can not find col:" + seqKey);
}

// seqBuffer.append("\n\t, \"function_column.sequence_col\" = '").append(dorisTab.seqKey)
// .append("'\n\t, \"function_column.sequence_type\"='").append(createColWrapper(p.get()).getMapperType()).append("'");

seqBuffer.append("\n\t, \"function_column.sequence_col\" = '").append(seqKey);
// .append("'\n\t, \"function_column.sequence_type\"='").append(createColWrapper(p.get()).getMapperType()).append("'");

// }
return seqBuffer;
}

/**
* seq cols候选列
*
* @return
*/
public static List<Option> getSeqKeys() {
List<Option> result = SelectedTab.getContextTableCols((cols) -> {
return cols.stream().filter((c) -> {
DataXReaderColType t = c.getType().getCollapse();
return t == DataXReaderColType.INT || t == DataXReaderColType.Long || t == DataXReaderColType.Date;
});
});
return result;
}

@TISExtension
public static class DftDescriptor extends Descriptor<SeqKey> {
public DftDescriptor() {
}


@Override
public String getDisplayName() {
return SWITCH_ON;
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
/**
* 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.datax.seq;

import com.alibaba.fastjson.JSONObject;
import com.qlangtech.tis.datax.IDataxProcessor;
import com.qlangtech.tis.extension.Describable;

/**
* https://doris.apache.org/docs/dev/data-operate/update-delete/sequence-column-manual?_highlight=seq
*
* @author: 百岁([email protected]
* @create: 2023-07-31 15:05
**/
public abstract class SeqKey implements Describable<SeqKey> {

public StringBuffer createDDLScript(IDataxProcessor.TableMap tableMapper) {
return new StringBuffer();
}

/**
* 是否已经开启时间序列功能
*
* @return
*/
public abstract boolean isOn();

public String getSeqColName() {
throw new UnsupportedOperationException();
}

public abstract void appendBatchCfgs(JSONObject props);
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"seqKey": {
"label": "Sequence列",
"enum": "com.qlangtech.tis.plugin.datax.doris.DorisSelectedTab.getSeqKeys():uncache_true"
"dftVal": "off"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"seqKey": {
"enum": "com.qlangtech.tis.plugin.datax.seq.OnSeqKey.getSeqKeys():uncache_true"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@
import com.qlangtech.tis.plugin.datax.test.TestSelectedTabs;
import com.qlangtech.tis.plugin.ds.*;
import com.qlangtech.tis.plugin.ds.mysql.MySQLDataSourceFactory;
import com.qlangtech.tis.plugin.ds.split.DefaultSplitTableStrategy;
import com.qlangtech.tis.plugin.ds.split.NoneSplitTableStrategy;
import com.qlangtech.tis.plugin.ds.split.SplitTableStrategyUtils;
import com.qlangtech.tis.plugin.test.BasicTest;
import com.qlangtech.tis.sql.parser.tuple.creator.EntityName;
import com.qlangtech.tis.trigger.util.JsonUtil;
Expand Down Expand Up @@ -312,8 +312,8 @@ public void testTempateGenerate() throws Exception {
MySQLDataSourceFactory mysqlDataSource = EasyMock.createMock("mysqlDataSourceFactory", MySQLDataSourceFactory.class);
mysqlDataSource.splitTableStrategy = new NoneSplitTableStrategy();

DefaultSplitTableStrategy.SplitableTableInDB tabsInDB
= new DefaultSplitTableStrategy.SplitableTableInDB(mysqlDataSource, SplitTableStrategy.PATTERN_PHYSICS_TABLE);
SplitTableStrategy.SplitableTableInDB tabsInDB
= new SplitTableStrategy.SplitableTableInDB(mysqlDataSource, SplitTableStrategy.PATTERN_PHYSICS_TABLE);
tabsInDB.add(TestDataxMySQLWriter.mysqlJdbcUrl, TestSelectedTabs.tabNameOrderDetail + "_01");
tabsInDB.add(TestDataxMySQLWriter.mysqlJdbcUrl, TestSelectedTabs.tabNameOrderDetail + "_02");

Expand Down Expand Up @@ -369,8 +369,8 @@ public Class<?> getOwnerClass() {

ReaderTemplate.validateDataXReader("mysql-datax-reader-asser-without-option-val.json", dataXName, mySQLReader);

DefaultSplitTableStrategy splitTableStrategy = new DefaultSplitTableStrategy();
mysqlDataSource.splitTableStrategy = splitTableStrategy;
// DefaultSplitTableStrategy splitTableStrategy = SplitTableStrategyUtils.createSplitTableStrategy();
mysqlDataSource.splitTableStrategy = SplitTableStrategyUtils.createSplitTableStrategy();
ReaderTemplate.validateDataXReader("mysql-datax-reader-assert-split-tabs.json", dataXName, mySQLReader);

EasyMock.verify(mysqlDataSource, dataDumper);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@
import com.qlangtech.tis.plugin.ds.DataSourceFactory;
import com.qlangtech.tis.plugin.ds.DataSourceFactoryPluginStore;
import com.qlangtech.tis.plugin.ds.mysql.MySQLDataSourceFactory;
import com.qlangtech.tis.plugin.ds.split.DefaultSplitTableStrategy;
import com.qlangtech.tis.plugin.ds.split.NoneSplitTableStrategy;
import com.qlangtech.tis.plugin.ds.split.SplitTableStrategyUtils;
import com.ververica.cdc.connectors.mysql.testutils.MySqlContainer;
import org.apache.commons.io.FileUtils;
import org.junit.Assert;
Expand Down Expand Up @@ -120,7 +120,7 @@ public DataSourceFactory getPlugin() {
public void testRealDumpWithSplitTabs() throws Exception {

MySQLDataSourceFactory mysqlDs = (MySQLDataSourceFactory) dsFactory;
mysqlDs.splitTableStrategy = new DefaultSplitTableStrategy();
mysqlDs.splitTableStrategy = SplitTableStrategyUtils.createSplitTableStrategy();
DataXJobInfo.parse("base_1.json/base_01,base_02");
Assert.assertNotNull(DataXJobInfo.getCurrent());

Expand Down
Loading

0 comments on commit 2a62202

Please sign in to comment.