MCPcopy Create free account
hub / github.com/araddon/qlbridge / NewSource

Function NewSource

exec/source.go:49–84  ·  view source on GitHub ↗

NewSource create a scanner to read from data source

(ctx *plan.Context, p *plan.Source)

Source from the content-addressed store, hash-verified

47
48// NewSource create a scanner to read from data source
49func NewSource(ctx *plan.Context, p *plan.Source) (*Source, error) {
50
51 if p.Stmt == nil {
52 return nil, fmt.Errorf("must have from for Source")
53 }
54 if p.Conn == nil {
55 return nil, fmt.Errorf("Must have existing connection on Plan")
56 }
57
58 scanner, hasScanner := p.Conn.(schema.ConnScanner)
59
60 // Some sources require context so we seed it here
61 if sourceContext, needsContext := p.Conn.(RequiresContext); needsContext {
62 sourceContext.SetContext(ctx)
63 }
64
65 if !hasScanner {
66 e, hasSourceExec := p.Conn.(ExecutorSource)
67 if hasSourceExec {
68 s := &Source{
69 TaskBase: NewTaskBase(ctx),
70 ExecSource: e,
71 p: p,
72 }
73 return s, nil
74 }
75 u.Warnf("source %T does not implement datasource.Scanner", p.Conn)
76 return nil, fmt.Errorf("%T Must Implement Scanner for %q", p.Conn, p.Stmt.String())
77 }
78 s := &Source{
79 TaskBase: NewTaskBase(ctx),
80 Scanner: scanner,
81 p: p,
82 }
83 return s, nil
84}
85
86// NewSourceScanner A scanner to read from sub-query data source (join, sub-query, static)
87func NewSourceScanner(ctx *plan.Context, p *plan.Source, scanner schema.ConnScanner) *Source {

Callers 2

WalkExecSourceMethod · 0.92
WalkSourceMethod · 0.70

Calls 4

NewTaskBaseFunction · 0.85
ErrorfMethod · 0.80
SetContextMethod · 0.65
StringMethod · 0.65

Tested by

no test coverage detected