Patch: Cover POSITION(bytea,bytea) with tests

Started by Aleksander Alekseev11 months ago6 messages
#1Aleksander Alekseev
aleksander@timescale.com
1 attachment(s)

Hi,

This function is currently not covered by any tests. The proposed
patch fixes this.

--
Best regards,
Aleksander Alekseev

Attachments:

v1-0001-Cover-POSITION-bytea-bytea-with-tests.patchapplication/octet-stream; name=v1-0001-Cover-POSITION-bytea-bytea-with-tests.patchDownload
From bbec536a4333ae62633a5f134ef02fe0f60e0ec5 Mon Sep 17 00:00:00 2001
From: Aleksander Alekseev <aleksander@timescale.com>
Date: Thu, 27 Feb 2025 15:39:29 +0300
Subject: [PATCH v1] Cover POSITION(bytea,bytea) with tests

Aleksander Alekseev, reviewed by TODO FIXME
Discussion: TODO FIXME
---
 src/test/regress/expected/strings.out | 24 ++++++++++++++++++++++++
 src/test/regress/sql/strings.sql      |  4 ++++
 2 files changed, 28 insertions(+)

diff --git a/src/test/regress/expected/strings.out b/src/test/regress/expected/strings.out
index b65bb2d5368..1bf096f8fe1 100644
--- a/src/test/regress/expected/strings.out
+++ b/src/test/regress/expected/strings.out
@@ -2630,6 +2630,30 @@ SELECT btrim(E'\\000trim\\000'::bytea, ''::bytea);
  \000trim\000
 (1 row)
 
+SELECT position(''::bytea IN '\x1122'::bytea);
+ position 
+----------
+        1
+(1 row)
+
+SELECT position('\x11'::bytea IN ''::bytea);
+ position 
+----------
+        0
+(1 row)
+
+SELECT position('\x3344'::bytea IN '\x11223344'::bytea);
+ position 
+----------
+        3
+(1 row)
+
+SELECT position('\x5566'::bytea IN '\x11223344'::bytea);
+ position 
+----------
+        0
+(1 row)
+
 SELECT encode(overlay(E'Th\\000omas'::bytea placing E'Th\\001omas'::bytea from 2),'escape');
    encode    
 -------------
diff --git a/src/test/regress/sql/strings.sql b/src/test/regress/sql/strings.sql
index 8e0f3a0e75f..691c294f80c 100644
--- a/src/test/regress/sql/strings.sql
+++ b/src/test/regress/sql/strings.sql
@@ -830,6 +830,10 @@ SELECT trim(trailing E'\\000'::bytea from E'\\000Tom\\000'::bytea);
 SELECT btrim(E'\\000trim\\000'::bytea, E'\\000'::bytea);
 SELECT btrim(''::bytea, E'\\000'::bytea);
 SELECT btrim(E'\\000trim\\000'::bytea, ''::bytea);
+SELECT position(''::bytea IN '\x1122'::bytea);
+SELECT position('\x11'::bytea IN ''::bytea);
+SELECT position('\x3344'::bytea IN '\x11223344'::bytea);
+SELECT position('\x5566'::bytea IN '\x11223344'::bytea);
 SELECT encode(overlay(E'Th\\000omas'::bytea placing E'Th\\001omas'::bytea from 2),'escape');
 SELECT encode(overlay(E'Th\\000omas'::bytea placing E'\\002\\003'::bytea from 8),'escape');
 SELECT encode(overlay(E'Th\\000omas'::bytea placing E'\\002\\003'::bytea from 5 for 3),'escape');
-- 
2.48.1

