-
Notifications
You must be signed in to change notification settings - Fork 336
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Doris support deducing partitions #280
base: master
Are you sure you want to change the base?
Changes from 4 commits
c021d6b
21ee69f
37a4631
fc240c6
6d82ddd
9be0a28
955c427
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
package com.bytedance.bitsail.connector.doris.partition; | ||
|
||
import com.fasterxml.jackson.annotation.JsonProperty; | ||
import lombok.AllArgsConstructor; | ||
import lombok.Data; | ||
import lombok.NoArgsConstructor; | ||
|
||
@AllArgsConstructor | ||
@NoArgsConstructor | ||
@Data | ||
public class DorisPartitionTemplate { | ||
|
||
@JsonProperty(value = "prefix", required = false, defaultValue = "p") | ||
private String prefix; | ||
|
||
@JsonProperty(value = "start_range", required = true) | ||
private String startRange; | ||
|
||
@JsonProperty(value = "end_range", required = true) | ||
private String endRange; | ||
|
||
@JsonProperty(value = "pattern", required = false, defaultValue = "yyyy-MM-dd") | ||
private String pattern; | ||
|
||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -21,11 +21,13 @@ | |
import com.bytedance.bitsail.base.connector.writer.v1.WriterCommitter; | ||
import com.bytedance.bitsail.base.serializer.BinarySerializer; | ||
import com.bytedance.bitsail.base.serializer.SimpleBinarySerializer; | ||
import com.bytedance.bitsail.common.BitSailException; | ||
import com.bytedance.bitsail.common.configuration.BitSailConfiguration; | ||
import com.bytedance.bitsail.common.exception.CommonErrorCode; | ||
import com.bytedance.bitsail.common.model.ColumnInfo; | ||
import com.bytedance.bitsail.common.type.TypeInfoConverter; | ||
import com.bytedance.bitsail.common.type.filemapping.FileMappingTypeInfoConverter; | ||
import com.bytedance.bitsail.common.util.DateUtil; | ||
import com.bytedance.bitsail.connector.doris.DorisConnectionHolder; | ||
import com.bytedance.bitsail.connector.doris.committer.DorisCommittable; | ||
import com.bytedance.bitsail.connector.doris.committer.DorisCommittableSerializer; | ||
|
@@ -36,6 +38,7 @@ | |
import com.bytedance.bitsail.connector.doris.option.DorisWriterOptions; | ||
import com.bytedance.bitsail.connector.doris.partition.DorisPartition; | ||
import com.bytedance.bitsail.connector.doris.partition.DorisPartitionManager; | ||
import com.bytedance.bitsail.connector.doris.partition.DorisPartitionTemplate; | ||
import com.bytedance.bitsail.connector.doris.sink.ddl.DorisSchemaManagerGenerator; | ||
|
||
import com.alibaba.fastjson.JSON; | ||
|
@@ -44,12 +47,16 @@ | |
|
||
import java.io.IOException; | ||
import java.sql.SQLException; | ||
import java.text.ParseException; | ||
import java.text.SimpleDateFormat; | ||
import java.util.ArrayList; | ||
import java.util.Collections; | ||
import java.util.Date; | ||
import java.util.HashMap; | ||
import java.util.List; | ||
import java.util.Map; | ||
import java.util.Optional; | ||
import java.util.Properties; | ||
import java.util.stream.Collectors; | ||
|
||
public class DorisSink<InputT> implements Sink<InputT, DorisCommittable, DorisWriterState> { | ||
private static final Logger LOG = LoggerFactory.getLogger(DorisSink.class); | ||
|
@@ -137,16 +144,38 @@ private void initDorisOptions(BitSailConfiguration writerConfiguration) { | |
// Need partition info in batch replace modes. | ||
if (isHasPartition && this.writeMode.equals(DorisExecutionOptions.WRITE_MODE.BATCH_REPLACE)) { | ||
//BATCH and REPLACE mode need the partition infos | ||
List<Map<String, Object>> partitionList = writerConfiguration.getNecessaryOption(DorisWriterOptions.PARTITIONS, CommonErrorCode.CONFIG_ERROR); | ||
builder.partitions( | ||
partitionList.stream() | ||
.map(partition -> JSON.parseObject(JSON.toJSONString(partition), DorisPartition.class)) | ||
.collect(Collectors.toList()) | ||
); | ||
DorisPartitionTemplate dorisPartitionTemplate = writerConfiguration.getNecessaryOption(DorisWriterOptions.PARTITIONS, CommonErrorCode.CONFIG_ERROR); | ||
List<DorisPartition> dorisPartitions = parseTemplateToDorisPartitions(dorisPartitionTemplate); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Great work, but I have one question.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @BlockLiu Thanks for your suggestion, now I understand what you mean. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Actually, I mean we can keep both two method for setting doris partition(s).
So we don't need a "step size", but an option to decide which way to use. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Like this:
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. OK,ths! |
||
builder.partitions(dorisPartitions); | ||
} | ||
dorisOptions = builder.build(); | ||
} | ||
|
||
private List<DorisPartition> parseTemplateToDorisPartitions(DorisPartitionTemplate dorisPartitionTemplate) { | ||
String pattern = dorisPartitionTemplate.getPattern(); | ||
String prefix = dorisPartitionTemplate.getPrefix(); | ||
String start = dorisPartitionTemplate.getStartRange(); | ||
String end = dorisPartitionTemplate.getEndRange(); | ||
|
||
SimpleDateFormat sdf = new SimpleDateFormat(pattern); | ||
try { | ||
Date dateStart = sdf.parse(start); | ||
Date dateEnd = sdf.parse(end); | ||
List<DorisPartition> dorisPartitions = new ArrayList<>(); | ||
List<Date> listDate = DateUtil.getDatesBetweenTwoDate(dateStart, dateEnd); | ||
listDate.forEach(date -> { | ||
DorisPartition dorisPartition = new DorisPartition(); | ||
dorisPartition.setName(prefix + sdf.format(date)); | ||
dorisPartition.setStartRange(Collections.singletonList(sdf.format(date))); | ||
dorisPartition.setEndRange(Collections.singletonList(sdf.format(DateUtil.getNDaysAfterDate(date, 1)))); | ||
dorisPartitions.add(dorisPartition); | ||
}); | ||
return dorisPartitions; | ||
} catch (ParseException e) { | ||
throw BitSailException.asBitSailException(CommonErrorCode.CONFIG_ERROR, "Can't parse configuration info: " + dorisPartitionTemplate, e); | ||
} | ||
} | ||
|
||
private void initDorisExecutionOptions(BitSailConfiguration writerConfiguration) { | ||
LOG.info("Start to init DorisExecutionOptions!"); | ||
final DorisExecutionOptions.DorisExecutionOptionsBuilder builder = DorisExecutionOptions.builder(); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There should be a license header. You can copy from other source files.