func NewSource(ctx *plan.Context, p *plan.Source) (*Source, error) {

	if p.Stmt == nil {
		return nil, fmt.Errorf("must have from for Source")
	}
	if p.Conn == nil {
		return nil, fmt.Errorf("Must have existing connection on Plan")
	}

	scanner, hasScanner := p.Conn.(schema.ConnScanner)

	// Some sources require context so we seed it here
	if sourceContext, needsContext := p.Conn.(RequiresContext); needsContext {
		sourceContext.SetContext(ctx)
	}

	if !hasScanner {
		e, hasSourceExec := p.Conn.(ExecutorSource)
		if hasSourceExec {
			s := &Source{
				TaskBase:   NewTaskBase(ctx),
				ExecSource: e,
				p:          p,
			}
			return s, nil
		}
		u.Warnf("source %T does not implement datasource.Scanner", p.Conn)
		return nil, fmt.Errorf("%T Must Implement Scanner for %q", p.Conn, p.Stmt.String())
	}
	s := &Source{
		TaskBase: NewTaskBase(ctx),
		Scanner:  scanner,
		p:        p,
	}
	return s, nil
}
// NewSource create a scanner to read from data source
NewSource create a scanner to read from data source
// NewSource create a scanner to read from data source
func NewSource(ctx *plan.Context, p *plan.Source) (*Source, error) {
	if p.Stmt == nil {
		return nil, fmt.Errorf("must have from for Source")
	}
	if p.Conn == nil {
		return nil, fmt.Errorf("Must have existing connection on Plan")
	}
	scanner, hasScanner := p.Conn.(schema.ConnScanner)
	if sourceContext, needsContext := p.Conn.(RequiresContext); needsContext {
		sourceContext.SetContext(ctx)
	}
	if !hasScanner {
		e, hasSourceExec := p.Conn.(ExecutorSource)
		if hasSourceExec {
			s := &Source{
				TaskBase:   NewTaskBase(ctx),
				ExecSource: e,
				p:          p,
			}
			return s, nil
		}
		u.Warnf("source %T does not implement datasource.Scanner", p.Conn)
		return nil, fmt.Errorf("%T Must Implement Scanner for %q", p.Conn, p.Stmt.String())
	}
	s := &Source{
		TaskBase: NewTaskBase(ctx),
		Scanner:  scanner,
		p:        p,
	}
	return s, nil
}
func NewSource ( ctx * plan . Context , p * plan . Source ) ( * Source , error ) { if p . Stmt == nil { return nil , fmt . Errorf ( " " ) } if p . Conn == nil { return nil , fmt . Errorf ( " " ) } scanner , hasScanner := p . Conn . ( schema . ConnScanner ) if sourceContext , needsContext := p . Conn . ( RequiresContext ) ; needsContext { sourceContext . SetContext ( ctx ) } if ! hasScanner { e , hasSourceExec := p . Conn . ( ExecutorSource ) if hasSourceExec { s := & Source { TaskBase : NewTaskBase ( ctx ) , ExecSource : e , p : p , } return s , nil } u . Warnf ( " " , p . Conn ) return nil , fmt . Errorf ( " " , p . Conn , p . Stmt . String ( ) ) } s := & Source { TaskBase : NewTaskBase ( ctx ) , Scanner : scanner , p : p , } return s , nil }
NewSource create a scanner to read from data source
NewSource create a scanner to read from data source
// Some sources require context so we seed it here