Skip to content

Commit 7045301

Browse files
committed
add TableIntegrator for custom table transformations
1 parent 7342810 commit 7045301

File tree

3 files changed

+23
-8
lines changed

3 files changed

+23
-8
lines changed

go/libraries/doltcore/sqle/database.go

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,17 @@ const (
7070
dontReadNonlocalTables readNonlocalTablesFlag = false
7171
)
7272

73+
// TableIntegrator provides a hook for extensions to customize or wrap table implementations. This allows libraries like
74+
// Doltgres to intercept system table creation and apply type conversions, schema modifications, or other customizations
75+
// without modifying the core Dolt implementation.
76+
type TableIntegrator interface {
77+
// CreateTable creates or wraps a system table. The factory receives all necessary parameters to construct the table
78+
// and can either build it from scratch or call the default constructor and wrap it.
79+
CreateTable(ctx *sql.Context, tableName string, ddb *doltdb.DoltDB, ws *doltdb.WorkingSet, rp env.RootsProvider[*sql.Context]) sql.Table
80+
}
81+
82+
var TableIntegrators map[string]TableIntegrator
83+
7384
// Database implements sql.Database for a dolt DB.
7485
type Database struct {
7586
rsr env.RepoStateReader[*sql.Context]
@@ -804,7 +815,11 @@ func (db Database) getTableInsensitiveWithRoot(ctx *sql.Context, head *doltdb.Co
804815
}
805816
}
806817

807-
dt, found = dtables.NewStatusTable(ctx, lwrName, db.ddb, ws, rootsProvider), true
818+
if systemTableFactory, ok := TableIntegrators[lwrName]; ok {
819+
dt, found = systemTableFactory.CreateTable(ctx, lwrName, db.ddb, ws, rootsProvider), true
820+
} else {
821+
dt, found = dtables.NewStatusTable(ctx, lwrName, db.ddb, ws, rootsProvider), true
822+
}
808823
}
809824
case doltdb.MergeStatusTableName, doltdb.GetMergeStatusTableName():
810825
isDoltgresSystemTable, err := resolve.IsDoltgresSystemTable(ctx, tname, root)

go/libraries/doltcore/sqle/enginetest/dolt_engine_tests.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -516,7 +516,7 @@ func RunDoltStoredProceduresTest(t *testing.T, h DoltEnginetestHarness) {
516516
for _, script := range DoltProcedureTests {
517517
func() {
518518
h := h.NewHarness(t)
519-
h.UseLocalFileSystem()
519+
//h.UseLocalFileSystem()
520520
defer h.Close()
521521
enginetest.TestScript(t, h, script)
522522
}()

go/libraries/utils/filesys/inmemfs.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,10 @@ package filesys
1616

1717
import (
1818
"bytes"
19-
"encoding/base32"
2019
"errors"
2120
"fmt"
2221
"io"
23-
"math/rand"
22+
"math/rand/v2"
2423
"os"
2524
"path/filepath"
2625
"strings"
@@ -688,10 +687,11 @@ func (fs *InMemFS) LastModified(path string) (t time.Time, exists bool) {
688687
}
689688

690689
func (fs *InMemFS) TempDir() string {
691-
buf := make([]byte, 16)
692-
rand.Read(buf)
693-
s := base32.HexEncoding.EncodeToString(buf)
694-
return "/var/folders/gc/" + s + "/T/"
690+
// TODO: this is creating a real directory on disk to support legacy components that spill to disk.
691+
// We should eventually fix those components to use the filesystem abstraction or this FS to not use real disk.
692+
path := filepath.Join(os.TempDir(), fmt.Sprintf("%016x%016x", rand.Uint64(), rand.Uint64()))
693+
//_ = os.MkdirAll(path, os.ModePerm)
694+
return path
695695
}
696696

697697
func (fs *InMemFS) pathToNative(path string) string {

0 commit comments

Comments
 (0)