* Copy directory table To QD. */
| 2059 | * Copy directory table To QD. |
| 2060 | */ |
| 2061 | static uint64 |
| 2062 | CopyToDirectoryTable(CopyToState cstate) |
| 2063 | { |
| 2064 | uint64 processed = 0; |
| 2065 | TupleTableSlot *slot; |
| 2066 | TableScanDesc scandesc; |
| 2067 | ScanKeyData skey; |
| 2068 | Datum datum; |
| 2069 | bool isnull; |
| 2070 | char *relative_path; |
| 2071 | char *scopedFileUrl; |
| 2072 | DirectoryTable *dirTable; |
| 2073 | UFile *file; |
| 2074 | int64_t file_size; |
| 2075 | pg_cryptohash_ctx *hashCtx; |
| 2076 | char hexMd5Sum[256]; |
| 2077 | uint8 md5Sum[MD5_DIGEST_LENGTH]; |
| 2078 | char *md5; |
| 2079 | |
| 2080 | Assert(cstate->rel); |
| 2081 | |
| 2082 | dirTable = GetDirectoryTable(RelationGetRelid(cstate->rel)); |
| 2083 | |
| 2084 | /* We use fe_msgbuf as a per-row buffer regardless of copy_dest */ |
| 2085 | cstate->fe_msgbuf = makeStringInfo(); |
| 2086 | |
| 2087 | /* |
| 2088 | * Create a temporary memory context that we can reset once per row to |
| 2089 | * recover palloc'd memory. This avoids any problems with leaks inside |
| 2090 | * datatype output routines, and should be faster than retail pfree's |
| 2091 | * anyway. (We don't need a whole econtext as CopyFrom does.) |
| 2092 | */ |
| 2093 | cstate->rowcontext = AllocSetContextCreate(CurrentMemoryContext, |
| 2094 | "COPY TO", |
| 2095 | ALLOCSET_DEFAULT_SIZES); |
| 2096 | |
| 2097 | ScanKeyInit(&skey, |
| 2098 | (AttrNumber) 1, |
| 2099 | BTEqualStrategyNumber, F_TEXTEQ, |
| 2100 | CStringGetTextDatum(cstate->dirfilename)); |
| 2101 | scandesc = table_beginscan(cstate->rel, GetActiveSnapshot(), 1, &skey); |
| 2102 | slot = table_slot_create(cstate->rel, NULL); |
| 2103 | |
| 2104 | processed = 0; |
| 2105 | if (table_scan_getnextslot(scandesc, ForwardScanDirection, slot)) |
| 2106 | { |
| 2107 | char buffer[4096]; |
| 2108 | char errorMessage[256]; |
| 2109 | int bytesRead; |
| 2110 | |
| 2111 | /* Deconstruct the tuple ... */ |
| 2112 | slot_getallattrs(slot); |
| 2113 | |
| 2114 | datum = slot_getattr(slot, 1, &isnull); |
| 2115 | Assert(isnull == false); |
| 2116 | relative_path = TextDatumGetCString(datum); |
| 2117 | scopedFileUrl = psprintf("%s/%s", dirTable->location, relative_path); |
| 2118 |
no test coverage detected