* Export data out of GPDB. * invoked by GPDB, be careful with C++ exceptions. */
| 320 | * invoked by GPDB, be careful with C++ exceptions. |
| 321 | */ |
| 322 | Datum s3_export(PG_FUNCTION_ARGS) { |
| 323 | /* Must be called via the external table format manager */ |
| 324 | if (!CALLED_AS_EXTPROTOCOL(fcinfo)) |
| 325 | elog(ERROR, "extprotocol_import: not called by external protocol manager"); |
| 326 | |
| 327 | /* Get our internal description of the protocol */ |
| 328 | gpcloudResHandle *resHandle = (gpcloudResHandle *)EXTPROTOCOL_GET_USER_CTX(fcinfo); |
| 329 | |
| 330 | /* last call. destroy writer */ |
| 331 | if (EXTPROTOCOL_IS_LAST_CALL(fcinfo)) { |
| 332 | destroyGpcloudResHandle(resHandle); |
| 333 | |
| 334 | EXTPROTOCOL_SET_USER_CTX(fcinfo, NULL); |
| 335 | PG_RETURN_INT32(0); |
| 336 | } |
| 337 | |
| 338 | /* first call. do any desired init */ |
| 339 | if (resHandle == NULL) { |
| 340 | if (!isGpcloudResReleaseCallbackRegistered) { |
| 341 | RegisterResourceReleaseCallback(gpcloudAbortCallback, NULL); |
| 342 | isGpcloudResReleaseCallbackRegistered = true; |
| 343 | } |
| 344 | resHandle = createGpcloudResHandle(); |
| 345 | |
| 346 | queryCancelFlag = false; |
| 347 | const char *url_with_options = EXTPROTOCOL_GET_URL(fcinfo); |
| 348 | const char *format = getFormatStr(fcinfo); |
| 349 | |
| 350 | thread_setup(); |
| 351 | |
| 352 | resHandle->gpwriter = writer_init(url_with_options, format); |
| 353 | if (!resHandle->gpwriter) { |
| 354 | ereport(ERROR, errmsg("Failed to init gpcloud extension (segid = %d, " |
| 355 | "segnum = %d), please check your " |
| 356 | "configurations and network connection: %s", |
| 357 | s3ext_segid, s3ext_segnum, s3extErrorMessage.c_str())); |
| 358 | } |
| 359 | |
| 360 | EXTPROTOCOL_SET_USER_CTX(fcinfo, resHandle); |
| 361 | } |
| 362 | |
| 363 | char *data_buf = EXTPROTOCOL_GET_DATABUF(fcinfo); |
| 364 | int32 data_len = EXTPROTOCOL_GET_DATALEN(fcinfo); |
| 365 | |
| 366 | if (!writer_transfer_data(resHandle->gpwriter, data_buf, data_len)) { |
| 367 | ereport(ERROR, |
| 368 | errmsg("s3_export: could not write data: %s", s3extErrorMessage.c_str())); |
| 369 | } |
| 370 | |
| 371 | PG_RETURN_INT32(data_len); |
| 372 | } |
nothing calls this directly
no test coverage detected