|
18 | 18 | @click.option("--debug", is_flag=True, required=False, help="Turn on logging with debug level") |
19 | 19 | @click.version_option() |
20 | 20 | @click.pass_context |
21 | | -def cli(ctx: click.Context, verbose: bool, debug: bool): |
| 21 | +def cli_load(ctx: click.Context, verbose: bool, debug: bool): |
22 | 22 | """ |
23 | 23 | Load data into CrateDB. |
24 | 24 | """ |
25 | 25 | return boot_click(ctx, verbose, debug) |
26 | 26 |
|
27 | 27 |
|
28 | | -@make_command(cli, name="table") |
| 28 | +@make_command(cli_load, name="table") |
29 | 29 | @click.argument("url") |
30 | 30 | @option_cluster_id |
31 | 31 | @option_cluster_name |
@@ -67,3 +67,60 @@ def load_table( |
67 | 67 | cluster_url=cluster_url, |
68 | 68 | ) |
69 | 69 | cluster.load_table(source=source, target=target, transformation=transformation) |
| 70 | + |
| 71 | + |
| 72 | +@click.group(cls=ClickAliasedGroup) # type: ignore[arg-type] |
| 73 | +@click.option("--verbose", is_flag=True, required=False, help="Turn on logging") |
| 74 | +@click.option("--debug", is_flag=True, required=False, help="Turn on logging with debug level") |
| 75 | +@click.version_option() |
| 76 | +@click.pass_context |
| 77 | +def cli_save(ctx: click.Context, verbose: bool, debug: bool): |
| 78 | + """ |
| 79 | + Export data from CrateDB. |
| 80 | + """ |
| 81 | + return boot_click(ctx, verbose, debug) |
| 82 | + |
| 83 | + |
| 84 | +@make_command(cli_save, name="table") |
| 85 | +@click.argument("url") |
| 86 | +@option_cluster_id |
| 87 | +@option_cluster_name |
| 88 | +@option_cluster_url |
| 89 | +@click.option("--schema", envvar="CRATEDB_SCHEMA", type=str, required=False, help="Schema where to import the data") |
| 90 | +@click.option("--table", envvar="CRATEDB_TABLE", type=str, required=False, help="Table where to import the data") |
| 91 | +@click.option("--format", "format_", type=str, required=False, help="File format of the import resource") |
| 92 | +@click.option("--compression", type=str, required=False, help="Compression format of the import resource") |
| 93 | +@click.option("--transformation", type=Path, required=False, help="Path to Zyp transformation file") |
| 94 | +@click.pass_context |
| 95 | +def save_table( |
| 96 | + ctx: click.Context, |
| 97 | + url: str, |
| 98 | + cluster_id: str, |
| 99 | + cluster_name: str, |
| 100 | + cluster_url: str, |
| 101 | + schema: str, |
| 102 | + table: str, |
| 103 | + format_: str, |
| 104 | + compression: str, |
| 105 | + transformation: t.Union[Path, None], |
| 106 | +): |
| 107 | + """ |
| 108 | + Export data from CrateDB and CrateDB Cloud clusters. |
| 109 | + """ |
| 110 | + |
| 111 | + # When `--transformation` is given, but empty, fix it. |
| 112 | + if transformation is not None and transformation.name == "": |
| 113 | + transformation = None |
| 114 | + |
| 115 | + # Encapsulate source and target parameters. |
| 116 | + source = TableAddress(schema=schema, table=table) |
| 117 | + target = InputOutputResource(url=url, format=format_, compression=compression) |
| 118 | + print("target:", target) |
| 119 | + |
| 120 | + # Dispatch "load table" operation. |
| 121 | + cluster = DatabaseCluster.create( |
| 122 | + cluster_id=cluster_id, |
| 123 | + cluster_name=cluster_name, |
| 124 | + cluster_url=cluster_url, |
| 125 | + ) |
| 126 | + cluster.save_table(source=source, target=target, transformation=transformation) |
0 commit comments