-
Notifications
You must be signed in to change notification settings - Fork 380
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[#3980]feat(flink-connector): Support partition for hive table operat…
…ion (#4096) ### What changes were proposed in this pull request? - support partitions for the hive table ### Why are the changes needed? - Fix: #3980 ### Does this PR introduce _any_ user-facing change? - no ### How was this patch tested? - add ITs
- Loading branch information
Showing
5 changed files
with
234 additions
and
35 deletions.
There are no files selected for viewing
52 changes: 52 additions & 0 deletions
52
...nnector/src/main/java/org/apache/gravitino/flink/connector/DefaultPartitionConverter.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,52 @@ | ||
/* | ||
* 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.gravitino.flink.connector; | ||
|
||
import com.google.common.base.Preconditions; | ||
import java.util.Arrays; | ||
import java.util.List; | ||
import java.util.stream.Collectors; | ||
import org.apache.gravitino.rel.expressions.transforms.Transform; | ||
import org.apache.gravitino.rel.expressions.transforms.Transforms; | ||
|
||
public class DefaultPartitionConverter implements PartitionConverter { | ||
|
||
private DefaultPartitionConverter() {} | ||
|
||
public static final DefaultPartitionConverter INSTANCE = new DefaultPartitionConverter(); | ||
|
||
@Override | ||
public List<String> toFlinkPartitionKeys(Transform[] partitions) { | ||
List<String> partitionKeys = | ||
Arrays.stream(partitions) | ||
.filter(t -> t instanceof Transforms.IdentityTransform) | ||
.flatMap(t -> Arrays.stream(((Transforms.IdentityTransform) t).fieldName())) | ||
.collect(Collectors.toList()); | ||
Preconditions.checkArgument( | ||
partitionKeys.size() == partitions.length, | ||
"Flink only support identity transform for now."); | ||
return partitionKeys; | ||
} | ||
|
||
@Override | ||
public Transform[] toGravitinoPartitions(List<String> partitionsKey) { | ||
return partitionsKey.stream().map(Transforms::identity).toArray(Transform[]::new); | ||
} | ||
} |
46 changes: 46 additions & 0 deletions
46
flink-connector/src/main/java/org/apache/gravitino/flink/connector/PartitionConverter.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,46 @@ | ||
/* | ||
* 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.gravitino.flink.connector; | ||
|
||
import java.util.List; | ||
import org.apache.gravitino.rel.expressions.transforms.Transform; | ||
|
||
/** | ||
* The PartitionConverter is used to convert the partition between Flink and Gravitino. The Flink | ||
* only support identity transform. Some of the table like Apache Paimon will use the table | ||
* properties to store the partition transform, so we can implement this interface to achieve more | ||
* partition transform. | ||
*/ | ||
public interface PartitionConverter { | ||
/** | ||
* Convert the partition keys to Flink partition keys. | ||
* | ||
* @param partitions The partition keys in Gravitino. | ||
* @return The partition keys in Flink. | ||
*/ | ||
public abstract List<String> toFlinkPartitionKeys(Transform[] partitions); | ||
|
||
/** | ||
* Convert the partition keys to Gravitino partition keys. | ||
* | ||
* @param partitionsKey The partition keys in Flink. | ||
* @return The partition keys in Gravitino. | ||
*/ | ||
public abstract Transform[] toGravitinoPartitions(List<String> partitionsKey); | ||
} |
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
Oops, something went wrong.