Skip to content

Commit

Permalink
Runtime: rename source fix for external table storage (#4381)
Browse files Browse the repository at this point in the history
* rename source fix for external table storage

* temporary fix for external table storage and duckdb external transfers
  • Loading branch information
k-anshul authored and nishantmonu51 committed Mar 19, 2024
1 parent 281fdee commit 82f9816
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 6 deletions.
5 changes: 1 addition & 4 deletions runtime/drivers/duckdb/olap.go
Original file line number Diff line number Diff line change
Expand Up @@ -448,7 +448,7 @@ func (c *connection) InsertTableAsSelect(ctx context.Context, name string, byNam
// `DETACH foo__1`
// `rm foo/1.db`
func (c *connection) RenameTable(ctx context.Context, oldName, newName string, view bool) error {
c.logger.Debug("rename table", zap.String("from", oldName), zap.String("to", newName), zap.Bool("view", view))
c.logger.Debug("rename table", zap.String("from", oldName), zap.String("to", newName), zap.Bool("view", view), zap.Bool("ext", c.config.ExtTableStorage))
if strings.EqualFold(oldName, newName) {
return fmt.Errorf("rename: old and new name are same case insensitive strings")
}
Expand All @@ -461,9 +461,6 @@ func (c *connection) RenameTable(ctx context.Context, oldName, newName string, v
return err
}
if !exist {
if !view {
return fmt.Errorf("rename: table %q does not exist", oldName)
}
return c.dropAndReplace(ctx, oldName, newName, view)
}

Expand Down
5 changes: 3 additions & 2 deletions runtime/reconcilers/source.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,8 +88,9 @@ func (r *SourceReconciler) Reconcile(ctx context.Context, n *runtimev1.ResourceN
// Handle renames
if self.Meta.RenamedFrom != nil {
// Check if the table exists (it should, but might somehow have been corrupted)
t, ok := olapTableInfo(ctx, r.C, src.State.Connector, src.State.Table)
if ok && !t.View { // Checking View only out of caution (would indicate very corrupted DB)
_, ok := olapTableInfo(ctx, r.C, src.State.Connector, src.State.Table)
// NOTE: Not checking if it's a view because some backends will represent sources as views (like DuckDB with external table storage enabled).
if ok {
// Rename and update state
err = olapForceRenameTable(ctx, r.C, src.State.Connector, src.State.Table, false, tableName)
if err != nil {
Expand Down

1 comment on commit 82f9816

@github-actions
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🎉 Published on https://ui.rilldata.com as production
🚀 Deployed on https://65fa9c7030a58645fe9db798--rill-ui.netlify.app

Please sign in to comment.