Skip to content

Commit ee8c6d3

Browse files
committed
Added Documentation Strings
Signed-off-by: Jason Myers <[email protected]>
1 parent d9423ac commit ee8c6d3

File tree

2 files changed

+20
-0
lines changed

2 files changed

+20
-0
lines changed

redshift_sqlalchemy/dialect.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,17 +57,33 @@ def _get_column_info(self, name, format_type, default,
5757

5858

5959
class UnloadFromSelect(Executable, ClauseElement):
60+
''' Prepares a RedShift unload statement to drop a query to Amazon S3
61+
http://docs.aws.amazon.com/redshift/latest/dg/r_UNLOAD_command_examples.html
62+
'''
6063
def __init__(self, select, bucket, access_key, secret_key):
64+
''' Initializes an UnloadFromSelect instance
65+
66+
Args:
67+
self: An instance of UnloadFromSelect
68+
select: The select statement to be unloaded
69+
bucket: The Amazon S3 bucket where the result will be stored
70+
access_key: The Amazon Access Key ID
71+
secret_key: The Amazon Secret Access Key
72+
'''
6173
self.select = select
6274
self.bucket = bucket
6375
self.access_key = access_key
6476
self.secret_key = secret_key
6577

6678
@compiles(UnloadFromSelect)
6779
def visit_unload_from_select(element, compiler, **kw):
80+
''' Returns the actual sql query for the UnloadFromSelect class
81+
'''
6882
return "unload ('%(query)s') to '%(bucket)s' credentials 'aws_access_key_id=%(access_key)s;aws_secret_access_key=%(secret_key)s'" % {
6983
'query': element.select,
7084
'bucket': element.bucket,
7185
'access_key': element.access_key,
7286
'secret_key': element.secret_key,
7387
}
88+
89+

tests/test_unload_from_select.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,16 @@
77

88
class TestUnloadFromSelect(TestCase):
99
def setUp(self):
10+
''' Sets up a in memory sqlite instance with a table
11+
'''
1012
self.metadata = MetaData()
1113
self.t1 = Table('t1', self.metadata, Column('id', Integer, primary_key=True), Column('name', String))
1214
self.engine = create_engine('sqlite:///:memory:', echo=True)
1315
self.metadata.create_all(self.engine)
1416

1517
def test_basic_unload_case(self):
18+
''' Tests that the simplest type of UnloadFromSelect works
19+
'''
1620
expected_result = "unload ('SELECT count(t1.id) AS count_1 \nFROM t1') to 'cookies' credentials 'aws_access_key_id=cookies;aws_secret_access_key=cookies'"
1721
insert = UnloadFromSelect(select([func.count(self.t1.c.id)]), 'cookies', 'cookies', 'cookies')
1822
self.assertEqual(expected_result, str(insert))

0 commit comments

Comments
 (0)