ksml icon indicating copy to clipboard operation
ksml copied to clipboard

Support LogicalTypes in AVRO

Open jeroenvandisseldorp opened this issue 1 year ago • 1 comments

AVRO supports logical types, but KSML can not handle these yet.

Example:

{
  "type": "record",
  "name": "CreditCardTransaction",
  "namespace": "com.example.payment",
  "doc": "Represents a credit card transaction",
  "fields": [
    {
      "name": "transaction_id",
      "type": "string",
      "doc": "Unique identifier for the transaction"
    },
    {
      "name": "card_number_last4",
      "type": "string",
      "doc": "Last 4 digits of the credit card number"
    },
    {
      "name": "merchant_id",
      "type": "string",
      "doc": "Identifier for the merchant"
    },
    {
      "name": "merchant_name",
      "type": "string",
      "doc": "Name of the merchant"
    },
    {
      "name": "amount",
      "type": {
        "type": "bytes",
        "logicalType": "decimal",
        "precision": 10,
        "scale": 2
      },
      "doc": "Transaction amount in the specified currency"
    },
    {
      "name": "currency",
      "type": "string",
      "default": "USD",
      "doc": "ISO 4217 currency code"
    },
    {
      "name": "transaction_timestamp",
      "type": {
        "type": "long",
        "logicalType": "timestamp-millis"
      },
      "doc": "Timestamp of when the transaction occurred"
    },
    {
      "name": "transaction_type",
      "type": {
        "type": "enum",
        "name": "TransactionType",
        "symbols": ["PURCHASE", "REFUND", "AUTHORIZATION", "VOID"]
      },
      "doc": "Type of transaction"
    },
    {
      "name": "status",
      "type": {
        "type": "enum",
        "name": "TransactionStatus",
        "symbols": ["PENDING", "APPROVED", "DECLINED", "FAILED"]
      },
      "doc": "Current status of the transaction"
    },
    {
      "name": "card_type",
      "type": ["null", "string"],
      "default": null,
      "doc": "Type of credit card (VISA, MASTERCARD, AMEX, etc.)"
    },
    {
      "name": "billing_zip_code",
      "type": ["null", "string"],
      "default": null,
      "doc": "Billing ZIP/postal code"
    },
    {
      "name": "authorization_code",
      "type": ["null", "string"],
      "default": null,
      "doc": "Authorization code from the payment processor"
    },
    {
      "name": "metadata",
      "type": ["null", {
        "type": "map",
        "values": "string"
      }],
      "default": null,
      "doc": "Additional metadata about the transaction"
    }
  ]
}

jeroenvandisseldorp avatar Nov 12 '25 13:11 jeroenvandisseldorp

@jeroenvandisseldorp can you add an explanation what the requested behaviour is?

Which of the Avro standard logical types should be supported? What should the Java/Python counterpart be?

If you can add it to the story we can write verification tests even before the implementation

richard-axual avatar Dec 18 '25 15:12 richard-axual