-
Notifications
You must be signed in to change notification settings - Fork 2k
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
[FLINK-35152][pipeline-connector/doris] Support create doris auto partition table #3871
Open
qg-lin
wants to merge
2
commits into
apache:master
Choose a base branch
from
qg-lin:FLINK-35152
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 1 commit
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -182,6 +182,25 @@ pipeline: | |
See more about <a href="https://doris.apache.org/docs/dev/sql-manual/sql-statements/Data-Definition-Statements/Create/CREATE-TABLE/"> Doris Table Properties</a></td> | ||
</td> | ||
</tr> | ||
<tr> | ||
<td>table.create.auto-partition.properties.*</td> | ||
<td>optional</td> | ||
<td style="word-wrap: break-word;">(none)</td> | ||
<td>String</td> | ||
<td>Create the auto partition Properties configuration of the table.<br/> | ||
Currently the partition function only supports date_trunc, and the partition column supports only DATE or DATETIME types, and the version of Doris must greater than 2.1.6. See more about <a href="https://doris.apache.org/docs/table-design/data-partitioning/auto-partitioning">Doris Auto Partitioning</a><br/> | ||
These properties are supported now:<br/> | ||
<code> table.create.auto-partition.properties.include</code>A collection of tables after route to include, separated by commas, supports regular expressions;<br/> | ||
<code> table.create.auto-partition.properties.exclude</code>A collection of tables after route to exclude, separated by commas, supports regular expressions;<br/> | ||
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. It's better not to let user aware of the concept of |
||
<code> table.create.auto-partition.properties.default_partition_key</code>The default partition key;<br/> | ||
<code> table.create.auto-partition.properties.default_partition_unit</code>The default partition unit;<br/> | ||
<code> table.create.auto-partition.properties.DB.TABLE.partition_key</code>The partition key of a specific table. If not set, the default partition key is used;<br/> | ||
<code> table.create.auto-partition.properties.DB.TABLE.partition_unit</code>The partition unit of a specific table. If not set, the default partition unit is used.<br/> | ||
Note:<br/> | ||
1: If the partition key is not DATE/DATETIME type, auto partition tables won't be created.<br/> | ||
2: Doris AUTO RANGE PARTITION does not support NULLABLE columns as partition key, if Flink CDC get a NULL value or a NULLABLE partition key was added after the table was created, will automatically fill it with a default value(DATE:<code>1970-01-01</code>, DATETIME:<code>1970-01-01 00:00:00</code>), chose a suitable partition key is very important. | ||
</td> | ||
</tr> | ||
</tbody> | ||
</table> | ||
</div> | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
107 changes: 107 additions & 0 deletions
107
...tor-doris/src/main/java/org/apache/flink/cdc/connectors/doris/utils/DorisSchemaUtils.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,107 @@ | ||
/* | ||
* 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 | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* 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 org.apache.flink.cdc.connectors.doris.utils; | ||
|
||
import org.apache.flink.api.java.tuple.Tuple2; | ||
import org.apache.flink.cdc.common.configuration.Configuration; | ||
import org.apache.flink.cdc.common.event.TableId; | ||
import org.apache.flink.cdc.common.schema.Schema; | ||
import org.apache.flink.cdc.common.schema.Selectors; | ||
import org.apache.flink.cdc.common.types.DataType; | ||
import org.apache.flink.cdc.common.types.DateType; | ||
import org.apache.flink.cdc.common.types.LocalZonedTimestampType; | ||
import org.apache.flink.cdc.common.types.TimestampType; | ||
import org.apache.flink.cdc.common.types.ZonedTimestampType; | ||
import org.apache.flink.cdc.common.utils.StringUtils; | ||
import org.apache.flink.cdc.connectors.doris.sink.DorisDataSinkOptions; | ||
|
||
import java.util.Map; | ||
|
||
import static org.apache.flink.cdc.connectors.doris.sink.DorisDataSinkOptions.TABLE_CREATE_AUTO_PARTITION_PROPERTIES_PREFIX; | ||
import static org.apache.flink.cdc.connectors.doris.sink.DorisDataSinkOptions.TABLE_CREATE_DEFAULT_PARTITION_KEY; | ||
import static org.apache.flink.cdc.connectors.doris.sink.DorisDataSinkOptions.TABLE_CREATE_DEFAULT_PARTITION_UNIT; | ||
import static org.apache.flink.cdc.connectors.doris.sink.DorisDataSinkOptions.TABLE_CREATE_PARTITION_EXCLUDE; | ||
import static org.apache.flink.cdc.connectors.doris.sink.DorisDataSinkOptions.TABLE_CREATE_PARTITION_INCLUDE; | ||
import static org.apache.flink.cdc.connectors.doris.sink.DorisDataSinkOptions.TABLE_CREATE_PARTITION_KEY; | ||
import static org.apache.flink.cdc.connectors.doris.sink.DorisDataSinkOptions.TABLE_CREATE_PARTITION_UNIT; | ||
|
||
/** Utilities for doris schema. */ | ||
public class DorisSchemaUtils { | ||
|
||
public static final String DEFAULT_DATE = "1970-01-01"; | ||
public static final String DEFAULT_DATETIME = "1970-01-01 00:00:00"; | ||
|
||
/** | ||
* Get partition info by config. Currently only supports DATE/TIMESTAMP AUTO RANGE PARTITION and | ||
* doris version should greater than 2.1.6 | ||
* | ||
* @param config | ||
* @param schema | ||
* @param tableId | ||
* @return | ||
*/ | ||
public static Tuple2<String, String> getPartitionInfo( | ||
Configuration config, Schema schema, TableId tableId) { | ||
Map<String, String> autoPartitionProperties = | ||
DorisDataSinkOptions.getPropertiesByPrefix( | ||
config, TABLE_CREATE_AUTO_PARTITION_PROPERTIES_PREFIX); | ||
String excludes = autoPartitionProperties.get(TABLE_CREATE_PARTITION_EXCLUDE); | ||
if (!StringUtils.isNullOrWhitespaceOnly(excludes)) { | ||
Selectors selectExclude = | ||
new Selectors.SelectorsBuilder().includeTables(excludes).build(); | ||
if (selectExclude.isMatch(tableId)) { | ||
return null; | ||
} | ||
} | ||
|
||
String includes = autoPartitionProperties.get(TABLE_CREATE_PARTITION_INCLUDE); | ||
if (!StringUtils.isNullOrWhitespaceOnly(includes)) { | ||
Selectors selectInclude = | ||
new Selectors.SelectorsBuilder().includeTables(includes).build(); | ||
if (!selectInclude.isMatch(tableId)) { | ||
return null; | ||
} | ||
} | ||
|
||
String partitionKey = | ||
autoPartitionProperties.get( | ||
tableId.identifier() + "." + TABLE_CREATE_PARTITION_KEY); | ||
String partitionUnit = | ||
autoPartitionProperties.get( | ||
tableId.identifier() + "." + TABLE_CREATE_PARTITION_UNIT); | ||
if (StringUtils.isNullOrWhitespaceOnly(partitionKey)) { | ||
partitionKey = autoPartitionProperties.get(TABLE_CREATE_DEFAULT_PARTITION_KEY); | ||
} | ||
if (StringUtils.isNullOrWhitespaceOnly(partitionUnit)) { | ||
partitionUnit = autoPartitionProperties.get(TABLE_CREATE_DEFAULT_PARTITION_UNIT); | ||
} | ||
|
||
if (schema.getColumn(partitionKey).isPresent() | ||
&& !StringUtils.isNullOrWhitespaceOnly(partitionKey)) { | ||
|
||
DataType dataType = schema.getColumn(partitionKey).get().getType(); | ||
if (dataType instanceof LocalZonedTimestampType | ||
|| dataType instanceof TimestampType | ||
|| dataType instanceof ZonedTimestampType | ||
|| dataType instanceof DateType) { | ||
return new Tuple2<>(partitionKey, partitionUnit); | ||
} | ||
} | ||
return null; | ||
} | ||
} |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Could we add these properties though transform?