github.com/databricks/cli@v0.203.0/bundle/run/output/task.go (about) 1 package output 2 3 import ( 4 "encoding/json" 5 "fmt" 6 7 "github.com/databricks/databricks-sdk-go/service/jobs" 8 ) 9 10 type NotebookOutput jobs.NotebookOutput 11 type DbtOutput jobs.DbtOutput 12 type SqlOutput jobs.SqlOutput 13 type LogsOutput struct { 14 Logs string `json:"logs"` 15 LogsTruncated bool `json:"logs_truncated"` 16 } 17 18 func structToString(val interface{}) (string, error) { 19 b, err := json.MarshalIndent(val, "", " ") 20 if err != nil { 21 return "", err 22 } 23 return string(b), nil 24 } 25 26 func (out *NotebookOutput) String() (string, error) { 27 if out.Truncated { 28 return fmt.Sprintf("%s\n[truncated...]\n", out.Result), nil 29 } 30 return out.Result, nil 31 } 32 33 func (out *DbtOutput) String() (string, error) { 34 outputString, err := structToString(out) 35 if err != nil { 36 return "", err 37 } 38 39 // We add this prefix to make this output non machine readable. 40 // JSON is used because it's a convenient representation. 41 // If user needs machine parsable output, they can use the --output json 42 // flag 43 return fmt.Sprintf("Dbt Task Output:\n%s", outputString), nil 44 } 45 46 func (out *SqlOutput) String() (string, error) { 47 outputString, err := structToString(out) 48 if err != nil { 49 return "", err 50 } 51 52 // We add this prefix to make this output non machine readable. 53 // JSON is used because it's a convenient representation. 54 // If user needs machine parsable output, they can use the --output json 55 // flag 56 return fmt.Sprintf("SQL Task Output:\n%s", outputString), nil 57 } 58 59 func (out *LogsOutput) String() (string, error) { 60 if out.LogsTruncated { 61 return fmt.Sprintf("%s\n[truncated...]\n", out.Logs), nil 62 } 63 return out.Logs, nil 64 } 65 66 func toRunOutput(output *jobs.RunOutput) RunOutput { 67 switch { 68 case output.NotebookOutput != nil: 69 result := NotebookOutput(*output.NotebookOutput) 70 return &result 71 case output.DbtOutput != nil: 72 result := DbtOutput(*output.DbtOutput) 73 return &result 74 75 case output.SqlOutput != nil: 76 result := SqlOutput(*output.SqlOutput) 77 return &result 78 // Corresponds to JAR, python script and python wheel tasks 79 case output.Logs != "": 80 result := LogsOutput{ 81 Logs: output.Logs, 82 LogsTruncated: output.LogsTruncated, 83 } 84 return &result 85 default: 86 return nil 87 } 88 }