Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Feature][Connector-V2][JDBC] support sqlite Source & Sink #3089

Merged
merged 32 commits into from
Nov 24, 2022
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
04e2395
refactor JDBC[SqLite] connector
nutsjian Oct 13, 2022
cf1ddc4
[Improve] [JDBC] [SQLite] Connector test more field types
nutsjian Oct 14, 2022
2981c1a
add [JDBC] [SQLite] doc
nutsjian Oct 14, 2022
0643e4a
fix [JDBC] [SQLite] e2e test case method name
nutsjian Oct 14, 2022
f3de959
[fix] class name error
nutsjian Oct 15, 2022
6f3b792
[Hotfix] [JDBC] [SQLite] connector e2e test path problem
nutsjian Oct 15, 2022
e4bf558
[fix] [JDBC] [SQLite] flink e2e test docker container db file cannot …
nutsjian Oct 18, 2022
45701f3
[fix] [JDBC] [SQLite] flink e2e test
nutsjian Oct 19, 2022
7bd5125
Merge branch 'dev' into jdbc-sqlite
nutsjian Oct 19, 2022
e587104
[fix] [JDBC] [SQLite] flink e2e test database closed error
nutsjian Oct 20, 2022
049f6c7
Merge branch 'dev' into jdbc-sqlite
nutsjian Oct 20, 2022
803dec9
Merge branch 'dev' into jdbc-sqlite
nutsjian Oct 20, 2022
ce5ddf0
[fix] [JDBC] [SQLite] e2e test, rerun workflows commit
nutsjian Oct 24, 2022
eb321b0
Merge branch 'dev' into jdbc-sqlite
nutsjian Oct 28, 2022
0118847
update [JDBC] [SQLite] add change log
nutsjian Nov 1, 2022
7ef5bfe
Merge branch 'dev' into jdbc-sqlite
nutsjian Nov 1, 2022
d5ed310
update [JDBC] [SQLite] change log doc
nutsjian Nov 1, 2022
a861767
update [JDBC] [SQLite] connector map tinyint smallint to SeaTunnel Sh…
nutsjian Nov 8, 2022
8fbaad8
refactor JDBC[SqLite] connector
nutsjian Oct 13, 2022
dfd660c
Merge branch 'dev' into jdbc-sqlite
nutsjian Nov 11, 2022
93468b5
update, merge upstream dev, add e2e in flink/spark e2e module so that…
nutsjian Nov 11, 2022
18cf506
update checkstyle
nutsjian Nov 11, 2022
70494ae
Merge branch 'dev' into jdbc-sqlite
nutsjian Nov 15, 2022
03fba9f
[checkstyle] remove unused import
nutsjian Nov 15, 2022
976c5a6
Merge remote-tracking branch 'upstream' into jdbc-sqlite
nutsjian Nov 15, 2022
6197196
Merge branch 'dev' of https://github.com/apache/incubator-seatunnel i…
nutsjian Nov 16, 2022
d03bf4d
update [JDBC] [SQLite] connector
nutsjian Nov 16, 2022
5ad4b4c
Merge branch 'dev' into jdbc-sqlite
nutsjian Nov 18, 2022
fa00b72
Merge branch 'dev' into jdbc-sqlite
nutsjian Nov 18, 2022
5c0b7e8
Merge branch 'dev' into jdbc-sqlite
nutsjian Nov 22, 2022
f4d4d33
fix [JDBC] [SQLite] connector, remove root pom.xml dup net.alchim31.m…
nutsjian Nov 22, 2022
3204610
update [Connector] [JDBC] SQLite, remove typeAffinity option, impleme…
nutsjian Nov 22, 2022
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions docs/en/connector-v2/sink/Jdbc.md
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,7 @@ there are some reference value for params above.
| phoenix | org.apache.phoenix.queryserver.client.Driver | jdbc:phoenix:thin:url=http://localhost:8765;serialization=PROTOBUF | / | https://mvnrepository.com/artifact/com.aliyun.phoenix/ali-phoenix-shaded-thin-client |
| sqlserver | com.microsoft.sqlserver.jdbc.SQLServerDriver | jdbc:microsoft:sqlserver://localhost:1433 | com.microsoft.sqlserver.jdbc.SQLServerXADataSource | https://mvnrepository.com/artifact/com.microsoft.sqlserver/mssql-jdbc |
| oracle | oracle.jdbc.OracleDriver | jdbc:oracle:thin:@localhost:1521/xepdb1 | oracle.jdbc.xa.OracleXADataSource | https://mvnrepository.com/artifact/com.oracle.database.jdbc/ojdbc8 |
| sqlite | org.sqlite.JDBC | Jdbc:sqlite:test.db | / | https://mvnrepository.com/artifact/org.xerial/sqlite-jdbc |
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Driver right?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done


