Skip to content

Instantly share code, notes, and snippets.

@nenorbot
Created May 10, 2023 13:31
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nenorbot/5a92e24f8f3615488f75e2a18a105c76 to your computer and use it in GitHub Desktop.
Save nenorbot/5a92e24f8f3615488f75e2a18a105c76 to your computer and use it in GitHub Desktop.
Generate an avro file with a single row containing all null values
import fastavro
schema = {
"type": "record",
"name": "topLevelRecord",
"fields": [
{"name": "string_col", "type": ["null", "string"], "default": None},
{"name": "int_col", "type": ["null", "int"], "default": None},
{"name": "bool_col", "type": ["null", "boolean"], "default": None},
{"name": "bigint_col", "type": ["null", "long"], "default": None},
{"name": "float_col", "type": ["null", "float"], "default": None},
{"name": "double_col", "type": ["null", "double"], "default": None},
{"name": "bytes_col", "type": ["null", "bytes"], "default": None}
]
}
data = {"string_col": None, "int_col": None, "bool_col": None, "bigint_col": None, "float_col": None, "double_col": None, "bytes_col": None}
with open("alltypes_nulls_plain.avro", "wb") as avro_file:
fastavro.writer(avro_file, schema, [data])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment