Serializing with Primitive

Serde with Primitive data types supports character strings, binary strings, and numeric data types. Below are a few (non-exhaustive) examples of serialization with primitive data types. See our list of Primitive data types for a full list of the primitive types that are supported.

Character String

With the following DDL and query:

CREATE STREAM primitiveExample (
  "stringValue" VARCHAR
) WITH (
  'topic' = 'primitiveExample', 'value.format' = 'Primitive'
);
SELECT * FROM primitiveExample;

For the given input records:

// input record bytes as String
abc

// output will read bytes as String
{ "stringValue": "abc" }
// input record bytes as Integer
123

// output record will read bytes as String
{ "stringValue": "\u0000\u0000\u0000{" }

Numeric

With the following DDL and query:

CREATE STREAM primitiveExample (
  "intValue" INTEGER
) WITH (
  'topic' = 'primitiveExample', 'value.format' = 'Primitive'
);
SELECT * FROM primitiveExample;

For the given input records:

// input record bytes as Integer
123

// output will read bytes as Integer
{ "intValue": 123 }
// input record bytes as String
abcd

// output will be read bytes as String
// It's also likely for other string bytes that there will be a 
// deserialization error while attempting to cast String to Integer
{ "intValue": 1633837924 }

Binary String

With the following DDL and query:

CREATE STREAM primitiveExample (
  "bytesValue" VARBINARY
) WITH (
  'topic' = 'primitiveExample', 'value.format' = 'Primitive'
);
SELECT * FROM primitiveExample;

For the given input records:

// input record bytes as Bytes
aG93ZHk=

// output will read bytes as Bytes
{ "bytesValue": "aG93ZHk=" }

Last updated