Skip to content

Commit

Permalink
Test reading NULL only varchar from Redshift view
Browse files Browse the repository at this point in the history
Corresponding pr to Redshift JDBC driver:
aws/amazon-redshift-jdbc-driver#75

Co-authored-by: Sasha Sheikin <[email protected]>
  • Loading branch information
findinpath and ssheikin committed Mar 13, 2023
1 parent 99033a7 commit 3e4dbbc
Showing 1 changed file with 28 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@
import static io.trino.plugin.redshift.RedshiftQueryRunner.createRedshiftQueryRunner;
import static io.trino.plugin.redshift.RedshiftQueryRunner.executeInRedshift;
import static io.trino.plugin.redshift.RedshiftQueryRunner.executeWithRedshift;
import static io.trino.testing.DataProviders.cartesianProduct;
import static io.trino.testing.DataProviders.trueFalse;
import static io.trino.testing.TestingNames.randomNameSuffix;
import static java.lang.String.format;
import static java.util.Locale.ENGLISH;
Expand Down Expand Up @@ -151,6 +153,30 @@ public void testReadFromLateBindingView(String redshiftType, String trinoType)
}
}

@Test(dataProvider = "testReadNullFromViewDataProvider")
public void testReadNullFromView(String redshiftType, String trinoType, boolean lateBindingView)
{
try (TestView view = new TestView(
onRemoteDatabase(),
TEST_SCHEMA + ".cast_null_view",
"SELECT CAST(NULL AS %s) AS value %s".formatted(redshiftType, lateBindingView ? "WITH NO SCHEMA BINDING" : ""))) {
assertThat(query("SELECT value FROM %s".formatted(view.getName())))
.skippingTypesCheck() // trino returns 'unknown' for null
.matches("VALUES null");

assertThat(query("SHOW COLUMNS FROM %s LIKE 'value'".formatted(view.getName())))
.projected(1)
.skippingTypesCheck()
.matches("VALUES '%s'".formatted(trinoType));
}
}

@DataProvider
public Object[][] testReadNullFromViewDataProvider()
{
return cartesianProduct(redshiftTypeToTrinoTypes(), trueFalse());
}

@DataProvider
public Object[][] redshiftTypeToTrinoTypes()
{
Expand All @@ -164,6 +190,8 @@ public Object[][] redshiftTypeToTrinoTypes()
{"BOOLEAN", "boolean"},
{"CHAR(1)", "char(1)"},
{"VARCHAR(1)", "varchar(1)"},
// consider to extract "CHARACTER VARYING" type from here as it requires exact length, 0 - is for the empty string
{"CHARACTER VARYING", "varchar(0)"},
{"TIME", "time(6)"},
{"TIMESTAMP", "timestamp(6)"},
{"TIMESTAMPTZ", "timestamp(6) with time zone"}};
Expand Down

0 comments on commit 3e4dbbc

Please sign in to comment.