From 63ca3239b51a3e02d42a85b0352aa3dbabe9f67c Mon Sep 17 00:00:00 2001 From: Zhou Yang Date: Thu, 6 Jan 2022 15:59:27 +0800 Subject: [PATCH] feat: support Trino and Redshift source. --- README.md | 23 ++++++++++++++++--- pom.xml | 11 +++++++++ .../ping/connector/impl/CustomConnector.java | 3 +-- .../connector/impl/RedshiftConnector.java | 7 ++++++ .../ping/connector/impl/TrinoConnector.java | 6 +++++ .../ping/de.xab.ping.connector.DBConnector | 4 +++- 6 files changed, 48 insertions(+), 6 deletions(-) create mode 100644 src/main/java/de/xab/ping/connector/impl/RedshiftConnector.java create mode 100644 src/main/java/de/xab/ping/connector/impl/TrinoConnector.java diff --git a/README.md b/README.md index 5afa984..3a6e73a 100644 --- a/README.md +++ b/README.md @@ -26,14 +26,19 @@ ping is a universal data source connection test project. ## Common Driver -ping have some builtin drivers - ### PostgreSQL required parameters: type, url, sql, username, password ``` java -jar ping.jar --type postgresql --url "jdbc:postgresql://127.0.0.1:5432/postgres" --username postgres --password password --sql "SELECT 1" ``` + +### Redshift + +required parameters: type, url, sql, username, password +``` +java -jar ping.jar --type redshift --url "jdbc:redshift://127.0.0.1:5432/abc" --username foo --password bar --sql "SELECT 1" +``` ### PrestoDB required addon parameters which used to auth with Kerberos or LDAP @@ -46,6 +51,18 @@ java -jar ping.jar --type prestodb --url "jdbc:presto://127.0.0.1:8081/hive/bi" java -jar ping.jar --type prestodb --username hive --url "jdbc:presto://127.0.0.1:7778?SSL=true&KerberosKeytabPath=./impala.keytab&KerberosPrincipal=impala/foo.org@BAR.COM&SSLTrustStorePath=./keystore.jks&SSLTrustStorePassword=password&KerberosRemoteServiceName=impala&KerberosConfigPath=./krb5.conf" --sql "SELECT 1" ``` +### Trino + +required addon parameters which used to auth with Kerberos or LDAP + +``` +java -jar ping.jar --type trino --url "jdbc:trino://127.0.0.1:8081/hive/bi" --sql "SELECT 1" +``` + +``` +java -jar ping.jar --type trino --username hive --url "jdbc:trino://127.0.0.1:7778?SSL=true&KerberosKeytabPath=./impala.keytab&KerberosPrincipal=impala/foo.org@BAR.COM&SSLTrustStorePath=./keystore.jks&SSLTrustStorePassword=password&KerberosRemoteServiceName=impala&KerberosConfigPath=./krb5.conf" --sql "SELECT 1" +``` + ## Builtin Driver ping also support builtin drivers, located in [drivers](src/main/resources/drivers) @@ -85,7 +102,7 @@ Using custom driver, `--driverFolder` and `--driverClass` is required to specify For example: ``` -java -jar ping.ar --type external --username dbadmin --password dbadmin --url "jdbc:vertica://127.0.0.1:5433/vmart" --sql "SELECT * FROM "online_sales"."call_center_dimension" LIMIT 3" --driverFolder "path_to_folder" --driverClass "com.vertica.jdbc.Driver" +java -jar ping.jar --type external --username dbadmin --password dbadmin --url "jdbc:vertica://127.0.0.1:5433/vmart" --sql "SELECT * FROM "online_sales"."call_center_dimension" LIMIT 3" --driverFolder "path_to_folder" --driverClass "com.vertica.jdbc.Driver" ``` ## How to add Connector diff --git a/pom.xml b/pom.xml index cedec2d..c9d563a 100644 --- a/pom.xml +++ b/pom.xml @@ -56,6 +56,17 @@ presto-jdbc 0.263.1 + + io.trino + trino-jdbc + 364 + + + com.amazon.redshift + redshift-jdbc42 + 2.1.0.3 + + ${project.artifactId} diff --git a/src/main/java/de/xab/ping/connector/impl/CustomConnector.java b/src/main/java/de/xab/ping/connector/impl/CustomConnector.java index c33fd3b..8b73be9 100644 --- a/src/main/java/de/xab/ping/connector/impl/CustomConnector.java +++ b/src/main/java/de/xab/ping/connector/impl/CustomConnector.java @@ -76,8 +76,7 @@ protected ClassLoader initClassloader(String url, String driverFolder) throws IO FileSystems.newFileSystem(uri, env); Path dirPath = Paths.get(uri); list = Files.list(dirPath).map(path -> { - try { - InputStream in = Files.newInputStream(path); + try (InputStream in = Files.newInputStream(path)){ final File tempFile = File.createTempFile("PREFIX", "SUFFIX"); tempFile.deleteOnExit(); try (FileOutputStream out = new FileOutputStream(tempFile)) { diff --git a/src/main/java/de/xab/ping/connector/impl/RedshiftConnector.java b/src/main/java/de/xab/ping/connector/impl/RedshiftConnector.java new file mode 100644 index 0000000..8b72ec6 --- /dev/null +++ b/src/main/java/de/xab/ping/connector/impl/RedshiftConnector.java @@ -0,0 +1,7 @@ +package de.xab.ping.connector.impl; + +import de.xab.ping.connector.JDBCConnector; + +public class RedshiftConnector extends JDBCConnector { + +} diff --git a/src/main/java/de/xab/ping/connector/impl/TrinoConnector.java b/src/main/java/de/xab/ping/connector/impl/TrinoConnector.java new file mode 100644 index 0000000..903428d --- /dev/null +++ b/src/main/java/de/xab/ping/connector/impl/TrinoConnector.java @@ -0,0 +1,6 @@ +package de.xab.ping.connector.impl; + +import de.xab.ping.connector.JDBCConnector; + +public class TrinoConnector extends JDBCConnector { +} diff --git a/src/main/resources/META-INF/ping/de.xab.ping.connector.DBConnector b/src/main/resources/META-INF/ping/de.xab.ping.connector.DBConnector index 4ebd416..2a701a6 100644 --- a/src/main/resources/META-INF/ping/de.xab.ping.connector.DBConnector +++ b/src/main/resources/META-INF/ping/de.xab.ping.connector.DBConnector @@ -4,4 +4,6 @@ postgresql=de.xab.ping.connector.impl.PostgreSQLConnector hive=de.xab.ping.connector.impl.HiveConnector impala=de.xab.ping.connector.impl.ImpalaConnector prestodb=de.xab.ping.connector.impl.PrestoDBConnector -mysql=de.xab.ping.connector.impl.MySQLConnector \ No newline at end of file +mysql=de.xab.ping.connector.impl.MySQLConnector +trino=de.xab.ping.connector.impl.TrinoConnector +redshift=de.xab.ping.connector.impl.RedshiftConnector \ No newline at end of file