Skip to content

Commit 788bc5a

Browse files
- Existing test suite passing.
1 parent 7e18ec5 commit 788bc5a

File tree

5 files changed

+37
-11
lines changed

5 files changed

+37
-11
lines changed

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ require (
2121
github.com/spf13/viper v1.10.1
2222
github.com/stackql/any-sdk v0.1.2-alpha37
2323
github.com/stackql/go-suffix-map v0.0.1-alpha01
24-
github.com/stackql/psql-wire v0.1.1-alpha07
24+
github.com/stackql/psql-wire v0.1.1-beta20
2525
github.com/stackql/stackql-parser v0.0.14-alpha05
2626
github.com/stretchr/testify v1.10.0
2727
golang.org/x/sync v0.10.0

go.sum

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -486,8 +486,8 @@ github.com/stackql/any-sdk v0.1.2-alpha37 h1:bvU576YCwqtjztMD4wSpgj//StNH8qGoBRB
486486
github.com/stackql/any-sdk v0.1.2-alpha37/go.mod h1:4jYKpPoX2GWEK+qBnlGLvr8SUfndiYwHMIkg1dn9tFM=
487487
github.com/stackql/go-suffix-map v0.0.1-alpha01 h1:TDUDS8bySu41Oo9p0eniUeCm43mnRM6zFEd6j6VUaz8=
488488
github.com/stackql/go-suffix-map v0.0.1-alpha01/go.mod h1:QAi+SKukOyf4dBtWy8UMy+hsXXV+yyEE4vmBkji2V7g=
489-
github.com/stackql/psql-wire v0.1.1-alpha07 h1:LQWVUlx4Bougk6dztDNG5tmXxpIVeeTSsInTj801xCs=
490-
github.com/stackql/psql-wire v0.1.1-alpha07/go.mod h1:a44Wd8kDC3irFLpGutarKDBqhJ/aqXlj1aMzO5bVJYg=
489+
github.com/stackql/psql-wire v0.1.1-beta20 h1:ppLGNaaZGt0LncXJ4ElSHyJz6cQCAYFNwYQjIgSFJho=
490+
github.com/stackql/psql-wire v0.1.1-beta20/go.mod h1:a44Wd8kDC3irFLpGutarKDBqhJ/aqXlj1aMzO5bVJYg=
491491
github.com/stackql/readline v0.0.2-alpha05 h1:ID4QzGdplFBsrSnTuz8pvKzWw96JbrJg8fsLry2UriU=
492492
github.com/stackql/readline v0.0.2-alpha05/go.mod h1:OFAYOdXk/X4+5GYiDXFfaGrk+bCN6Qv0SYY5HNzD2E0=
493493
github.com/stackql/stackql-go-sqlite3 v1.0.3-stackql h1:j0yt6T5thZuz5+HIr81PXz2AClAtCko0vzr5tm8C1g8=

internal/stackql/cmd/srv.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ var srvCmd = &cobra.Command{
4545
iqlerror.PrintErrorAndExitOneIfError(err)
4646
handlerCtx, err := entryutil.BuildHandlerContext(runtimeCtx, nil, queryCache, inputBundle, false)
4747
iqlerror.PrintErrorAndExitOneIfError(err)
48-
sbe := driver.NewStackQLDriverFactory(handlerCtx)
48+
sbe := driver.NewStackQLDriverFactory(handlerCtx, true)
4949
server, err := psqlwire.MakeWireServer(sbe, runtimeCtx)
5050
iqlerror.PrintErrorAndExitOneIfError(err)
5151
server.Serve() //nolint:errcheck // TODO: investigate

internal/stackql/driver/driver.go

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package driver
22

33
import (
4+
"bytes"
45
"context"
56
"fmt"
67

@@ -28,7 +29,8 @@ type StackQLDriverFactory interface {
2829
}
2930

3031
type basicStackQLDriverFactory struct {
31-
handlerCtx handler.HandlerContext
32+
isCaptureDebug bool
33+
handlerCtx handler.HandlerContext
3234
}
3335

3436
func (sdf *basicStackQLDriverFactory) NewSQLBackend() (sqlbackend.ISQLBackend, error) {
@@ -59,16 +61,23 @@ func (sdf *basicStackQLDriverFactory) newSQLDriver() (StackQLDriver, error) {
5961
sdf.handlerCtx.SetTSM(tsmInstance)
6062
clonedCtx := sdf.handlerCtx.Clone()
6163
clonedCtx.SetTxnCounterMgr(txCtr)
64+
buf := bytes.NewBuffer([]byte{})
65+
if sdf.isCaptureDebug {
66+
logging.GetLogger().Debugln("debug mode enabled")
67+
clonedCtx.SetOutErrFile(buf)
68+
}
6269
rv := &basicStackQLDriver{
70+
debugBuf: buf,
6371
handlerCtx: clonedCtx,
6472
txnOrchestrator: txnOrchestrator,
6573
}
6674
return rv, nil
6775
}
6876

69-
func NewStackQLDriverFactory(handlerCtx handler.HandlerContext) sqlbackend.SQLBackendFactory {
77+
func NewStackQLDriverFactory(handlerCtx handler.HandlerContext, isCaptureDebug bool) sqlbackend.SQLBackendFactory {
7078
return &basicStackQLDriverFactory{
71-
handlerCtx: handlerCtx,
79+
isCaptureDebug: isCaptureDebug,
80+
handlerCtx: handlerCtx,
7281
}
7382
}
7483

@@ -121,10 +130,18 @@ func (dr *basicStackQLDriver) ProcessQuery(query string) {
121130
}
122131

123132
type basicStackQLDriver struct {
133+
debugBuf *bytes.Buffer
124134
handlerCtx handler.HandlerContext
125135
txnOrchestrator tsm_physio.Orchestrator
126136
}
127137

138+
func (dr *basicStackQLDriver) GetDebugStr() string {
139+
if dr.debugBuf != nil {
140+
return dr.debugBuf.String()
141+
}
142+
return ""
143+
}
144+
128145
func (dr *basicStackQLDriver) CloneSQLBackend() sqlbackend.ISQLBackend {
129146
return &basicStackQLDriver{
130147
handlerCtx: dr.handlerCtx.Clone(),

internal/stackql/handler/handler.go

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,8 @@ type HandlerContext interface { //nolint:revive // don't mind stuttering this on
7979
SetQuery(string)
8080
SetRawQuery(string)
8181
//
82+
SetOutErrFile(io.Writer)
83+
//
8284
GetTxnCoordinatorCtx() txn_context.ITransactionCoordinatorContext
8385

8486
GetTypingConfig() typing.Config
@@ -197,10 +199,17 @@ func (hc *standardHandlerContext) GetAuthContexts() dto.AuthContexts {
197199
return hc.authContexts
198200
}
199201

200-
func (hc *standardHandlerContext) GetRegistry() anysdk.RegistryAPI { return hc.registry }
201-
func (hc *standardHandlerContext) GetErrorPresentation() string { return hc.errorPresentation }
202-
func (hc *standardHandlerContext) GetOutfile() io.Writer { return hc.outfile }
203-
func (hc *standardHandlerContext) GetOutErrFile() io.Writer { return hc.outErrFile }
202+
func (hc *standardHandlerContext) GetRegistry() anysdk.RegistryAPI { return hc.registry }
203+
func (hc *standardHandlerContext) GetErrorPresentation() string { return hc.errorPresentation }
204+
func (hc *standardHandlerContext) GetOutfile() io.Writer { return hc.outfile }
205+
func (hc *standardHandlerContext) GetOutErrFile() io.Writer {
206+
return hc.outErrFile
207+
}
208+
func (hc *standardHandlerContext) SetOutErrFile(w io.Writer) {
209+
defer hc.sessionCtxMutex.Unlock()
210+
hc.sessionCtxMutex.Lock()
211+
hc.outErrFile = w
212+
}
204213
func (hc *standardHandlerContext) GetLRUCache() *lrucache.LRUCache { return hc.lRUCache }
205214
func (hc *standardHandlerContext) GetSQLEngine() sqlengine.SQLEngine { return hc.sqlEngine }
206215
func (hc *standardHandlerContext) GetSQLSystem() sql_system.SQLSystem { return hc.sqlSystem }

0 commit comments

Comments
 (0)