* Import data into GPDB. * invoked by GPDB, be careful with C++ exceptions. */
| 263 | * invoked by GPDB, be careful with C++ exceptions. |
| 264 | */ |
| 265 | Datum s3_import(PG_FUNCTION_ARGS) { |
| 266 | /* Must be called via the external table format manager */ |
| 267 | if (!CALLED_AS_EXTPROTOCOL(fcinfo)) |
| 268 | elog(ERROR, "extprotocol_import: not called by external protocol manager"); |
| 269 | |
| 270 | /* Get our internal description of the protocol */ |
| 271 | gpcloudResHandle *resHandle = (gpcloudResHandle *)EXTPROTOCOL_GET_USER_CTX(fcinfo); |
| 272 | |
| 273 | /* last call. destroy reader */ |
| 274 | if (EXTPROTOCOL_IS_LAST_CALL(fcinfo)) { |
| 275 | destroyGpcloudResHandle(resHandle); |
| 276 | |
| 277 | EXTPROTOCOL_SET_USER_CTX(fcinfo, NULL); |
| 278 | PG_RETURN_INT32(0); |
| 279 | } |
| 280 | |
| 281 | /* first call. do any desired init */ |
| 282 | if (resHandle == NULL) { |
| 283 | if (!isGpcloudResReleaseCallbackRegistered) { |
| 284 | RegisterResourceReleaseCallback(gpcloudAbortCallback, NULL); |
| 285 | isGpcloudResReleaseCallbackRegistered = true; |
| 286 | } |
| 287 | resHandle = createGpcloudResHandle(); |
| 288 | |
| 289 | queryCancelFlag = false; |
| 290 | const char *url_with_options = EXTPROTOCOL_GET_URL(fcinfo); |
| 291 | |
| 292 | // has HEADER? and newline EOL? |
| 293 | parseFormatOpts(fcinfo); |
| 294 | |
| 295 | thread_setup(); |
| 296 | |
| 297 | resHandle->gpreader = reader_init(url_with_options); |
| 298 | if (!resHandle->gpreader) { |
| 299 | ereport(ERROR, errmsg("Failed to init gpcloud extension (segid = %d, " |
| 300 | "segnum = %d), please check your " |
| 301 | "configurations and network connection: %s", |
| 302 | s3ext_segid, s3ext_segnum, s3extErrorMessage.c_str())); |
| 303 | } |
| 304 | |
| 305 | EXTPROTOCOL_SET_USER_CTX(fcinfo, resHandle); |
| 306 | } |
| 307 | |
| 308 | char *data_buf = EXTPROTOCOL_GET_DATABUF(fcinfo); |
| 309 | int32 data_len = EXTPROTOCOL_GET_DATALEN(fcinfo); |
| 310 | |
| 311 | if (!reader_transfer_data(resHandle->gpreader, data_buf, data_len)) { |
| 312 | ereport(ERROR, |
| 313 | errmsg("s3_import: could not read data: %s", s3extErrorMessage.c_str())); |
| 314 | } |
| 315 | PG_RETURN_INT32(data_len); |
| 316 | } |
| 317 | |
| 318 | /* |
| 319 | * Export data out of GPDB. |
nothing calls this directly
no test coverage detected