## Example

Expand Down
1 change: 1 addition & 0 deletions docs/en/connector-v2/source/Jdbc.md
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ there are some reference value for params above.
| phoenix | org.apache.phoenix.queryserver.client.Driver | jdbc:phoenix:thin:url=http://localhost:8765;serialization=PROTOBUF | https://mvnrepository.com/artifact/com.aliyun.phoenix/ali-phoenix-shaded-thin-client |
| sqlserver | com.microsoft.sqlserver.jdbc.SQLServerDriver | jdbc:microsoft:sqlserver://localhost:1433 | https://mvnrepository.com/artifact/com.microsoft.sqlserver/mssql-jdbc |
| oracle | oracle.jdbc.OracleDriver | jdbc:oracle:thin:@localhost:1521/xepdb1 | https://mvnrepository.com/artifact/com.oracle.database.jdbc/ojdbc8 |
| sqlite | org.sqlite.JDBC | jdbc:sqlite:test.db | https://mvnrepository.com/artifact/org.xerial/sqlite-jdbc |

## Example

Expand Down
12 changes: 11 additions & 1 deletion seatunnel-connectors-v2/connector-jdbc/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
<sqlserver.version>9.2.1.jre8</sqlserver.version>
<phoenix.version>5.2.5-HBase-2.x</phoenix.version>
<oracle.version>12.2.0.1</oracle.version>
<sqlite.version>3.39.3.0</sqlite.version>
</properties>

<dependencyManagement>
Expand Down Expand Up @@ -76,7 +77,12 @@
<version>${oracle.version}</version>
<scope>provided</scope>
</dependency>

<dependency>
<groupId>org.xerial</groupId>
<artifactId>sqlite-jdbc</artifactId>
<version>${sqlite.version}</version>
<scope>provided</scope>
</dependency>
</dependencies>
</dependencyManagement>

Expand Down Expand Up @@ -108,6 +114,10 @@
<groupId>com.oracle.database.jdbc</groupId>
<artifactId>ojdbc8</artifactId>
</dependency>
<dependency>
<groupId>org.xerial</groupId>
<artifactId>sqlite-jdbc</artifactId>
</dependency>
</dependencies>

</project>
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,6 @@ public class JdbcConfig implements Serializable {

public static final String TRANSACTION_TIMEOUT_SEC = "transaction_timeout_sec";


//source config
public static final String PARTITION_COLUMN = "partition_column";
public static final String PARTITION_UPPER_BOUND = "partition_upper_bound";
Expand Down Expand Up @@ -95,6 +94,7 @@ public static JdbcConnectionOptions buildJdbcConnectionOptions(Config config) {
jdbcOptions.transactionTimeoutSec = config.getInt(JdbcConfig.TRANSACTION_TIMEOUT_SEC);
}
}

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please revert it.

return jdbcOptions;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
/*
* 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.sqlite;

import org.apache.seatunnel.connectors.seatunnel.jdbc.internal.converter.JdbcRowConverter;
import org.apache.seatunnel.connectors.seatunnel.jdbc.internal.dialect.JdbcDialect;
import org.apache.seatunnel.connectors.seatunnel.jdbc.internal.dialect.JdbcDialectTypeMapper;

public class SqliteDialect implements JdbcDialect {
@Override
public String dialectName() {
return "Sqlite";
}

@Override
public JdbcRowConverter getRowConverter() {
return new SqliteJdbcRowConverter();
}

@Override
public JdbcDialectTypeMapper getJdbcDialectTypeMapper() {
return new SqliteTypeMapper();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
/*
* 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.sqlite;

import org.apache.seatunnel.connectors.seatunnel.jdbc.internal.dialect.JdbcDialect;
import org.apache.seatunnel.connectors.seatunnel.jdbc.internal.dialect.JdbcDialectFactory;

import com.google.auto.service.AutoService;

/**
* Factory for {@link SqliteDialect}.
*/

