Skip to content

Commit

Permalink
Change rows {convert,query} to be lazy
Browse files Browse the repository at this point in the history
  • Loading branch information
turicas committed Mar 22, 2018
1 parent a7bca78 commit ac33e7f
Showing 1 changed file with 13 additions and 6 deletions.
19 changes: 13 additions & 6 deletions rows/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -318,6 +318,7 @@ def print_(input_encoding, output_encoding, input_locale, output_locale,
@click.option('--output-encoding')
@click.option('--input-locale')
@click.option('--output-locale')
@click.option('--samples', default=1000)
@click.option('--verify-ssl', default=True, type=bool)
@click.option('--output')
@click.argument('query', required=True)
Expand All @@ -341,26 +342,31 @@ def query(input_encoding, output_encoding, input_locale, output_locale,
else:
if input_locale is not None:
with rows.locale_context(input_locale):
table = import_from_source(source, DEFAULT_INPUT_ENCODING)
table = import_from_source(source, DEFAULT_INPUT_ENCODING,
lazy=True, samples=samples)
else:
table = import_from_source(source, DEFAULT_INPUT_ENCODING)
table = import_from_source(source, DEFAULT_INPUT_ENCODING,
lazy=True, samples=samples)

sqlite_connection = sqlite3.Connection(':memory:')
rows.export_to_sqlite(table,
sqlite_connection,
table_name='table1')
result = rows.import_from_sqlite(sqlite_connection, query=query)
result = rows.import_from_sqlite(sqlite_connection, query=query,
lazy=True, samples=samples)

else:
# TODO: if all sources are SQLite we can also optimize the import
if input_locale is not None:
with rows.locale_context(input_locale):
tables = [_import_table(source, encoding=input_encoding,
verify_ssl=verify_ssl)
verify_ssl=verify_ssl, lazy=True,
samples=samples)
for source in sources]
else:
tables = [_import_table(source, encoding=input_encoding,
verify_ssl=verify_ssl)
verify_ssl=verify_ssl, lazy=True,
samples=samples)
for source in sources]

sqlite_connection = sqlite3.Connection(':memory:')
Expand All @@ -369,7 +375,8 @@ def query(input_encoding, output_encoding, input_locale, output_locale,
sqlite_connection,
table_name='table{}'.format(index))

result = rows.import_from_sqlite(sqlite_connection, query=query)
result = rows.import_from_sqlite(sqlite_connection, query=query,
lazy=True, samples=samples)

# TODO: may use sys.stdout.encoding if output_file = '-'
output_encoding = output_encoding or sys.stdout.encoding or \
Expand Down

0 comments on commit ac33e7f

Please sign in to comment.