public class AvroSchemaUtils extends Object
| Modifier and Type | Method and Description |
|---|---|
static org.apache.avro.Schema |
appendFieldsToSchema(org.apache.avro.Schema schema,
List<org.apache.avro.Schema.Field> newFields)
Appends provided new fields at the end of the given schema
NOTE: No deduplication is made, this method simply appends fields at the end of the list
of the source schema as is
|
static boolean |
canProject(org.apache.avro.Schema prevSchema,
org.apache.avro.Schema newSchema)
Check that each field in the prevSchema can be populated in the newSchema
|
static void |
checkSchemaCompatible(org.apache.avro.Schema tableSchema,
org.apache.avro.Schema writerSchema,
boolean shouldValidate,
boolean allowProjection,
Set<String> dropPartitionColNames)
Checks whether writer schema is compatible with table schema considering
AVRO_SCHEMA_VALIDATE_ENABLE
and SCHEMA_ALLOW_AUTO_EVOLUTION_COLUMN_DROP options. |
static void |
checkValidEvolution(org.apache.avro.Schema incomingSchema,
org.apache.avro.Schema tableSchema)
Validate whether the
incomingSchema is a valid evolution of tableSchema. |
static boolean |
containsFieldInSchema(org.apache.avro.Schema schema,
String fieldName)
Returns true in case when schema contains the field w/ provided name
|
static org.apache.avro.Schema |
createNullableSchema(org.apache.avro.Schema.Type avroType)
Creates schema following Avro's typical nullable schema definition:
Union(Schema.Type.NULL, <NonNullType>),
wrapping around provided target non-null type |
static org.apache.avro.Schema |
createNullableSchema(org.apache.avro.Schema schema) |
static String |
createSchemaErrorString(String errorMessage,
org.apache.avro.Schema writerSchema,
org.apache.avro.Schema tableSchema) |
static String |
getAvroRecordQualifiedName(String tableName)
Generates fully-qualified name for the Avro's schema based on the Table's name
NOTE: PLEASE READ CAREFULLY BEFORE CHANGING
This method should not change for compatibility reasons as older versions
of Avro might be comparing fully-qualified names rather than just the record
names
|
static boolean |
isCompatibleProjectionOf(org.apache.avro.Schema sourceSchema,
org.apache.avro.Schema targetSchema)
Validate whether the
targetSchema is a "compatible" projection of sourceSchema. |
static boolean |
isNullable(org.apache.avro.Schema schema)
Returns true in case provided
Schema is nullable (ie accepting null values),
returns false otherwise |
static boolean |
isSchemaCompatible(org.apache.avro.Schema prevSchema,
org.apache.avro.Schema newSchema)
See
isSchemaCompatible(Schema, Schema, boolean, boolean) doc for more details |
static boolean |
isSchemaCompatible(org.apache.avro.Schema prevSchema,
org.apache.avro.Schema newSchema,
boolean allowProjection)
See
isSchemaCompatible(Schema, Schema, boolean, boolean) doc for more details |
static boolean |
isSchemaCompatible(org.apache.avro.Schema prevSchema,
org.apache.avro.Schema newSchema,
boolean checkNaming,
boolean allowProjection)
Establishes whether
newSchema is compatible w/ prevSchema, as
defined by Avro's AvroSchemaCompatibility. |
static boolean |
isStrictProjectionOf(org.apache.avro.Schema sourceSchema,
org.apache.avro.Schema targetSchema)
Validate whether the
targetSchema is a strict projection of sourceSchema. |
static org.apache.avro.Schema |
resolveNullableSchema(org.apache.avro.Schema schema)
Resolves typical Avro's nullable schema definition:
Union(Schema.Type.NULL, <NonNullType>),
decomposing union and returning the target non-null type |
static org.apache.avro.Schema |
resolveUnionSchema(org.apache.avro.Schema schema,
String fieldSchemaFullName)
Passed in
Union schema and will try to resolve the field with the fieldSchemaFullName
w/in the union returning its corresponding schema |
public static boolean isSchemaCompatible(org.apache.avro.Schema prevSchema,
org.apache.avro.Schema newSchema)
isSchemaCompatible(Schema, Schema, boolean, boolean) doc for more detailspublic static boolean isSchemaCompatible(org.apache.avro.Schema prevSchema,
org.apache.avro.Schema newSchema,
boolean allowProjection)
isSchemaCompatible(Schema, Schema, boolean, boolean) doc for more detailspublic static boolean isSchemaCompatible(org.apache.avro.Schema prevSchema,
org.apache.avro.Schema newSchema,
boolean checkNaming,
boolean allowProjection)
newSchema is compatible w/ prevSchema, as
defined by Avro's AvroSchemaCompatibility.
From avro's compatibility standpoint, prevSchema is writer schema and new schema is reader schema.
newSchema is considered compatible to prevSchema, iff data written using prevSchema
could be read by newSchemaprevSchema - previous instance of the schemanewSchema - new instance of the schemacheckNaming - controls whether schemas fully-qualified names should be checkedpublic static boolean canProject(org.apache.avro.Schema prevSchema,
org.apache.avro.Schema newSchema)
prevSchema - prev schema.newSchema - new schemapublic static String getAvroRecordQualifiedName(String tableName)
public static boolean isCompatibleProjectionOf(org.apache.avro.Schema sourceSchema,
org.apache.avro.Schema targetSchema)
targetSchema is a "compatible" projection of sourceSchema.
Only difference of this method from isStrictProjectionOf(Schema, Schema) is
the fact that it allows some legitimate type promotions (like int -> long,
decimal(3, 2) -> decimal(5, 2), etc) that allows projection to have a "wider"
atomic type (whereas strict projection requires atomic type to be identical)public static boolean isStrictProjectionOf(org.apache.avro.Schema sourceSchema,
org.apache.avro.Schema targetSchema)
targetSchema is a strict projection of sourceSchema.
Schema B is considered a strict projection of schema A iff
public static org.apache.avro.Schema appendFieldsToSchema(org.apache.avro.Schema schema,
List<org.apache.avro.Schema.Field> newFields)
public static org.apache.avro.Schema resolveUnionSchema(org.apache.avro.Schema schema,
String fieldSchemaFullName)
Union schema and will try to resolve the field with the fieldSchemaFullName
w/in the union returning its corresponding schemaschema - target schema to be inspectedfieldSchemaFullName - target field-name to be looked up w/in the unionfieldSchemaFullNamepublic static boolean isNullable(org.apache.avro.Schema schema)
Schema is nullable (ie accepting null values),
returns false otherwisepublic static org.apache.avro.Schema resolveNullableSchema(org.apache.avro.Schema schema)
Union(Schema.Type.NULL, <NonNullType>),
decomposing union and returning the target non-null typepublic static org.apache.avro.Schema createNullableSchema(org.apache.avro.Schema.Type avroType)
Union(Schema.Type.NULL, <NonNullType>),
wrapping around provided target non-null typepublic static org.apache.avro.Schema createNullableSchema(org.apache.avro.Schema schema)
public static boolean containsFieldInSchema(org.apache.avro.Schema schema,
String fieldName)
public static void checkSchemaCompatible(org.apache.avro.Schema tableSchema,
org.apache.avro.Schema writerSchema,
boolean shouldValidate,
boolean allowProjection,
Set<String> dropPartitionColNames)
throws SchemaCompatibilityException
AVRO_SCHEMA_VALIDATE_ENABLE
and SCHEMA_ALLOW_AUTO_EVOLUTION_COLUMN_DROP options.
To avoid collision of SCHEMA_ALLOW_AUTO_EVOLUTION_COLUMN_DROP and DROP_PARTITION_COLUMNS
partition column names should be passed as dropPartitionColNames.
Passed empty set means DROP_PARTITION_COLUMNS is disabled.tableSchema - the latest dataset schemawriterSchema - writer schemashouldValidate - whether AvroSchemaCompatibility check being performedallowProjection - whether column dropping check being performeddropPartitionColNames - partition column names to being excluded from column dropping checkSchemaCompatibilityException - if writer schema is not compatiblepublic static void checkValidEvolution(org.apache.avro.Schema incomingSchema,
org.apache.avro.Schema tableSchema)
incomingSchema is a valid evolution of tableSchema.incomingSchema - schema of the incoming datasettableSchema - latest table schemaCopyright © 2024 The Apache Software Foundation. All rights reserved.