
com.huaweicloud.dws.client.TableConfig Maven / Gradle / Ivy
package com.huaweicloud.dws.client;
import com.huaweicloud.dws.client.model.ConflictStrategy;
import com.huaweicloud.dws.client.model.CopyMode;
import com.huaweicloud.dws.client.model.CreateTempTableMode;
import com.huaweicloud.dws.client.model.WriteMode;
import lombok.Getter;
import java.io.Serializable;
import java.util.Arrays;
import java.util.List;
import java.util.Set;
import java.util.stream.Collectors;
/**
* @ProjectName: dws-connector
* @ClassName: TableConfig
* @Description:
* @Date: 2023/2/15 19:09
* @Version: 1.0
*/
@Getter
public class TableConfig implements Serializable {
/**
* 运行参数
*/
protected ConflictStrategy conflictStrategy = ConflictStrategy.INSERT_OR_UPDATE;
/**
* 写入模式
*/
protected WriteMode writeMode = WriteMode.AUTO;
protected CopyMode copyMode = CopyMode.CSV;
protected String delimiter = copyMode.getDelimiter();
protected String eof = copyMode.getEof();
/**
* 在 WriteMode.AUTO 为自动模式下,数据量最低多少使用copy方式入库
*/
protected int copyWriteBatchSize = 6000;
protected long autoFlushMaxIntervalMs = 3000L;
protected int autoFlushBatchSize = 5000;
protected boolean updateAll = true;
protected Set compareField;
/**
* 事务自动提交
*/
protected boolean autoCommit = true;
/**
* 缓存溢出系数
*/
protected int batchOutWeighRatio = 1;
/**
* 内核优化参数
*/
protected boolean enableHstoreUpsertAutocommit;
protected List uniqueKeys;
protected boolean caseSensitive;
protected CreateTempTableMode createTempTableMode = CreateTempTableMode.AS;
/**
* 如果数据库是时间类型,数据为数字类型将当时间戳入库
*/
protected boolean numberAsEpochMsForDatetime;
/**
* 如果数据库是时间类型,数据为字符串,将用该格式转换为时间类型
*/
protected String stringToDatetimeFormat;
public TableConfig withNumberAsEpochMsForDatetime(boolean numberAsEpochMsForDatetime) {
this.numberAsEpochMsForDatetime = numberAsEpochMsForDatetime;
return this;
}
public TableConfig withStringToDatetimeFormat(String stringToDatetimeFormat) {
this.stringToDatetimeFormat = stringToDatetimeFormat;
return this;
}
public TableConfig withUniqueKeys(List uniqueKeys) {
this.uniqueKeys = uniqueKeys;
return this;
}
public TableConfig withConflictStrategy(ConflictStrategy conflictStrategy) {
this.conflictStrategy = conflictStrategy;
return this;
}
public TableConfig withWriteMode(WriteMode writeMode) {
this.writeMode = writeMode;
return this;
}
public TableConfig withCopyWriteBatchSize(int copyWriteBatchSize) {
this.copyWriteBatchSize = copyWriteBatchSize;
return this;
}
public TableConfig withAutoFlushMaxIntervalMs(long autoFlushMaxIntervalMs) {
this.autoFlushMaxIntervalMs = autoFlushMaxIntervalMs;
return this;
}
public TableConfig withAutoFlushBatchSize(int autoFlushBatchSize) {
this.autoFlushBatchSize = autoFlushBatchSize;
return this;
}
public TableConfig withBatchOutWeighRatio(int batchOutWeighRatio) {
this.batchOutWeighRatio = batchOutWeighRatio;
return this;
}
public TableConfig withEnableHstoreUpsertAutocommit(boolean enableHstoreUpsertAutocommit) {
this.enableHstoreUpsertAutocommit = enableHstoreUpsertAutocommit;
return this;
}
public TableConfig withCopyMode(CopyMode mode, String delimiter, String eof) {
this.copyMode = mode;
this.delimiter = delimiter;
this.eof = eof;
return this;
}
public TableConfig withCopyMode(CopyMode mode) {
this.copyMode = mode;
this.delimiter = mode.getDelimiter();
this.eof = mode.getEof();
return this;
}
public TableConfig withCaseSensitive(boolean caseSensitive) {
this.caseSensitive = caseSensitive;
return this;
}
public TableConfig withCreateTempTableMode(CreateTempTableMode createTempTableMode) {
this.createTempTableMode = createTempTableMode;
return this;
}
public TableConfig withUpdateAll(boolean updateAll) {
this.updateAll = updateAll;
return this;
}
public TableConfig withCompareField(String compareField) {
if (compareField == null) {
return this;
}
this.compareField = Arrays.stream(compareField.split(",")).collect(Collectors.toSet());
return this;
}
public TableConfig withCompareField(Set compareField) {
this.compareField = compareField;
return this;
}
public TableConfig withAutoCommit(boolean autoCommit) {
this.autoCommit = autoCommit;
return this;
}
public TableConfig copy() {
return new TableConfig()
.withAutoFlushBatchSize(this.autoFlushBatchSize)
.withAutoFlushMaxIntervalMs(this.autoFlushMaxIntervalMs)
.withConflictStrategy(this.conflictStrategy)
.withCopyMode(this.copyMode, this.delimiter, this.eof)
.withEnableHstoreUpsertAutocommit(this.enableHstoreUpsertAutocommit)
.withBatchOutWeighRatio(this.batchOutWeighRatio)
.withCopyWriteBatchSize(this.copyWriteBatchSize)
.withCaseSensitive(this.caseSensitive)
.withCreateTempTableMode(this.createTempTableMode)
.withNumberAsEpochMsForDatetime(this.numberAsEpochMsForDatetime)
.withStringToDatetimeFormat(this.stringToDatetimeFormat)
.withCompareField(compareField)
.withUpdateAll(updateAll)
.withAutoCommit(autoCommit)
.withWriteMode(this.writeMode);
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy