|
3 | 3 | from pathlib import Path |
4 | 4 |
|
5 | 5 | import click |
6 | | -from click_aliases import ClickAliasedGroup |
7 | 6 |
|
8 | 7 | from cratedb_toolkit.cluster.core import DatabaseCluster |
9 | 8 | from cratedb_toolkit.model import InputOutputResource, TableAddress |
10 | 9 | from cratedb_toolkit.option import option_cluster_id, option_cluster_name, option_cluster_url |
11 | | -from cratedb_toolkit.util.cli import boot_click, make_command |
| 10 | +from cratedb_toolkit.util.app import make_cli |
| 11 | +from cratedb_toolkit.util.cli import make_command |
12 | 12 |
|
13 | 13 | logger = logging.getLogger(__name__) |
14 | 14 |
|
15 | 15 |
|
16 | | -@click.group(cls=ClickAliasedGroup) # type: ignore[arg-type] |
17 | | -@click.option("--verbose", is_flag=True, required=False, help="Turn on logging") |
18 | | -@click.option("--debug", is_flag=True, required=False, help="Turn on logging with debug level") |
19 | | -@click.version_option() |
20 | | -@click.pass_context |
21 | | -def cli(ctx: click.Context, verbose: bool, debug: bool): |
22 | | - """ |
23 | | - Load data into CrateDB. |
24 | | - """ |
25 | | - return boot_click(ctx, verbose, debug) |
| 16 | +cli = make_cli() |
| 17 | +cli.help = "Load data into CrateDB." |
26 | 18 |
|
27 | 19 |
|
28 | 20 | @make_command(cli, name="table") |
@@ -67,3 +59,34 @@ def load_table( |
67 | 59 | cluster_url=cluster_url, |
68 | 60 | ) |
69 | 61 | cluster.load_table(source=source, target=target, transformation=transformation) |
| 62 | + |
| 63 | + logger.info(f"Importing table succeeded. source={source}, target={target}") |
| 64 | + |
| 65 | + |
| 66 | +@make_command(cli, name="dataset") |
| 67 | +@click.argument("name", envvar="DATASET_NAME", type=str) |
| 68 | +@click.option("--schema", envvar="CRATEDB_SCHEMA", type=str, required=False, help="Schema where to import the data") |
| 69 | +@click.option("--table", envvar="CRATEDB_TABLE", type=str, required=False, help="Table where to import the data") |
| 70 | +@click.pass_context |
| 71 | +def load_dataset( |
| 72 | + ctx: click.Context, |
| 73 | + name: str, |
| 74 | + schema: str, |
| 75 | + table: str, |
| 76 | +): |
| 77 | + """ |
| 78 | + Import named dataset into CrateDB and CrateDB Cloud clusters. |
| 79 | + """ |
| 80 | + |
| 81 | + # Adjust/convert target table parameter. |
| 82 | + effective_table = None |
| 83 | + if table is not None: |
| 84 | + table_address = TableAddress(schema=schema, table=table) |
| 85 | + effective_table = table_address.fullname |
| 86 | + |
| 87 | + # Dispatch "load dataset" operation. |
| 88 | + cluster = DatabaseCluster.from_ctx(ctx) |
| 89 | + ds = cluster.load_dataset(name=name, table=effective_table) |
| 90 | + |
| 91 | + logger.info(f"Importing dataset succeeded. Name: {name}, Table: {ds.table}") |
| 92 | + logger.info(f"Peek SQL: SELECT * FROM {ds.table} LIMIT 42;") |
0 commit comments