MCPcopy Create free account
hub / github.com/apecloud/myduckserver / NewCsvDataLoader

Function NewCsvDataLoader

pgserver/dataloader.go:156–190  ·  view source on GitHub ↗
(
	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
)

Source from the content-addressed store, hash-verified

154var _ DataLoader = (*CsvDataLoader)(nil)
155
156func 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
191func newCopyContext(ctx *sql.Context) (*sql.Context, context.CancelFunc) {
192 return ctx.NewSubContext()
193}

Callers 1

handleCopyDataHelperMethod · 0.85

Calls 3

executeCopyMethod · 0.95
buildSQLMethod · 0.95
CreatePipeMethod · 0.80

Tested by

no test coverage detected