-
Notifications
You must be signed in to change notification settings - Fork 368
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Improve dbt errors #2895
Improve dbt errors #2895
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -135,8 +135,9 @@ func CopyModels(ctx context.Context, models []model, continueOnError bool, fromS | |||||
return err | ||||||
} | ||||||
fmt.Printf("copy %s.%s -> %s.%s failed: %s\n", m.Schema, m.Alias, toSchema, m.Alias, err) | ||||||
} else { | ||||||
fmt.Printf("copied %s.%s -> %s.%s\n", m.Schema, m.Alias, toSchema, m.Alias) | ||||||
} | ||||||
fmt.Printf("copied %s.%s -> %s.%s\n", m.Schema, m.Alias, toSchema, m.Alias) | ||||||
} | ||||||
return nil | ||||||
} | ||||||
|
@@ -146,7 +147,7 @@ func getDbtTables(projectRoot string) ([]model, error) { | |||||
dbtCmd.Dir = projectRoot | ||||||
output, err := dbtCmd.Output() | ||||||
if err != nil { | ||||||
return nil, err | ||||||
return nil, fmt.Errorf("failed to run dbt debug with output:\n %s\n and error: %s", output, err) | ||||||
} | ||||||
models := make([]model, 0) | ||||||
scan := bufio.NewScanner(bytes.NewReader(output)) | ||||||
|
@@ -155,7 +156,7 @@ func getDbtTables(projectRoot string) ([]model, error) { | |||||
var m model | ||||||
err = json.Unmarshal(line, &m) | ||||||
if err != nil { | ||||||
return nil, err | ||||||
return nil, fmt.Errorf("failed to unmarshal json: %w", err) | ||||||
} | ||||||
models = append(models, m) | ||||||
} | ||||||
|
@@ -168,7 +169,7 @@ func dbtDebug(projectRoot string) string { | |||||
dbtCmd.Dir = projectRoot | ||||||
output, err := dbtCmd.Output() | ||||||
if err != nil { | ||||||
DieErr(err) | ||||||
DieFmt("failed to run dbt debug with output:\n %s\n and error: %s", output, err) | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done |
||||||
} | ||||||
submatch := schemaRegex.FindSubmatch(output) | ||||||
if submatch == nil || len(submatch) < 2 { | ||||||
|
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -44,7 +44,11 @@ type Client interface { | |||||
func CopyOrMerge(ctx context.Context, fromClient, toClient Client, fromDB, fromTable, toDB, toTable, toBranch, serde string, partition []string, fixSparkPlaceHolder bool, dbfsLocation string) error { | ||||||
transformLocation := func(location string) (string, error) { | ||||||
location = HandleDBFSLocation(location, dbfsLocation) | ||||||
return ReplaceBranchName(location, toBranch) | ||||||
transformedLocation, err := ReplaceBranchName(location, toBranch) | ||||||
if err != nil { | ||||||
return "", fmt.Errorf("failed to replace branch name with location: %s and branch: %s : %w", location, toBranch, err) | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done |
||||||
} | ||||||
return transformedLocation, nil | ||||||
} | ||||||
return copyOrMergeWithTransformLocation(ctx, fromClient, toClient, fromDB, fromTable, toDB, toTable, serde, false, partition, transformLocation, fixSparkPlaceHolder) | ||||||
} | ||||||
|
@@ -55,22 +59,30 @@ func CopyDB(ctx context.Context, fromClient, toClient Client, fromDB, toDB, toBr | |||||
return "", nil | ||||||
} | ||||||
location = HandleDBFSLocation(location, dbfsLocation) | ||||||
return ReplaceBranchName(location, toBranch) | ||||||
transformedLocation, err := ReplaceBranchName(location, toBranch) | ||||||
if err != nil { | ||||||
return "", fmt.Errorf("failed to replace branch name with location: %s and branch: %s : %w", location, toBranch, err) | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. optional:
Suggested change
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done |
||||||
} | ||||||
return transformedLocation, nil | ||||||
} | ||||||
return copyDBWithTransformLocation(ctx, fromClient, toClient, fromDB, toDB, transformLocation) | ||||||
} | ||||||
|
||||||
func copyDBWithTransformLocation(ctx context.Context, fromClient, toClient Client, fromDB string, toDB string, transformLocation func(location string) (string, error)) error { | ||||||
schema, err := fromClient.GetDatabase(ctx, fromDB) | ||||||
if err != nil { | ||||||
return err | ||||||
return fmt.Errorf("failed to get database on copy: %w", err) | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. would add the fromDB to the error There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done |
||||||
} | ||||||
schema.Name = toDB | ||||||
schema.LocationURI, err = transformLocation(schema.LocationURI) | ||||||
if err != nil { | ||||||
return err | ||||||
} | ||||||
return toClient.CreateDatabase(ctx, schema) | ||||||
err = toClient.CreateDatabase(ctx, schema) | ||||||
if err != nil { | ||||||
return fmt.Errorf("failed to create database with name %s and location %s :%w", schema.Name, schema.LocationURI, err) | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done |
||||||
} | ||||||
return nil | ||||||
} | ||||||
|
||||||
func copyOrMergeWithTransformLocation(ctx context.Context, fromClient, toClient Client, fromDB, fromTable, toDB, toTable, serde string, setSymlink bool, partition []string, transformLocation func(location string) (string, error), fixSparkPlaceHolder bool) error { | ||||||
|
@@ -146,10 +158,12 @@ func CopyOrMergeAll(ctx context.Context, fromClient, toClient Client, schemaFilt | |||||
|
||||||
// HandleDBFSLocation translates Data Bricks File system path to the S3 path using the dbfsLocation | ||||||
func HandleDBFSLocation(location string, dbfsLocation string) string { | ||||||
l := location | ||||||
if dbfsLocation != "" && strings.HasPrefix(location, dbfsPrefix) { | ||||||
location = strings.Replace(location, dbfsPrefix, dbfsLocation, 1) | ||||||
l = strings.Replace(location, dbfsPrefix, dbfsLocation, 1) | ||||||
} | ||||||
return location | ||||||
logging.Default().WithFields(logging.Fields{"dbfsLocation": dbfsLocation, "location": location, "new_location": l}).Info("translate databricks file system path to s3 path") | ||||||
return l | ||||||
} | ||||||
|
||||||
func ImportAll(ctx context.Context, fromClient, toClient Client, schemaFilter, tableFilter, repo, toBranch string, continueOnError, fixSparkPlaceHolder bool, dbfsLocation string) error { | ||||||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
not sure about this one - it looks like an error that goes to the output not something that failed - it capture the output.
is that right?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For some reason, when dbt debug returns an error, the information for the error is printed to the standard outpout
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Changed it, now, in case of error: the output is first printed as output and the error as error