* Copy FROM directory table TO file, in the dispatcher. Starts a COPY TO command * on each of the executors and gathers all the results and writes it out. */
| 1798 | * on each of the executors and gathers all the results and writes it out. |
| 1799 | */ |
| 1800 | static uint64 |
| 1801 | CopyToDispatchDirectoryTable(CopyToState cstate) |
| 1802 | { |
| 1803 | CopyStmt *stmt = glob_copystmt; |
| 1804 | TupleDesc tupDesc; |
| 1805 | CdbCopy *cdbCopy; |
| 1806 | uint64 processed = 0; |
| 1807 | |
| 1808 | tupDesc = cstate->rel->rd_att; |
| 1809 | |
| 1810 | cstate->fe_msgbuf = makeStringInfo(); |
| 1811 | cdbCopy = makeCdbCopyTo(cstate); |
| 1812 | |
| 1813 | /* |
| 1814 | * Start a COPY command in every db of every segment in Apache Cloudberry. |
| 1815 | * |
| 1816 | * From this point in the code we need to be extra careful |
| 1817 | * about error handling. ereport() must not be called until |
| 1818 | * the COPY command sessions are closed on the executors. |
| 1819 | * Calling ereport() will leave the executors hanging in |
| 1820 | * COPY state. |
| 1821 | */ |
| 1822 | elog(DEBUG5, "COPY command sent to segdbs"); |
| 1823 | |
| 1824 | PG_TRY(); |
| 1825 | { |
| 1826 | bool done; |
| 1827 | |
| 1828 | cdbCopyStart(cdbCopy, stmt, cstate->file_encoding); |
| 1829 | |
| 1830 | if (!cstate->opts.binary) |
| 1831 | ereport(ERROR, |
| 1832 | (errcode(ERRCODE_FEATURE_NOT_SUPPORTED), |
| 1833 | errmsg("Only support copy binary to directory table."))); |
| 1834 | |
| 1835 | /* |
| 1836 | * This is the main work-loop. In here we keep collecting data from the |
| 1837 | * COPY commands on the segdbs, until no more data is available. We |
| 1838 | * keep writing data out a chunk at a time. |
| 1839 | */ |
| 1840 | do |
| 1841 | { |
| 1842 | bool copy_cancel = (QueryCancelPending ? true : false); |
| 1843 | |
| 1844 | /* get a chunk of data rows from the QE's */ |
| 1845 | done = cdbCopyGetData(cdbCopy, copy_cancel, &processed); |
| 1846 | |
| 1847 | /* send the chunk of data rows to destination (file or stdout) */ |
| 1848 | if (cdbCopy->copy_out_buf.len > 0) /* conditional is important! */ |
| 1849 | { |
| 1850 | /* |
| 1851 | * in the dispatcher we receive chunks of file and flush it. |
| 1852 | */ |
| 1853 | CopySendData(cstate, (void *) cdbCopy->copy_out_buf.data, cdbCopy->copy_out_buf.len); |
| 1854 | CopyToDispatchFlush(cstate); |
| 1855 | } |
| 1856 | } while (!done); |
| 1857 |
no test coverage detected