Skip to content

Commit

Permalink
Test map representation in JDBC ResultSet
Browse files Browse the repository at this point in the history
  • Loading branch information
findepi committed Jul 29, 2020
1 parent 0222860 commit df0313f
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions presto-jdbc/src/test/java/io/prestosql/jdbc/TestJdbcResultSet.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
*/
package io.prestosql.jdbc;

import com.google.common.collect.ImmutableMap;
import io.airlift.log.Logging;
import io.prestosql.server.testing.TestingPrestoServer;
import org.testng.annotations.AfterClass;
Expand All @@ -35,6 +36,8 @@
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.LocalTime;
import java.util.HashMap;
import java.util.Map;

import static java.lang.String.format;
import static java.util.concurrent.TimeUnit.DAYS;
Expand Down Expand Up @@ -287,6 +290,25 @@ public void testArray()
checkRepresentation("ARRAY[1, 2]", Types.ARRAY, (rs, column) -> assertEquals(rs.getArray(column).getArray(), new int[] {1, 2}));
}

@Test
public void testMap()
throws Exception
{
checkRepresentation("map(ARRAY['k1', 'k2'], ARRAY[BIGINT '42', -117])", Types.JAVA_OBJECT, (rs, column) -> {
assertEquals(rs.getObject(column), ImmutableMap.of("k1", 42L, "k2", -117L));
assertEquals(rs.getObject(column, Map.class), ImmutableMap.of("k1", 42L, "k2", -117L));
});

// NULL value
checkRepresentation("map(ARRAY['k1', 'k2'], ARRAY[42, NULL])", Types.JAVA_OBJECT, (rs, column) -> {
Map<String, Integer> expected = new HashMap<>();
expected.put("k1", 42);
expected.put("k2", null);
assertEquals(rs.getObject(column), expected);
assertEquals(rs.getObject(column, Map.class), expected);
});
}

private void checkRepresentation(String expression, int expectedSqlType, Object expectedRepresentation)
throws Exception
{
Expand Down

0 comments on commit df0313f

Please sign in to comment.