#!/bin/bash
# Prints the Glue and S3 state of trips_mor that the blog shows after the first write, with the same commands.
# Run on the EMR primary node right after the first write. Later runs show the table's later state.
# Replace <bucket>/<prefix> and <glue_db> first. Needs jq (sudo dnf install -y jq on EMR 7).
set -euo pipefail
BUCKET_PREFIX="s3://<bucket>/<prefix>"
DB="<glue_db>"
T=trips_mor

echo "\$ aws glue get-table --database-name $DB --name $T --query 'Table.{TableType:Parameters.table_type,MetadataLocation:Parameters.metadata_location}'"
aws glue get-table --database-name "$DB" --name "$T" \
  --query 'Table.{TableType:Parameters.table_type,MetadataLocation:Parameters.metadata_location}'

echo; echo "\$ aws s3 ls $BUCKET_PREFIX/tables/$T/"
aws s3 ls "$BUCKET_PREFIX/tables/$T/"

ML=$(aws glue get-table --database-name "$DB" --name "$T" --query 'Table.Parameters.metadata_location' --output text)
echo; echo "\$ aws s3 cp <metadata_location> - | jq '{\"format-version\", \"current-snapshot-id\", \"next-row-id\"}'"
aws s3 cp "$ML" - | jq '{"format-version", "current-snapshot-id", "next-row-id"}'

echo; echo "\$ aws s3 cp $BUCKET_PREFIX/tables/$T/.hoodie/hoodie.properties - | grep table.format"
aws s3 cp "$BUCKET_PREFIX/tables/$T/.hoodie/hoodie.properties" - | grep table.format
