Skip to content

Commit

Permalink
adding catalog table function interface (#1955)
Browse files Browse the repository at this point in the history
* view diff

* adding catalog table

---------

Co-authored-by: James Cor <james@dolthub.com>
  • Loading branch information
jycor and James Cor authored Aug 23, 2023
1 parent a356b9a commit 1aac383
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
7 changes: 7 additions & 0 deletions sql/planbuilder/from.go
Original file line number Diff line number Diff line change
Expand Up @@ -514,6 +514,13 @@ func (b *Builder) buildTableFunc(inScope *scope, t *ast.TableFuncExpr) (outScope
b.handleErr(err)
}

if ctf, isCTF := newInstance.(sql.CatalogTableFunction); isCTF {
newInstance, err = ctf.WithCatalog(b.cat)
if err != nil {
b.handleErr(err)
}
}

// Table Function must always have an alias, pick function name as alias if none is provided
var newAlias *plan.TableAlias
if t.Alias.IsEmpty() {
Expand Down
12 changes: 11 additions & 1 deletion sql/tables.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,9 @@

package sql

import "fmt"
import (
"fmt"
)

// Table is a SQL table.
type Table interface {
Expand All @@ -41,6 +43,14 @@ type TableFunction interface {
NewInstance(ctx *Context, db Database, args []Expression) (Node, error)
}

// CatalogTableFunction is a table function that can be used as a table factor in many SQL queries.
type CatalogTableFunction interface {
TableFunction

// WithCatalog returns a new instance of the table function with the given catalog
WithCatalog(c Catalog) (TableFunction, error)
}

// TemporaryTable allows tables to declare that they are temporary (created by CREATE TEMPORARY TABLE).
// Only used for validation of certain DDL operations -- in almost all respects TemporaryTables are indistinguishable
// from persisted tables to the engine.
Expand Down

0 comments on commit 1aac383

Please sign in to comment.