#2Ilia Evdokimov
ilya.evdokimov@tantorlabs.com
In reply to: Aleksander Alekseev (#1)
Re: Patch: Cover POSITION(bytea,bytea) with tests

On 27.02.2025 17:40, Aleksander Alekseev wrote:

Hi,

This function is currently not covered by any tests. The proposed
patch fixes this.

--
Best regards,
Aleksander Alekseev

Hi,

+1. The 'POSISTION' tests include 'text', 'bits' types, but not 'bytea'.

--
Best regards,
Ilia Evdokimov,
Tantor Labs LLC.

#3Peter Smith
smithpb2250@gmail.com
In reply to: Aleksander Alekseev (#1)
Re: Patch: Cover POSITION(bytea,bytea) with tests

+1 for this.

Some minor comments:

1. I thought the new test cases should be located earlier in the file
where there were already a couple of POSITION tests.
(see "-- E021-11 position expression")

2. Maybe one of your test cases can be identical to the example from
the docs [1]https://www.postgresql.org/docs/17/functions-binarystring.html.
position('\x5678'::bytea in '\x1234567890'::bytea) → 3

======
[1]: https://www.postgresql.org/docs/17/functions-binarystring.html

Kind Regards,
Peter Smith.
Fujitsu Australia

#4Aleksander Alekseev
aleksander@timescale.com
In reply to: Peter Smith (#3)
1 attachment(s)
Re: Patch: Cover POSITION(bytea,bytea) with tests

Hi Peter,

Some minor comments:

1. I thought the new test cases should be located earlier in the file
where there were already a couple of POSITION tests.
(see "-- E021-11 position expression")

2. Maybe one of your test cases can be identical to the example from
the docs [1].
position('\x5678'::bytea in '\x1234567890'::bytea) → 3

Thanks.

Here is the corrected patch.

--
Best regards,
Aleksander Alekseev

Attachments:

v2-0001-Cover-POSITION-bytea-bytea-with-tests.patchapplication/octet-stream; name=v2-0001-Cover-POSITION-bytea-bytea-with-tests.patchDownload
From cab2fc3b5ed144dca28055c0ef0c2684bebb0610 Mon Sep 17 00:00:00 2001
From: Aleksander Alekseev <aleksander@timescale.com>
Date: Thu, 27 Feb 2025 15:39:29 +0300
Subject: [PATCH v2] Cover POSITION(bytea,bytea) with tests

Aleksander Alekseev, reviewed by Peter Smith, Ilia Evdokimov
Discussion: https://postgr.es/m/CAJ7c6TMT6XCooMVKnCd_tR2oBdGcnjefSeCDCv8jzKy9VkWA5w%40mail.gmail.com
---
 src/test/regress/expected/strings.out | 30 +++++++++++++++++++++++++++
 src/test/regress/sql/strings.sql      |  6 ++++++
 2 files changed, 36 insertions(+)

diff --git a/src/test/regress/expected/strings.out b/src/test/regress/expected/strings.out
index fbe7d7be71f..dc485735aa4 100644
--- a/src/test/regress/expected/strings.out
+++ b/src/test/regress/expected/strings.out
@@ -1353,6 +1353,36 @@ SELECT POSITION('5' IN '1234567890') = '5' AS "5";
  t
 (1 row)
 
+SELECT POSITION('\x11'::bytea IN ''::bytea) = 0 AS "0";
+ 0 
+---
+ t
+(1 row)
+
+SELECT POSITION('\x33'::bytea IN '\x1122'::bytea) = 0 AS "0";
+ 0 
+---
+ t
+(1 row)
+
+SELECT POSITION(''::bytea IN '\x1122'::bytea) = 1 AS "1";
+ 1 
+---
+ t
+(1 row)
+
+SELECT POSITION('\x22'::bytea IN '\x1122'::bytea) = 2 AS "2";
+ 2 
+---
+ t
+(1 row)
+
+SELECT POSITION('\x5678'::bytea IN '\x1234567890'::bytea) = 3 AS "3";
+ 3 
+---
+ t
+(1 row)
+
 -- T312 character overlay function
 SELECT OVERLAY('abcdef' PLACING '45' FROM 4) AS "abc45f";
  abc45f 
diff --git a/src/test/regress/sql/strings.sql b/src/test/regress/sql/strings.sql
index ed054e6e99c..aeba798dac1 100644
--- a/src/test/regress/sql/strings.sql
+++ b/src/test/regress/sql/strings.sql
@@ -367,6 +367,12 @@ SELECT POSITION('4' IN '1234567890') = '4' AS "4";
 
 SELECT POSITION('5' IN '1234567890') = '5' AS "5";
 
+SELECT POSITION('\x11'::bytea IN ''::bytea) = 0 AS "0";
+SELECT POSITION('\x33'::bytea IN '\x1122'::bytea) = 0 AS "0";
+SELECT POSITION(''::bytea IN '\x1122'::bytea) = 1 AS "1";
+SELECT POSITION('\x22'::bytea IN '\x1122'::bytea) = 2 AS "2";
+SELECT POSITION('\x5678'::bytea IN '\x1234567890'::bytea) = 3 AS "3";
+
 -- T312 character overlay function
 SELECT OVERLAY('abcdef' PLACING '45' FROM 4) AS "abc45f";
 
-- 
2.48.1

#5Rustam ALLAKOV
rustamallakov@gmail.com
In reply to: Aleksander Alekseev (#4)
Re: Patch: Cover POSITION(bytea,bytea) with tests

The following review has been posted through the commitfest application:
make installcheck-world: tested, passed
Implements feature: tested, passed
Spec compliant: tested, passed
Documentation: tested, passed

Hi Aleksander,
your patch looks good to me.
Changing status to `Ready for Committer`

Regards,
Rustam Allakov

The new status of this patch is: Ready for Committer

#6David Rowley
dgrowleyml@gmail.com
In reply to: Aleksander Alekseev (#4)
Re: Patch: Cover POSITION(bytea,bytea) with tests

On Tue, 18 Mar 2025 at 03:14, Aleksander Alekseev
<aleksander@timescale.com> wrote:

Here is the corrected patch.

I had a look at this and it all seems good to me.

Pushed.

David