-
Notifications
You must be signed in to change notification settings - Fork 68
Expand file tree
/
Copy pathapi.go
More file actions
executable file
·1968 lines (1754 loc) · 79.2 KB
/
api.go
File metadata and controls
executable file
·1968 lines (1754 loc) · 79.2 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
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
// Code generated from OpenAPI specs by Databricks SDK Generator. DO NOT EDIT.
// These APIs allow you to manage Alerts, Alerts Legacy, Alerts V2, Dashboard Widgets, Dashboards, Data Sources, Dbsql Permissions, Queries, Queries Legacy, Query History, Query Visualizations, Query Visualizations Legacy, Redash Config, Statement Execution, Warehouses, etc.
package sql
import (
"context"
"fmt"
"time"
"github.com/databricks/databricks-sdk-go/client"
"github.com/databricks/databricks-sdk-go/listing"
"github.com/databricks/databricks-sdk-go/retries"
"github.com/databricks/databricks-sdk-go/useragent"
)
type AlertsInterface interface {
// Creates an alert.
Create(ctx context.Context, request CreateAlertRequest) (*Alert, error)
// Moves an alert to the trash. Trashed alerts immediately disappear from
// searches and list views, and can no longer trigger. You can restore a trashed
// alert through the UI. A trashed alert is permanently deleted after 30 days.
Delete(ctx context.Context, request TrashAlertRequest) error
// Moves an alert to the trash. Trashed alerts immediately disappear from
// searches and list views, and can no longer trigger. You can restore a trashed
// alert through the UI. A trashed alert is permanently deleted after 30 days.
DeleteById(ctx context.Context, id string) error
// Gets an alert.
Get(ctx context.Context, request GetAlertRequest) (*Alert, error)
// Gets an alert.
GetById(ctx context.Context, id string) (*Alert, error)
// Gets a list of alerts accessible to the user, ordered by creation time.
// **Warning:** Calling this API concurrently 10 or more times could result in
// throttling, service degradation, or a temporary ban.
//
// This method is generated by Databricks SDK Code Generator.
List(ctx context.Context, request ListAlertsRequest) listing.Iterator[ListAlertsResponseAlert]
// Gets a list of alerts accessible to the user, ordered by creation time.
// **Warning:** Calling this API concurrently 10 or more times could result in
// throttling, service degradation, or a temporary ban.
//
// This method is generated by Databricks SDK Code Generator.
ListAll(ctx context.Context, request ListAlertsRequest) ([]ListAlertsResponseAlert, error)
// ListAlertsResponseAlertDisplayNameToIdMap calls [AlertsAPI.ListAll] and creates a map of results with [ListAlertsResponseAlert].DisplayName as key and [ListAlertsResponseAlert].Id as value.
//
// Returns an error if there's more than one [ListAlertsResponseAlert] with the same .DisplayName.
//
// Note: All [ListAlertsResponseAlert] instances are loaded into memory before creating a map.
//
// This method is generated by Databricks SDK Code Generator.
ListAlertsResponseAlertDisplayNameToIdMap(ctx context.Context, request ListAlertsRequest) (map[string]string, error)
// GetByDisplayName calls [AlertsAPI.ListAlertsResponseAlertDisplayNameToIdMap] and returns a single [ListAlertsResponseAlert].
//
// Returns an error if there's more than one [ListAlertsResponseAlert] with the same .DisplayName.
//
// Note: All [ListAlertsResponseAlert] instances are loaded into memory before returning matching by name.
//
// This method is generated by Databricks SDK Code Generator.
GetByDisplayName(ctx context.Context, name string) (*ListAlertsResponseAlert, error)
// Updates an alert.
Update(ctx context.Context, request UpdateAlertRequest) (*Alert, error)
}
func NewAlerts(client *client.DatabricksClient) *AlertsAPI {
return &AlertsAPI{
alertsImpl: alertsImpl{
client: client,
},
}
}
// The alerts API can be used to perform CRUD operations on alerts. An alert is
// a Databricks SQL object that periodically runs a query, evaluates a condition
// of its result, and notifies one or more users and/or notification
// destinations if the condition was met. Alerts can be scheduled using the
// `sql_task` type of the Jobs API, e.g. :method:jobs/create.
type AlertsAPI struct {
alertsImpl
}
// Moves an alert to the trash. Trashed alerts immediately disappear from
// searches and list views, and can no longer trigger. You can restore a trashed
// alert through the UI. A trashed alert is permanently deleted after 30 days.
func (a *AlertsAPI) DeleteById(ctx context.Context, id string) error {
return a.alertsImpl.Delete(ctx, TrashAlertRequest{
Id: id,
})
}
// Gets an alert.
func (a *AlertsAPI) GetById(ctx context.Context, id string) (*Alert, error) {
return a.alertsImpl.Get(ctx, GetAlertRequest{
Id: id,
})
}
// ListAlertsResponseAlertDisplayNameToIdMap calls [AlertsAPI.ListAll] and creates a map of results with [ListAlertsResponseAlert].DisplayName as key and [ListAlertsResponseAlert].Id as value.
//
// Returns an error if there's more than one [ListAlertsResponseAlert] with the same .DisplayName.
//
// Note: All [ListAlertsResponseAlert] instances are loaded into memory before creating a map.
//
// This method is generated by Databricks SDK Code Generator.
func (a *AlertsAPI) ListAlertsResponseAlertDisplayNameToIdMap(ctx context.Context, request ListAlertsRequest) (map[string]string, error) {
ctx = useragent.InContext(ctx, "sdk-feature", "name-to-id")
mapping := map[string]string{}
result, err := a.ListAll(ctx, request)
if err != nil {
return nil, err
}
for _, v := range result {
key := v.DisplayName
_, duplicate := mapping[key]
if duplicate {
return nil, fmt.Errorf("duplicate .DisplayName: %s", key)
}
mapping[key] = v.Id
}
return mapping, nil
}
// GetByDisplayName calls [AlertsAPI.ListAlertsResponseAlertDisplayNameToIdMap] and returns a single [ListAlertsResponseAlert].
//
// Returns an error if there's more than one [ListAlertsResponseAlert] with the same .DisplayName.
//
// Note: All [ListAlertsResponseAlert] instances are loaded into memory before returning matching by name.
//
// This method is generated by Databricks SDK Code Generator.
func (a *AlertsAPI) GetByDisplayName(ctx context.Context, name string) (*ListAlertsResponseAlert, error) {
ctx = useragent.InContext(ctx, "sdk-feature", "get-by-name")
result, err := a.ListAll(ctx, ListAlertsRequest{})
if err != nil {
return nil, err
}
tmp := map[string][]ListAlertsResponseAlert{}
for _, v := range result {
key := v.DisplayName
tmp[key] = append(tmp[key], v)
}
alternatives, ok := tmp[name]
if !ok || len(alternatives) == 0 {
return nil, fmt.Errorf("ListAlertsResponseAlert named '%s' does not exist", name)
}
if len(alternatives) > 1 {
return nil, fmt.Errorf("there are %d instances of ListAlertsResponseAlert named '%s'", len(alternatives), name)
}
return &alternatives[0], nil
}
type AlertsLegacyInterface interface {
// Creates an alert. An alert is a Databricks SQL object that periodically runs
// a query, evaluates a condition of its result, and notifies users or
// notification destinations if the condition was met.
//
// **Warning**: This API is deprecated. Please use :method:alerts/create
// instead. [Learn more]
//
// [Learn more]: https://docs.databricks.com/en/sql/dbsql-api-latest.html
Create(ctx context.Context, request CreateAlert) (*LegacyAlert, error)
// Deletes an alert. Deleted alerts are no longer accessible and cannot be
// restored. **Note**: Unlike queries and dashboards, alerts cannot be moved to
// the trash.
//
// **Warning**: This API is deprecated. Please use :method:alerts/delete
// instead. [Learn more]
//
// [Learn more]: https://docs.databricks.com/en/sql/dbsql-api-latest.html
Delete(ctx context.Context, request DeleteAlertsLegacyRequest) error
// Deletes an alert. Deleted alerts are no longer accessible and cannot be
// restored. **Note**: Unlike queries and dashboards, alerts cannot be moved to
// the trash.
//
// **Warning**: This API is deprecated. Please use :method:alerts/delete
// instead. [Learn more]
//
// [Learn more]: https://docs.databricks.com/en/sql/dbsql-api-latest.html
DeleteByAlertId(ctx context.Context, alertId string) error
// Gets an alert.
//
// **Warning**: This API is deprecated. Please use :method:alerts/get instead.
// [Learn more]
//
// [Learn more]: https://docs.databricks.com/en/sql/dbsql-api-latest.html
Get(ctx context.Context, request GetAlertsLegacyRequest) (*LegacyAlert, error)
// Gets an alert.
//
// **Warning**: This API is deprecated. Please use :method:alerts/get instead.
// [Learn more]
//
// [Learn more]: https://docs.databricks.com/en/sql/dbsql-api-latest.html
GetByAlertId(ctx context.Context, alertId string) (*LegacyAlert, error)
// Gets a list of alerts.
//
// **Warning**: This API is deprecated. Please use :method:alerts/list instead.
// [Learn more]
//
// [Learn more]: https://docs.databricks.com/en/sql/dbsql-api-latest.html
List(ctx context.Context) ([]LegacyAlert, error)
// Updates an alert.
//
// **Warning**: This API is deprecated. Please use :method:alerts/update
// instead. [Learn more]
//
// [Learn more]: https://docs.databricks.com/en/sql/dbsql-api-latest.html
Update(ctx context.Context, request EditAlert) error
}
func NewAlertsLegacy(client *client.DatabricksClient) *AlertsLegacyAPI {
return &AlertsLegacyAPI{
alertsLegacyImpl: alertsLegacyImpl{
client: client,
},
}
}
// The alerts API can be used to perform CRUD operations on alerts. An alert is
// a Databricks SQL object that periodically runs a query, evaluates a condition
// of its result, and notifies one or more users and/or notification
// destinations if the condition was met. Alerts can be scheduled using the
// `sql_task` type of the Jobs API, e.g. :method:jobs/create.
//
// **Warning**: This API is deprecated. Please see the latest version of the
// Databricks SQL API. [Learn more]
//
// [Learn more]: https://docs.databricks.com/en/sql/dbsql-api-latest.html
type AlertsLegacyAPI struct {
alertsLegacyImpl
}
// Deletes an alert. Deleted alerts are no longer accessible and cannot be
// restored. **Note**: Unlike queries and dashboards, alerts cannot be moved to
// the trash.
//
// **Warning**: This API is deprecated. Please use :method:alerts/delete
// instead. [Learn more]
//
// [Learn more]: https://docs.databricks.com/en/sql/dbsql-api-latest.html
func (a *AlertsLegacyAPI) DeleteByAlertId(ctx context.Context, alertId string) error {
return a.alertsLegacyImpl.Delete(ctx, DeleteAlertsLegacyRequest{
AlertId: alertId,
})
}
// Gets an alert.
//
// **Warning**: This API is deprecated. Please use :method:alerts/get instead.
// [Learn more]
//
// [Learn more]: https://docs.databricks.com/en/sql/dbsql-api-latest.html
func (a *AlertsLegacyAPI) GetByAlertId(ctx context.Context, alertId string) (*LegacyAlert, error) {
return a.alertsLegacyImpl.Get(ctx, GetAlertsLegacyRequest{
AlertId: alertId,
})
}
type AlertsV2Interface interface {
// Create Alert
CreateAlert(ctx context.Context, request CreateAlertV2Request) (*AlertV2, error)
// Gets an alert.
GetAlert(ctx context.Context, request GetAlertV2Request) (*AlertV2, error)
// Gets an alert.
GetAlertById(ctx context.Context, id string) (*AlertV2, error)
// Gets a list of alerts accessible to the user, ordered by creation time.
//
// This method is generated by Databricks SDK Code Generator.
ListAlerts(ctx context.Context, request ListAlertsV2Request) listing.Iterator[AlertV2]
// Gets a list of alerts accessible to the user, ordered by creation time.
//
// This method is generated by Databricks SDK Code Generator.
ListAlertsAll(ctx context.Context, request ListAlertsV2Request) ([]AlertV2, error)
// AlertV2DisplayNameToIdMap calls [AlertsV2API.ListAlertsAll] and creates a map of results with [AlertV2].DisplayName as key and [AlertV2].Id as value.
//
// Returns an error if there's more than one [AlertV2] with the same .DisplayName.
//
// Note: All [AlertV2] instances are loaded into memory before creating a map.
//
// This method is generated by Databricks SDK Code Generator.
AlertV2DisplayNameToIdMap(ctx context.Context, request ListAlertsV2Request) (map[string]string, error)
// GetByDisplayName calls [AlertsV2API.AlertV2DisplayNameToIdMap] and returns a single [AlertV2].
//
// Returns an error if there's more than one [AlertV2] with the same .DisplayName.
//
// Note: All [AlertV2] instances are loaded into memory before returning matching by name.
//
// This method is generated by Databricks SDK Code Generator.
GetByDisplayName(ctx context.Context, name string) (*AlertV2, error)
// Moves an alert to the trash. Trashed alerts immediately disappear from list
// views, and can no longer trigger. You can restore a trashed alert through the
// UI. A trashed alert is permanently deleted after 30 days.
TrashAlert(ctx context.Context, request TrashAlertV2Request) error
// Moves an alert to the trash. Trashed alerts immediately disappear from list
// views, and can no longer trigger. You can restore a trashed alert through the
// UI. A trashed alert is permanently deleted after 30 days.
TrashAlertById(ctx context.Context, id string) error
// Update alert
UpdateAlert(ctx context.Context, request UpdateAlertV2Request) (*AlertV2, error)
}
func NewAlertsV2(client *client.DatabricksClient) *AlertsV2API {
return &AlertsV2API{
alertsV2Impl: alertsV2Impl{
client: client,
},
}
}
// New version of SQL Alerts
type AlertsV2API struct {
alertsV2Impl
}
// Gets an alert.
func (a *AlertsV2API) GetAlertById(ctx context.Context, id string) (*AlertV2, error) {
return a.alertsV2Impl.GetAlert(ctx, GetAlertV2Request{
Id: id,
})
}
// AlertV2DisplayNameToIdMap calls [AlertsV2API.ListAlertsAll] and creates a map of results with [AlertV2].DisplayName as key and [AlertV2].Id as value.
//
// Returns an error if there's more than one [AlertV2] with the same .DisplayName.
//
// Note: All [AlertV2] instances are loaded into memory before creating a map.
//
// This method is generated by Databricks SDK Code Generator.
func (a *AlertsV2API) AlertV2DisplayNameToIdMap(ctx context.Context, request ListAlertsV2Request) (map[string]string, error) {
ctx = useragent.InContext(ctx, "sdk-feature", "name-to-id")
mapping := map[string]string{}
result, err := a.ListAlertsAll(ctx, request)
if err != nil {
return nil, err
}
for _, v := range result {
key := v.DisplayName
_, duplicate := mapping[key]
if duplicate {
return nil, fmt.Errorf("duplicate .DisplayName: %s", key)
}
mapping[key] = v.Id
}
return mapping, nil
}
// GetByDisplayName calls [AlertsV2API.AlertV2DisplayNameToIdMap] and returns a single [AlertV2].
//
// Returns an error if there's more than one [AlertV2] with the same .DisplayName.
//
// Note: All [AlertV2] instances are loaded into memory before returning matching by name.
//
// This method is generated by Databricks SDK Code Generator.
func (a *AlertsV2API) GetByDisplayName(ctx context.Context, name string) (*AlertV2, error) {
ctx = useragent.InContext(ctx, "sdk-feature", "get-by-name")
result, err := a.ListAlertsAll(ctx, ListAlertsV2Request{})
if err != nil {
return nil, err
}
tmp := map[string][]AlertV2{}
for _, v := range result {
key := v.DisplayName
tmp[key] = append(tmp[key], v)
}
alternatives, ok := tmp[name]
if !ok || len(alternatives) == 0 {
return nil, fmt.Errorf("AlertV2 named '%s' does not exist", name)
}
if len(alternatives) > 1 {
return nil, fmt.Errorf("there are %d instances of AlertV2 named '%s'", len(alternatives), name)
}
return &alternatives[0], nil
}
// Moves an alert to the trash. Trashed alerts immediately disappear from list
// views, and can no longer trigger. You can restore a trashed alert through the
// UI. A trashed alert is permanently deleted after 30 days.
func (a *AlertsV2API) TrashAlertById(ctx context.Context, id string) error {
return a.alertsV2Impl.TrashAlert(ctx, TrashAlertV2Request{
Id: id,
})
}
type DashboardWidgetsInterface interface {
// Adds a widget to a dashboard
Create(ctx context.Context, request CreateWidget) (*Widget, error)
// Removes a widget from a dashboard
Delete(ctx context.Context, request DeleteDashboardWidgetRequest) error
// Removes a widget from a dashboard
DeleteById(ctx context.Context, id string) error
// Updates an existing widget
Update(ctx context.Context, request UpdateWidgetRequest) (*Widget, error)
}
func NewDashboardWidgets(client *client.DatabricksClient) *DashboardWidgetsAPI {
return &DashboardWidgetsAPI{
dashboardWidgetsImpl: dashboardWidgetsImpl{
client: client,
},
}
}
// This is an evolving API that facilitates the addition and removal of widgets
// from existing dashboards within the Databricks Workspace. Data structures may
// change over time.
type DashboardWidgetsAPI struct {
dashboardWidgetsImpl
}
// Removes a widget from a dashboard
func (a *DashboardWidgetsAPI) DeleteById(ctx context.Context, id string) error {
return a.dashboardWidgetsImpl.Delete(ctx, DeleteDashboardWidgetRequest{
Id: id,
})
}
type DashboardsInterface interface {
// Moves a dashboard to the trash. Trashed dashboards do not appear in list
// views or searches, and cannot be shared.
//
// **Warning**: This API is deprecated. Please use the AI/BI Dashboards API
// instead. [Learn more]
//
// [Learn more]: https://docs.databricks.com/en/dashboards/
Delete(ctx context.Context, request DeleteDashboardRequest) error
// Moves a dashboard to the trash. Trashed dashboards do not appear in list
// views or searches, and cannot be shared.
//
// **Warning**: This API is deprecated. Please use the AI/BI Dashboards API
// instead. [Learn more]
//
// [Learn more]: https://docs.databricks.com/en/dashboards/
DeleteByDashboardId(ctx context.Context, dashboardId string) error
// Returns a JSON representation of a dashboard object, including its
// visualization and query objects.
//
// **Warning**: This API is deprecated. Please use the AI/BI Dashboards API
// instead. [Learn more]
//
// [Learn more]: https://docs.databricks.com/en/dashboards/
Get(ctx context.Context, request GetDashboardRequest) (*Dashboard, error)
// Returns a JSON representation of a dashboard object, including its
// visualization and query objects.
//
// **Warning**: This API is deprecated. Please use the AI/BI Dashboards API
// instead. [Learn more]
//
// [Learn more]: https://docs.databricks.com/en/dashboards/
GetByDashboardId(ctx context.Context, dashboardId string) (*Dashboard, error)
// Fetch a paginated list of dashboard objects.
//
// **Warning**: Calling this API concurrently 10 or more times could result in
// throttling, service degradation, or a temporary ban.
//
// **Warning**: This API is deprecated. Please use the AI/BI Dashboards API
// instead. [Learn more]
//
// [Learn more]: https://docs.databricks.com/en/dashboards/
//
// This method is generated by Databricks SDK Code Generator.
List(ctx context.Context, request ListDashboardsRequest) listing.Iterator[Dashboard]
// Fetch a paginated list of dashboard objects.
//
// **Warning**: Calling this API concurrently 10 or more times could result in
// throttling, service degradation, or a temporary ban.
//
// **Warning**: This API is deprecated. Please use the AI/BI Dashboards API
// instead. [Learn more]
//
// [Learn more]: https://docs.databricks.com/en/dashboards/
//
// This method is generated by Databricks SDK Code Generator.
ListAll(ctx context.Context, request ListDashboardsRequest) ([]Dashboard, error)
// A restored dashboard appears in list views and searches and can be shared.
//
// **Warning**: This API is deprecated. Please use the AI/BI Dashboards API
// instead. [Learn more]
//
// [Learn more]: https://docs.databricks.com/en/dashboards/
Restore(ctx context.Context, request RestoreDashboardRequest) error
// Modify this dashboard definition. This operation only affects attributes of
// the dashboard object. It does not add, modify, or remove widgets.
//
// **Note**: You cannot undo this operation.
//
// **Warning**: This API is deprecated. Please use the AI/BI Dashboards API
// instead. [Learn more]
//
// [Learn more]: https://docs.databricks.com/en/dashboards/
Update(ctx context.Context, request DashboardEditContent) (*Dashboard, error)
}
func NewDashboards(client *client.DatabricksClient) *DashboardsAPI {
return &DashboardsAPI{
dashboardsImpl: dashboardsImpl{
client: client,
},
}
}
// In general, there is little need to modify dashboards using the API. However,
// it can be useful to use dashboard objects to look-up a collection of related
// query IDs. The API can also be used to duplicate multiple dashboards at once
// since you can get a dashboard definition with a GET request and then POST it
// to create a new one. Dashboards can be scheduled using the `sql_task` type of
// the Jobs API, e.g. :method:jobs/create.
//
// **Warning**: This API is deprecated. Please use the AI/BI Dashboards API
// instead. [Learn more]
//
// [Learn more]: https://docs.databricks.com/en/dashboards/
type DashboardsAPI struct {
dashboardsImpl
}
// Moves a dashboard to the trash. Trashed dashboards do not appear in list
// views or searches, and cannot be shared.
//
// **Warning**: This API is deprecated. Please use the AI/BI Dashboards API
// instead. [Learn more]
//
// [Learn more]: https://docs.databricks.com/en/dashboards/
func (a *DashboardsAPI) DeleteByDashboardId(ctx context.Context, dashboardId string) error {
return a.dashboardsImpl.Delete(ctx, DeleteDashboardRequest{
DashboardId: dashboardId,
})
}
// Returns a JSON representation of a dashboard object, including its
// visualization and query objects.
//
// **Warning**: This API is deprecated. Please use the AI/BI Dashboards API
// instead. [Learn more]
//
// [Learn more]: https://docs.databricks.com/en/dashboards/
func (a *DashboardsAPI) GetByDashboardId(ctx context.Context, dashboardId string) (*Dashboard, error) {
return a.dashboardsImpl.Get(ctx, GetDashboardRequest{
DashboardId: dashboardId,
})
}
type DataSourcesInterface interface {
// Retrieves a full list of SQL warehouses available in this workspace. All
// fields that appear in this API response are enumerated for clarity. However,
// you need only a SQL warehouse's `id` to create new queries against it.
//
// **Warning**: This API is deprecated. Please use :method:warehouses/list
// instead. [Learn more]
//
// [Learn more]: https://docs.databricks.com/en/sql/dbsql-api-latest.html
List(ctx context.Context) ([]DataSource, error)
}
func NewDataSources(client *client.DatabricksClient) *DataSourcesAPI {
return &DataSourcesAPI{
dataSourcesImpl: dataSourcesImpl{
client: client,
},
}
}
// This API is provided to assist you in making new query objects. When creating
// a query object, you may optionally specify a `data_source_id` for the SQL
// warehouse against which it will run. If you don't already know the
// `data_source_id` for your desired SQL warehouse, this API will help you find
// it.
//
// This API does not support searches. It returns the full list of SQL
// warehouses in your workspace. We advise you to use any text editor, REST
// client, or `grep` to search the response from this API for the name of your
// SQL warehouse as it appears in Databricks SQL.
//
// **Warning**: This API is deprecated. Please see the latest version of the
// Databricks SQL API. [Learn more]
//
// [Learn more]: https://docs.databricks.com/en/sql/dbsql-api-latest.html
type DataSourcesAPI struct {
dataSourcesImpl
}
type DbsqlPermissionsInterface interface {
// Gets a JSON representation of the access control list (ACL) for a specified
// object.
//
// **Warning**: This API is deprecated. Please use
// :method:workspace/getpermissions instead. [Learn more]
//
// [Learn more]: https://docs.databricks.com/en/sql/dbsql-api-latest.html
Get(ctx context.Context, request GetDbsqlPermissionRequest) (*GetResponse, error)
// Gets a JSON representation of the access control list (ACL) for a specified
// object.
//
// **Warning**: This API is deprecated. Please use
// :method:workspace/getpermissions instead. [Learn more]
//
// [Learn more]: https://docs.databricks.com/en/sql/dbsql-api-latest.html
GetByObjectTypeAndObjectId(ctx context.Context, objectType ObjectTypePlural, objectId string) (*GetResponse, error)
// Sets the access control list (ACL) for a specified object. This operation
// will complete rewrite the ACL.
//
// **Warning**: This API is deprecated. Please use
// :method:workspace/setpermissions instead. [Learn more]
//
// [Learn more]: https://docs.databricks.com/en/sql/dbsql-api-latest.html
Set(ctx context.Context, request SetRequest) (*SetResponse, error)
// Transfers ownership of a dashboard, query, or alert to an active user.
// Requires an admin API key.
//
// **Warning**: This API is deprecated. For queries and alerts, please use
// :method:queries/update and :method:alerts/update respectively instead. [Learn
// more]
//
// [Learn more]: https://docs.databricks.com/en/sql/dbsql-api-latest.html
TransferOwnership(ctx context.Context, request TransferOwnershipRequest) (*Success, error)
}
func NewDbsqlPermissions(client *client.DatabricksClient) *DbsqlPermissionsAPI {
return &DbsqlPermissionsAPI{
dbsqlPermissionsImpl: dbsqlPermissionsImpl{
client: client,
},
}
}
// The SQL Permissions API is similar to the endpoints of the
// :method:permissions/set. However, this exposes only one endpoint, which gets
// the Access Control List for a given object. You cannot modify any permissions
// using this API.
//
// There are three levels of permission:
//
// - `CAN_VIEW`: Allows read-only access
//
// - `CAN_RUN`: Allows read access and run access (superset of `CAN_VIEW`)
//
// - `CAN_MANAGE`: Allows all actions: read, run, edit, delete, modify
// permissions (superset of `CAN_RUN`)
//
// **Warning**: This API is deprecated. Please see the latest version of the
// Databricks SQL API. [Learn more]
//
// [Learn more]: https://docs.databricks.com/en/sql/dbsql-api-latest.html
type DbsqlPermissionsAPI struct {
dbsqlPermissionsImpl
}
// Gets a JSON representation of the access control list (ACL) for a specified
// object.
//
// **Warning**: This API is deprecated. Please use
// :method:workspace/getpermissions instead. [Learn more]
//
// [Learn more]: https://docs.databricks.com/en/sql/dbsql-api-latest.html
func (a *DbsqlPermissionsAPI) GetByObjectTypeAndObjectId(ctx context.Context, objectType ObjectTypePlural, objectId string) (*GetResponse, error) {
return a.dbsqlPermissionsImpl.Get(ctx, GetDbsqlPermissionRequest{
ObjectType: objectType,
ObjectId: objectId,
})
}
type QueriesInterface interface {
// Creates a query.
Create(ctx context.Context, request CreateQueryRequest) (*Query, error)
// Moves a query to the trash. Trashed queries immediately disappear from
// searches and list views, and cannot be used for alerts. You can restore a
// trashed query through the UI. A trashed query is permanently deleted after 30
// days.
Delete(ctx context.Context, request TrashQueryRequest) error
// Moves a query to the trash. Trashed queries immediately disappear from
// searches and list views, and cannot be used for alerts. You can restore a
// trashed query through the UI. A trashed query is permanently deleted after 30
// days.
DeleteById(ctx context.Context, id string) error
// Gets a query.
Get(ctx context.Context, request GetQueryRequest) (*Query, error)
// Gets a query.
GetById(ctx context.Context, id string) (*Query, error)
// Gets a list of queries accessible to the user, ordered by creation time.
// **Warning:** Calling this API concurrently 10 or more times could result in
// throttling, service degradation, or a temporary ban.
//
// This method is generated by Databricks SDK Code Generator.
List(ctx context.Context, request ListQueriesRequest) listing.Iterator[ListQueryObjectsResponseQuery]
// Gets a list of queries accessible to the user, ordered by creation time.
// **Warning:** Calling this API concurrently 10 or more times could result in
// throttling, service degradation, or a temporary ban.
//
// This method is generated by Databricks SDK Code Generator.
ListAll(ctx context.Context, request ListQueriesRequest) ([]ListQueryObjectsResponseQuery, error)
// ListQueryObjectsResponseQueryDisplayNameToIdMap calls [QueriesAPI.ListAll] and creates a map of results with [ListQueryObjectsResponseQuery].DisplayName as key and [ListQueryObjectsResponseQuery].Id as value.
//
// Returns an error if there's more than one [ListQueryObjectsResponseQuery] with the same .DisplayName.
//
// Note: All [ListQueryObjectsResponseQuery] instances are loaded into memory before creating a map.
//
// This method is generated by Databricks SDK Code Generator.
ListQueryObjectsResponseQueryDisplayNameToIdMap(ctx context.Context, request ListQueriesRequest) (map[string]string, error)
// GetByDisplayName calls [QueriesAPI.ListQueryObjectsResponseQueryDisplayNameToIdMap] and returns a single [ListQueryObjectsResponseQuery].
//
// Returns an error if there's more than one [ListQueryObjectsResponseQuery] with the same .DisplayName.
//
// Note: All [ListQueryObjectsResponseQuery] instances are loaded into memory before returning matching by name.
//
// This method is generated by Databricks SDK Code Generator.
GetByDisplayName(ctx context.Context, name string) (*ListQueryObjectsResponseQuery, error)
// Gets a list of visualizations on a query.
//
// This method is generated by Databricks SDK Code Generator.
ListVisualizations(ctx context.Context, request ListVisualizationsForQueryRequest) listing.Iterator[Visualization]
// Gets a list of visualizations on a query.
//
// This method is generated by Databricks SDK Code Generator.
ListVisualizationsAll(ctx context.Context, request ListVisualizationsForQueryRequest) ([]Visualization, error)
// Gets a list of visualizations on a query.
ListVisualizationsById(ctx context.Context, id string) (*ListVisualizationsForQueryResponse, error)
// Updates a query.
Update(ctx context.Context, request UpdateQueryRequest) (*Query, error)
}
func NewQueries(client *client.DatabricksClient) *QueriesAPI {
return &QueriesAPI{
queriesImpl: queriesImpl{
client: client,
},
}
}
// The queries API can be used to perform CRUD operations on queries. A query is
// a Databricks SQL object that includes the target SQL warehouse, query text,
// name, description, tags, and parameters. Queries can be scheduled using the
// `sql_task` type of the Jobs API, e.g. :method:jobs/create.
type QueriesAPI struct {
queriesImpl
}
// Moves a query to the trash. Trashed queries immediately disappear from
// searches and list views, and cannot be used for alerts. You can restore a
// trashed query through the UI. A trashed query is permanently deleted after 30
// days.
func (a *QueriesAPI) DeleteById(ctx context.Context, id string) error {
return a.queriesImpl.Delete(ctx, TrashQueryRequest{
Id: id,
})
}
// Gets a query.
func (a *QueriesAPI) GetById(ctx context.Context, id string) (*Query, error) {
return a.queriesImpl.Get(ctx, GetQueryRequest{
Id: id,
})
}
// ListQueryObjectsResponseQueryDisplayNameToIdMap calls [QueriesAPI.ListAll] and creates a map of results with [ListQueryObjectsResponseQuery].DisplayName as key and [ListQueryObjectsResponseQuery].Id as value.
//
// Returns an error if there's more than one [ListQueryObjectsResponseQuery] with the same .DisplayName.
//
// Note: All [ListQueryObjectsResponseQuery] instances are loaded into memory before creating a map.
//
// This method is generated by Databricks SDK Code Generator.
func (a *QueriesAPI) ListQueryObjectsResponseQueryDisplayNameToIdMap(ctx context.Context, request ListQueriesRequest) (map[string]string, error) {
ctx = useragent.InContext(ctx, "sdk-feature", "name-to-id")
mapping := map[string]string{}
result, err := a.ListAll(ctx, request)
if err != nil {
return nil, err
}
for _, v := range result {
key := v.DisplayName
_, duplicate := mapping[key]
if duplicate {
return nil, fmt.Errorf("duplicate .DisplayName: %s", key)
}
mapping[key] = v.Id
}
return mapping, nil
}
// GetByDisplayName calls [QueriesAPI.ListQueryObjectsResponseQueryDisplayNameToIdMap] and returns a single [ListQueryObjectsResponseQuery].
//
// Returns an error if there's more than one [ListQueryObjectsResponseQuery] with the same .DisplayName.
//
// Note: All [ListQueryObjectsResponseQuery] instances are loaded into memory before returning matching by name.
//
// This method is generated by Databricks SDK Code Generator.
func (a *QueriesAPI) GetByDisplayName(ctx context.Context, name string) (*ListQueryObjectsResponseQuery, error) {
ctx = useragent.InContext(ctx, "sdk-feature", "get-by-name")
result, err := a.ListAll(ctx, ListQueriesRequest{})
if err != nil {
return nil, err
}
tmp := map[string][]ListQueryObjectsResponseQuery{}
for _, v := range result {
key := v.DisplayName
tmp[key] = append(tmp[key], v)
}
alternatives, ok := tmp[name]
if !ok || len(alternatives) == 0 {
return nil, fmt.Errorf("ListQueryObjectsResponseQuery named '%s' does not exist", name)
}
if len(alternatives) > 1 {
return nil, fmt.Errorf("there are %d instances of ListQueryObjectsResponseQuery named '%s'", len(alternatives), name)
}
return &alternatives[0], nil
}
// Gets a list of visualizations on a query.
func (a *QueriesAPI) ListVisualizationsById(ctx context.Context, id string) (*ListVisualizationsForQueryResponse, error) {
return a.queriesImpl.internalListVisualizations(ctx, ListVisualizationsForQueryRequest{
Id: id,
})
}
type QueriesLegacyInterface interface {
// Creates a new query definition. Queries created with this endpoint belong to
// the authenticated user making the request.
//
// The `data_source_id` field specifies the ID of the SQL warehouse to run this
// query against. You can use the Data Sources API to see a complete list of
// available SQL warehouses. Or you can copy the `data_source_id` from an
// existing query.
//
// **Note**: You cannot add a visualization until you create the query.
//
// **Warning**: This API is deprecated. Please use :method:queries/create
// instead. [Learn more]
//
// [Learn more]: https://docs.databricks.com/en/sql/dbsql-api-latest.html
Create(ctx context.Context, request QueryPostContent) (*LegacyQuery, error)
// Moves a query to the trash. Trashed queries immediately disappear from
// searches and list views, and they cannot be used for alerts. The trash is
// deleted after 30 days.
//
// **Warning**: This API is deprecated. Please use :method:queries/delete
// instead. [Learn more]
//
// [Learn more]: https://docs.databricks.com/en/sql/dbsql-api-latest.html
Delete(ctx context.Context, request DeleteQueriesLegacyRequest) error
// Moves a query to the trash. Trashed queries immediately disappear from
// searches and list views, and they cannot be used for alerts. The trash is
// deleted after 30 days.
//
// **Warning**: This API is deprecated. Please use :method:queries/delete
// instead. [Learn more]
//
// [Learn more]: https://docs.databricks.com/en/sql/dbsql-api-latest.html
DeleteByQueryId(ctx context.Context, queryId string) error
// Retrieve a query object definition along with contextual permissions
// information about the currently authenticated user.
//
// **Warning**: This API is deprecated. Please use :method:queries/get instead.
// [Learn more]
//
// [Learn more]: https://docs.databricks.com/en/sql/dbsql-api-latest.html
Get(ctx context.Context, request GetQueriesLegacyRequest) (*LegacyQuery, error)
// Retrieve a query object definition along with contextual permissions
// information about the currently authenticated user.
//
// **Warning**: This API is deprecated. Please use :method:queries/get instead.
// [Learn more]
//
// [Learn more]: https://docs.databricks.com/en/sql/dbsql-api-latest.html
GetByQueryId(ctx context.Context, queryId string) (*LegacyQuery, error)
// Gets a list of queries. Optionally, this list can be filtered by a search
// term.
//
// **Warning**: Calling this API concurrently 10 or more times could result in
// throttling, service degradation, or a temporary ban.
//
// **Warning**: This API is deprecated. Please use :method:queries/list instead.
// [Learn more]
//
// [Learn more]: https://docs.databricks.com/en/sql/dbsql-api-latest.html
//
// This method is generated by Databricks SDK Code Generator.
List(ctx context.Context, request ListQueriesLegacyRequest) listing.Iterator[LegacyQuery]
// Gets a list of queries. Optionally, this list can be filtered by a search
// term.
//
// **Warning**: Calling this API concurrently 10 or more times could result in
// throttling, service degradation, or a temporary ban.
//
// **Warning**: This API is deprecated. Please use :method:queries/list instead.
// [Learn more]
//
// [Learn more]: https://docs.databricks.com/en/sql/dbsql-api-latest.html
//
// This method is generated by Databricks SDK Code Generator.
ListAll(ctx context.Context, request ListQueriesLegacyRequest) ([]LegacyQuery, error)
// Restore a query that has been moved to the trash. A restored query appears in
// list views and searches. You can use restored queries for alerts.
//
// **Warning**: This API is deprecated. Please see the latest version. [Learn
// more]
//
// [Learn more]: https://docs.databricks.com/en/sql/dbsql-api-latest.html
Restore(ctx context.Context, request RestoreQueriesLegacyRequest) error
// Modify this query definition.
//
// **Note**: You cannot undo this operation.
//
// **Warning**: This API is deprecated. Please use :method:queries/update
// instead. [Learn more]
//
// [Learn more]: https://docs.databricks.com/en/sql/dbsql-api-latest.html
Update(ctx context.Context, request QueryEditContent) (*LegacyQuery, error)
}
func NewQueriesLegacy(client *client.DatabricksClient) *QueriesLegacyAPI {
return &QueriesLegacyAPI{
queriesLegacyImpl: queriesLegacyImpl{
client: client,
},
}
}
// These endpoints are used for CRUD operations on query definitions. Query
// definitions include the target SQL warehouse, query text, name, description,
// tags, parameters, and visualizations. Queries can be scheduled using the
// `sql_task` type of the Jobs API, e.g. :method:jobs/create.
//
// **Warning**: This API is deprecated. Please see the latest version of the
// Databricks SQL API. [Learn more]
//
// [Learn more]: https://docs.databricks.com/en/sql/dbsql-api-latest.html
type QueriesLegacyAPI struct {
queriesLegacyImpl
}
// Moves a query to the trash. Trashed queries immediately disappear from
// searches and list views, and they cannot be used for alerts. The trash is
// deleted after 30 days.
//
// **Warning**: This API is deprecated. Please use :method:queries/delete
// instead. [Learn more]
//
// [Learn more]: https://docs.databricks.com/en/sql/dbsql-api-latest.html
func (a *QueriesLegacyAPI) DeleteByQueryId(ctx context.Context, queryId string) error {