-
Notifications
You must be signed in to change notification settings - Fork 2k
[FLINK-35152][pipeline-connector/doris] Support create doris auto partition table #3871
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
Merged
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
07531bf
[FLINK-35152][pipeline-connector/doris] Support create doris auto par…
qg-lin 9a21c04
[FLINK-35152][pipeline-connector/doris] Support create doris auto par…
qg-lin 5c1b829
Merge branch 'apache:master' into FLINK-35152
qg-lin 69c5259
Update pom.xml
qg-lin 84d08ac
update test case
qg-lin 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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
131 changes: 131 additions & 0 deletions
131
...tor-doris/src/main/java/org/apache/flink/cdc/connectors/doris/utils/DorisSchemaUtils.java
This file contains hidden or 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,131 @@ | ||
/* | ||
* 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); | ||
if (autoPartitionProperties.isEmpty()) { | ||
return null; | ||
} | ||
|
||
if (isExcluded(autoPartitionProperties, tableId) | ||
|| !isIncluded(autoPartitionProperties, tableId)) { | ||
return null; | ||
} | ||
|
||
String partitionKey = | ||
getPartitionProperty( | ||
autoPartitionProperties, | ||
tableId, | ||
TABLE_CREATE_PARTITION_KEY, | ||
TABLE_CREATE_DEFAULT_PARTITION_KEY); | ||
if (partitionKey == null || !schema.getColumn(partitionKey).isPresent()) { | ||
return null; | ||
} | ||
|
||
String partitionUnit = | ||
getPartitionProperty( | ||
autoPartitionProperties, | ||
tableId, | ||
TABLE_CREATE_PARTITION_UNIT, | ||
TABLE_CREATE_DEFAULT_PARTITION_UNIT); | ||
if (partitionUnit == null) { | ||
return null; | ||
} | ||
|
||
DataType dataType = schema.getColumn(partitionKey).get().getType(); | ||
return isValidDataType(dataType) ? new Tuple2<>(partitionKey, partitionUnit) : null; | ||
} | ||
|
||
private static boolean isExcluded(Map<String, String> properties, TableId tableId) { | ||
String excludes = properties.get(TABLE_CREATE_PARTITION_EXCLUDE); | ||
if (!StringUtils.isNullOrWhitespaceOnly(excludes)) { | ||
Selectors selectExclude = | ||
new Selectors.SelectorsBuilder().includeTables(excludes).build(); | ||
return selectExclude.isMatch(tableId); | ||
} | ||
return false; | ||
} | ||
|
||
private static boolean isIncluded(Map<String, String> properties, TableId tableId) { | ||
String includes = properties.get(TABLE_CREATE_PARTITION_INCLUDE); | ||
if (!StringUtils.isNullOrWhitespaceOnly(includes)) { | ||
Selectors selectInclude = | ||
new Selectors.SelectorsBuilder().includeTables(includes).build(); | ||
return selectInclude.isMatch(tableId); | ||
} | ||
return true; | ||
} | ||
|
||
private static String getPartitionProperty( | ||
Map<String, String> properties, | ||
TableId tableId, | ||
String specificKey, | ||
String defaultKey) { | ||
String key = properties.get(tableId.identifier() + "." + specificKey); | ||
return StringUtils.isNullOrWhitespaceOnly(key) ? properties.get(defaultKey) : key; | ||
} | ||
|
||
private static boolean isValidDataType(DataType dataType) { | ||
return dataType instanceof LocalZonedTimestampType | ||
|| dataType instanceof TimestampType | ||
|| dataType instanceof ZonedTimestampType | ||
|| dataType instanceof DateType; | ||
} | ||
} |
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.
It's better not to let user aware of the concept of
route
, which will make it hard to understand.