( ctx *sql.Context, handler *DuckHandler, schema string, table sql.InsertableTable, columns tree.NameList, options *tree.CopyOptions, rawOptions string, // For non-PG-parsable COPY FROM, unused for now )
| 154 | var _ DataLoader = (*CsvDataLoader)(nil) |
| 155 | |
| 156 | func NewCsvDataLoader( |
| 157 | ctx *sql.Context, handler *DuckHandler, |
| 158 | schema string, table sql.InsertableTable, columns tree.NameList, options *tree.CopyOptions, |
| 159 | rawOptions string, // For non-PG-parsable COPY FROM, unused for now |
| 160 | ) (DataLoader, error) { |
| 161 | // Create the FIFO pipe |
| 162 | duckBuilder := handler.e.Analyzer.ExecBuilder.PriorityBuilder.(*backend.DuckBuilder) |
| 163 | pipePath, err := duckBuilder.CreatePipe(ctx, "pg-copy-from") |
| 164 | if err != nil { |
| 165 | return nil, err |
| 166 | } |
| 167 | |
| 168 | // Create a child without mutating the parent context into its own ancestor. |
| 169 | ctx, cancel := newCopyContext(ctx) |
| 170 | |
| 171 | loader := &CsvDataLoader{ |
| 172 | PipeDataLoader: PipeDataLoader{ |
| 173 | ctx: ctx, |
| 174 | cancel: cancel, |
| 175 | schema: schema, |
| 176 | table: table, |
| 177 | columns: columns, |
| 178 | pipePath: pipePath, |
| 179 | rowCount: make(chan int64, 1), |
| 180 | logger: ctx.GetLogger(), |
| 181 | }, |
| 182 | options: options, |
| 183 | } |
| 184 | loader.read = func() { |
| 185 | loader.executeCopy(loader.buildSQL(), pipePath) |
| 186 | } |
| 187 | |
| 188 | return loader, nil |
| 189 | } |
| 190 | |
| 191 | func newCopyContext(ctx *sql.Context) (*sql.Context, context.CancelFunc) { |
| 192 | return ctx.NewSubContext() |
| 193 | } |
no test coverage detected