Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .nextchanges/cli/pipelines-public-api.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
* Show table names and a hint for previewing more rows in `pipelines show`, and support pipeline IDs in `pipelines history`. ([#6995](https://github.com/databricks/cli/pull/6995))
2 changes: 2 additions & 0 deletions acceptance/pipelines/history/basic/out.test.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Cloud = false
EnvMatrix.DATABRICKS_BUNDLE_ENGINE = ["direct"]
59 changes: 59 additions & 0 deletions acceptance/pipelines/history/basic/output.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@

=== default history by pipeline id

>>> [CLI] pipelines history [UUID]
Updates Summary for pipeline [UUID]:
Update ID: update-3
State: COMPLETED
Creation Time: [TIMESTAMP]
Full Refresh: false
Validate Only: false
Update ID: update-2
State: FAILED
Creation Time: [TIMESTAMP]
Full Refresh: false
Validate Only: true
Update ID: update-1
State: CANCELED
Creation Time: [TIMESTAMP]
Full Refresh: false
Validate Only: false

=== json output

>>> [CLI] pipelines history [UUID] --output json
{
"Key": "[UUID]",
"Updates": [
{
"creation_time": 1640995200000,
"state": "COMPLETED",
"update_id": "update-3",
"validate_only": false
},
{
"creation_time": 1640908800000,
"state": "FAILED",
"update_id": "update-2",
"validate_only": true
},
{
"creation_time": 1640822400000,
"state": "CANCELED",
"update_id": "update-1",
"validate_only": false
}
]
}

=== wire request uses pipeline id

>>> print_requests.py //api/2.0/pipelines/[UUID]/updates --get
{
"method": "GET",
"path": "/api/2.0/pipelines/[UUID]/updates"
}
{
"method": "GET",
"path": "/api/2.0/pipelines/[UUID]/updates"
}
8 changes: 8 additions & 0 deletions acceptance/pipelines/history/basic/script
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
title "default history by pipeline id\n"
trace $CLI pipelines history 3fb8e5a1-0d2c-4a6b-9f1e-2c7d8e9f0a1b

title "json output\n"
trace $CLI pipelines history 3fb8e5a1-0d2c-4a6b-9f1e-2c7d8e9f0a1b --output json

title "wire request uses pipeline id\n"
trace print_requests.py //api/2.0/pipelines/3fb8e5a1-0d2c-4a6b-9f1e-2c7d8e9f0a1b/updates --get
16 changes: 16 additions & 0 deletions acceptance/pipelines/history/basic/test.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
Cloud = false

EnvMatrix.DATABRICKS_BUNDLE_ENGINE = ["direct"]
RecordRequests = true

[[Server]]
Pattern = "GET /api/2.0/pipelines/{pipeline_id}/updates"
Response.Body = '''
{
"updates": [
{"update_id": "update-3", "state": "COMPLETED", "creation_time": 1640995200000, "validate_only": false},
{"update_id": "update-2", "state": "FAILED", "creation_time": 1640908800000, "validate_only": true},
{"update_id": "update-1", "state": "CANCELED", "creation_time": 1640822400000, "validate_only": false}
]
}
'''
1 change: 1 addition & 0 deletions acceptance/pipelines/show/basic/output.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
=== table output

>>> [CLI] pipelines show main.default.people
Table: main.default.people
id name
-- -----
1 alice
Expand Down
1 change: 1 addition & 0 deletions acceptance/pipelines/show/rendering/output.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
=== table output: long note truncated, ragged row blank cell

>>> [CLI] pipelines show main.default.people
Table: main.default.people
name id note
----- -- ----------------------------------------
alice 1 this is a very long note value that e...
Expand Down
52 changes: 34 additions & 18 deletions cmd/pipelines/history.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,26 @@ package pipelines

import (
"fmt"
"regexp"

"github.com/databricks/cli/cmd/bundle/utils"
"github.com/databricks/cli/cmd/root"
"github.com/databricks/cli/libs/cmdctx"
"github.com/databricks/cli/libs/cmdgroup"
"github.com/databricks/cli/libs/cmdio"
databricks "github.com/databricks/databricks-sdk-go"
"github.com/databricks/databricks-sdk-go/service/pipelines"
"github.com/spf13/cobra"
)

var pipelineIDRegex = regexp.MustCompile(`^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$`)

func historyCommand() *cobra.Command {
cmd := &cobra.Command{
Use: "history [flags] [KEY]",
Use: "history [flags] [KEY|PIPELINE_ID]",
Args: root.MaximumNArgs(1),
Short: "Retrieve past runs for a pipeline",
Long: `Retrieve past runs for a pipeline identified by KEY, the unique name of the pipeline as defined in its YAML file.`,
Long: `Retrieve past runs for a pipeline identified by KEY, the unique name of the pipeline as defined in its YAML file, or by PIPELINE_ID, the unique identifier of the pipeline.`,
}

var startTimeStr string
Expand All @@ -34,25 +39,36 @@ func historyCommand() *cobra.Command {
wrappedCmd.AddFlagGroup(historyGroup)

cmd.RunE = func(cmd *cobra.Command, args []string) error {
b, err := utils.ProcessBundle(cmd, utils.ProcessOptions{
InitIDs: true,
})
if err != nil {
return err
}
ctx := cmd.Context()
var key, pipelineId string
var w *databricks.WorkspaceClient
if len(args) == 1 && pipelineIDRegex.MatchString(args[0]) {
if err := root.MustWorkspaceClient(cmd, args); err != nil {
return err
}
pipelineId = args[0]
key = pipelineId
w = cmdctx.WorkspaceClient(cmd.Context())
} else {
b, err := utils.ProcessBundle(cmd, utils.ProcessOptions{
InitIDs: true,
})
if err != nil {
return err
}
ctx := cmd.Context()

key, err := resolvePipelineArgument(ctx, b, args)
if err != nil {
return err
}
key, err = resolvePipelineArgument(ctx, b, args)
if err != nil {
return err
}

pipelineId, err := resolvePipelineIdFromKey(ctx, b, key)
if err != nil {
return err
pipelineId, err = resolvePipelineIdFromKey(ctx, b, key)
if err != nil {
return err
}
w = b.WorkspaceClient(ctx)
}

w := b.WorkspaceClient(ctx)
ctx := cmd.Context()

startTimePtr, err := parseTimeToUnixMillis(startTimeStr)
if err != nil {
Expand Down
11 changes: 10 additions & 1 deletion cmd/pipelines/show.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,16 @@ schema.table (legacy Hive metastore).`,
return err
}

return render(ctx, cmd, result.Columns, result.Rows)
if root.OutputType(cmd) == flags.OutputText {
fmt.Fprintf(cmd.OutOrStdout(), "Table: %s\n", args[0])
}
if err := render(ctx, cmd, result.Columns, result.Rows); err != nil {
return err
}
if root.OutputType(cmd) == flags.OutputText && !cmd.Flags().Changed("limit") && len(result.Rows) == limit {
fmt.Fprintln(cmd.OutOrStdout(), "Use --limit <n> to preview more rows.")
}
return nil
},
}

Expand Down
Loading