Skip to content

Commit 1aac383

Browse files
jycorJames Cor
andauthored
adding catalog table function interface (#1955)
* view diff * adding catalog table --------- Co-authored-by: James Cor <[email protected]>
1 parent a356b9a commit 1aac383

File tree

2 files changed

+18
-1
lines changed

2 files changed

+18
-1
lines changed

sql/planbuilder/from.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -514,6 +514,13 @@ func (b *Builder) buildTableFunc(inScope *scope, t *ast.TableFuncExpr) (outScope
514514
b.handleErr(err)
515515
}
516516

517+
if ctf, isCTF := newInstance.(sql.CatalogTableFunction); isCTF {
518+
newInstance, err = ctf.WithCatalog(b.cat)
519+
if err != nil {
520+
b.handleErr(err)
521+
}
522+
}
523+
517524
// Table Function must always have an alias, pick function name as alias if none is provided
518525
var newAlias *plan.TableAlias
519526
if t.Alias.IsEmpty() {

sql/tables.go

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,9 @@
1414

1515
package sql
1616

17-
import "fmt"
17+
import (
18+
"fmt"
19+
)
1820

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

46+
// CatalogTableFunction is a table function that can be used as a table factor in many SQL queries.
47+
type CatalogTableFunction interface {
48+
TableFunction
49+
50+
// WithCatalog returns a new instance of the table function with the given catalog
51+
WithCatalog(c Catalog) (TableFunction, error)
52+
}
53+
4454
// TemporaryTable allows tables to declare that they are temporary (created by CREATE TEMPORARY TABLE).
4555
// Only used for validation of certain DDL operations -- in almost all respects TemporaryTables are indistinguishable
4656
// from persisted tables to the engine.

0 commit comments

Comments
 (0)