From 804b1738ecc54cb75cf062cd63e9cbcc6f823922 Mon Sep 17 00:00:00 2001 From: Piotr Findeisen Date: Mon, 27 Jul 2020 12:29:48 +0200 Subject: [PATCH] Test row representation in JDBC ResultSet --- .../io/prestosql/jdbc/TestJdbcResultSet.java | 30 +++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/presto-jdbc/src/test/java/io/prestosql/jdbc/TestJdbcResultSet.java b/presto-jdbc/src/test/java/io/prestosql/jdbc/TestJdbcResultSet.java index 9adb6bf0ec03b..4102b01a6f6a7 100644 --- a/presto-jdbc/src/test/java/io/prestosql/jdbc/TestJdbcResultSet.java +++ b/presto-jdbc/src/test/java/io/prestosql/jdbc/TestJdbcResultSet.java @@ -309,6 +309,36 @@ public void testMap() }); } + @Test + public void testRow() + throws Exception + { + // named row + checkRepresentation("CAST(ROW(42, 'Presto') AS ROW(a_bigint bigint, a_varchar varchar(17)))", Types.JAVA_OBJECT, (rs, column) -> { + assertEquals(rs.getObject(column), ImmutableMap.of("a_bigint", 42L, "a_varchar", "Presto")); + assertEquals(rs.getObject(column, Map.class), ImmutableMap.of("a_bigint", 42L, "a_varchar", "Presto")); + }); + + // partially named row + checkRepresentation("CAST(ROW(42, 'Presto') AS ROW(a_bigint bigint, varchar(17)))", Types.JAVA_OBJECT, (rs, column) -> { + assertEquals(rs.getObject(column), ImmutableMap.of("a_bigint", 42L, "field1", "Presto")); + assertEquals(rs.getObject(column, Map.class), ImmutableMap.of("a_bigint", 42L, "field1", "Presto")); + }); + + // anonymous row + checkRepresentation("ROW(42, 'Presto')", Types.JAVA_OBJECT, (rs, column) -> { + assertEquals(rs.getObject(column), ImmutableMap.of("field0", 42, "field1", "Presto")); + assertEquals(rs.getObject(column, Map.class), ImmutableMap.of("field0", 42, "field1", "Presto")); + }); + + // name collision + checkRepresentation("CAST(ROW(42, 'Presto') AS ROW(field1 integer, varchar(17)))", Types.JAVA_OBJECT, (rs, column) -> { + // TODO (https://github.com/prestosql/presto/issues/4594) both fields should be visible or exception thrown + assertEquals(rs.getObject(column), ImmutableMap.of("field1", "Presto")); + assertEquals(rs.getObject(column, Map.class), ImmutableMap.of("field1", "Presto")); + }); + } + private void checkRepresentation(String expression, int expectedSqlType, Object expectedRepresentation) throws Exception {