Class AvroUtils.AvroSchemaHelper
- Enclosing class:
- AvroUtils
This will match avroSchema
against catalystSchema
, attempting to find a matching field in
the Avro schema for each field in the Catalyst schema and vice-versa, respecting settings for
case sensitivity. The match results can be accessed using the getter methods.
param: avroSchema The schema in which to search for fields. Must be of type RECORD.
param: catalystSchema The Catalyst schema to use for matching.
param: avroPath The seq of parent field names leading to avroSchema
.
param: catalystPath The seq of parent field names leading to catalystSchema
.
param: positionalFieldMatch If true, perform field matching in a positional fashion
(structural comparison between schemas, ignoring names);
otherwise, perform field matching using field names.
-
Constructor Summary
ConstructorDescriptionAvroSchemaHelper
(org.apache.avro.Schema avroSchema, StructType catalystSchema, scala.collection.Seq<String> avroPath, scala.collection.Seq<String> catalystPath, boolean positionalFieldMatch) -
Method Summary
Modifier and TypeMethodDescriptionscala.Option<org.apache.avro.Schema.Field>
getAvroField
(String fieldName, int catalystPos) Get the Avro field corresponding to the provided Catalyst field name/position, if any.scala.collection.Seq<org.apache.spark.sql.avro.AvroUtils.AvroMatchedField>
The fields which have matching equivalents in both Avro and Catalyst schemas.void
validateNoExtraCatalystFields
(boolean ignoreNullable) Validate that there are no Catalyst fields which don't have a matching Avro field, throwingIncompatibleSchemaException
if such extra fields are found.void
Validate that there are no Avro fields which don't have a matching Catalyst field, throwingIncompatibleSchemaException
if such extra fields are found.
-
Constructor Details
-
AvroSchemaHelper
public AvroSchemaHelper(org.apache.avro.Schema avroSchema, StructType catalystSchema, scala.collection.Seq<String> avroPath, scala.collection.Seq<String> catalystPath, boolean positionalFieldMatch)
-
-
Method Details
-
getAvroField
Get the Avro field corresponding to the provided Catalyst field name/position, if any. -
matchedFields
public scala.collection.Seq<org.apache.spark.sql.avro.AvroUtils.AvroMatchedField> matchedFields()The fields which have matching equivalents in both Avro and Catalyst schemas. -
validateNoExtraCatalystFields
public void validateNoExtraCatalystFields(boolean ignoreNullable) Validate that there are no Catalyst fields which don't have a matching Avro field, throwingIncompatibleSchemaException
if such extra fields are found. IfignoreNullable
is false, consider nullable Catalyst fields to be eligible to be an extra field; otherwise, ignore nullable Catalyst fields when checking for extras.- Parameters:
ignoreNullable
- (undocumented)
-
validateNoExtraRequiredAvroFields
public void validateNoExtraRequiredAvroFields()Validate that there are no Avro fields which don't have a matching Catalyst field, throwingIncompatibleSchemaException
if such extra fields are found. Only required (non-nullable) fields are checked; nullable fields are ignored.
-