Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1u0cZn-004YO5-7H for pgsql-hackers@arkaria.postgresql.org; Fri, 04 Apr 2025 08:38:59 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.94.2) (envelope-from ) id 1u0cZl-00FQSv-VM for pgsql-hackers@arkaria.postgresql.org; Fri, 04 Apr 2025 08:38:57 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1u0cZk-00FQSf-RV for pgsql-hackers@lists.postgresql.org; Fri, 04 Apr 2025 08:38:57 +0000 Received: from mail.clear-code.com ([2401:2500:102:3037:153:126:203:179]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1u0cZf-003Jrc-2O for pgsql-hackers@postgresql.org; Fri, 04 Apr 2025 08:38:55 +0000 Received: from localhost (unknown [IPv6:2404:7a80:9f01:f500:af1b:fa00:91d6:aaa9]) by mail.clear-code.com (Postfix) with ESMTPSA id B0D1F6A13DB; Fri, 4 Apr 2025 17:38:41 +0900 (JST) DKIM-Filter: OpenDKIM Filter v2.11.0 mail.clear-code.com B0D1F6A13DB DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=clear-code.com; s=default; t=1743755921; bh=3dTOkrQf5Q5szCj25T9ZLc+00jZeouVFeNN3tdkIe9k=; h=Date:To:Cc:Subject:From:In-Reply-To:References:From; b=eOBRMQDcEAd35GxVloPChBBLcnYP6V284TYQi8vxhgsoe+n/j5vezvvvv1PscRXtF kcB1nRgqwwj50Xr7R86GQX+e7FaHBzr+/DuovgYCiS7NjrEytNOJKlhgAg/1dYwhS8 eHRiBU4bxCeIi2Z3j8cllE3fbstBxdIpi+8x8Nfc= Date: Fri, 04 Apr 2025 17:38:39 +0900 (JST) Message-Id: <20250404.173839.2270460917518093037.kou@clear-code.com> To: sawada.mshk@gmail.com Cc: david.g.johnston@gmail.com, tgl@sss.pgh.pa.us, zhjwpku@gmail.com, michael@paquier.xyz, pgsql-hackers@postgresql.org Subject: Re: Make COPY format extendable: Extract COPY TO format implementations From: Sutou Kouhei In-Reply-To: References: <20250329.175753.98922209929527465.kou@clear-code.com> X-Mailer: Mew version 6.8 on Emacs 30.1 Mime-Version: 1.0 Content-Type: Text/Plain; charset=us-ascii Content-Transfer-Encoding: 7bit X-Rspamd-Server: mail.clear-code.com X-Rspamd-Queue-Id: B0D1F6A13DB X-Rspamd-Action: no action X-Spamd-Result: default: False [2.90 / 999.00]; SUSPICIOUS_RECIPS(1.50)[]; MID_CONTAINS_FROM(1.00)[]; MV_CASE(0.50)[]; MIME_GOOD(-0.10)[text/plain]; FUZZY_RATELIMITED(0.00)[rspamd.com]; ARC_NA(0.00)[]; ASN(0.00)[asn:2518, ipnet:2404:7a80::/29, country:JP]; TAGGED_RCPT(0.00)[]; MIME_TRACE(0.00)[0:+]; RCVD_COUNT_ZERO(0.00)[0]; FREEMAIL_ENVRCPT(0.00)[gmail.com]; FREEMAIL_CC(0.00)[gmail.com,sss.pgh.pa.us,paquier.xyz,postgresql.org]; FROM_HAS_DN(0.00)[]; FREEMAIL_TO(0.00)[gmail.com]; FROM_EQ_ENVFROM(0.00)[]; TO_MATCH_ENVRCPT_ALL(0.00)[]; TO_DN_NONE(0.00)[]; RCPT_COUNT_FIVE(0.00)[6] List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk Hi, In "Re: Make COPY format extendable: Extract COPY TO format implementations" on Mon, 31 Mar 2025 12:35:23 -0700, Masahiko Sawada wrote: > Most of the queries under test_copy_format/sql verifies the input > patterns of the FORMAT option. I find that the regression tests > included in that directory probably should focus on testing new > callback APIs and some regression tests for FORMAT option handling can > be moved into the normal regression test suite (e.g., in copy.sql or a > new file like copy_format.sql). IIUC testing for invalid input > patterns can be done even without creating artificial wrong handler > functions. Can we clarify what should we do for the next patch set before we create the next patch set? Are the followings correct? 1. Move invalid input patterns in src/test/modules/test_copy_format/sql/invalid.sql to src/test/regress/sql/copy.sql as much as possible. * We can do only 4 patterns in 16 patterns. * Other tests in src/test/modules/test_copy_format/sql/*.sql depend on custom COPY handler for test. So we can't move to src/test/regress/sql/copy.sql. 2. Create src/test/modules/test_copy_format/sql/test_copy_format.sql and move all contents in existing *.sql to the file > I'd like to see in the comment what the tests expect. Taking the > following queries as an example, > > COPY public.test FROM stdin WITH (FORMAT 'test_copy_format'); > \. > COPY public.test TO stdout WITH (FORMAT 'test_copy_format'); > > it would help readers understand the test case better if we have a > comment like for example: > > -- Specify the custom format name without schema. We test if both > -- COPY TO and COPY FROM can find the correct handler function > -- in public schema. I agree with you that the comment is useful when we use src/test/modules/test_copy_format/sql/test_copy_format.sql for all tests. (I feel that it's redundant when we use no_schema.sql.) I'll add it when I create test_copy_format.sql in the next patch set. >> BTW, the current implementation always uses >> pg_catalog.{text,csv,binary} for (not-qualified) "text", >> "csv" and "binary" even when there are >> myschema.{text,csv,binary}. See >> src/test/modules/test_copy_format/sql/builtin.sql. But I >> haven't looked into it why... > > Sorry, I don't follow that. IIUC test_copy_format extension doesn't > create a handler function in myschema schema, and SQLs in builtin.sql > seem to work as expected (specifying a non-qualified built-in format > unconditionally uses the built-in format). Ah, sorry. I should have not used "myschema." in the text with builtin.sql reference. I just wanted to say "qualified text,csv,binary formats" by "myschema.{text,csv,binary}". In builtin.sql uses "public" schema not "myschema" schema. Sorry. Yes. builtin.sql works as expected but I don't know why. I don't add any special codes for them. If "test_copy_format" exists in public schema, "FORMAT 'test_copy_format'" uses it. But if "text" exists in public schema, "FORMAT 'text'" doesn't uses it. ("pg_catalog.text" is used instead.) >> We can do it but I suggest that we do it as a refactoring >> (or cleanup) in a separated patch for easy to review. > > I think that csv_mode and binary are used mostly in > ProcessCopyOptions() so probably we can use local variables for that. > I find there are two other places where to use csv_mode: > NextCopyFromRawFields() and CopyToTextLikeStart(). I think we can > simply check the handler function's OID there, or we can define macros > like COPY_FORMAT_IS_TEXT/CSV/BINARY checking the OID and use them > there. We need this change for "ready for merge", right? Can we clarify items should be resolved for "ready for merge"? Are the followings correct? 1. Move invalid input patterns in src/test/modules/test_copy_format/sql/invalid.sql to src/test/regress/sql/copy.sql as much as possible. 2. Create src/test/modules/test_copy_format/sql/test_copy_format.sql and move all contents in existing *.sql to the file. 3. Add comments what the tests expect to src/test/modules/test_copy_format/sql/test_copy_format.sql. 4. Remove CopyFormatOptions::{binary,csv_mode}. 5. Squash the "Support custom format" patch and the "Define handler functions for built-in formats" patch. * Could you do it when you push it? Or is it required for "ready for merge"? 6. Use handler OID for detecting the default built-in format instead of comparing the given format as string. 7. Update documentation. There are 3 unconfirmed suggested changes for tests in: https://www.postgresql.org/message-id/20250330.113126.433742864258096312.kou%40clear-code.com Here are my opinions for them: > 1.: There is no difference between single-quoting and > double-quoting here. Because the information what quote > was used for the given FORMAT value isn't remained > here. Should we update gram.y? > > 2.: I don't have a strong opinion for it. If nobody objects > it, I'll remove them. > > 3.: I don't have a strong opinion for it. If nobody objects > it, I'll remove them. Is the 1. required for "ready for merge"? If so, is there any suggestion? I don't have a strong opinion for it. If there are no more opinions for 2. and 3., I'll remove them. Thanks, -- kou