Skip to content

Commit

Permalink
[Feature] Support clickhouse jdbc datasource(#40894)
Browse files Browse the repository at this point in the history
Signed-off-by: samcchen <[email protected]>
  • Loading branch information
DataScientistSamChan committed Apr 8, 2024
1 parent 67bcade commit 7228a86
Show file tree
Hide file tree
Showing 10 changed files with 874 additions and 27 deletions.
52 changes: 50 additions & 2 deletions be/src/exec/jdbc_scanner.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -195,14 +195,41 @@ void JDBCScanner::_init_profile() {

StatusOr<LogicalType> JDBCScanner::_precheck_data_type(const std::string& java_class, SlotDescriptor* slot_desc) {
auto type = slot_desc->type().type;
if (java_class == "java.lang.Short") {
if (java_class == "java.lang.Byte") {
if (type != TYPE_BOOLEAN && type != TYPE_TINYINT && type != TYPE_SMALLINT && type != TYPE_INT && type != TYPE_BIGINT) {
return Status::NotSupported(
fmt::format("Type mismatches on column[{}], JDBC result type is Byte, please set the type to "
"one of boolean,tinyint,smallint,int,bigint",
slot_desc->col_name()));
}
if(type == TYPE_BOOLEAN){
return TYPE_BOOLEAN;
}
return TYPE_TINYINT;
} else if (java_class == "com.clickhouse.data.value.UnsignedByte") {
if (type != TYPE_SMALLINT && type != TYPE_INT && type != TYPE_BIGINT) {
return Status::NotSupported(
fmt::format("Type mismatches on column[{}], JDBC result type is UnsignedByte, please set the type to "
"one of smallint,int,bigint",
slot_desc->col_name()));
}
return TYPE_SMALLINT;
} else if (java_class == "java.lang.Short") {
if (type != TYPE_TINYINT && type != TYPE_SMALLINT && type != TYPE_INT && type != TYPE_BIGINT) {
return Status::NotSupported(
fmt::format("Type mismatches on column[{}], JDBC result type is Short, please set the type to "
"one of tinyint,smallint,int,bigint",
slot_desc->col_name()));
}
return TYPE_SMALLINT;
} else if (java_class == "com.clickhouse.data.value.UnsignedShort") {
if (type != TYPE_INT && type != TYPE_BIGINT) {
return Status::NotSupported(
fmt::format("Type mismatches on column[{}], JDBC result type is UnsignedShort, please set the type to "
"one of int,bigint",
slot_desc->col_name()));
}
return TYPE_INT;
} else if (java_class == "java.lang.Integer") {
if (type != TYPE_TINYINT && type != TYPE_SMALLINT && type != TYPE_INT && type != TYPE_BIGINT) {
return Status::NotSupported(
Expand All @@ -218,6 +245,13 @@ StatusOr<LogicalType> JDBCScanner::_precheck_data_type(const std::string& java_c
slot_desc->col_name()));
}
return TYPE_VARCHAR;
} else if (java_class == "com.clickhouse.data.value.UnsignedInteger") {
if (type != TYPE_BIGINT) {
return Status::NotSupported(fmt::format(
"Type mismatches on column[{}], JDBC result type is UnsignedInteger, please set the type to bigint",
slot_desc->col_name()));
}
return TYPE_BIGINT;
} else if (java_class == "java.lang.Long") {
if (type != TYPE_BIGINT) {
return Status::NotSupported(fmt::format(
Expand All @@ -232,6 +266,13 @@ StatusOr<LogicalType> JDBCScanner::_precheck_data_type(const std::string& java_c
slot_desc->col_name()));
}
return TYPE_VARCHAR;
} else if (java_class == "com.clickhouse.data.value.UnsignedLong") {
if (type != TYPE_LARGEINT) {
return Status::NotSupported(fmt::format(
"Type mismatches on column[{}], JDBC result type is UnsignedLong, please set the type to largeint",
slot_desc->col_name()));
}
return TYPE_VARCHAR;
} else if (java_class == "java.lang.Boolean") {
if (type != TYPE_BOOLEAN && type != TYPE_SMALLINT && type != TYPE_INT && type != TYPE_BIGINT) {
return Status::NotSupported(
Expand Down Expand Up @@ -261,7 +302,7 @@ StatusOr<LogicalType> JDBCScanner::_precheck_data_type(const std::string& java_c
slot_desc->col_name()));
}
return TYPE_VARCHAR;
} else if (java_class == "java.sql.Date") {
} else if (java_class == "java.sql.Date" ) {
if (type != TYPE_DATE) {
return Status::NotSupported(
fmt::format("Type mismatches on column[{}], JDBC result type is Date, please set the type to date",
Expand All @@ -282,6 +323,13 @@ StatusOr<LogicalType> JDBCScanner::_precheck_data_type(const std::string& java_c
slot_desc->col_name()));
}
return TYPE_VARCHAR;
} else if (java_class == "java.time.LocalDate") {
if (type != TYPE_DATE) {
return Status::NotSupported(fmt::format(
"Type mismatches on column[{}], JDBC result type is LocalDate, please set the type to date",
slot_desc->col_name()));
}
return TYPE_VARCHAR;
} else if (java_class == "java.math.BigDecimal") {
if (type != TYPE_DECIMAL32 && type != TYPE_DECIMAL64 && type != TYPE_DECIMAL128 && type != TYPE_VARCHAR) {
return Status::NotSupported(
Expand Down
7 changes: 7 additions & 0 deletions fe/fe-core/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -793,6 +793,13 @@ under the License.
<artifactId>postgresql</artifactId>
</dependency>

<!-- https://mvnrepository.com/artifact/com.clickhouse/clickhouse-jdbc -->
<!-- we need clickhouse driver for jdbc connector -->
<dependency>
<groupId>com.clickhouse</groupId>
<artifactId>clickhouse-jdbc</artifactId>
</dependency>

<!-- https://mvnrepository.com/artifact/com.mockrunner/mockrunner-jdbc -->
<dependency>
<groupId>com.mockrunner</groupId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -280,6 +280,8 @@ public enum ProtocolType {
MYSQL,
POSTGRES,
ORACLE,
MARIADB
MARIADB,

CLICKHOUSE
}
}
Loading

0 comments on commit 7228a86

Please sign in to comment.