@AutoService(JdbcDialectFactory.class)
public class SqliteDialectFactory implements JdbcDialectFactory {
@Override
public boolean acceptsURL(String url) {
return url.startsWith("jdbc:sqlite:");
}

@Override
public JdbcDialect create() {
return new SqliteDialect();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
/*
* 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.sqlite;

import org.apache.seatunnel.api.table.type.SeaTunnelRow;
import org.apache.seatunnel.api.table.type.SeaTunnelRowType;
import org.apache.seatunnel.connectors.seatunnel.jdbc.internal.converter.AbstractJdbcRowConverter;

import java.sql.ResultSet;
import java.sql.ResultSetMetaData;
import java.sql.SQLException;

public class SqliteJdbcRowConverter extends AbstractJdbcRowConverter {

@Override
public String converterName() {
return "Sqlite";
}

@Override
public SeaTunnelRow toInternal(ResultSet rs, ResultSetMetaData metaData, SeaTunnelRowType typeInfo) throws SQLException {
return super.toInternal(rs, metaData, typeInfo);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,176 @@
/*
* 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.sqlite;

import org.apache.seatunnel.api.table.type.BasicType;
import org.apache.seatunnel.api.table.type.PrimitiveByteArrayType;
import org.apache.seatunnel.api.table.type.SeaTunnelDataType;
import org.apache.seatunnel.connectors.seatunnel.jdbc.internal.dialect.JdbcDialectTypeMapper;

import lombok.extern.slf4j.Slf4j;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.sql.ResultSetMetaData;
import java.sql.SQLException;

@Slf4j
public class SqliteTypeMapper implements JdbcDialectTypeMapper {

private static final Logger LOG = LoggerFactory.getLogger(SqliteTypeMapper.class);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Useless code


// ============================data types=====================

private static final String SQLITE_UNKNOWN = "UNKNOWN";
private static final String SQLITE_BIT = "BIT";
private static final String SQLITE_BOOLEAN = "BOOLEAN";

// -------------------------integer----------------------------
private static final String SQLITE_TINYINT = "TINYINT";
private static final String SQLITE_TINYINT_UNSIGNED = "TINYINT UNSIGNED";
private static final String SQLITE_SMALLINT = "SMALLINT";
private static final String SQLITE_SMALLINT_UNSIGNED = "SMALLINT UNSIGNED";
private static final String SQLITE_MEDIUMINT = "MEDIUMINT";
private static final String SQLITE_MEDIUMINT_UNSIGNED = "MEDIUMINT UNSIGNED";
private static final String SQLITE_INT = "INT";
private static final String SQLITE_INT_UNSIGNED = "INT UNSIGNED";
private static final String SQLITE_INTEGER = "INTEGER";
private static final String SQLITE_INTEGER_UNSIGNED = "INTEGER UNSIGNED";
private static final String SQLITE_BIGINT = "BIGINT";
private static final String SQLITE_BIGINT_UNSIGNED = "BIGINT UNSIGNED";
private static final String SQLITE_DECIMAL = "DECIMAL";
private static final String SQLITE_DECIMAL_UNSIGNED = "DECIMAL UNSIGNED";
private static final String SQLITE_FLOAT = "FLOAT";
private static final String SQLITE_FLOAT_UNSIGNED = "FLOAT UNSIGNED";
private static final String SQLITE_DOUBLE = "DOUBLE";
private static final String SQLITE_DOUBLE_PRECISION = "DOUBLE PRECISION";
private static final String SQLITE_DOUBLE_UNSIGNED = "DOUBLE UNSIGNED";
private static final String SQLITE_NUMERIC = "NUMERIC";
private static final String SQLITE_REAL = "REAL";

// -------------------------text----------------------------
private static final String SQLITE_CHAR = "CHAR";
private static final String SQLITE_CHARACTER = "CHARACTER";
private static final String SQLITE_VARYING_CHARACTER = "VARYING_CHARACTER";
private static final String SQLITE_NATIVE_CHARACTER = "NATIVE_CHARACTER";
private static final String SQLITE_NCHAR = "NCHAR";
private static final String SQLITE_VARCHAR = "VARCHAR";
private static final String SQLITE_LONGVARCHAR = "LONGVARCHAR";
private static final String SQLITE_LONGNVARCHAR = "LONGNVARCHAR";
private static final String SQLITE_NVARCHAR = "NVARCHAR";
private static final String SQLITE_TINYTEXT = "TINYTEXT";
private static final String SQLITE_MEDIUMTEXT = "MEDIUMTEXT";
private static final String SQLITE_TEXT = "TEXT";
private static final String SQLITE_LONGTEXT = "LONGTEXT";
private static final String SQLITE_JSON = "JSON";
private static final String SQLITE_CLOB = "CLOB";

// ------------------------------time(text)-------------------------
private static final String SQLITE_DATE = "DATE";
private static final String SQLITE_DATETIME = "DATETIME";
private static final String SQLITE_TIME = "TIME";
private static final String SQLITE_TIMESTAMP = "TIMESTAMP";

// ------------------------------blob-------------------------
private static final String SQLITE_TINYBLOB = "TINYBLOB";
private static final String SQLITE_MEDIUMBLOB = "MEDIUMBLOB";
private static final String SQLITE_BLOB = "BLOB";
private static final String SQLITE_LONGBLOB = "LONGBLOB";
private static final String SQLITE_BINARY = "BINARY";
private static final String SQLITE_VARBINARY = "VARBINARY";
private static final String SQLITE_LONGVARBINARY = "LONGVARBINARY";

@Override
public SeaTunnelDataType<?> mapping(ResultSetMetaData metadata, int colIndex) throws SQLException {
String columnTypeName = metadata.getColumnTypeName(colIndex).toUpperCase().trim();
switch (columnTypeName) {
case SQLITE_BIT:
case SQLITE_BOOLEAN:
return BasicType.BOOLEAN_TYPE;
case SQLITE_TINYINT:
case SQLITE_TINYINT_UNSIGNED:
case SQLITE_SMALLINT:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We also support short type, you can use it to map smallint and tinyint.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thx, I'll test it.

case SQLITE_SMALLINT_UNSIGNED:
case SQLITE_MEDIUMINT:
case SQLITE_MEDIUMINT_UNSIGNED:
case SQLITE_INT:
case SQLITE_INTEGER:
return BasicType.INT_TYPE;
case SQLITE_INT_UNSIGNED:
case SQLITE_INTEGER_UNSIGNED:
case SQLITE_BIGINT:
case SQLITE_BIGINT_UNSIGNED:
case SQLITE_NUMERIC:
return BasicType.LONG_TYPE;
case SQLITE_DECIMAL:
case SQLITE_DECIMAL_UNSIGNED:
case SQLITE_DOUBLE:
case SQLITE_DOUBLE_PRECISION:
case SQLITE_REAL:
return BasicType.DOUBLE_TYPE;
case SQLITE_FLOAT:
return BasicType.FLOAT_TYPE;
case SQLITE_FLOAT_UNSIGNED:
LOG.warn("{} will probably cause value overflow.", SQLITE_FLOAT_UNSIGNED);
return BasicType.FLOAT_TYPE;
case SQLITE_DOUBLE_UNSIGNED:
LOG.warn("{} will probably cause value overflow.", SQLITE_DOUBLE_UNSIGNED);
return BasicType.DOUBLE_TYPE;
case SQLITE_CHARACTER:
case SQLITE_VARYING_CHARACTER:
case SQLITE_NATIVE_CHARACTER:
case SQLITE_NVARCHAR:
case SQLITE_NCHAR:
case SQLITE_LONGNVARCHAR:
case SQLITE_LONGVARCHAR:
case SQLITE_CLOB:
case SQLITE_CHAR:
case SQLITE_TINYTEXT:
case SQLITE_MEDIUMTEXT:
case SQLITE_TEXT:
case SQLITE_VARCHAR:
case SQLITE_JSON:
case SQLITE_LONGTEXT:

case SQLITE_DATE:
case SQLITE_TIME:
case SQLITE_DATETIME:
case SQLITE_TIMESTAMP:
return BasicType.STRING_TYPE;

case SQLITE_TINYBLOB:
case SQLITE_MEDIUMBLOB:
case SQLITE_BLOB:
case SQLITE_LONGBLOB:
case SQLITE_VARBINARY:
case SQLITE_BINARY:
case SQLITE_LONGVARBINARY:
return PrimitiveByteArrayType.INSTANCE;

//Doesn't support yet
case SQLITE_UNKNOWN:
default:
final String jdbcColumnName = metadata.getColumnName(colIndex);
throw new UnsupportedOperationException(
String.format(
"Doesn't support SQLite type '%s' on column '%s' yet.",
columnTypeName, jdbcColumnName));
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,11 @@
<artifactId>mssql-jdbc</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.xerial</groupId>
<artifactId>sqlite-jdbc</artifactId>
<scope>test</scope>
</dependency>
</dependencies>

</project>
Loading