@Test public void testEmptyBuildSql() throws SQLException { TupleDomain<ColumnHandle> tupleDomain = TupleDomain.withColumnDomains(ImmutableMap.of( columns.get(0), Domain.all(BIGINT), columns.get(1), Domain.onlyNull(DOUBLE))); Connection connection = database.getConnection(); try (PreparedStatement preparedStatement = new QueryBuilder("\"").buildSql(jdbcClient, connection, "", "", "test_table", columns, tupleDomain, Optional.empty()); ResultSet resultSet = preparedStatement.executeQuery()) { assertEquals(resultSet.next(), false); } }
@Test public void testBuildSqlWithFloat() throws SQLException { TupleDomain<ColumnHandle> tupleDomain = TupleDomain.withColumnDomains(ImmutableMap.of( columns.get(10), Domain.create(SortedRangeSet.copyOf(REAL, ImmutableList.of( Range.equal(REAL, (long) floatToRawIntBits(100.0f + 0)), Range.equal(REAL, (long) floatToRawIntBits(100.008f + 0)), Range.equal(REAL, (long) floatToRawIntBits(100.0f + 14)))), false))); Connection connection = database.getConnection(); try (PreparedStatement preparedStatement = new QueryBuilder("\"").buildSql(jdbcClient, connection, "", "", "test_table", columns, tupleDomain, Optional.empty()); ResultSet resultSet = preparedStatement.executeQuery()) { ImmutableSet.Builder<Long> longBuilder = ImmutableSet.builder(); ImmutableSet.Builder<Float> floatBuilder = ImmutableSet.builder(); while (resultSet.next()) { longBuilder.add((Long) resultSet.getObject("col_0")); floatBuilder.add((Float) resultSet.getObject("col_10")); } assertEquals(longBuilder.build(), ImmutableSet.of(0L, 14L)); assertEquals(floatBuilder.build(), ImmutableSet.of(100.0f, 114.0f)); } }
@Override public PreparedStatement buildSql(Connection connection, JdbcSplit split, List<JdbcColumnHandle> columnHandles) throws SQLException { return new QueryBuilder(identifierQuote).buildSql( this, connection, split.getCatalogName(), split.getSchemaName(), split.getTableName(), columnHandles, split.getTupleDomain(), split.getAdditionalPredicate()); }
@Test public void testBuildSqlWithVarchar() throws SQLException { TupleDomain<ColumnHandle> tupleDomain = TupleDomain.withColumnDomains(ImmutableMap.of( columns.get(3), Domain.create(SortedRangeSet.copyOf(VARCHAR, ImmutableList.of( Range.range(VARCHAR, utf8Slice("test_str_700"), true, utf8Slice("test_str_702"), false), Range.equal(VARCHAR, utf8Slice("test_str_180")), Range.equal(VARCHAR, utf8Slice("test_str_196")))), false))); Connection connection = database.getConnection(); try (PreparedStatement preparedStatement = new QueryBuilder("\"").buildSql(jdbcClient, connection, "", "", "test_table", columns, tupleDomain, Optional.empty()); ResultSet resultSet = preparedStatement.executeQuery()) { ImmutableSet.Builder<String> builder = ImmutableSet.builder(); while (resultSet.next()) { builder.add((String) resultSet.getObject("col_3")); } assertEquals(builder.build(), ImmutableSet.of("test_str_700", "test_str_701", "test_str_180", "test_str_196")); assertContains(preparedStatement.toString(), "\"col_3\" >= ?"); assertContains(preparedStatement.toString(), "\"col_3\" < ?"); assertContains(preparedStatement.toString(), "\"col_3\" IN (?,?)"); } }
@Test public void testBuildSqlWithChar() throws SQLException { CharType charType = CharType.createCharType(0); TupleDomain<ColumnHandle> tupleDomain = TupleDomain.withColumnDomains(ImmutableMap.of( columns.get(11), Domain.create(SortedRangeSet.copyOf(charType, ImmutableList.of( Range.range(charType, utf8Slice("test_str_700"), true, utf8Slice("test_str_702"), false), Range.equal(charType, utf8Slice("test_str_180")), Range.equal(charType, utf8Slice("test_str_196")))), false))); Connection connection = database.getConnection(); try (PreparedStatement preparedStatement = new QueryBuilder("\"").buildSql(jdbcClient, connection, "", "", "test_table", columns, tupleDomain, Optional.empty()); ResultSet resultSet = preparedStatement.executeQuery()) { ImmutableSet.Builder<String> builder = ImmutableSet.builder(); while (resultSet.next()) { builder.add((String) resultSet.getObject("col_11")); } assertEquals(builder.build(), ImmutableSet.of("test_str_700", "test_str_701", "test_str_180", "test_str_196")); assertContains(preparedStatement.toString(), "\"col_11\" >= ?"); assertContains(preparedStatement.toString(), "\"col_11\" < ?"); assertContains(preparedStatement.toString(), "\"col_11\" IN (?,?)"); } }
@Test public void testBuildSqlWithTimestamp() throws SQLException { TupleDomain<ColumnHandle> tupleDomain = TupleDomain.withColumnDomains(ImmutableMap.of( columns.get(6), Domain.create(SortedRangeSet.copyOf(TIMESTAMP, ImmutableList.of( Range.equal(TIMESTAMP, toTimestamp(2016, 6, 3, 0, 23, 37).getTime()), Range.equal(TIMESTAMP, toTimestamp(2016, 10, 19, 16, 23, 37).getTime()), Range.range(TIMESTAMP, toTimestamp(2016, 6, 7, 8, 23, 37).getTime(), false, toTimestamp(2016, 6, 9, 12, 23, 37).getTime(), true))), false))); Connection connection = database.getConnection(); try (PreparedStatement preparedStatement = new QueryBuilder("\"").buildSql(jdbcClient, connection, "", "", "test_table", columns, tupleDomain, Optional.empty()); ResultSet resultSet = preparedStatement.executeQuery()) { ImmutableSet.Builder<Timestamp> builder = ImmutableSet.builder(); while (resultSet.next()) { builder.add((Timestamp) resultSet.getObject("col_6")); } assertEquals(builder.build(), ImmutableSet.of( toTimestamp(2016, 6, 3, 0, 23, 37), toTimestamp(2016, 6, 8, 10, 23, 37), toTimestamp(2016, 6, 9, 12, 23, 37), toTimestamp(2016, 10, 19, 16, 23, 37))); assertContains(preparedStatement.toString(), "\"col_6\" > ?"); assertContains(preparedStatement.toString(), "\"col_6\" <= ?"); assertContains(preparedStatement.toString(), "\"col_6\" IN (?,?)"); } }
try (PreparedStatement preparedStatement = new QueryBuilder("\"").buildSql(jdbcClient, connection, "", "", "test_table", columns, tupleDomain, Optional.empty()); ResultSet resultSet = preparedStatement.executeQuery()) { ImmutableSet.Builder<Date> dateBuilder = ImmutableSet.builder();
try (PreparedStatement preparedStatement = new QueryBuilder("\"").buildSql(jdbcClient, connection, "", "", "test_table", columns, tupleDomain, Optional.empty()); ResultSet resultSet = preparedStatement.executeQuery()) { ImmutableSet.Builder<Long> builder = ImmutableSet.builder();
@Test public void testEmptyBuildSql() throws SQLException { TupleDomain<ColumnHandle> tupleDomain = TupleDomain.withColumnDomains(ImmutableMap.of( columns.get(0), Domain.all(BIGINT), columns.get(1), Domain.onlyNull(DOUBLE))); Connection connection = database.getConnection(); try (PreparedStatement preparedStatement = new QueryBuilder("\"").buildSql(jdbcClient, connection, "", "", "test_table", columns, tupleDomain); ResultSet resultSet = preparedStatement.executeQuery()) { assertEquals(resultSet.next(), false); } }
@Override public PreparedStatement buildSql(JdbcSplit split, List<JdbcColumnHandle> columnHandles) throws SQLException { return new QueryBuilder(identifierQuote).buildSql( getConnection(split), split.getCatalogName(), split.getSchemaName(), split.getTableName(), columnHandles, split.getTupleDomain()); }
@Test public void testBuildSqlWithFloat() throws SQLException { TupleDomain<ColumnHandle> tupleDomain = TupleDomain.withColumnDomains(ImmutableMap.of( columns.get(10), Domain.create(SortedRangeSet.copyOf(REAL, ImmutableList.of( Range.equal(REAL, (long) floatToRawIntBits(100.0f + 0)), Range.equal(REAL, (long) floatToRawIntBits(100.008f + 0)), Range.equal(REAL, (long) floatToRawIntBits(100.0f + 14)))), false))); Connection connection = database.getConnection(); try (PreparedStatement preparedStatement = new QueryBuilder("\"").buildSql(jdbcClient, connection, "", "", "test_table", columns, tupleDomain); ResultSet resultSet = preparedStatement.executeQuery()) { ImmutableSet.Builder<Long> longBuilder = ImmutableSet.builder(); ImmutableSet.Builder<Float> floatBuilder = ImmutableSet.builder(); while (resultSet.next()) { longBuilder.add((Long) resultSet.getObject("col_0")); floatBuilder.add((Float) resultSet.getObject("col_10")); } assertEquals(longBuilder.build(), ImmutableSet.of(0L, 14L)); assertEquals(floatBuilder.build(), ImmutableSet.of(100.0f, 114.0f)); } }
@Test public void testBuildSqlWithVarchar() throws SQLException { TupleDomain<ColumnHandle> tupleDomain = TupleDomain.withColumnDomains(ImmutableMap.of( columns.get(3), Domain.create(SortedRangeSet.copyOf(VARCHAR, ImmutableList.of( Range.range(VARCHAR, utf8Slice("test_str_700"), true, utf8Slice("test_str_702"), false), Range.equal(VARCHAR, utf8Slice("test_str_180")), Range.equal(VARCHAR, utf8Slice("test_str_196")))), false))); Connection connection = database.getConnection(); try (PreparedStatement preparedStatement = new QueryBuilder("\"").buildSql(jdbcClient, connection, "", "", "test_table", columns, tupleDomain); ResultSet resultSet = preparedStatement.executeQuery()) { ImmutableSet.Builder<String> builder = ImmutableSet.builder(); while (resultSet.next()) { builder.add((String) resultSet.getObject("col_3")); } assertEquals(builder.build(), ImmutableSet.of("test_str_700", "test_str_701", "test_str_180", "test_str_196")); assertContains(preparedStatement.toString(), "\"col_3\" >= ?"); assertContains(preparedStatement.toString(), "\"col_3\" < ?"); assertContains(preparedStatement.toString(), "\"col_3\" IN (?,?)"); } }
@Test public void testBuildSqlWithChar() throws SQLException { CharType charType = CharType.createCharType(0); TupleDomain<ColumnHandle> tupleDomain = TupleDomain.withColumnDomains(ImmutableMap.of( columns.get(11), Domain.create(SortedRangeSet.copyOf(charType, ImmutableList.of( Range.range(charType, utf8Slice("test_str_700"), true, utf8Slice("test_str_702"), false), Range.equal(charType, utf8Slice("test_str_180")), Range.equal(charType, utf8Slice("test_str_196")))), false))); Connection connection = database.getConnection(); try (PreparedStatement preparedStatement = new QueryBuilder("\"").buildSql(jdbcClient, connection, "", "", "test_table", columns, tupleDomain); ResultSet resultSet = preparedStatement.executeQuery()) { ImmutableSet.Builder<String> builder = ImmutableSet.builder(); while (resultSet.next()) { builder.add((String) resultSet.getObject("col_11")); } assertEquals(builder.build(), ImmutableSet.of("test_str_700", "test_str_701", "test_str_180", "test_str_196")); assertContains(preparedStatement.toString(), "\"col_11\" >= ?"); assertContains(preparedStatement.toString(), "\"col_11\" < ?"); assertContains(preparedStatement.toString(), "\"col_11\" IN (?,?)"); } }
@Test public void testBuildSqlWithTimestamp() throws SQLException { TupleDomain<ColumnHandle> tupleDomain = TupleDomain.withColumnDomains(ImmutableMap.of( columns.get(6), Domain.create(SortedRangeSet.copyOf(TIMESTAMP, ImmutableList.of( Range.equal(TIMESTAMP, toTimestamp(2016, 6, 3, 0, 23, 37).getTime()), Range.equal(TIMESTAMP, toTimestamp(2016, 10, 19, 16, 23, 37).getTime()), Range.range(TIMESTAMP, toTimestamp(2016, 6, 7, 8, 23, 37).getTime(), false, toTimestamp(2016, 6, 9, 12, 23, 37).getTime(), true))), false))); Connection connection = database.getConnection(); try (PreparedStatement preparedStatement = new QueryBuilder("\"").buildSql(jdbcClient, connection, "", "", "test_table", columns, tupleDomain); ResultSet resultSet = preparedStatement.executeQuery()) { ImmutableSet.Builder<Timestamp> builder = ImmutableSet.builder(); while (resultSet.next()) { builder.add((Timestamp) resultSet.getObject("col_6")); } assertEquals(builder.build(), ImmutableSet.of( toTimestamp(2016, 6, 3, 0, 23, 37), toTimestamp(2016, 6, 8, 10, 23, 37), toTimestamp(2016, 6, 9, 12, 23, 37), toTimestamp(2016, 10, 19, 16, 23, 37))); assertContains(preparedStatement.toString(), "\"col_6\" > ?"); assertContains(preparedStatement.toString(), "\"col_6\" <= ?"); assertContains(preparedStatement.toString(), "\"col_6\" IN (?,?)"); } }
try (PreparedStatement preparedStatement = new QueryBuilder("\"").buildSql(jdbcClient, connection, "", "", "test_table", columns, tupleDomain); ResultSet resultSet = preparedStatement.executeQuery()) { ImmutableSet.Builder<Date> dateBuilder = ImmutableSet.builder();
try (PreparedStatement preparedStatement = new QueryBuilder("\"").buildSql(jdbcClient, connection, "", "", "test_table", columns, tupleDomain); ResultSet resultSet = preparedStatement.executeQuery()) { ImmutableSet.Builder<Long> builder = ImmutableSet.builder();