Skip to content

Instantly share code, notes, and snippets.

@lsheng
Created March 14, 2013 22:20
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 lsheng/5165785 to your computer and use it in GitHub Desktop.
Save lsheng/5165785 to your computer and use it in GitHub Desktop.
Script to generate a flat Kiji schema shell DDL based on the headers for a CSV
#!/bin/bash
# Generates a flat Kiji schema shell DDL based on the headers for a CSV
FILENAME=$1
if [ ! -e "$FILENAME" ]; then
echo "Could not find file: $FILENAME"
exit 1
fi
echo "CREATE TABLE train WITH DESCRIPTION 'Training data'"
echo "ROW KEY FORMAT HASHED"
echo " WITH LOCALITY GROUP default"
echo " WITH DESCRIPTION 'Main locality group' ("
echo " MAXVERSIONS = 10,"
echo " TTL = FOREVER,"
echo " INMEMORY = false,"
echo " COMPRESSED WITH NONE,"
echo " FAMILY info WITH DESCRIPTION 'basic information' ("
# Loop over fields and put in the relevant description lines
FIRST=true
for x in `head -1 $FILENAME | tr -d '\r' | tr , '\n'`; do
if [ "$FIRST" != "true" ]; then
echo ,
fi
echo -n " $x \"string\" WITH DESCRIPTION 'Imported $x'"
FIRST=false
done
echo
echo " )"
echo ");"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment