Created
March 14, 2013 22:20
-
-
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
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
#!/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