(sql string, pipePath string)
| 81 | func (loader *ArrowDataLoader) executeInsert(sql string, pipePath string) { |
| 82 | defer close(loader.rowCount) |
| 83 | |
| 84 | // Open the pipe for reading. |
| 85 | loader.logger.Debugf("Opening pipe for reading: %s", pipePath) |
| 86 | pipe, err := os.OpenFile(pipePath, os.O_RDONLY, os.ModeNamedPipe) |
| 87 | if err != nil { |
| 88 | loader.err.Store(&err) |
| 89 | // Open the pipe once to unblock the writer |
| 90 | pipe, _ = os.OpenFile(pipePath, os.O_RDONLY, os.ModeNamedPipe) |
| 91 | loader.errPipe.Store(pipe) |
| 92 | return |
| 93 | } |
| 94 | |
| 95 | // Create an Arrow IPC reader from the pipe. |
| 96 | loader.logger.Debugf("Creating Arrow IPC reader from pipe: %s", pipePath) |
| 97 | arrowReader, err := ipc.NewReader(pipe) |
| 98 | if err != nil { |
| 99 | loader.err.Store(&err) |
| 100 | return |
| 101 | } |
| 102 | defer arrowReader.Release() |
| 103 | |
| 104 | conn, err := adapter.GetConn(loader.ctx) |
| 105 | if err != nil { |
| 106 | loader.err.Store(&err) |
| 107 | return |
| 108 | } |
| 109 | |
| 110 | // Register the Arrow IPC reader to DuckDB. |
| 111 | loader.logger.Debugf("Registering Arrow IPC reader into DuckDB: %s", loader.arrowName) |
| 112 | var release func() |
| 113 | if err := conn.Raw(func(driverConn any) error { |
| 114 | conn := driverConn.(*duckdb.Conn) |
| 115 | arrow, err := duckdb.NewArrowFromConn(conn) |
| 116 | if err != nil { |
| 117 | return err |
| 118 | } |
| 119 | |
| 120 | release, err = arrow.RegisterView(arrowReader, loader.arrowName) |
| 121 | return err |
| 122 | }); err != nil { |
| 123 | loader.err.Store(&err) |
| 124 | return |
| 125 | } |
| 126 | defer release() |
| 127 | |
| 128 | // Execute the INSERT statement. |
| 129 | // This will block until the reader has finished reading the data. |
| 130 | loader.logger.Debugln("Executing SQL:", sql) |
| 131 | result, err := conn.ExecContext(loader.ctx, sql) |
| 132 | if err != nil { |
| 133 | loader.err.Store(&err) |
| 134 | return |
| 135 | } |
| 136 | |
| 137 | rows, err := result.RowsAffected() |
| 138 | if err != nil { |
| 139 | loader.err.Store(&err) |
| 140 | return |
no test coverage detected