Created
May 10, 2023 13:31
-
-
Save nenorbot/5a92e24f8f3615488f75e2a18a105c76 to your computer and use it in GitHub Desktop.
Generate an avro file with a single row containing all null values
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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