xiarixiaoyao commented on a change in pull request #4910:
URL: https://github.com/apache/hudi/pull/4910#discussion_r830465724
##########
File path:
hudi-client/hudi-spark-client/src/main/scala/org/apache/hudi/HoodieSparkUtils.scala
##########
@@ -297,17 +303,25 @@ object HoodieSparkUtils extends SparkAdapterSupport {
AttributeReference(columnName, field.get.dataType, field.get.nullable)()
}
- def getRequiredSchema(tableAvroSchema: Schema, requiredColumns:
Array[String]): (Schema, StructType) = {
- // First get the required avro-schema, then convert the avro-schema to
spark schema.
- val name2Fields = tableAvroSchema.getFields.asScala.map(f => f.name() ->
f).toMap
- // Here have to create a new Schema.Field object
- // to prevent throwing exceptions like
"org.apache.avro.AvroRuntimeException: Field already used".
- val requiredFields = requiredColumns.map(c => name2Fields(c))
- .map(f => new Schema.Field(f.name(), f.schema(), f.doc(),
f.defaultVal(), f.order())).toList
- val requiredAvroSchema = Schema.createRecord(tableAvroSchema.getName,
tableAvroSchema.getDoc,
- tableAvroSchema.getNamespace, tableAvroSchema.isError,
requiredFields.asJava)
- val requiredStructSchema =
AvroConversionUtils.convertAvroSchemaToStructType(requiredAvroSchema)
- (requiredAvroSchema, requiredStructSchema)
+ def getRequiredSchema(tableAvroSchema: Schema, requiredColumns:
Array[String], internalSchema: InternalSchema =
InternalSchema.getDummyInternalSchema): (Schema, StructType, InternalSchema) = {
+ if (internalSchema.isDummySchema) {
+ // First get the required avro-schema, then convert the avro-schema to
spark schema.
+ val name2Fields = tableAvroSchema.getFields.asScala.map(f => f.name() ->
f).toMap
+ // Here have to create a new Schema.Field object
+ // to prevent throwing exceptions like
"org.apache.avro.AvroRuntimeException: Field already used".
+ val requiredFields = requiredColumns.map(c => name2Fields(c))
+ .map(f => new Schema.Field(f.name(), f.schema(), f.doc(),
f.defaultVal(), f.order())).toList
+ val requiredAvroSchema = Schema.createRecord(tableAvroSchema.getName,
tableAvroSchema.getDoc,
+ tableAvroSchema.getNamespace, tableAvroSchema.isError,
requiredFields.asJava)
+ val requiredStructSchema =
AvroConversionUtils.convertAvroSchemaToStructType(requiredAvroSchema)
+ (requiredAvroSchema, requiredStructSchema, internalSchema)
+ } else {
+ // support nested project
Review comment:
yes, nested projection is supported,
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]