forked from apache/hudi
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[HUDI-4865] Optimize HoodieAvroUtils#isMetadataField to use O(1) comp…
…lexity (apache#6702)
- Loading branch information
Showing
7 changed files
with
81 additions
and
22 deletions.
There are no files selected for viewing
60 changes: 60 additions & 0 deletions
60
hudi-client/hudi-spark-client/src/main/scala/org/apache/hudi/util/SparkKeyGenUtils.scala
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,60 @@ | ||
/* | ||
* 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.hudi.util | ||
|
||
import org.apache.hudi.common.config.TypedProperties | ||
import org.apache.hudi.keygen.constant.KeyGeneratorOptions | ||
import org.apache.hudi.keygen.{BaseKeyGenerator, CustomAvroKeyGenerator, CustomKeyGenerator, KeyGenerator} | ||
import org.apache.hudi.keygen.factory.HoodieSparkKeyGeneratorFactory | ||
|
||
import java.util.Properties | ||
import scala.collection.JavaConverters._ | ||
|
||
object SparkKeyGenUtils { | ||
|
||
/** | ||
* @param properties config properties | ||
* @return partition columns | ||
*/ | ||
def getPartitionColumns(properties: Properties): String = { | ||
val props = new TypedProperties(properties) | ||
val keyGenerator = HoodieSparkKeyGeneratorFactory.createKeyGenerator(props) | ||
getPartitionColumns(keyGenerator, props) | ||
} | ||
|
||
/** | ||
* @param keyGen key generator | ||
* @return partition columns | ||
*/ | ||
def getPartitionColumns(keyGen: KeyGenerator, typedProperties: TypedProperties): String = { | ||
keyGen match { | ||
// For CustomKeyGenerator and CustomAvroKeyGenerator, the partition path filed format | ||
// is: "field_name: field_type", we extract the field_name from the partition path field. | ||
case c: BaseKeyGenerator | ||
if c.isInstanceOf[CustomKeyGenerator] || c.isInstanceOf[CustomAvroKeyGenerator] => | ||
c.getPartitionPathFields.asScala.map(pathField => | ||
pathField.split(CustomAvroKeyGenerator.SPLIT_REGEX) | ||
.headOption.getOrElse(s"Illegal partition path field format: '$pathField' for ${c.getClass.getSimpleName}")) | ||
.mkString(",") | ||
|
||
case b: BaseKeyGenerator => b.getPartitionPathFields.asScala.mkString(",") | ||
case _ => typedProperties.getString(KeyGeneratorOptions.PARTITIONPATH_FIELD_NAME.key()) | ||
} | ||
} | ||
|
||
} |
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