confluent-kafka-dotnet
Show / Hide Table of Contents

Class VariantLogicalType

The Avro variant logical type: a record of two bytes fields (metadata, value) carrying a Spark/Parquet Variant. A field with this logical type decodes to / encodes from a Variant, so serde consumers and CEL rules see a first-class Variant. The Avro serializer and deserializer register it automatically via EnsureRegistered(). This is the .NET counterpart of Java's io.confluent.avro.type.VariantConversion.

Inheritance
object
LogicalType
VariantLogicalType
Inherited Members
LogicalType.Name
object.Equals(object)
object.Equals(object, object)
object.GetHashCode()
object.GetType()
object.MemberwiseClone()
object.ReferenceEquals(object, object)
object.ToString()
Namespace: Confluent.SchemaRegistry.Serdes
Assembly: Confluent.SchemaRegistry.Serdes.Avro.dll
Syntax
public class VariantLogicalType : LogicalType

Constructors

VariantLogicalType()

Initializes a new instance of the VariantLogicalType class.

Declaration
public VariantLogicalType()

Fields

LogicalTypeName

The Avro logical type name, "variant".

Declaration
public const string LogicalTypeName = "variant"
Field Value
Type Description
string

Methods

ConvertToBaseValue(object, LogicalSchema)

Converts a Variant to its base Avro record (two bytes fields).

Declaration
public override object ConvertToBaseValue(object logicalValue, LogicalSchema schema)
Parameters
Type Name Description
object logicalValue
LogicalSchema schema
Returns
Type Description
object
Overrides
LogicalType.ConvertToBaseValue(object, LogicalSchema)

ConvertToLogicalValue(object, LogicalSchema)

Converts a base Avro record (two bytes fields) to a Variant.

Declaration
public override object ConvertToLogicalValue(object baseValue, LogicalSchema schema)
Parameters
Type Name Description
object baseValue
LogicalSchema schema
Returns
Type Description
object
Overrides
LogicalType.ConvertToLogicalValue(object, LogicalSchema)

EnsureRegistered()

Registers the variant logical type with the process-wide Avro.Util.LogicalTypeFactory exactly once. Called from the Avro serializer and deserializer constructors so a confluent.type.Variant record surfaces as a Variant without any explicit setup by the caller.

Declaration
public static void EnsureRegistered()

GetCSharpType(bool)

Returns the CLR type a variant field surfaces as, Variant.

Declaration
public override Type GetCSharpType(bool nullable)
Parameters
Type Name Description
bool nullable
Returns
Type Description
Type
Overrides
LogicalType.GetCSharpType(bool)

IsInstanceOfLogicalType(object)

Returns whether logicalValue is a Variant.

Declaration
public override bool IsInstanceOfLogicalType(object logicalValue)
Parameters
Type Name Description
object logicalValue
Returns
Type Description
bool
Overrides
LogicalType.IsInstanceOfLogicalType(object)

ValidateSchema(LogicalSchema)

Validates that the base schema is a record with exactly the two bytes fields metadata and value.

Declaration
public override void ValidateSchema(LogicalSchema schema)
Parameters
Type Name Description
LogicalSchema schema
Overrides
Avro.Util.LogicalType.ValidateSchema(Avro.LogicalSchema)
Remarks

The field names and types are checked, not just the field count, because ConvertToBaseValue(object, LogicalSchema) and ConvertToLogicalValue(object, LogicalSchema) index the record by those names and cast both to byte[]. Without the full check a two-field record of any shape passed validation and then failed later with a KeyNotFoundException or an InvalidCastException. Matches the Java reference, whose VariantLogicalType.isVariantSchema applies exactly these conditions.

In this article