-
Notifications
You must be signed in to change notification settings - Fork 222
Expand file tree
/
Copy pathtables.go
More file actions
711 lines (565 loc) · 23.4 KB
/
Copy pathtables.go
File metadata and controls
711 lines (565 loc) · 23.4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
// Code generated from OpenAPI specs by Databricks SDK Generator. DO NOT EDIT.
package tables
import (
"fmt"
"github.com/databricks/cli/cmd/root"
"github.com/databricks/cli/libs/cmdctx"
"github.com/databricks/cli/libs/cmdio"
"github.com/databricks/cli/libs/flags"
"github.com/databricks/databricks-sdk-go/service/catalog"
"github.com/spf13/cobra"
)
// Slice with functions to override default command behavior.
// Functions can be added from the `init()` function in manually curated files in this directory.
var cmdOverrides []func(*cobra.Command)
func New() *cobra.Command {
cmd := &cobra.Command{
Use: "tables",
Short: `A table resides in the third layer of Unity Catalog’s three-level namespace.`,
Long: `A table resides in the third layer of Unity Catalog’s three-level namespace.
It contains rows of data. To create a table, users must have CREATE_TABLE and
USE_SCHEMA permissions on the schema, and they must have the USE_CATALOG
permission on its parent catalog. To query a table, users must have the SELECT
permission on the table, and they must have the USE_CATALOG permission on its
parent catalog and the USE_SCHEMA permission on its parent schema.
A table can be managed or external. From an API perspective, a __VIEW__ is a
particular kind of table (rather than a managed or external table).`,
GroupID: "catalog",
RunE: root.ReportUnknownSubcommand,
}
cmd.Annotations = make(map[string]string)
cmd.Annotations["launch_stage"] = "GA"
cmd.Annotations["launch_stage_display"] = "GA"
// Add methods
cmd.AddCommand(newCreate())
cmd.AddCommand(newDelete())
cmd.AddCommand(newExists())
cmd.AddCommand(newGet())
cmd.AddCommand(newList())
cmd.AddCommand(newListSummaries())
cmd.AddCommand(newUpdate())
// Apply optional overrides to this command.
for _, fn := range cmdOverrides {
fn(cmd)
}
return cmd
}
// start create command
// Slice with functions to override default command behavior.
// Functions can be added from the `init()` function in manually curated files in this directory.
var createOverrides []func(
*cobra.Command,
*catalog.CreateTableRequest,
)
func newCreate() *cobra.Command {
cmd := &cobra.Command{}
var createReq catalog.CreateTableRequest
var createJson flags.JsonFlag
cmd.Flags().Var(&createJson, "json", `either inline JSON string or @path/to/file.json with request body`)
// TODO: array: columns
// TODO: map via StringToStringVar: properties
cmd.Use = "create NAME CATALOG_NAME SCHEMA_NAME TABLE_TYPE DATA_SOURCE_FORMAT STORAGE_LOCATION"
cmd.Short = `*Public Preview* Create a table.`
cmd.Long = `This command is in Public Preview and may change without notice.
Create a table.
Creates a new table in the specified catalog and schema.
To create an external delta table, the caller must have the
**EXTERNAL_USE_SCHEMA** privilege on the parent schema and the
**EXTERNAL_USE_LOCATION** privilege on the external location. These privileges
must always be granted explicitly, and cannot be inherited through ownership
or **ALL_PRIVILEGES**.
Standard UC permissions needed to create tables still apply: **USE_CATALOG**
on the parent catalog (or ownership of the parent catalog), **CREATE_TABLE**
and **USE_SCHEMA** on the parent schema (or ownership of the parent schema),
and **CREATE_EXTERNAL_TABLE** on external location.
The **columns** field needs to be in a Spark compatible format, so we
recommend you use Spark to create these tables. The API itself does not
validate the correctness of the column spec. If the spec is not Spark
compatible, the tables may not be readable by Databricks Runtime.
NOTE: The Create Table API for external clients only supports creating
**external delta tables**. The values shown in the respective enums are all
values supported by Databricks, however for this specific Create Table API,
only **table_type** **EXTERNAL** and **data_source_format** **DELTA** are
supported. Additionally, column masks are not supported when creating tables
through this API.
Arguments:
NAME: Name of table, relative to parent schema.
CATALOG_NAME: Name of parent catalog.
SCHEMA_NAME: Name of parent schema relative to its parent catalog.
TABLE_TYPE:
Supported values: [
EXTERNAL,
EXTERNAL_SHALLOW_CLONE,
FOREIGN,
MANAGED,
MANAGED_SHALLOW_CLONE,
MATERIALIZED_VIEW,
METRIC_VIEW,
STREAMING_TABLE,
VIEW,
]
DATA_SOURCE_FORMAT:
Supported values: [
AVRO,
BIGQUERY_FORMAT,
CSV,
DATABRICKS_FORMAT,
DATABRICKS_ROW_STORE_FORMAT,
DELTA,
DELTASHARING,
DELTA_UNIFORM_HUDI,
DELTA_UNIFORM_ICEBERG,
HIVE,
ICEBERG,
JSON,
MONGODB_FORMAT,
MYSQL_FORMAT,
NETSUITE_FORMAT,
ORACLE_FORMAT,
ORC,
PARQUET,
POSTGRESQL_FORMAT,
REDSHIFT_FORMAT,
SALESFORCE_DATA_CLOUD_FORMAT,
SALESFORCE_FORMAT,
SNOWFLAKE_FORMAT,
SQLDW_FORMAT,
SQLSERVER_FORMAT,
TERADATA_FORMAT,
TEXT,
UNITY_CATALOG,
VECTOR_INDEX_FORMAT,
WORKDAY_RAAS_FORMAT,
]
STORAGE_LOCATION: Storage root URL for table (for **MANAGED**, **EXTERNAL** tables).`
cmd.Annotations = make(map[string]string)
cmd.Annotations["launch_stage"] = "PUBLIC_PREVIEW"
cmd.Annotations["launch_stage_display"] = "Public Preview"
cmd.Args = func(cmd *cobra.Command, args []string) error {
if cmd.Flags().Changed("json") {
err := root.ExactArgs(0)(cmd, args)
if err != nil {
return fmt.Errorf("when --json flag is specified, no positional arguments are allowed. Provide 'name', 'catalog_name', 'schema_name', 'table_type', 'data_source_format', 'storage_location' in your JSON input")
}
return nil
}
check := root.ExactArgs(6)
return check(cmd, args)
}
cmd.PreRunE = root.MustWorkspaceClient
cmd.RunE = func(cmd *cobra.Command, args []string) (err error) {
ctx := cmd.Context()
w := cmdctx.WorkspaceClient(ctx)
if cmd.Flags().Changed("json") {
diags := createJson.Unmarshal(&createReq)
if diags.HasError() {
return diags.Error()
}
if len(diags) > 0 {
err := cmdio.RenderDiagnostics(ctx, diags)
if err != nil {
return err
}
}
}
if !cmd.Flags().Changed("json") {
createReq.Name = args[0]
}
if !cmd.Flags().Changed("json") {
createReq.CatalogName = args[1]
}
if !cmd.Flags().Changed("json") {
createReq.SchemaName = args[2]
}
if !cmd.Flags().Changed("json") {
_, err = fmt.Sscan(args[3], &createReq.TableType)
if err != nil {
return fmt.Errorf("invalid TABLE_TYPE: %s", args[3])
}
}
if !cmd.Flags().Changed("json") {
_, err = fmt.Sscan(args[4], &createReq.DataSourceFormat)
if err != nil {
return fmt.Errorf("invalid DATA_SOURCE_FORMAT: %s", args[4])
}
}
if !cmd.Flags().Changed("json") {
createReq.StorageLocation = args[5]
}
response, err := w.Tables.Create(ctx, createReq)
if err != nil {
return err
}
return cmdio.Render(ctx, response)
}
// Disable completions since they are not applicable.
// Can be overridden by manual implementation in `override.go`.
cmd.ValidArgsFunction = cobra.NoFileCompletions
// Apply optional overrides to this command.
for _, fn := range createOverrides {
fn(cmd, &createReq)
}
return cmd
}
// start delete command
// Slice with functions to override default command behavior.
// Functions can be added from the `init()` function in manually curated files in this directory.
var deleteOverrides []func(
*cobra.Command,
*catalog.DeleteTableRequest,
)
func newDelete() *cobra.Command {
cmd := &cobra.Command{}
var deleteReq catalog.DeleteTableRequest
cmd.Use = "delete FULL_NAME"
cmd.Short = `Delete a table.`
cmd.Long = `Delete a table.
Deletes a table from the specified parent catalog and schema. The caller must
be the owner of the parent catalog, have the **USE_CATALOG** privilege on the
parent catalog and be the owner of the parent schema, or be the owner of the
table and have the **USE_CATALOG** privilege on the parent catalog and the
**USE_SCHEMA** privilege on the parent schema.
Arguments:
FULL_NAME: Full name of the table.`
cmd.Annotations = make(map[string]string)
cmd.Annotations["launch_stage"] = "GA"
cmd.Annotations["launch_stage_display"] = "GA"
cmd.Args = func(cmd *cobra.Command, args []string) error {
check := root.ExactArgs(1)
return check(cmd, args)
}
cmd.PreRunE = root.MustWorkspaceClient
cmd.RunE = func(cmd *cobra.Command, args []string) (err error) {
ctx := cmd.Context()
w := cmdctx.WorkspaceClient(ctx)
deleteReq.FullName = args[0]
err = w.Tables.Delete(ctx, deleteReq)
if err != nil {
return err
}
return nil
}
// Disable completions since they are not applicable.
// Can be overridden by manual implementation in `override.go`.
cmd.ValidArgsFunction = cobra.NoFileCompletions
// Apply optional overrides to this command.
for _, fn := range deleteOverrides {
fn(cmd, &deleteReq)
}
return cmd
}
// start exists command
// Slice with functions to override default command behavior.
// Functions can be added from the `init()` function in manually curated files in this directory.
var existsOverrides []func(
*cobra.Command,
*catalog.ExistsRequest,
)
func newExists() *cobra.Command {
cmd := &cobra.Command{}
var existsReq catalog.ExistsRequest
cmd.Use = "exists FULL_NAME"
cmd.Short = `Get boolean reflecting if table exists.`
cmd.Long = `Get boolean reflecting if table exists.
Gets if a table exists in the metastore for a specific catalog and schema. The
caller must satisfy one of the following requirements: * Be a metastore admin
* Be the owner of the parent catalog * Be the owner of the parent schema and
have the **USE_CATALOG** privilege on the parent catalog * Have the
**USE_CATALOG** privilege on the parent catalog and the **USE_SCHEMA**
privilege on the parent schema, and either be the table owner or have the
**SELECT** privilege on the table. * Have **BROWSE** privilege on the parent
catalog * Have **BROWSE** privilege on the parent schema
Arguments:
FULL_NAME: Full name of the table.`
cmd.Annotations = make(map[string]string)
cmd.Annotations["launch_stage"] = "GA"
cmd.Annotations["launch_stage_display"] = "GA"
cmd.Args = func(cmd *cobra.Command, args []string) error {
check := root.ExactArgs(1)
return check(cmd, args)
}
cmd.PreRunE = root.MustWorkspaceClient
cmd.RunE = func(cmd *cobra.Command, args []string) (err error) {
ctx := cmd.Context()
w := cmdctx.WorkspaceClient(ctx)
existsReq.FullName = args[0]
response, err := w.Tables.Exists(ctx, existsReq)
if err != nil {
return err
}
return cmdio.Render(ctx, response)
}
// Disable completions since they are not applicable.
// Can be overridden by manual implementation in `override.go`.
cmd.ValidArgsFunction = cobra.NoFileCompletions
// Apply optional overrides to this command.
for _, fn := range existsOverrides {
fn(cmd, &existsReq)
}
return cmd
}
// start get command
// Slice with functions to override default command behavior.
// Functions can be added from the `init()` function in manually curated files in this directory.
var getOverrides []func(
*cobra.Command,
*catalog.GetTableRequest,
)
func newGet() *cobra.Command {
cmd := &cobra.Command{}
var getReq catalog.GetTableRequest
cmd.Flags().BoolVar(&getReq.IncludeBrowse, "include-browse", getReq.IncludeBrowse, `Whether to include tables in the response for which the principal can only access selective metadata for.`)
cmd.Flags().BoolVar(&getReq.IncludeDeltaMetadata, "include-delta-metadata", getReq.IncludeDeltaMetadata, `Whether delta metadata should be included in the response.`)
cmd.Flags().BoolVar(&getReq.IncludeManifestCapabilities, "include-manifest-capabilities", getReq.IncludeManifestCapabilities, `Whether to include a manifest containing table capabilities in the response.`)
cmd.Use = "get FULL_NAME"
cmd.Short = `Get a table.`
cmd.Long = `Get a table.
Gets a table from the metastore for a specific catalog and schema. The caller
must satisfy one of the following requirements: * Be a metastore admin * Be
the owner of the parent catalog * Be the owner of the parent schema and have
the **USE_CATALOG** privilege on the parent catalog * Have the **USE_CATALOG**
privilege on the parent catalog and the **USE_SCHEMA** privilege on the parent
schema, and either be the table owner or have the **SELECT** privilege on the
table.
Arguments:
FULL_NAME: Full name of the table.`
cmd.Annotations = make(map[string]string)
cmd.Annotations["launch_stage"] = "GA"
cmd.Annotations["launch_stage_display"] = "GA"
cmd.Args = func(cmd *cobra.Command, args []string) error {
check := root.ExactArgs(1)
return check(cmd, args)
}
cmd.PreRunE = root.MustWorkspaceClient
cmd.RunE = func(cmd *cobra.Command, args []string) (err error) {
ctx := cmd.Context()
w := cmdctx.WorkspaceClient(ctx)
getReq.FullName = args[0]
response, err := w.Tables.Get(ctx, getReq)
if err != nil {
return err
}
return cmdio.Render(ctx, response)
}
// Disable completions since they are not applicable.
// Can be overridden by manual implementation in `override.go`.
cmd.ValidArgsFunction = cobra.NoFileCompletions
// Apply optional overrides to this command.
for _, fn := range getOverrides {
fn(cmd, &getReq)
}
return cmd
}
// start list command
// Slice with functions to override default command behavior.
// Functions can be added from the `init()` function in manually curated files in this directory.
var listOverrides []func(
*cobra.Command,
*catalog.ListTablesRequest,
)
func newList() *cobra.Command {
cmd := &cobra.Command{}
var listReq catalog.ListTablesRequest
// Registered for all paginated methods. Validated at call time in the
// method-call template. Paginated list methods never have Wait or LRO
// branches, so the method-call path is always reached.
var listLimit int
cmd.Flags().BoolVar(&listReq.IncludeBrowse, "include-browse", listReq.IncludeBrowse, `Whether to include tables in the response for which the principal can only access selective metadata for.`)
cmd.Flags().BoolVar(&listReq.IncludeManifestCapabilities, "include-manifest-capabilities", listReq.IncludeManifestCapabilities, `Whether to include a manifest containing table capabilities in the response.`)
cmd.Flags().BoolVar(&listReq.OmitColumns, "omit-columns", listReq.OmitColumns, `Whether to omit the columns of the table from the response or not.`)
cmd.Flags().BoolVar(&listReq.OmitProperties, "omit-properties", listReq.OmitProperties, `Whether to omit the properties of the table from the response or not.`)
cmd.Flags().BoolVar(&listReq.OmitUsername, "omit-username", listReq.OmitUsername, `Whether to omit the username of the table (e.g.`)
// Limit flag for total result capping.
cmd.Flags().IntVar(&listLimit, "limit", 0, `Maximum number of results to return.`)
// Hidden pagination flags (internal API parameters).
cmd.Flags().StringVar(&listReq.PageToken, "page-token", listReq.PageToken, `Pagination token.`)
cmd.Flags().Lookup("page-token").Hidden = true
cmd.Flags().IntVar(&listReq.MaxResults, "max-results", listReq.MaxResults, `Maximum number of tables to return.`)
cmd.Flags().Lookup("max-results").Hidden = true
cmd.Use = "list CATALOG_NAME SCHEMA_NAME"
cmd.Short = `List tables.`
cmd.Long = `List tables.
Gets an array of all tables for the current metastore under the parent catalog
and schema. The caller must be a metastore admin or an owner of (or have the
**SELECT** privilege on) the table. For the latter case, the caller must also
be the owner or have the **USE_CATALOG** privilege on the parent catalog and
the **USE_SCHEMA** privilege on the parent schema. There is no guarantee of a
specific ordering of the elements in the array.
NOTE: **view_dependencies** and **table_constraints** are not returned by
ListTables queries.
NOTE: we recommend using max_results=0 to use the paginated version of this
API. Unpaginated calls will be deprecated soon.
PAGINATION BEHAVIOR: When using pagination (max_results >= 0), a page may
contain zero results while still providing a next_page_token. Clients must
continue reading pages until next_page_token is absent, which is the only
indication that the end of results has been reached.
Arguments:
CATALOG_NAME: Name of parent catalog for tables of interest.
SCHEMA_NAME: Parent schema of tables.`
cmd.Annotations = make(map[string]string)
cmd.Annotations["launch_stage"] = "GA"
cmd.Annotations["launch_stage_display"] = "GA"
cmd.Args = func(cmd *cobra.Command, args []string) error {
check := root.ExactArgs(2)
return check(cmd, args)
}
cmd.PreRunE = root.MustWorkspaceClient
cmd.RunE = func(cmd *cobra.Command, args []string) (err error) {
ctx := cmd.Context()
w := cmdctx.WorkspaceClient(ctx)
listReq.CatalogName = args[0]
listReq.SchemaName = args[1]
response := w.Tables.List(ctx, listReq)
if listLimit < 0 {
return fmt.Errorf("--limit must be a non-negative integer, got %d", listLimit)
}
if listLimit > 0 {
ctx = cmdio.WithLimit(ctx, listLimit)
}
return cmdio.RenderIterator(ctx, response)
}
// Disable completions since they are not applicable.
// Can be overridden by manual implementation in `override.go`.
cmd.ValidArgsFunction = cobra.NoFileCompletions
// Apply optional overrides to this command.
for _, fn := range listOverrides {
fn(cmd, &listReq)
}
return cmd
}
// start list-summaries command
// Slice with functions to override default command behavior.
// Functions can be added from the `init()` function in manually curated files in this directory.
var listSummariesOverrides []func(
*cobra.Command,
*catalog.ListSummariesRequest,
)
func newListSummaries() *cobra.Command {
cmd := &cobra.Command{}
var listSummariesReq catalog.ListSummariesRequest
// Registered for all paginated methods. Validated at call time in the
// method-call template. Paginated list methods never have Wait or LRO
// branches, so the method-call path is always reached.
var listSummariesLimit int
cmd.Flags().BoolVar(&listSummariesReq.IncludeManifestCapabilities, "include-manifest-capabilities", listSummariesReq.IncludeManifestCapabilities, `Whether to include a manifest containing table capabilities in the response.`)
cmd.Flags().IntVar(&listSummariesReq.MaxResults, "max-results", listSummariesReq.MaxResults, `Maximum number of summaries for tables to return.`)
cmd.Flags().StringVar(&listSummariesReq.SchemaNamePattern, "schema-name-pattern", listSummariesReq.SchemaNamePattern, `A sql LIKE pattern (% and _) for schema names.`)
cmd.Flags().StringVar(&listSummariesReq.TableNamePattern, "table-name-pattern", listSummariesReq.TableNamePattern, `A sql LIKE pattern (% and _) for table names.`)
// Limit flag for total result capping.
cmd.Flags().IntVar(&listSummariesLimit, "limit", 0, `Maximum number of results to return.`)
// Hidden pagination flags (internal API parameters).
cmd.Flags().StringVar(&listSummariesReq.PageToken, "page-token", listSummariesReq.PageToken, `Pagination token.`)
cmd.Flags().Lookup("page-token").Hidden = true
cmd.Use = "list-summaries CATALOG_NAME"
cmd.Short = `List table summaries.`
cmd.Long = `List table summaries.
Gets an array of summaries for tables for a schema and catalog within the
metastore. The table summaries returned are either:
* summaries for tables (within the current metastore and parent catalog and
schema), when the user is a metastore admin, or: * summaries for tables and
schemas (within the current metastore and parent catalog) for which the user
has ownership or the **SELECT** privilege on the table and ownership or
**USE_SCHEMA** privilege on the schema, provided that the user also has
ownership or the **USE_CATALOG** privilege on the parent catalog.
There is no guarantee of a specific ordering of the elements in the array.
PAGINATION BEHAVIOR: The API is by default paginated, a page may contain zero
results while still providing a next_page_token. Clients must continue reading
pages until next_page_token is absent, which is the only indication that the
end of results has been reached.
Arguments:
CATALOG_NAME: Name of parent catalog for tables of interest.`
cmd.Annotations = make(map[string]string)
cmd.Annotations["launch_stage"] = "GA"
cmd.Annotations["launch_stage_display"] = "GA"
cmd.Args = func(cmd *cobra.Command, args []string) error {
check := root.ExactArgs(1)
return check(cmd, args)
}
cmd.PreRunE = root.MustWorkspaceClient
cmd.RunE = func(cmd *cobra.Command, args []string) (err error) {
ctx := cmd.Context()
w := cmdctx.WorkspaceClient(ctx)
listSummariesReq.CatalogName = args[0]
response := w.Tables.ListSummaries(ctx, listSummariesReq)
if listSummariesLimit < 0 {
return fmt.Errorf("--limit must be a non-negative integer, got %d", listSummariesLimit)
}
if listSummariesLimit > 0 {
ctx = cmdio.WithLimit(ctx, listSummariesLimit)
}
return cmdio.RenderIterator(ctx, response)
}
// Disable completions since they are not applicable.
// Can be overridden by manual implementation in `override.go`.
cmd.ValidArgsFunction = cobra.NoFileCompletions
// Apply optional overrides to this command.
for _, fn := range listSummariesOverrides {
fn(cmd, &listSummariesReq)
}
return cmd
}
// start update command
// Slice with functions to override default command behavior.
// Functions can be added from the `init()` function in manually curated files in this directory.
var updateOverrides []func(
*cobra.Command,
*catalog.UpdateTableRequest,
)
func newUpdate() *cobra.Command {
cmd := &cobra.Command{}
var updateReq catalog.UpdateTableRequest
var updateJson flags.JsonFlag
cmd.Flags().Var(&updateJson, "json", `either inline JSON string or @path/to/file.json with request body`)
cmd.Flags().StringVar(&updateReq.Owner, "owner", updateReq.Owner, `Username of current owner of table.`)
cmd.Use = "update FULL_NAME"
cmd.Short = `Update a table owner.`
cmd.Long = `Update a table owner.
Change the owner of the table. The caller must be the owner of the parent
catalog, have the **USE_CATALOG** privilege on the parent catalog and be the
owner of the parent schema, or be the owner of the table and have the
**USE_CATALOG** privilege on the parent catalog and the **USE_SCHEMA**
privilege on the parent schema.
Arguments:
FULL_NAME: Full name of the table.`
// This command is being previewed; hide from help output.
cmd.Hidden = true
cmd.Annotations = make(map[string]string)
cmd.Annotations["launch_stage"] = "PRIVATE_PREVIEW"
cmd.Annotations["launch_stage_display"] = "Private Preview"
cmd.Args = func(cmd *cobra.Command, args []string) error {
check := root.ExactArgs(1)
return check(cmd, args)
}
cmd.PreRunE = root.MustWorkspaceClient
cmd.RunE = func(cmd *cobra.Command, args []string) (err error) {
ctx := cmd.Context()
w := cmdctx.WorkspaceClient(ctx)
if cmd.Flags().Changed("json") {
diags := updateJson.Unmarshal(&updateReq)
if diags.HasError() {
return diags.Error()
}
if len(diags) > 0 {
err := cmdio.RenderDiagnostics(ctx, diags)
if err != nil {
return err
}
}
}
updateReq.FullName = args[0]
err = w.Tables.Update(ctx, updateReq)
if err != nil {
return err
}
return nil
}
// Disable completions since they are not applicable.
// Can be overridden by manual implementation in `override.go`.
cmd.ValidArgsFunction = cobra.NoFileCompletions
// Apply optional overrides to this command.
for _, fn := range updateOverrides {
fn(cmd, &updateReq)
}
return cmd
}
// end service Tables