NewSource create a scanner to read from data source
(ctx *plan.Context, p *plan.Source)
| 47 | |
| 48 | // NewSource create a scanner to read from data source |
| 49 | func 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) |
| 87 | func NewSourceScanner(ctx *plan.Context, p *plan.Source, scanner schema.ConnScanner) *Source { |
no test coverage detected