Skip to content

Commit

Permalink
Merge pull request #798 from zhicwu/patch-release
Browse files Browse the repository at this point in the history
Prepare patch release
  • Loading branch information
zhicwu authored Jan 7, 2022
2 parents 0eff748 + be3a8ff commit 6e4b5a7
Show file tree
Hide file tree
Showing 3 changed files with 99 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -348,7 +348,7 @@ public Date getDate(String columnLabel) throws SQLException {
@Override
public Date getDate(int columnIndex, Calendar cal) throws SQLException {
ClickHouseValue value = getValue(columnIndex);
if (value == null || value.isNullOrEmpty()) {
if (value.isNullOrEmpty()) {
return null;
}

Expand Down Expand Up @@ -588,7 +588,7 @@ public Time getTime(String columnLabel) throws SQLException {
@Override
public Time getTime(int columnIndex, Calendar cal) throws SQLException {
ClickHouseValue value = getValue(columnIndex);
if (value == null || value.isNullOrEmpty()) {
if (value.isNullOrEmpty()) {
return null;
}

Expand Down Expand Up @@ -619,7 +619,7 @@ public Timestamp getTimestamp(String columnLabel) throws SQLException {
@Override
public Timestamp getTimestamp(int columnIndex, Calendar cal) throws SQLException {
ClickHouseValue value = getValue(columnIndex);
if (value == null || value.isNullOrEmpty()) {
if (value.isNullOrEmpty()) {
return null;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,82 @@
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.Properties;
import java.util.function.BiFunction;

import com.clickhouse.client.ClickHouseDataType;
import com.clickhouse.client.ClickHouseValues;

import org.testng.Assert;
import org.testng.annotations.DataProvider;
import org.testng.annotations.Test;

public class ClickHouseResultSetTest extends JdbcIntegrationTest {
@DataProvider(name = "nullableTypes")
private Object[][] getNullableTypes() {
return new Object[][] {
new Object[] { ClickHouseDataType.Int32, Integer.valueOf(12345),
new BiFunction<ResultSet, Integer, Object>() {
@Override
public Object apply(ResultSet rs, Integer i) {
try {
Object obj = rs.getInt(i);
if (obj != null) {
obj = rs.getFloat(i);
}
if (obj != null) {
obj = rs.getBigDecimal(i);
}
return obj;
} catch (SQLException e) {
throw new IllegalArgumentException(e);
}
}
} },
new Object[] { ClickHouseDataType.Date, LocalDate.of(2022, 1, 7),
new BiFunction<ResultSet, Integer, Object>() {
@Override
public Object apply(ResultSet rs, Integer i) {
try {
Object obj = rs.getDate(i);
if (obj != null) {
obj = rs.getTime(i);
}
if (obj != null) {
obj = rs.getTimestamp(i);
}
return obj;
} catch (SQLException e) {
throw new IllegalArgumentException(e);
}
}
} },
new Object[] { ClickHouseDataType.DateTime, LocalDateTime.of(2022, 1, 7, 19, 11, 55),
new BiFunction<ResultSet, Integer, Object>() {
@Override
public Object apply(ResultSet rs, Integer i) {
try {
Object obj = rs.getDate(i);
if (obj != null) {
obj = rs.getTime(i);
}
if (obj != null) {
obj = rs.getTimestamp(i);
}
return obj;
} catch (SQLException e) {
throw new IllegalArgumentException(e);
}
}
} }
};
}

@Test(groups = "integration")
public void testBigDecimal() throws SQLException {
try (ClickHouseConnection conn = newConnection(new Properties());
Expand Down Expand Up @@ -78,4 +144,28 @@ public void testTuple() throws SQLException {
Assert.assertFalse(rs.next());
}
}

@Test(dataProvider = "nullableTypes", groups = "integration")
public void testNullableValues(ClickHouseDataType type, Object value, BiFunction<ResultSet, Integer, Object> func)
throws SQLException {
try (ClickHouseConnection conn = newConnection(new Properties());
Statement stmt = conn.createStatement()) {
String table = "test_nullable_" + type.name().toLowerCase();
String ddl = "drop table if exists " + table + "; create table " + table + "(v1 " + type.name()
+ ", v2 Nullable(" + type.name() + "))engine=Memory;";
String insert = "insert into " + table + " values(" + ClickHouseValues.convertToSqlExpression(value)
+ ", null);";
String query = "select * from " + table;

ResultSet rs = stmt.executeQuery(ddl + insert + query);
Assert.assertTrue(rs.next());
Assert.assertEquals(rs.getObject(1), value);
Assert.assertNotNull(rs.getString(1));
Assert.assertNotNull(func.apply(rs, 1));
Assert.assertNull(rs.getObject(2));
Assert.assertNull(rs.getString(2));
Assert.assertNull(func.apply(rs, 2));
Assert.assertFalse(rs.next());
}
}
}
12 changes: 6 additions & 6 deletions third-party-libraries/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
<name>${project.artifactId}</name>
<description>Repackaged third party libraries for JPMS compatibility</description>
<url>https://github.com/ClickHouse/clickhouse-jdbc/tree/master/third-party-libraries</url>
<inceptionYear>2021</inceptionYear>
<inceptionYear>2022</inceptionYear>

<organization>
<name>ClickHouse, Inc.</name>
Expand Down Expand Up @@ -68,14 +68,14 @@
</distributionManagement>

<properties>
<revision>1.1.0</revision>
<project.current.year>2021</project.current.year>
<revision>1.1.1</revision>
<project.current.year>2022</project.current.year>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<grpc.version>1.40.1</grpc.version>
<gson.version>2.8.8</gson.version>
<grpc.version>1.40.2</grpc.version>
<gson.version>2.8.9</gson.version>
<opencensus.version>0.28.3</opencensus.version>
<roaring-bitmap.version>0.9.22</roaring-bitmap.version>
<roaring-bitmap.version>0.9.23</roaring-bitmap.version>
<assembly-plugin.version>3.3.0</assembly-plugin.version>
<deploy-plugin.version>3.0.0-M1</deploy-plugin.version>
<flatten-plugin.version>1.2.7</flatten-plugin.version>
Expand Down

0 comments on commit 6e4b5a7

Please sign in to comment.