Skip to content

Instantly share code, notes, and snippets.

View filipelenfers's full-sized avatar

Filipe Pais Lenfers filipelenfers

View GitHub Profile
@filipelenfers
filipelenfers / dict_to_dynamodb_item.py
Last active October 10, 2019 19:10 — forked from JamieCressey/dict_to_dynamodb_item.py
Coverts a standard Python3 dictionary to a Boto3 DynamoDB item
def dict_to_item(raw:dict):
return {
key: _dict_to_item_recurse(value)
for key, value in raw.items()
}
def _dict_to_item_recurse(raw):
if isinstance(raw, dict):
return {
@filipelenfers
filipelenfers / README.md
Created November 19, 2019 17:00 — forked from davideicardi/README.md
Write and read Avro records from bytes array

Avro serialization

There are 4 possible serialization format when using avro:

@filipelenfers
filipelenfers / avro_write_file_in_memory.py
Last active December 19, 2024 16:01
Generate AVRO bytes as a in-memory file, with the schema, Python3.
import io
import snappy
import avro.schema
from avro.datafile import DataFileReader, DataFileWriter
from avro.io import DatumReader, DatumWriter, BinaryEncoder
#Generate avro bytes as a in-memory file, with the schema.
def generate_avro_bytes(schema,avro_dicts, codec='snappy'):
bytes_writer = io.BytesIO()
writer = DataFileWriter(bytes_writer, DatumWriter(), schema, codec=codec)
@filipelenfers
filipelenfers / remove_glue_table_partition_add_again.py
Created April 21, 2020 14:59
Remove all partitions from a Glue Table and add again (sometimes solves the HIVE_PARTITION_SCHEMA_MISMATCH in Athena)
# !!!THIS SCRIPT ASSUME HIVE COMPATIBLE PARTITIONS!!!
#
# When you get the following error:
# HIVE_PARTITION_SCHEMA_MISMATCH: There is a mismatch between the table and partition schemas. The types are incompatible and cannot be coerced.
# what happened is that some column type changed in the table, and partitions have they own version of the schema,
# and the version that partitions have cached are not compatible with the table actual version on glue.
# We need to:
# 1. remove partitions
# 2. add partitions again
#