From a3ed6badd16169db00e7c4fa1a6118bab1d1dadf Mon Sep 17 00:00:00 2001 From: Ashhar Hasan Date: Wed, 9 Mar 2022 12:49:28 +0530 Subject: [PATCH] Add type mapping tests for Postgres serial types --- .../postgresql/TestPostgreSqlTypeMapping.java | 36 +++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/plugin/trino-postgresql/src/test/java/io/trino/plugin/postgresql/TestPostgreSqlTypeMapping.java b/plugin/trino-postgresql/src/test/java/io/trino/plugin/postgresql/TestPostgreSqlTypeMapping.java index ea98c41cdd2f..88400d2e0a11 100644 --- a/plugin/trino-postgresql/src/test/java/io/trino/plugin/postgresql/TestPostgreSqlTypeMapping.java +++ b/plugin/trino-postgresql/src/test/java/io/trino/plugin/postgresql/TestPostgreSqlTypeMapping.java @@ -218,6 +218,18 @@ public void testSmallint() .execute(getQueryRunner(), trinoCreateAndInsert("test_smallint")); } + @Test + public void testSmallserial() + { + // smallserial is an autoincrementing smallint and doesn't accept NULLs + SqlDataTypeTest.create() + .addRoundTrip("smallserial", "-32768", SMALLINT, "SMALLINT '-32768'") // min value in PostgreSQL and Trino + .addRoundTrip("smallserial", "32456", SMALLINT, "SMALLINT '32456'") + .addRoundTrip("smallserial", "32767", SMALLINT, "SMALLINT '32767'") // max value in PostgreSQL and Trino + .execute(getQueryRunner(), postgresCreateAndInsert("tpch.test_smallserial")) + .execute(getQueryRunner(), postgresCreateTrinoInsert("tpch.test_smallserial")); + } + @Test public void testUnsupportedSmallint() { @@ -244,6 +256,18 @@ public void testInteger() .execute(getQueryRunner(), trinoCreateAndInsert("test_int")); } + @Test + public void testSerial() + { + // serial is an autoincrementing int and doesn't accept NULLs + SqlDataTypeTest.create() + .addRoundTrip("serial", "-2147483648", INTEGER, "-2147483648") // min value in PostgreSQL and Trino + .addRoundTrip("serial", "1234567890", INTEGER, "1234567890") + .addRoundTrip("serial", "2147483647", INTEGER, "2147483647") // max value in PostgreSQL and Trino + .execute(getQueryRunner(), postgresCreateAndInsert("tpch.test_serial")) + .execute(getQueryRunner(), postgresCreateTrinoInsert("tpch.test_serial")); + } + @Test public void testUnsupportedInteger() { @@ -270,6 +294,18 @@ public void testBigint() .execute(getQueryRunner(), trinoCreateAndInsert("test_bigint")); } + @Test + public void testBigserial() + { + // bigserial is an autoincrementing bigint and doesn't accept NULLs + SqlDataTypeTest.create() + .addRoundTrip("bigserial", "-9223372036854775808", BIGINT, "-9223372036854775808") // min value in PostgreSQL and Trino + .addRoundTrip("bigserial", "123456789012", BIGINT, "123456789012") + .addRoundTrip("bigserial", "9223372036854775807", BIGINT, "9223372036854775807") // max value in PostgreSQL and Trino + .execute(getQueryRunner(), postgresCreateAndInsert("tpch.test_bigserial")) + .execute(getQueryRunner(), postgresCreateTrinoInsert("tpch.test_bigserial")); + } + @Test public void testUnsupportedBigint() {