|
11 | 11 | from rich.table import Table
|
12 | 12 |
|
13 | 13 | from wherobots.db import connect, connect_direct
|
14 |
| -from wherobots.db.constants import DEFAULT_ENDPOINT, DEFAULT_SESSION_TYPE |
| 14 | +from wherobots.db.constants import ( |
| 15 | + DEFAULT_ENDPOINT, |
| 16 | + DEFAULT_SESSION_TYPE, |
| 17 | + DEFAULT_STORAGE_FORMAT, |
| 18 | +) |
15 | 19 | from wherobots.db.connection import Connection
|
16 | 20 | from wherobots.db.region import Region
|
17 | 21 | from wherobots.db.session_type import SessionType
|
| 22 | +from wherobots.db.result_storage import StorageFormat, Store |
18 | 23 |
|
19 | 24 | if __name__ == "__main__":
|
20 | 25 | parser = argparse.ArgumentParser()
|
|
47 | 52 | parser.add_argument(
|
48 | 53 | "--wide", help="Enable wide output", action="store_const", const=80, default=30
|
49 | 54 | )
|
| 55 | + parser.add_argument( |
| 56 | + "-s", |
| 57 | + "--store", |
| 58 | + help="Store results in temporary storage", |
| 59 | + action="store_true", |
| 60 | + ) |
50 | 61 | parser.add_argument("sql", nargs="+", help="SQL query to execute")
|
| 62 | + |
| 63 | + args, unknown = parser.parse_known_args() |
| 64 | + if args.store: |
| 65 | + parser.add_argument( |
| 66 | + "-sf", |
| 67 | + "--storage-format", |
| 68 | + help="Storage format for the results", |
| 69 | + default=DEFAULT_STORAGE_FORMAT, |
| 70 | + choices=[sf.value for sf in StorageFormat], |
| 71 | + ) |
| 72 | + parser.add_argument( |
| 73 | + "--single", |
| 74 | + help="Generate only a single part file", |
| 75 | + action="store_true", |
| 76 | + ) |
| 77 | + parser.add_argument( |
| 78 | + "-p", |
| 79 | + "--presigned-url", |
| 80 | + help="Generate a presigned URL for the results (only when --single is set)", |
| 81 | + action="store_true", |
| 82 | + ) |
| 83 | + |
51 | 84 | args = parser.parse_args()
|
52 | 85 |
|
53 | 86 | logging.basicConfig(
|
|
72 | 105 | token = f.read().strip()
|
73 | 106 | headers = {"Authorization": f"Bearer {token}"}
|
74 | 107 |
|
| 108 | + store = None |
| 109 | + if args.store: |
| 110 | + store = Store( |
| 111 | + format=StorageFormat(args.storage_format) |
| 112 | + if args.storage_format |
| 113 | + else DEFAULT_STORAGE_FORMAT, |
| 114 | + single=args.single, |
| 115 | + generate_presigned_url=args.presigned_url, |
| 116 | + ) |
| 117 | + |
75 | 118 | if args.ws_url:
|
76 | 119 | conn_func = functools.partial(connect_direct, uri=args.ws_url, headers=headers)
|
77 | 120 | else:
|
|
84 | 127 | wait_timeout=900,
|
85 | 128 | region=Region(args.region) if args.region else Region.AWS_US_WEST_2,
|
86 | 129 | session_type=SessionType(args.session_type),
|
| 130 | + store=store, |
87 | 131 | )
|
88 | 132 |
|
89 | 133 | def render(results: pandas.DataFrame) -> None:
|
|
0 commit comments