forked from apache/seatunnel
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Feature][Connector-V2] Jdbc connector support SAP HANA. (apache#3017)
- Loading branch information
1 parent
0e7638d
commit 7ecc19e
Showing
11 changed files
with
392 additions
and
3 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
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
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
47 changes: 47 additions & 0 deletions
47
...g/apache/seatunnel/connectors/seatunnel/jdbc/internal/dialect/saphana/SapHanaDialect.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,47 @@ | ||
/* | ||
* 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.saphana; | ||
|
||
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; | ||
|
||
import java.util.Optional; | ||
|
||
public class SapHanaDialect implements JdbcDialect { | ||
@Override | ||
public String dialectName() { | ||
return "SapHana"; | ||
} | ||
|
||
@Override | ||
public JdbcRowConverter getRowConverter() { | ||
return new SapHanaJdbcRowConverter(); | ||
} | ||
|
||
@Override | ||
public JdbcDialectTypeMapper getJdbcDialectTypeMapper() { | ||
return new SapHanaTypeMapper(); | ||
} | ||
|
||
@Override | ||
public Optional<String> getUpsertStatement(String tableName, String[] fieldNames, String[] uniqueKeyFields) { | ||
return Optional.empty(); | ||
} | ||
} |
41 changes: 41 additions & 0 deletions
41
...e/seatunnel/connectors/seatunnel/jdbc/internal/dialect/saphana/SapHanaDialectFactory.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,41 @@ | ||
/* | ||
* 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.saphana; | ||
|
||
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; | ||
|
||
/** | ||
* Dialect Factory of {@link SapHanaDialect} | ||
*/ | ||
|
||
@AutoService(JdbcDialectFactory.class) | ||
public class SapHanaDialectFactory implements JdbcDialectFactory { | ||
@Override | ||
public boolean acceptsURL(String url) { | ||
return url.startsWith("jdbc:sap://"); | ||
} | ||
|
||
@Override | ||
public JdbcDialect create() { | ||
return new SapHanaDialect(); | ||
} | ||
} |
28 changes: 28 additions & 0 deletions
28
...seatunnel/connectors/seatunnel/jdbc/internal/dialect/saphana/SapHanaJdbcRowConverter.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.saphana; | ||
|
||
import org.apache.seatunnel.connectors.seatunnel.jdbc.internal.converter.AbstractJdbcRowConverter; | ||
|
||
public class SapHanaJdbcRowConverter extends AbstractJdbcRowConverter { | ||
@Override | ||
public String converterName() { | ||
return "SapHana"; | ||
} | ||
} |
110 changes: 110 additions & 0 deletions
110
...pache/seatunnel/connectors/seatunnel/jdbc/internal/dialect/saphana/SapHanaTypeMapper.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,110 @@ | ||
/* | ||
* 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.saphana; | ||
|
||
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.PrimitiveByteArrayType; | ||
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; | ||
import java.util.Locale; | ||
|
||
public class SapHanaTypeMapper implements JdbcDialectTypeMapper { | ||
|
||
// refer to https://help.sap.com/docs/SAP_BUSINESSOBJECTS_BUSINESS_INTELLIGENCE_PLATFORM/aa4cb9ab429349e49678e146f05d7341/ec3313286fdb101497906a7cb0e91070.html?locale=zh-CN | ||
private static final String SAP_HANA_BLOB = "blob"; | ||
private static final String SAP_HANA_VARBINARY = "varbinary"; | ||
private static final String SAP_HANA_DATE = "date"; | ||
private static final String SAP_HANA_TIME = "time"; | ||
private static final String SAP_HANA_LONGDATE = "longtime"; | ||
private static final String SAP_HANA_SECONDDATE = "seconddate"; | ||
private static final String SAP_HANA_TIMESTAMP = "timestamp"; | ||
private static final String SAP_HANA_DECIMAL = "decimal"; | ||
private static final String SAP_HANA_REAL = "real"; | ||
private static final String SAP_HANA_SMALLDECIMAL = "smalldecimal"; | ||
private static final String SAP_HANA_BIGINT = "bigint"; | ||
private static final String SAP_HANA_INTEGER = "integer"; | ||
private static final String SAP_HANA_SMALLINT = "smallint"; | ||
private static final String SAP_HANA_TINYINT = "tinyint"; | ||
private static final String SAP_HANA_DOUBLE = "double"; | ||
private static final String SAP_HANA_CLOB = "clob"; | ||
private static final String SAP_HANA_NCLOB = "nclob"; | ||
private static final String SAP_HANA_TEXT = "text"; | ||
private static final String SAP_HANA_ALPHANUM = "alphanum"; | ||
private static final String SAP_HANA_NVARCHAR = "nvarchar"; | ||
private static final String SAP_HANA_SHORTTEXT = "shorttext"; | ||
private static final String SAP_HANA_VARCHAR = "varchar"; | ||
private static final String SAP_HANA_BINARY = "binary"; | ||
|
||
@Override | ||
public SeaTunnelDataType<?> mapping(ResultSetMetaData metadata, int colIndex) throws SQLException { | ||
String typeName = metadata.getColumnTypeName(colIndex).toLowerCase(Locale.ROOT); | ||
|
||
int precision = metadata.getPrecision(colIndex); | ||
int scale = metadata.getScale(colIndex); | ||
|
||
switch (typeName) { | ||
case SAP_HANA_BLOB: | ||
case SAP_HANA_VARBINARY: | ||
case SAP_HANA_BINARY: | ||
return PrimitiveByteArrayType.INSTANCE; | ||
case SAP_HANA_DATE: | ||
return LocalTimeType.LOCAL_DATE_TYPE; | ||
case SAP_HANA_TIME: | ||
return LocalTimeType.LOCAL_TIME_TYPE; | ||
case SAP_HANA_TIMESTAMP: | ||
case SAP_HANA_LONGDATE: | ||
case SAP_HANA_SECONDDATE: | ||
return LocalTimeType.LOCAL_DATE_TIME_TYPE; | ||
case SAP_HANA_DECIMAL: | ||
return new DecimalType(precision, scale); | ||
case SAP_HANA_REAL: | ||
case SAP_HANA_SMALLDECIMAL: | ||
return BasicType.FLOAT_TYPE; | ||
case SAP_HANA_BIGINT: | ||
return BasicType.LONG_TYPE; | ||
case SAP_HANA_INTEGER: | ||
return BasicType.INT_TYPE; | ||
case SAP_HANA_SMALLINT: | ||
return BasicType.SHORT_TYPE; | ||
case SAP_HANA_TINYINT: | ||
return BasicType.BYTE_TYPE; | ||
case SAP_HANA_DOUBLE: | ||
return BasicType.DOUBLE_TYPE; | ||
case SAP_HANA_CLOB: | ||
case SAP_HANA_NCLOB: | ||
case SAP_HANA_TEXT: | ||
case SAP_HANA_ALPHANUM: | ||
case SAP_HANA_NVARCHAR: | ||
case SAP_HANA_SHORTTEXT: | ||
case SAP_HANA_VARCHAR: | ||
return BasicType.STRING_TYPE; | ||
default: | ||
final String jdbcColumnName = metadata.getColumnName(colIndex); | ||
throw new UnsupportedOperationException( | ||
String.format( | ||
"Doesn't support SapHana type '%s' on column '%s' yet.", | ||
typeName, jdbcColumnName)); | ||
} | ||
} | ||
} |
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
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
Oops, something went wrong.