Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1oJ1di-0001mx-DB for pgsql-hackers@arkaria.postgresql.org; Tue, 02 Aug 2022 23:49:30 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1oJ1dh-0007HE-3Y for pgsql-hackers@arkaria.postgresql.org; Tue, 02 Aug 2022 23:49:29 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1oJ1dg-0007H5-Nl for pgsql-hackers@lists.postgresql.org; Tue, 02 Aug 2022 23:49:28 +0000 Received: from mail-pl1-x636.google.com ([2607:f8b0:4864:20::636]) by magus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1oJ1db-00068A-TS for pgsql-hackers@postgresql.org; Tue, 02 Aug 2022 23:49:28 +0000 Received: by mail-pl1-x636.google.com with SMTP id iw1so14861501plb.6 for ; Tue, 02 Aug 2022 16:49:23 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to; bh=v+9FwutrPUMFv8gy0aMDswTJO9wqPpNT40KOgQbMEns=; b=IcBqUPnDTttVDkAcyDNENmNPq5aqWlS3ViQkZM7mW4nFsxPwokvCxMjLJoQf9Zn7Gb gKtWWp5Rx1SU8WXG04mxZn9ZX+0z+mxHvHgspLWW/hH7lmE66p6OZ5d2/WcYybtrhr4g YU+mQEJ7mCgUHoGOnl2SkY5m1k0q0S9pAdMlYLxIG+qXILdTlq+E0BwVtRXAh5osLa5p v8UXQv5gd2GicI7YjGv9XLsuYF4ij16J9c4EVGe170eHF/pH3tH7hOXnIgvIQS3Q3Hwn AmEqkkaEJBRv3h89SoaGD/23VhturMdrHuFT0CEDVPZW2ujUuADA0t2Q/U4ud3wCVNKO Wk5Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=v+9FwutrPUMFv8gy0aMDswTJO9wqPpNT40KOgQbMEns=; b=1cyHC4KqMpXHQ20HS04Dn8GUbDFDpGCUKeScQGJgnF2inwE6mu2CghpIG2Dp3qQ0BT lNhpAyZCI/xiCSq5Iow+HVRSAKQChNLbc9vgnJ00aR9clKn8BL9xSu6KjOtPSLCoc4FP yIQ4dekZKWwkxExbT35c2hEzNzv2fq6l3SixN8gSUw4+HBzwc2ztfz9tYQGjfmWmq1FD pyS1/CdTyPc2dTwMLo+pTdLG7ooG/RNtVJwS5oQhhL+dte31QItzVlNssOHudLbLDXHs xtqVOhbh6uO5/AIGmGNfCwDafXCmo0PBJzNBi4clxOzltd5x7P17AbCQrW+3yu2MnwLE J8Cw== X-Gm-Message-State: ACgBeo10hjBNbp/8PE0spqSv6uyy4RVtw/+7LTgbRqab6oTPXXS1Yuvt nifbgQlqgRrn9RKrncHlUiI= X-Google-Smtp-Source: AA6agR4HeGjjs9VGiwfdyaYuw/w4QJ33JF+gbgkkMNQ6jDnCwIsHGF6Z4lCAJ8tlFYZG14nG/9bhcw== X-Received: by 2002:a17:902:e549:b0:16d:d024:2de2 with SMTP id n9-20020a170902e54900b0016dd0242de2mr23145328plf.66.1659484161780; Tue, 02 Aug 2022 16:49:21 -0700 (PDT) Received: from nathanxps13 ([50.54.155.70]) by smtp.gmail.com with ESMTPSA id x187-20020a6231c4000000b0052c4b3e6f6asm11758668pfx.97.2022.08.02.16.49.21 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 02 Aug 2022 16:49:21 -0700 (PDT) Date: Tue, 2 Aug 2022 16:49:19 -0700 From: Nathan Bossart To: Michael Paquier Cc: Soumyadeep Chakraborty , "Sanaba, Bilva" , "pgsql-hackers@postgresql.org" Subject: Re: Adding Support for Copy callback functionality on COPY TO api Message-ID: <20220802234919.GA841243@nathanxps13> References: <253C21D1-FCEB-41D9-A2AF-E6517015B7D7@amazon.com> <20200930074151.GR1996@paquier.xyz> MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="gBBFr7Ir9EOA20Yy" Content-Disposition: inline In-Reply-To: <20200930074151.GR1996@paquier.xyz> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk --gBBFr7Ir9EOA20Yy Content-Type: text/plain; charset=us-ascii Content-Disposition: inline On Wed, Sep 30, 2020 at 04:41:51PM +0900, Michael Paquier wrote: > This feedback has not been answered after two weeks, so I have marked > the patch as returned with feedback. I've rebased this patch and will register it in the next commitfest shortly. -- Nathan Bossart Amazon Web Services: https://aws.amazon.com --gBBFr7Ir9EOA20Yy Content-Type: text/x-diff; charset=us-ascii Content-Disposition: attachment; filename="v2-0001-Support-COPY-TO-callback-functions.patch" From a1c0704a094f849a587c7332a547c89581f4f7e6 Mon Sep 17 00:00:00 2001 From: Nathan Bossart Date: Tue, 2 Aug 2022 16:15:01 -0700 Subject: [PATCH v2 1/1] Support COPY TO callback functions. --- src/backend/commands/copy.c | 2 +- src/backend/commands/copyto.c | 18 +++++++++++++++--- src/include/commands/copy.h | 3 ++- src/tools/pgindent/typedefs.list | 1 + 4 files changed, 19 insertions(+), 5 deletions(-) diff --git a/src/backend/commands/copy.c b/src/backend/commands/copy.c index 3ac731803b..f714c5e22e 100644 --- a/src/backend/commands/copy.c +++ b/src/backend/commands/copy.c @@ -304,7 +304,7 @@ DoCopy(ParseState *pstate, const CopyStmt *stmt, cstate = BeginCopyTo(pstate, rel, query, relid, stmt->filename, stmt->is_program, - stmt->attlist, stmt->options); + NULL, stmt->attlist, stmt->options); *processed = DoCopyTo(cstate); /* copy from database to file */ EndCopyTo(cstate); } diff --git a/src/backend/commands/copyto.c b/src/backend/commands/copyto.c index fca29a9a10..a7b8ec030d 100644 --- a/src/backend/commands/copyto.c +++ b/src/backend/commands/copyto.c @@ -51,6 +51,7 @@ typedef enum CopyDest { COPY_FILE, /* to file (or a piped program) */ COPY_FRONTEND, /* to frontend */ + COPY_CALLBACK, /* to callback function */ } CopyDest; /* @@ -85,6 +86,7 @@ typedef struct CopyToStateData List *attnumlist; /* integer list of attnums to copy */ char *filename; /* filename, or NULL for STDOUT */ bool is_program; /* is 'filename' a program to popen? */ + copy_data_dest_cb data_dest_cb; /* function for writing data */ CopyFormatOptions opts; Node *whereClause; /* WHERE condition (or NULL) */ @@ -247,6 +249,9 @@ CopySendEndOfRow(CopyToState cstate) /* Dump the accumulated row as one CopyData message */ (void) pq_putmessage('d', fe_msgbuf->data, fe_msgbuf->len); break; + case COPY_CALLBACK: + cstate->data_dest_cb(fe_msgbuf->data, fe_msgbuf->len); + break; } /* Update the progress */ @@ -344,11 +349,12 @@ BeginCopyTo(ParseState *pstate, Oid queryRelId, const char *filename, bool is_program, + copy_data_dest_cb data_dest_cb, List *attnamelist, List *options) { CopyToState cstate; - bool pipe = (filename == NULL); + bool pipe = (filename == NULL && data_dest_cb == NULL); TupleDesc tupDesc; int num_phys_attrs; MemoryContext oldcontext; @@ -656,7 +662,13 @@ BeginCopyTo(ParseState *pstate, cstate->copy_dest = COPY_FILE; /* default */ - if (pipe) + if (data_dest_cb) + { + progress_vals[1] = PROGRESS_COPY_TYPE_CALLBACK; + cstate->copy_dest = COPY_CALLBACK; + cstate->data_dest_cb = data_dest_cb; + } + else if (pipe) { progress_vals[1] = PROGRESS_COPY_TYPE_PIPE; @@ -769,7 +781,7 @@ EndCopyTo(CopyToState cstate) uint64 DoCopyTo(CopyToState cstate) { - bool pipe = (cstate->filename == NULL); + bool pipe = (cstate->filename == NULL && cstate->data_dest_cb == NULL); bool fe_copy = (pipe && whereToSendOutput == DestRemote); TupleDesc tupDesc; int num_phys_attrs; diff --git a/src/include/commands/copy.h b/src/include/commands/copy.h index cb0096aeb6..76b9d5c23f 100644 --- a/src/include/commands/copy.h +++ b/src/include/commands/copy.h @@ -66,6 +66,7 @@ typedef struct CopyFromStateData *CopyFromState; typedef struct CopyToStateData *CopyToState; typedef int (*copy_data_source_cb) (void *outbuf, int minread, int maxread); +typedef void (*copy_data_dest_cb) (void *data, int len); extern void DoCopy(ParseState *state, const CopyStmt *stmt, int stmt_location, int stmt_len, @@ -91,7 +92,7 @@ extern DestReceiver *CreateCopyDestReceiver(void); */ extern CopyToState BeginCopyTo(ParseState *pstate, Relation rel, RawStmt *query, Oid queryRelId, const char *filename, bool is_program, - List *attnamelist, List *options); + copy_data_dest_cb data_dest_cb, List *attnamelist, List *options); extern void EndCopyTo(CopyToState cstate); extern uint64 DoCopyTo(CopyToState cstate); extern List *CopyGetAttnums(TupleDesc tupDesc, Relation rel, diff --git a/src/tools/pgindent/typedefs.list b/src/tools/pgindent/typedefs.list index 35c9f1efce..83e5270034 100644 --- a/src/tools/pgindent/typedefs.list +++ b/src/tools/pgindent/typedefs.list @@ -3189,6 +3189,7 @@ compare_context config_var_value contain_aggs_of_level_context convert_testexpr_context +copy_data_dest_cb copy_data_source_cb core_YYSTYPE core_yy_extra_type -- 2.25.1 --gBBFr7Ir9EOA20Yy--