-
Notifications
You must be signed in to change notification settings - Fork 536
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Ddlog update #376
Ddlog update #376
Changes from 1 commit
e5958de
0b387b3
70e8342
05852e4
2bec633
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
#!/usr/bin/env bats | ||
# Tests for initdb | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Maybe it's more important to test the python script for generating CREATE TABLE statements? |
||
|
||
. "$BATS_TEST_DIRNAME"/env.sh >&2 | ||
|
||
setup() { | ||
cd "$BATS_TEST_DIRNAME"/spouse_example | ||
} | ||
|
||
@test "$DBVARIANT initdb from ddlog" { | ||
cd ddlog || skip | ||
deepdive initdb articles | ||
[[ $(deepdive sql eval "SELECT * FROM articles" format=csv header=1) = 'article_id,text' ]] | ||
deepdive sql "INSERT INTO articles VALUES ('foo', 'bar')" | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
#! /usr/bin/env python | ||
# Generate create table statement given a ddlog exported schema and a table name. | ||
# Usage: ddlog_initdb SCHEMA.JSON TABLE_NAME | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Let's give a better name to this script. How about I was originally thinking this SQL generator should go under each driver, e.g., to handle |
||
|
||
import json, sys | ||
|
||
def main(): | ||
# load schema.json | ||
with open(sys.argv[1]) as schema_file: | ||
schema = json.load(schema_file) | ||
table = sys.argv[2] | ||
# the given table is not in the schema, do nothing | ||
if table not in schema["relations"]: | ||
print "" | ||
else: | ||
columns_json = schema["relations"][table]["columns"] | ||
columns = range(len(columns_json)) | ||
for k, v in columns_json.iteritems(): | ||
columns[v["index"]] = "%s %s" %(k, v["type"]) | ||
print "CREATE TABLE %s(%s)\n" %(table, ", ".join(columns)) | ||
|
||
if __name__ == "__main__": | ||
main() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Rather than having these argument count checks buried deep inside, I think it's much clearer to define initdb's behavior entirely differently when arguments are specified. Please see my comment on the PR for reorganizing.