dremio-cli 1.0.0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- dremio_cli/__init__.py +5 -0
- dremio_cli/__main__.py +6 -0
- dremio_cli/cli.py +191 -0
- dremio_cli/client/__init__.py +1 -0
- dremio_cli/client/auth.py +100 -0
- dremio_cli/client/base.py +190 -0
- dremio_cli/client/cloud.py +305 -0
- dremio_cli/client/factory.py +122 -0
- dremio_cli/client/software.py +561 -0
- dremio_cli/commands/__init__.py +1 -0
- dremio_cli/commands/catalog.py +143 -0
- dremio_cli/commands/favorite.py +162 -0
- dremio_cli/commands/folder.py +290 -0
- dremio_cli/commands/grant.py +202 -0
- dremio_cli/commands/history.py +122 -0
- dremio_cli/commands/job.py +321 -0
- dremio_cli/commands/lineage.py +9 -0
- dremio_cli/commands/profile.py +165 -0
- dremio_cli/commands/role.py +319 -0
- dremio_cli/commands/source.py +375 -0
- dremio_cli/commands/space.py +226 -0
- dremio_cli/commands/sql.py +280 -0
- dremio_cli/commands/table.py +155 -0
- dremio_cli/commands/tag.py +145 -0
- dremio_cli/commands/udf.py +9 -0
- dremio_cli/commands/user.py +250 -0
- dremio_cli/commands/view.py +369 -0
- dremio_cli/commands/wiki.py +163 -0
- dremio_cli/config.py +193 -0
- dremio_cli/env.py +175 -0
- dremio_cli/formatters/__init__.py +1 -0
- dremio_cli/formatters/json.py +19 -0
- dremio_cli/formatters/table.py +45 -0
- dremio_cli/formatters/yaml.py +17 -0
- dremio_cli/history.py +198 -0
- dremio_cli/utils/__init__.py +1 -0
- dremio_cli/utils/exceptions.py +35 -0
- dremio_cli/utils/helpers.py +73 -0
- dremio_cli/utils/validators.py +147 -0
- dremio_cli-1.0.0.dist-info/METADATA +261 -0
- dremio_cli-1.0.0.dist-info/RECORD +45 -0
- dremio_cli-1.0.0.dist-info/WHEEL +5 -0
- dremio_cli-1.0.0.dist-info/entry_points.txt +2 -0
- dremio_cli-1.0.0.dist-info/licenses/LICENSE +21 -0
- dremio_cli-1.0.0.dist-info/top_level.txt +1 -0
|
@@ -0,0 +1,226 @@
|
|
|
1
|
+
"""Space management commands."""
|
|
2
|
+
|
|
3
|
+
import json
|
|
4
|
+
import click
|
|
5
|
+
from rich.console import Console
|
|
6
|
+
from pathlib import Path
|
|
7
|
+
|
|
8
|
+
from dremio_cli.config import ProfileManager
|
|
9
|
+
from dremio_cli.client.factory import create_client
|
|
10
|
+
from dremio_cli.formatters.table import format_as_table
|
|
11
|
+
from dremio_cli.formatters.json import format_as_json
|
|
12
|
+
from dremio_cli.formatters.yaml import format_as_yaml
|
|
13
|
+
|
|
14
|
+
console = Console()
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
@click.group()
|
|
18
|
+
def space() -> None:
|
|
19
|
+
"""Space management operations.
|
|
20
|
+
|
|
21
|
+
Note: In Cloud, this creates top-level folders in the project catalog.
|
|
22
|
+
In Software, this creates traditional spaces.
|
|
23
|
+
"""
|
|
24
|
+
pass
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
@space.command("create")
|
|
28
|
+
@click.option("--name", required=True, help="Space name")
|
|
29
|
+
@click.option("--description", help="Space description")
|
|
30
|
+
@click.pass_context
|
|
31
|
+
def create_space(ctx, name: str, description: str) -> None:
|
|
32
|
+
"""Create a new space.
|
|
33
|
+
|
|
34
|
+
Examples:
|
|
35
|
+
dremio space create --name "Analytics"
|
|
36
|
+
dremio space create --name "Sales" --description "Sales data and reports"
|
|
37
|
+
"""
|
|
38
|
+
try:
|
|
39
|
+
# Get profile
|
|
40
|
+
manager = ProfileManager()
|
|
41
|
+
profile_name = ctx.obj.profile_name
|
|
42
|
+
profile = manager.get_profile(profile_name)
|
|
43
|
+
|
|
44
|
+
if not profile:
|
|
45
|
+
console.print(f"[red]Profile '{profile_name}' not found[/red]")
|
|
46
|
+
raise click.Abort()
|
|
47
|
+
|
|
48
|
+
# Create client
|
|
49
|
+
client = create_client(profile)
|
|
50
|
+
|
|
51
|
+
# Create space (backend handles Cloud vs Software)
|
|
52
|
+
space_data = {
|
|
53
|
+
"name": name,
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
if description:
|
|
57
|
+
space_data["description"] = description
|
|
58
|
+
|
|
59
|
+
with console.status(f"[bold green]Creating space '{name}'..."):
|
|
60
|
+
result = client.create_space(space_data)
|
|
61
|
+
|
|
62
|
+
space_id = result.get("id")
|
|
63
|
+
space_path = result.get("path", [])
|
|
64
|
+
|
|
65
|
+
console.print(f"[green]✓[/green] Space created successfully")
|
|
66
|
+
console.print(f" ID: {space_id}")
|
|
67
|
+
console.print(f" Name: {name}")
|
|
68
|
+
if space_path:
|
|
69
|
+
console.print(f" Path: {'.'.join(space_path)}")
|
|
70
|
+
|
|
71
|
+
# Display full result if verbose
|
|
72
|
+
if ctx.obj.verbose:
|
|
73
|
+
output_format = ctx.obj.output_format
|
|
74
|
+
if output_format == "json":
|
|
75
|
+
console.print(format_as_json(result))
|
|
76
|
+
elif output_format == "yaml":
|
|
77
|
+
console.print(format_as_yaml(result))
|
|
78
|
+
|
|
79
|
+
except Exception as e:
|
|
80
|
+
console.print(f"[red]Error: {e}[/red]")
|
|
81
|
+
if ctx.obj.verbose:
|
|
82
|
+
import traceback
|
|
83
|
+
traceback.print_exc()
|
|
84
|
+
raise click.Abort()
|
|
85
|
+
|
|
86
|
+
|
|
87
|
+
@space.command("list")
|
|
88
|
+
@click.pass_context
|
|
89
|
+
def list_spaces(ctx) -> None:
|
|
90
|
+
"""List all spaces.
|
|
91
|
+
|
|
92
|
+
Examples:
|
|
93
|
+
dremio space list
|
|
94
|
+
"""
|
|
95
|
+
try:
|
|
96
|
+
# Get profile
|
|
97
|
+
manager = ProfileManager()
|
|
98
|
+
profile_name = ctx.obj.profile_name
|
|
99
|
+
profile = manager.get_profile(profile_name)
|
|
100
|
+
|
|
101
|
+
if not profile:
|
|
102
|
+
console.print(f"[red]Profile '{profile_name}' not found[/red]")
|
|
103
|
+
raise click.Abort()
|
|
104
|
+
|
|
105
|
+
# Create client
|
|
106
|
+
client = create_client(profile)
|
|
107
|
+
|
|
108
|
+
# Get catalog
|
|
109
|
+
with console.status(f"[bold green]Fetching spaces..."):
|
|
110
|
+
data = client.get_catalog()
|
|
111
|
+
|
|
112
|
+
items = data.get("data", [])
|
|
113
|
+
|
|
114
|
+
# Filter for spaces
|
|
115
|
+
spaces = [
|
|
116
|
+
item for item in items
|
|
117
|
+
if item.get("containerType") == "SPACE" or
|
|
118
|
+
(item.get("containerType") == "FOLDER" and len(item.get("path", [])) == 1)
|
|
119
|
+
]
|
|
120
|
+
|
|
121
|
+
# Format output
|
|
122
|
+
output_format = ctx.obj.output_format
|
|
123
|
+
|
|
124
|
+
if output_format == "json":
|
|
125
|
+
console.print(format_as_json(spaces))
|
|
126
|
+
elif output_format == "yaml":
|
|
127
|
+
console.print(format_as_yaml(spaces))
|
|
128
|
+
else:
|
|
129
|
+
if spaces:
|
|
130
|
+
format_as_table(spaces, title=f"Spaces ({profile_name})")
|
|
131
|
+
else:
|
|
132
|
+
console.print("[yellow]No spaces found[/yellow]")
|
|
133
|
+
|
|
134
|
+
except Exception as e:
|
|
135
|
+
console.print(f"[red]Error: {e}[/red]")
|
|
136
|
+
if ctx.obj.verbose:
|
|
137
|
+
import traceback
|
|
138
|
+
traceback.print_exc()
|
|
139
|
+
raise click.Abort()
|
|
140
|
+
|
|
141
|
+
|
|
142
|
+
@space.command("get")
|
|
143
|
+
@click.argument("space_id")
|
|
144
|
+
@click.pass_context
|
|
145
|
+
def get_space(ctx, space_id: str) -> None:
|
|
146
|
+
"""Get space by ID.
|
|
147
|
+
|
|
148
|
+
Examples:
|
|
149
|
+
dremio space get abc-123-def-456
|
|
150
|
+
"""
|
|
151
|
+
try:
|
|
152
|
+
# Get profile
|
|
153
|
+
manager = ProfileManager()
|
|
154
|
+
profile_name = ctx.obj.profile_name
|
|
155
|
+
profile = manager.get_profile(profile_name)
|
|
156
|
+
|
|
157
|
+
if not profile:
|
|
158
|
+
console.print(f"[red]Profile '{profile_name}' not found[/red]")
|
|
159
|
+
raise click.Abort()
|
|
160
|
+
|
|
161
|
+
# Create client
|
|
162
|
+
client = create_client(profile)
|
|
163
|
+
|
|
164
|
+
# Get space
|
|
165
|
+
with console.status(f"[bold green]Fetching space {space_id}..."):
|
|
166
|
+
data = client.get_catalog_item(space_id)
|
|
167
|
+
|
|
168
|
+
# Format output
|
|
169
|
+
output_format = ctx.obj.output_format
|
|
170
|
+
|
|
171
|
+
if output_format == "json":
|
|
172
|
+
console.print(format_as_json(data))
|
|
173
|
+
elif output_format == "yaml":
|
|
174
|
+
console.print(format_as_yaml(data))
|
|
175
|
+
else:
|
|
176
|
+
format_as_table(data, title=f"Space: {space_id}")
|
|
177
|
+
|
|
178
|
+
except Exception as e:
|
|
179
|
+
console.print(f"[red]Error: {e}[/red]")
|
|
180
|
+
if ctx.obj.verbose:
|
|
181
|
+
import traceback
|
|
182
|
+
traceback.print_exc()
|
|
183
|
+
raise click.Abort()
|
|
184
|
+
|
|
185
|
+
|
|
186
|
+
@space.command("delete")
|
|
187
|
+
@click.argument("space_id")
|
|
188
|
+
@click.option("--tag", help="Version tag for optimistic concurrency control")
|
|
189
|
+
@click.confirmation_option(prompt="Are you sure you want to delete this space?")
|
|
190
|
+
@click.pass_context
|
|
191
|
+
def delete_space(ctx, space_id: str, tag: str) -> None:
|
|
192
|
+
"""Delete a space.
|
|
193
|
+
|
|
194
|
+
Examples:
|
|
195
|
+
dremio space delete abc-123-def-456
|
|
196
|
+
"""
|
|
197
|
+
try:
|
|
198
|
+
# Get profile
|
|
199
|
+
manager = ProfileManager()
|
|
200
|
+
profile_name = ctx.obj.profile_name
|
|
201
|
+
profile = manager.get_profile(profile_name)
|
|
202
|
+
|
|
203
|
+
if not profile:
|
|
204
|
+
console.print(f"[red]Profile '{profile_name}' not found[/red]")
|
|
205
|
+
raise click.Abort()
|
|
206
|
+
|
|
207
|
+
# Create client
|
|
208
|
+
client = create_client(profile)
|
|
209
|
+
|
|
210
|
+
# Get tag if not provided
|
|
211
|
+
if not tag:
|
|
212
|
+
space = client.get_catalog_item(space_id)
|
|
213
|
+
tag = space.get("tag")
|
|
214
|
+
|
|
215
|
+
# Delete space
|
|
216
|
+
with console.status(f"[bold yellow]Deleting space {space_id}..."):
|
|
217
|
+
client.delete_space(space_id, tag)
|
|
218
|
+
|
|
219
|
+
console.print(f"[green]✓[/green] Space deleted successfully")
|
|
220
|
+
|
|
221
|
+
except Exception as e:
|
|
222
|
+
console.print(f"[red]Error: {e}[/red]")
|
|
223
|
+
if ctx.obj.verbose:
|
|
224
|
+
import traceback
|
|
225
|
+
traceback.print_exc()
|
|
226
|
+
raise click.Abort()
|
|
@@ -0,0 +1,280 @@
|
|
|
1
|
+
"""SQL execution commands."""
|
|
2
|
+
|
|
3
|
+
import json
|
|
4
|
+
import click
|
|
5
|
+
from rich.console import Console
|
|
6
|
+
from pathlib import Path
|
|
7
|
+
|
|
8
|
+
from dremio_cli.config import ProfileManager
|
|
9
|
+
from dremio_cli.client.factory import create_client
|
|
10
|
+
from dremio_cli.formatters.table import format_as_table
|
|
11
|
+
from dremio_cli.formatters.json import format_as_json
|
|
12
|
+
from dremio_cli.formatters.yaml import format_as_yaml
|
|
13
|
+
|
|
14
|
+
console = Console()
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
@click.group()
|
|
18
|
+
def sql() -> None:
|
|
19
|
+
"""SQL execution operations."""
|
|
20
|
+
pass
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
@sql.command("execute")
|
|
24
|
+
@click.argument("query", required=False)
|
|
25
|
+
@click.option("--file", "sql_file", type=click.Path(exists=True), help="Execute SQL from file")
|
|
26
|
+
@click.option("--context", help="Query context (space or folder path)")
|
|
27
|
+
@click.option("--async", "async_mode", is_flag=True, help="Execute asynchronously (return job ID immediately)")
|
|
28
|
+
@click.option("--output-file", type=click.Path(), help="Save results to file")
|
|
29
|
+
@click.pass_context
|
|
30
|
+
def execute_sql(ctx, query: str, sql_file: str, context: str, async_mode: bool, output_file: str) -> None:
|
|
31
|
+
"""Execute a SQL query.
|
|
32
|
+
|
|
33
|
+
Examples:
|
|
34
|
+
dremio sql execute "SELECT * FROM table LIMIT 10"
|
|
35
|
+
dremio sql execute --file query.sql
|
|
36
|
+
dremio sql execute "SELECT * FROM table" --context "MySpace"
|
|
37
|
+
dremio sql execute "SELECT * FROM large_table" --async
|
|
38
|
+
dremio sql execute "SELECT * FROM table" --output-file results.json
|
|
39
|
+
"""
|
|
40
|
+
try:
|
|
41
|
+
# Get profile
|
|
42
|
+
manager = ProfileManager()
|
|
43
|
+
profile_name = ctx.obj.profile_name
|
|
44
|
+
profile = manager.get_profile(profile_name)
|
|
45
|
+
|
|
46
|
+
if not profile:
|
|
47
|
+
console.print(f"[red]Profile '{profile_name}' not found[/red]")
|
|
48
|
+
raise click.Abort()
|
|
49
|
+
|
|
50
|
+
# Get SQL query
|
|
51
|
+
if sql_file:
|
|
52
|
+
with open(sql_file, 'r') as f:
|
|
53
|
+
query = f.read()
|
|
54
|
+
elif not query:
|
|
55
|
+
console.print("[red]Error: Either provide a query or use --file[/red]")
|
|
56
|
+
raise click.Abort()
|
|
57
|
+
|
|
58
|
+
# Create client
|
|
59
|
+
client = create_client(profile)
|
|
60
|
+
|
|
61
|
+
# Parse context
|
|
62
|
+
sql_context = None
|
|
63
|
+
if context:
|
|
64
|
+
sql_context = [c.strip() for c in context.split(",")]
|
|
65
|
+
|
|
66
|
+
# Execute SQL
|
|
67
|
+
with console.status(f"[bold green]Executing SQL query..."):
|
|
68
|
+
result = client.execute_sql(query, context=sql_context)
|
|
69
|
+
|
|
70
|
+
job_id = result.get("id")
|
|
71
|
+
|
|
72
|
+
if async_mode:
|
|
73
|
+
# Return job ID immediately
|
|
74
|
+
console.print(f"[green]✓[/green] Query submitted")
|
|
75
|
+
console.print(f" Job ID: {job_id}")
|
|
76
|
+
console.print(f"\n[dim]Use 'dremio job get {job_id}' to check status[/dim]")
|
|
77
|
+
console.print(f"[dim]Use 'dremio job results {job_id}' to get results[/dim]")
|
|
78
|
+
else:
|
|
79
|
+
# Wait for results
|
|
80
|
+
console.print(f"[green]✓[/green] Query executed")
|
|
81
|
+
console.print(f" Job ID: {job_id}")
|
|
82
|
+
|
|
83
|
+
# Get job results
|
|
84
|
+
if job_id:
|
|
85
|
+
try:
|
|
86
|
+
with console.status(f"[bold green]Fetching results..."):
|
|
87
|
+
results = client.get_job_results(job_id)
|
|
88
|
+
|
|
89
|
+
rows = results.get("rows", [])
|
|
90
|
+
row_count = results.get("rowCount", len(rows))
|
|
91
|
+
|
|
92
|
+
# Save to file if requested
|
|
93
|
+
if output_file:
|
|
94
|
+
output_path = Path(output_file)
|
|
95
|
+
if output_path.suffix == '.json':
|
|
96
|
+
output_path.write_text(json.dumps(results, indent=2))
|
|
97
|
+
elif output_path.suffix in ['.yaml', '.yml']:
|
|
98
|
+
import yaml
|
|
99
|
+
output_path.write_text(yaml.dump(results))
|
|
100
|
+
else:
|
|
101
|
+
# Default to JSON
|
|
102
|
+
output_path.write_text(json.dumps(results, indent=2))
|
|
103
|
+
|
|
104
|
+
console.print(f"\n[green]✓[/green] Results saved to {output_file}")
|
|
105
|
+
console.print(f" Rows: {row_count}")
|
|
106
|
+
else:
|
|
107
|
+
# Display results
|
|
108
|
+
output_format = ctx.obj.output_format
|
|
109
|
+
|
|
110
|
+
if output_format == "json":
|
|
111
|
+
console.print(format_as_json(results))
|
|
112
|
+
elif output_format == "yaml":
|
|
113
|
+
console.print(format_as_yaml(results))
|
|
114
|
+
else:
|
|
115
|
+
if rows:
|
|
116
|
+
format_as_table(rows, title=f"Query Results ({row_count} rows)")
|
|
117
|
+
else:
|
|
118
|
+
console.print("[yellow]No results returned[/yellow]")
|
|
119
|
+
|
|
120
|
+
except Exception as e:
|
|
121
|
+
console.print(f"\n[yellow]⚠[/yellow] Could not fetch results: {e}")
|
|
122
|
+
console.print(f"[dim]Job may still be running. Use 'dremio job results {job_id}' to check later[/dim]")
|
|
123
|
+
|
|
124
|
+
except Exception as e:
|
|
125
|
+
console.print(f"[red]Error: {e}[/red]")
|
|
126
|
+
if ctx.obj.verbose:
|
|
127
|
+
import traceback
|
|
128
|
+
traceback.print_exc()
|
|
129
|
+
raise click.Abort()
|
|
130
|
+
|
|
131
|
+
|
|
132
|
+
@sql.command("explain")
|
|
133
|
+
@click.argument("query", required=False)
|
|
134
|
+
@click.option("--file", "sql_file", type=click.Path(exists=True), help="Explain SQL from file")
|
|
135
|
+
@click.option("--context", help="Query context (space or folder path)")
|
|
136
|
+
@click.pass_context
|
|
137
|
+
def explain_sql(ctx, query: str, sql_file: str, context: str) -> None:
|
|
138
|
+
"""Explain a SQL query execution plan.
|
|
139
|
+
|
|
140
|
+
Examples:
|
|
141
|
+
dremio sql explain "SELECT * FROM table"
|
|
142
|
+
dremio sql explain --file query.sql
|
|
143
|
+
"""
|
|
144
|
+
try:
|
|
145
|
+
# Get profile
|
|
146
|
+
manager = ProfileManager()
|
|
147
|
+
profile_name = ctx.obj.profile_name
|
|
148
|
+
profile = manager.get_profile(profile_name)
|
|
149
|
+
|
|
150
|
+
if not profile:
|
|
151
|
+
console.print(f"[red]Profile '{profile_name}' not found[/red]")
|
|
152
|
+
raise click.Abort()
|
|
153
|
+
|
|
154
|
+
# Get SQL query
|
|
155
|
+
if sql_file:
|
|
156
|
+
with open(sql_file, 'r') as f:
|
|
157
|
+
query = f.read()
|
|
158
|
+
elif not query:
|
|
159
|
+
console.print("[red]Error: Either provide a query or use --file[/red]")
|
|
160
|
+
raise click.Abort()
|
|
161
|
+
|
|
162
|
+
# Create client
|
|
163
|
+
client = create_client(profile)
|
|
164
|
+
|
|
165
|
+
# Parse context
|
|
166
|
+
sql_context = None
|
|
167
|
+
if context:
|
|
168
|
+
sql_context = [c.strip() for c in context.split(",")]
|
|
169
|
+
|
|
170
|
+
# Explain query (execute with EXPLAIN prefix)
|
|
171
|
+
explain_query = f"EXPLAIN PLAN FOR {query}"
|
|
172
|
+
|
|
173
|
+
with console.status(f"[bold green]Generating execution plan..."):
|
|
174
|
+
result = client.execute_sql(explain_query, context=sql_context)
|
|
175
|
+
|
|
176
|
+
job_id = result.get("id")
|
|
177
|
+
|
|
178
|
+
console.print(f"[green]✓[/green] Execution plan generated")
|
|
179
|
+
console.print(f" Job ID: {job_id}")
|
|
180
|
+
|
|
181
|
+
# Get results
|
|
182
|
+
if job_id:
|
|
183
|
+
try:
|
|
184
|
+
with console.status(f"[bold green]Fetching plan..."):
|
|
185
|
+
results = client.get_job_results(job_id)
|
|
186
|
+
|
|
187
|
+
rows = results.get("rows", [])
|
|
188
|
+
|
|
189
|
+
# Display plan
|
|
190
|
+
output_format = ctx.obj.output_format
|
|
191
|
+
|
|
192
|
+
if output_format == "json":
|
|
193
|
+
console.print(format_as_json(results))
|
|
194
|
+
elif output_format == "yaml":
|
|
195
|
+
console.print(format_as_yaml(results))
|
|
196
|
+
else:
|
|
197
|
+
if rows:
|
|
198
|
+
console.print("\n[bold]Execution Plan:[/bold]\n")
|
|
199
|
+
for row in rows:
|
|
200
|
+
# Plan is usually in first column
|
|
201
|
+
plan_text = list(row.values())[0] if row else ""
|
|
202
|
+
console.print(plan_text)
|
|
203
|
+
else:
|
|
204
|
+
console.print("[yellow]No plan returned[/yellow]")
|
|
205
|
+
|
|
206
|
+
except Exception as e:
|
|
207
|
+
console.print(f"\n[yellow]⚠[/yellow] Could not fetch plan: {e}")
|
|
208
|
+
|
|
209
|
+
except Exception as e:
|
|
210
|
+
console.print(f"[red]Error: {e}[/red]")
|
|
211
|
+
if ctx.obj.verbose:
|
|
212
|
+
import traceback
|
|
213
|
+
traceback.print_exc()
|
|
214
|
+
raise click.Abort()
|
|
215
|
+
|
|
216
|
+
|
|
217
|
+
@sql.command("validate")
|
|
218
|
+
@click.argument("query", required=False)
|
|
219
|
+
@click.option("--file", "sql_file", type=click.Path(exists=True), help="Validate SQL from file")
|
|
220
|
+
@click.option("--context", help="Query context (space or folder path)")
|
|
221
|
+
@click.pass_context
|
|
222
|
+
def validate_sql(ctx, query: str, sql_file: str, context: str) -> None:
|
|
223
|
+
"""Validate SQL query syntax.
|
|
224
|
+
|
|
225
|
+
Examples:
|
|
226
|
+
dremio sql validate "SELECT * FROM table"
|
|
227
|
+
dremio sql validate --file query.sql
|
|
228
|
+
"""
|
|
229
|
+
try:
|
|
230
|
+
# Get profile
|
|
231
|
+
manager = ProfileManager()
|
|
232
|
+
profile_name = ctx.obj.profile_name
|
|
233
|
+
profile = manager.get_profile(profile_name)
|
|
234
|
+
|
|
235
|
+
if not profile:
|
|
236
|
+
console.print(f"[red]Profile '{profile_name}' not found[/red]")
|
|
237
|
+
raise click.Abort()
|
|
238
|
+
|
|
239
|
+
# Get SQL query
|
|
240
|
+
if sql_file:
|
|
241
|
+
with open(sql_file, 'r') as f:
|
|
242
|
+
query = f.read()
|
|
243
|
+
elif not query:
|
|
244
|
+
console.print("[red]Error: Either provide a query or use --file[/red]")
|
|
245
|
+
raise click.Abort()
|
|
246
|
+
|
|
247
|
+
# Create client
|
|
248
|
+
client = create_client(profile)
|
|
249
|
+
|
|
250
|
+
# Parse context
|
|
251
|
+
sql_context = None
|
|
252
|
+
if context:
|
|
253
|
+
sql_context = [c.strip() for c in context.split(",")]
|
|
254
|
+
|
|
255
|
+
# Validate by doing EXPLAIN (doesn't execute, just validates)
|
|
256
|
+
explain_query = f"EXPLAIN PLAN FOR {query}"
|
|
257
|
+
|
|
258
|
+
with console.status(f"[bold green]Validating SQL syntax..."):
|
|
259
|
+
try:
|
|
260
|
+
result = client.execute_sql(explain_query, context=sql_context)
|
|
261
|
+
job_id = result.get("id")
|
|
262
|
+
|
|
263
|
+
# If we got a job ID, syntax is valid
|
|
264
|
+
console.print(f"[green]✓[/green] SQL syntax is valid")
|
|
265
|
+
console.print(f" Job ID: {job_id}")
|
|
266
|
+
|
|
267
|
+
except Exception as e:
|
|
268
|
+
error_msg = str(e)
|
|
269
|
+
console.print(f"[red]✗[/red] SQL syntax error")
|
|
270
|
+
console.print(f"\n[red]{error_msg}[/red]")
|
|
271
|
+
raise click.Abort()
|
|
272
|
+
|
|
273
|
+
except click.Abort:
|
|
274
|
+
raise
|
|
275
|
+
except Exception as e:
|
|
276
|
+
console.print(f"[red]Error: {e}[/red]")
|
|
277
|
+
if ctx.obj.verbose:
|
|
278
|
+
import traceback
|
|
279
|
+
traceback.print_exc()
|
|
280
|
+
raise click.Abort()
|
|
@@ -0,0 +1,155 @@
|
|
|
1
|
+
"""Table operations commands."""
|
|
2
|
+
|
|
3
|
+
import json
|
|
4
|
+
import click
|
|
5
|
+
from rich.console import Console
|
|
6
|
+
from pathlib import Path
|
|
7
|
+
|
|
8
|
+
from dremio_cli.config import ProfileManager
|
|
9
|
+
from dremio_cli.client.factory import create_client
|
|
10
|
+
from dremio_cli.formatters.table import format_as_table
|
|
11
|
+
from dremio_cli.formatters.json import format_as_json
|
|
12
|
+
from dremio_cli.formatters.yaml import format_as_yaml
|
|
13
|
+
|
|
14
|
+
console = Console()
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
@click.group()
|
|
18
|
+
def table() -> None:
|
|
19
|
+
"""Table operations."""
|
|
20
|
+
pass
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
@table.command("promote")
|
|
24
|
+
@click.argument("dataset_id")
|
|
25
|
+
@click.pass_context
|
|
26
|
+
def promote_table(ctx, dataset_id: str) -> None:
|
|
27
|
+
"""Promote a dataset to a physical dataset (table).
|
|
28
|
+
|
|
29
|
+
Examples:
|
|
30
|
+
dremio table promote abc-123-def-456
|
|
31
|
+
"""
|
|
32
|
+
try:
|
|
33
|
+
# Get profile
|
|
34
|
+
manager = ProfileManager()
|
|
35
|
+
profile_name = ctx.obj.profile_name
|
|
36
|
+
profile = manager.get_profile(profile_name)
|
|
37
|
+
|
|
38
|
+
if not profile:
|
|
39
|
+
console.print(f"[red]Profile '{profile_name}' not found[/red]")
|
|
40
|
+
raise click.Abort()
|
|
41
|
+
|
|
42
|
+
# Create client
|
|
43
|
+
client = create_client(profile)
|
|
44
|
+
|
|
45
|
+
# Promote to table
|
|
46
|
+
with console.status(f"[bold green]Promoting dataset {dataset_id}..."):
|
|
47
|
+
result = client.promote_dataset(dataset_id)
|
|
48
|
+
|
|
49
|
+
console.print(f"[green]✓[/green] Dataset promoted successfully")
|
|
50
|
+
console.print(f" ID: {dataset_id}")
|
|
51
|
+
|
|
52
|
+
if ctx.obj.verbose:
|
|
53
|
+
output_format = ctx.obj.output_format
|
|
54
|
+
if output_format == "json":
|
|
55
|
+
console.print(format_as_json(result))
|
|
56
|
+
elif output_format == "yaml":
|
|
57
|
+
console.print(format_as_yaml(result))
|
|
58
|
+
|
|
59
|
+
except Exception as e:
|
|
60
|
+
console.print(f"[red]Error: {e}[/red]")
|
|
61
|
+
if ctx.obj.verbose:
|
|
62
|
+
import traceback
|
|
63
|
+
traceback.print_exc()
|
|
64
|
+
raise click.Abort()
|
|
65
|
+
|
|
66
|
+
|
|
67
|
+
@table.command("format")
|
|
68
|
+
@click.argument("dataset_id")
|
|
69
|
+
@click.option("--type", "format_type", required=True, help="Format type (e.g., CSV, JSON, Parquet)")
|
|
70
|
+
@click.option("--from-file", "format_file", type=click.Path(exists=True), help="Load format config from JSON file")
|
|
71
|
+
@click.pass_context
|
|
72
|
+
def format_table(ctx, dataset_id: str, format_type: str, format_file: str) -> None:
|
|
73
|
+
"""Configure format for a physical dataset.
|
|
74
|
+
|
|
75
|
+
Examples:
|
|
76
|
+
dremio table format abc-123 --type CSV --from-file csv_format.json
|
|
77
|
+
dremio table format abc-123 --type JSON
|
|
78
|
+
"""
|
|
79
|
+
try:
|
|
80
|
+
# Get profile
|
|
81
|
+
manager = ProfileManager()
|
|
82
|
+
profile_name = ctx.obj.profile_name
|
|
83
|
+
profile = manager.get_profile(profile_name)
|
|
84
|
+
|
|
85
|
+
if not profile:
|
|
86
|
+
console.print(f"[red]Profile '{profile_name}' not found[/red]")
|
|
87
|
+
raise click.Abort()
|
|
88
|
+
|
|
89
|
+
# Create client
|
|
90
|
+
client = create_client(profile)
|
|
91
|
+
|
|
92
|
+
# Build format config
|
|
93
|
+
if format_file:
|
|
94
|
+
with open(format_file, 'r') as f:
|
|
95
|
+
format_config = json.load(f)
|
|
96
|
+
else:
|
|
97
|
+
format_config = {
|
|
98
|
+
"type": format_type
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
# Set format
|
|
102
|
+
with console.status(f"[bold green]Setting format for {dataset_id}..."):
|
|
103
|
+
result = client.set_dataset_format(dataset_id, format_config)
|
|
104
|
+
|
|
105
|
+
console.print(f"[green]✓[/green] Format configured successfully")
|
|
106
|
+
console.print(f" Type: {format_type}")
|
|
107
|
+
|
|
108
|
+
except Exception as e:
|
|
109
|
+
console.print(f"[red]Error: {e}[/red]")
|
|
110
|
+
if ctx.obj.verbose:
|
|
111
|
+
import traceback
|
|
112
|
+
traceback.print_exc()
|
|
113
|
+
raise click.Abort()
|
|
114
|
+
|
|
115
|
+
|
|
116
|
+
@table.command("update")
|
|
117
|
+
@click.argument("dataset_id")
|
|
118
|
+
@click.option("--from-file", "table_file", type=click.Path(exists=True), required=True, help="Updated table JSON file")
|
|
119
|
+
@click.pass_context
|
|
120
|
+
def update_table(ctx, dataset_id: str, table_file: str) -> None:
|
|
121
|
+
"""Update table metadata.
|
|
122
|
+
|
|
123
|
+
Examples:
|
|
124
|
+
dremio table update abc-123 --from-file updated_table.json
|
|
125
|
+
"""
|
|
126
|
+
try:
|
|
127
|
+
# Get profile
|
|
128
|
+
manager = ProfileManager()
|
|
129
|
+
profile_name = ctx.obj.profile_name
|
|
130
|
+
profile = manager.get_profile(profile_name)
|
|
131
|
+
|
|
132
|
+
if not profile:
|
|
133
|
+
console.print(f"[red]Profile '{profile_name}' not found[/red]")
|
|
134
|
+
raise click.Abort()
|
|
135
|
+
|
|
136
|
+
# Create client
|
|
137
|
+
client = create_client(profile)
|
|
138
|
+
|
|
139
|
+
# Load table data
|
|
140
|
+
with open(table_file, 'r') as f:
|
|
141
|
+
table_data = json.load(f)
|
|
142
|
+
|
|
143
|
+
# Update table
|
|
144
|
+
with console.status(f"[bold green]Updating table {dataset_id}..."):
|
|
145
|
+
result = client.update_dataset(dataset_id, table_data)
|
|
146
|
+
|
|
147
|
+
console.print(f"[green]✓[/green] Table updated successfully")
|
|
148
|
+
console.print(f" ID: {dataset_id}")
|
|
149
|
+
|
|
150
|
+
except Exception as e:
|
|
151
|
+
console.print(f"[red]Error: {e}[/red]")
|
|
152
|
+
if ctx.obj.verbose:
|
|
153
|
+
import traceback
|
|
154
|
+
traceback.print_exc()
|
|
155
|
+
raise click.Abort()
|