-
Notifications
You must be signed in to change notification settings - Fork 1.8k
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.
- Loading branch information
Showing
10 changed files
with
564 additions
and
15 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
40 changes: 40 additions & 0 deletions
40
...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,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.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; | ||
|
||
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(); | ||
} | ||
} |
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"; | ||
} | ||
} |
107 changes: 107 additions & 0 deletions
107
...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,107 @@ | ||
/* | ||
* 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: | ||
case SAP_HANA_INTEGER: | ||
case SAP_HANA_SMALLINT: | ||
case SAP_HANA_TINYINT: | ||
return BasicType.INT_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)); | ||
} | ||
} | ||
} |
Oops, something went wrong.