forked from apache/seatunnel
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(clickhouse): clickhouse支持jdbc方式读
- Loading branch information
chaorongzhi
committed
Sep 2, 2024
1 parent
1a5cc46
commit f68bc4a
Showing
7 changed files
with
244 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
42 changes: 42 additions & 0 deletions
42
...a/org/apache/seatunnel/connectors/seatunnel/jdbc/internal/dialect/DatabaseIdentifier.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one or more | ||
* contributor license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright ownership. | ||
* The ASF licenses this file to You under the Apache License, Version 2.0 | ||
* (the "License"); you may not use this file except in compliance with | ||
* the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package org.apache.seatunnel.connectors.seatunnel.jdbc.internal.dialect; | ||
|
||
public class DatabaseIdentifier { | ||
public static final String DB_2 = "DB2"; | ||
public static final String DAMENG = "Dameng"; | ||
public static final String GBASE_8A = "Gbase8a"; | ||
public static final String HIVE = "HIVE"; | ||
public static final String INFORMIX = "Informix"; | ||
public static final String KINGBASE = "KingBase"; | ||
public static final String MYSQL = "MySQL"; | ||
public static final String ORACLE = "Oracle"; | ||
public static final String PHOENIX = "Phoenix"; | ||
public static final String POSTGRESQL = "Postgres"; | ||
public static final String REDSHIFT = "Redshift"; | ||
public static final String SAP_HANA = "SapHana"; | ||
public static final String SNOWFLAKE = "Snowflake"; | ||
public static final String SQLITE = "Sqlite"; | ||
public static final String SQLSERVER = "SqlServer"; | ||
public static final String TABLE_STORE = "Tablestore"; | ||
public static final String TERADATA = "Teradata"; | ||
public static final String VERTICA = "Vertica"; | ||
public static final String OCENABASE = "OceanBase"; | ||
public static final String TIDB = "TiDB"; | ||
public static final String CLICKHOUSE = "Clickhouse"; | ||
} |
37 changes: 37 additions & 0 deletions
37
...he/seatunnel/connectors/seatunnel/jdbc/internal/dialect/clickhouse/ClickhouseDialect.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
package org.apache.seatunnel.connectors.seatunnel.jdbc.internal.dialect.clickhouse; | ||
|
||
import org.apache.seatunnel.connectors.seatunnel.jdbc.internal.converter.JdbcRowConverter; | ||
import org.apache.seatunnel.connectors.seatunnel.jdbc.internal.dialect.DatabaseIdentifier; | ||
import org.apache.seatunnel.connectors.seatunnel.jdbc.internal.dialect.JdbcDialect; | ||
import org.apache.seatunnel.connectors.seatunnel.jdbc.internal.dialect.JdbcDialectTypeMapper; | ||
|
||
import java.util.Optional; | ||
|
||
/** | ||
* Description Copyright © 启明星辰 版权所有 | ||
* | ||
* @author chaorongzhi | ||
* @date 2024/1/5 | ||
*/ | ||
public class ClickhouseDialect implements JdbcDialect { | ||
@Override | ||
public String dialectName() { | ||
return DatabaseIdentifier.CLICKHOUSE; | ||
} | ||
|
||
@Override | ||
public JdbcRowConverter getRowConverter() { | ||
return new ClickhouseJdbcRowConverter(); | ||
} | ||
|
||
@Override | ||
public JdbcDialectTypeMapper getJdbcDialectTypeMapper() { | ||
return new ClickhouseTypeMapper(); | ||
} | ||
|
||
@Override | ||
public Optional<String> getUpsertStatement( | ||
String database, String tableName, String[] fieldNames, String[] uniqueKeyFields) { | ||
return Optional.empty(); | ||
} | ||
} |
38 changes: 38 additions & 0 deletions
38
...unnel/connectors/seatunnel/jdbc/internal/dialect/clickhouse/ClickhouseDialectFactory.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one or more | ||
* contributor license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright ownership. | ||
* The ASF licenses this file to You under the Apache License, Version 2.0 | ||
* (the "License"); you may not use this file except in compliance with | ||
* the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package org.apache.seatunnel.connectors.seatunnel.jdbc.internal.dialect.clickhouse; | ||
|
||
import org.apache.seatunnel.connectors.seatunnel.jdbc.internal.dialect.JdbcDialect; | ||
import org.apache.seatunnel.connectors.seatunnel.jdbc.internal.dialect.JdbcDialectFactory; | ||
import org.apache.seatunnel.connectors.seatunnel.jdbc.internal.dialect.mysql.MysqlDialect; | ||
|
||
import com.google.auto.service.AutoService; | ||
|
||
/** Factory for {@link MysqlDialect}. */ | ||
@AutoService(JdbcDialectFactory.class) | ||
public class ClickhouseDialectFactory implements JdbcDialectFactory { | ||
@Override | ||
public boolean acceptsURL(String url) { | ||
return url.startsWith("jdbc:clickhouse:"); | ||
} | ||
|
||
@Override | ||
public JdbcDialect create() { | ||
return new ClickhouseDialect(); | ||
} | ||
} |
28 changes: 28 additions & 0 deletions
28
...nel/connectors/seatunnel/jdbc/internal/dialect/clickhouse/ClickhouseJdbcRowConverter.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one or more | ||
* contributor license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright ownership. | ||
* The ASF licenses this file to You under the Apache License, Version 2.0 | ||
* (the "License"); you may not use this file except in compliance with | ||
* the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package org.apache.seatunnel.connectors.seatunnel.jdbc.internal.dialect.clickhouse; | ||
|
||
import org.apache.seatunnel.connectors.seatunnel.jdbc.internal.converter.AbstractJdbcRowConverter; | ||
import org.apache.seatunnel.connectors.seatunnel.jdbc.internal.dialect.DatabaseIdentifier; | ||
|
||
public class ClickhouseJdbcRowConverter extends AbstractJdbcRowConverter { | ||
@Override | ||
public String converterName() { | ||
return DatabaseIdentifier.CLICKHOUSE; | ||
} | ||
} |
80 changes: 80 additions & 0 deletions
80
...seatunnel/connectors/seatunnel/jdbc/internal/dialect/clickhouse/ClickhouseTypeMapper.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one or more | ||
* contributor license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright ownership. | ||
* The ASF licenses this file to You under the Apache License, Version 2.0 | ||
* (the "License"); you may not use this file except in compliance with | ||
* the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package org.apache.seatunnel.connectors.seatunnel.jdbc.internal.dialect.clickhouse; | ||
|
||
import org.apache.seatunnel.api.table.type.BasicType; | ||
import org.apache.seatunnel.api.table.type.DecimalType; | ||
import org.apache.seatunnel.api.table.type.LocalTimeType; | ||
import org.apache.seatunnel.api.table.type.SeaTunnelDataType; | ||
import org.apache.seatunnel.connectors.seatunnel.jdbc.internal.dialect.JdbcDialectTypeMapper; | ||
|
||
import java.sql.ResultSetMetaData; | ||
import java.sql.SQLException; | ||
|
||
public class ClickhouseTypeMapper implements JdbcDialectTypeMapper { | ||
|
||
@Override | ||
public SeaTunnelDataType<?> mapping(ResultSetMetaData metadata, int colIndex) | ||
throws SQLException { | ||
String clickhouseType = metadata.getColumnTypeName(colIndex); | ||
int precision = metadata.getPrecision(colIndex); | ||
int scale = metadata.getScale(colIndex); | ||
switch (clickhouseType) { | ||
case "UInt32": | ||
case "UInt64": | ||
case "Int64": | ||
case "IntervalYear": | ||
case "IntervalQuarter": | ||
case "IntervalMonth": | ||
case "IntervalWeek": | ||
case "IntervalDay": | ||
case "IntervalHour": | ||
case "IntervalMinute": | ||
case "IntervalSecond": | ||
return BasicType.LONG_TYPE; | ||
case "Float64": | ||
return BasicType.DOUBLE_TYPE; | ||
case "Float32": | ||
return BasicType.FLOAT_TYPE; | ||
case "Int8": | ||
case "UInt8": | ||
case "Int16": | ||
case "UInt16": | ||
case "Int32": | ||
return BasicType.INT_TYPE; | ||
case "Date": | ||
return LocalTimeType.LOCAL_DATE_TYPE; | ||
case "DateTime": | ||
return LocalTimeType.LOCAL_DATE_TIME_TYPE; | ||
case "Decimal": | ||
case "Decimal64": | ||
case "Decimal128": | ||
case "Decimal256": | ||
return new DecimalType(precision, scale); | ||
case "String": | ||
case "Int128": | ||
case "UInt128": | ||
case "Int256": | ||
case "UInt256": | ||
case "Point": | ||
case "Polygon": | ||
default: | ||
return BasicType.STRING_TYPE; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters