Skip to content

Commit

Permalink
[clickhousereader] Use offical recommended Handling DateTime and time…
Browse files Browse the repository at this point in the history
… zone method.
  • Loading branch information
wgzhao committed Jan 8, 2022
1 parent b118f3a commit 4c9a08f
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 6 deletions.
2 changes: 1 addition & 1 deletion plugin/reader/clickhousereader/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
</dependency>

<dependency>
<groupId>ru.yandex.clickhouse</groupId>
<groupId>com.clickhouse</groupId>
<artifactId>clickhouse-jdbc</artifactId>
<version>${clickhouse.jdbc.version}</version>
</dependency>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,13 @@
import java.sql.ResultSet;
import java.sql.ResultSetMetaData;
import java.sql.SQLException;
import java.sql.Timestamp;
import java.sql.Types;
import java.util.Calendar;
import java.time.LocalDateTime;
import java.util.List;

import static com.wgzhao.addax.common.base.Constant.DEFAULT_FETCH_SIZE;

public class ClickHouseReader
extends Reader
{
Expand All @@ -54,7 +57,7 @@ public static class Job
public void init()
{
this.originalConfig = super.getPluginJobConf();
this.originalConfig.set(Key.FETCH_SIZE, Integer.MIN_VALUE);
this.originalConfig.set(Key.FETCH_SIZE, DEFAULT_FETCH_SIZE);

this.commonRdbmsReaderJob = new CommonRdbmsReader.Job(DATABASE_TYPE);
this.originalConfig = this.commonRdbmsReaderJob.init(this.originalConfig);
Expand Down Expand Up @@ -103,15 +106,17 @@ protected Column createColumn(ResultSet rs, ResultSetMetaData metaData, int i)
throws SQLException, UnsupportedEncodingException
{
int dataType = metaData.getColumnType(i);
// Please to use java.time.LocalDateTime or java.time.OffsetDateTime instead of java.sql.Timestamp,
// and java.time.LocalDate instead of java.sql.Date.
// references https://github.com/ClickHouse/clickhouse-jdbc/tree/master/clickhouse-jdbc
if (dataType == Types.TIMESTAMP) {
return new TimestampColumn(rs.getTimestamp(i, Calendar.getInstance()));
return new TimestampColumn(Timestamp.valueOf((LocalDateTime) rs.getObject(i)));
}
else if (dataType == Types.OTHER) {
String tz = "Asia/Chongqing";
// database-specific type, convert it to string as default
String dType = metaData.getColumnTypeName(i);
if (dType.startsWith("DateTime")) {
return new TimestampColumn(rs.getTimestamp(i));
return new TimestampColumn(Timestamp.valueOf((LocalDateTime) rs.getObject(i)));
}
else {
return new StringColumn(rs.getObject(i).toString());
Expand Down

0 comments on commit 4c9a08f

Please sign in to comment.