You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@seatunnel.apache.org by "Hisoka-X (via GitHub)" <gi...@apache.org> on 2024/06/05 09:42:38 UTC
[PR] [Feature] Support jdbc hana catalog and type convertor [seatunnel]
Hisoka-X opened a new pull request, #6950:
URL: https://github.com/apache/seatunnel/pull/6950
<!--
Thank you for contributing to SeaTunnel! Please make sure that your code changes
are covered with tests. And in case of new features or big changes
remember to adjust the documentation.
Feel free to ping committers for the review!
## Contribution Checklist
- Make sure that the pull request corresponds to a [GITHUB issue](https://github.com/apache/seatunnel/issues).
- Name the pull request in the form "[Feature] [component] Title of the pull request", where *Feature* can be replaced by `Hotfix`, `Bug`, etc.
- Minor fixes should be named following this pattern: `[hotfix] [docs] Fix typo in README.md doc`.
-->
### Purpose of this pull request
<!-- Describe the purpose of this pull request. For example: This pull request adds checkstyle plugin.-->
### Does this PR introduce _any_ user-facing change?
<!--
Note that it means *any* user-facing change including all aspects such as the documentation fix.
If yes, please clarify the previous behavior and the change this PR proposes - provide the console output, description and/or an example to show the behavior difference if possible.
If possible, please also clarify if this is a user-facing change compared to the released SeaTunnel versions or within the unreleased branches such as dev.
If no, write 'No'.
If you are adding/modifying connector documents, please follow our new specifications: https://github.com/apache/seatunnel/issues/4544.
-->
### How was this patch tested?
<!--
If tests were added, say they were added here. Please make sure to add some test cases that check the changes thoroughly including negative and positive cases if possible.
If it was tested in a way different from regular unit tests, please clarify how you tested step by step, ideally copy and paste-able, so that other reviewers can test and check, and descendants can verify in the future.
If tests were not added, please describe why they were not added and/or why it was difficult to add.
If you are adding E2E test cases, maybe refer to https://github.com/apache/seatunnel/blob/dev/seatunnel-e2e/seatunnel-connector-v2-e2e/connector-cdc-mysql-e2e/src/test/resources/mysqlcdc_to_mysql.conf, here is a good example.
-->
### Check list
* [ ] If any new Jar binary package adding in your PR, please add License Notice according
[New License Guide](https://github.com/apache/seatunnel/blob/dev/docs/en/contribution/new-license.md)
* [ ] If necessary, please update the documentation to describe the new feature. https://github.com/apache/seatunnel/tree/dev/docs
* [ ] If you are contributing the connector code, please check that the following files are updated:
1. Update change log that in connector document. For more details you can refer to [connector-v2](https://github.com/apache/seatunnel/tree/dev/docs/en/connector-v2)
2. Update [plugin-mapping.properties](https://github.com/apache/seatunnel/blob/dev/plugin-mapping.properties) and add new connector information in it
3. Update the pom file of [seatunnel-dist](https://github.com/apache/seatunnel/blob/dev/seatunnel-dist/pom.xml)
* [ ] Update the [`release-note`](https://github.com/apache/seatunnel/blob/dev/release-note.md).
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@seatunnel.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [Feature][Connector-V2] Support jdbc hana catalog and type convertor [seatunnel]
Posted by "EricJoy2048 (via GitHub)" <gi...@apache.org>.
EricJoy2048 merged PR #6950:
URL: https://github.com/apache/seatunnel/pull/6950
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@seatunnel.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [Feature][Connector-V2] Support jdbc hana catalog and type convertor [seatunnel]
Posted by "hailin0 (via GitHub)" <gi...@apache.org>.
hailin0 commented on code in PR #6950:
URL: https://github.com/apache/seatunnel/pull/6950#discussion_r1668568030
##########
seatunnel-connectors-v2/connector-jdbc/src/main/java/org/apache/seatunnel/connectors/seatunnel/jdbc/internal/dialect/saphana/SapHanaTypeConverter.java:
##########
@@ -0,0 +1,487 @@
+/*
+ * 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.catalog.Column;
+import org.apache.seatunnel.api.table.catalog.PhysicalColumn;
+import org.apache.seatunnel.api.table.converter.BasicTypeDefine;
+import org.apache.seatunnel.api.table.converter.TypeConverter;
+import org.apache.seatunnel.api.table.type.ArrayType;
+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.common.exception.CommonError;
+import org.apache.seatunnel.connectors.seatunnel.common.source.TypeDefineUtils;
+import org.apache.seatunnel.connectors.seatunnel.jdbc.internal.dialect.DatabaseIdentifier;
+
+import com.google.auto.service.AutoService;
+import lombok.extern.slf4j.Slf4j;
+
+import java.util.Arrays;
+import java.util.List;
+
+// reference
+// https://help.sap.com/docs/SAP_HANA_PLATFORM/4fe29514fd584807ac9f2a04f6754767/20a1569875191014b507cf392724b7eb.html?locale=en-US
+@Slf4j
+@AutoService(TypeConverter.class)
+public class SapHanaTypeConverter implements TypeConverter<BasicTypeDefine> {
+ // ============================data types=====================
+
+ // -------------------------binary-------------------------
+ public static final String HANA_BINARY = "BINARY";
+ public static final String HANA_VARBINARY = "VARBINARY";
+
+ // -------------------------boolean----------------------------
+ public static final String HANA_BOOLEAN = "BOOLEAN";
+
+ // -------------------------string----------------------------
+ public static final String HANA_VARCHAR = "VARCHAR";
+ public static final String HANA_NVARCHAR = "NVARCHAR";
+ public static final String HANA_ALPHANUM = "ALPHANUM";
+ public static final String HANA_SHORTTEXT = "SHORTTEXT";
+
+ // -------------------------datetime----------------------------
+ public static final String HANA_DATE = "DATE";
+ public static final String HANA_TIME = "TIME";
+ public static final String HANA_SECONDDATE = "SECONDDATE";
+ public static final String HANA_TIMESTAMP = "TIMESTAMP";
+
+ // -------------------------lob----------------------------
+ public static final String HANA_BLOB = "BLOB";
+ public static final String HANA_CLOB = "CLOB";
+ public static final String HANA_NCLOB = "NCLOB";
+ public static final String HANA_TEXT = "TEXT";
+ public static final String HANA_BINTEXT = "BINTEXT";
+
+ // -------------------------array----------------------------
+ public static final String HANA_ARRAY = "ARRAY";
+
+ // -------------------------number----------------------------
+ public static final String HANA_TINYINT = "TINYINT";
+ public static final String HANA_SMALLINT = "SMALLINT";
+ public static final String HANA_INTEGER = "INTEGER";
+ public static final String HANA_BIGINT = "BIGINT";
+ public static final String HANA_SMALLDECIMAL = "SMALLDECIMAL";
+ public static final String HANA_DECIMAL = "DECIMAL";
+ public static final String HANA_DOUBLE = "DOUBLE";
+ public static final String HANA_REAL = "REAL";
+
+ // -------------------------special----------------------------
+ public static final String HANA_ST_POINT = "ST_POINT";
+ public static final String HANA_ST_GEOMETRY = "ST_GEOMETRY";
+
+ public static final int MAX_PRECISION = 38;
+ public static final int DEFAULT_PRECISION = MAX_PRECISION;
+ public static final int MAX_SCALE = 6176;
+ public static final int MAX_SMALL_DECIMAL_SCALE = 368;
+ public static final int DEFAULT_SCALE = 0;
+ public static final int TIMESTAMP_DEFAULT_SCALE = 7;
+ public static final int MAX_TIMESTAMP_SCALE = 7;
+ public static final long MAX_BINARY_LENGTH = 5000;
+ public static final long MAX_LOB_LENGTH = Integer.MAX_VALUE;
+ public static final long MAX_NVARCHAR_LENGTH = 5000;
+
+ public static final List<String> shouldAppendLength =
+ Arrays.asList(
+ HANA_BINARY,
+ HANA_VARBINARY,
+ HANA_VARCHAR,
+ HANA_NVARCHAR,
+ HANA_ALPHANUM,
+ HANA_SHORTTEXT);
+
+ public static final SapHanaTypeConverter INSTANCE = new SapHanaTypeConverter();
+
+ @Override
+ public String identifier() {
+ return DatabaseIdentifier.SAP_HANA;
+ }
+
+ @Override
+ public Column convert(BasicTypeDefine typeDefine) {
+ PhysicalColumn.PhysicalColumnBuilder builder =
+ PhysicalColumn.builder()
+ .name(typeDefine.getName())
+ .sourceType(typeDefine.getColumnType())
+ .nullable(typeDefine.isNullable())
+ .defaultValue(typeDefine.getDefaultValue())
+ .comment(typeDefine.getComment());
+
+ String hanaType = typeDefine.getDataType().toUpperCase();
+ if (typeDefine.getColumnType().endsWith(" ARRAY")) {
+ typeDefine.setColumnType(typeDefine.getColumnType().replace(" ARRAY", ""));
+ typeDefine.setDataType(removeColumnSizeIfNeed(typeDefine.getColumnType()));
+ Column arrayColumn = convert(typeDefine);
+ SeaTunnelDataType<?> newType;
+ switch (arrayColumn.getDataType().getSqlType()) {
+ case STRING:
+ newType = ArrayType.STRING_ARRAY_TYPE;
+ break;
+ case BOOLEAN:
+ newType = ArrayType.BOOLEAN_ARRAY_TYPE;
+ break;
+ case TINYINT:
+ newType = ArrayType.BYTE_ARRAY_TYPE;
+ break;
+ case SMALLINT:
+ newType = ArrayType.SHORT_ARRAY_TYPE;
+ break;
+ case INT:
+ newType = ArrayType.INT_ARRAY_TYPE;
+ break;
+ case BIGINT:
+ newType = ArrayType.LONG_ARRAY_TYPE;
+ break;
+ case FLOAT:
+ newType = ArrayType.FLOAT_ARRAY_TYPE;
+ break;
+ case DOUBLE:
+ newType = ArrayType.DOUBLE_ARRAY_TYPE;
+ break;
+ case DATE:
+ newType = ArrayType.LOCAL_DATE_ARRAY_TYPE;
+ break;
+ case TIME:
+ newType = ArrayType.LOCAL_TIME_ARRAY_TYPE;
+ break;
+ case TIMESTAMP:
+ newType = ArrayType.LOCAL_DATE_TIME_ARRAY_TYPE;
+ break;
+ default:
+ throw CommonError.unsupportedDataType(
+ "SeaTunnel",
+ arrayColumn.getDataType().getSqlType().toString(),
+ typeDefine.getName());
+ }
+ return new PhysicalColumn(
+ arrayColumn.getName(),
+ newType,
+ arrayColumn.getColumnLength(),
+ arrayColumn.getScale(),
+ arrayColumn.isNullable(),
+ arrayColumn.getDefaultValue(),
+ arrayColumn.getComment(),
+ arrayColumn.getSourceType() + " ARRAY",
+ arrayColumn.getOptions());
+ }
+ switch (hanaType) {
+ case HANA_BINARY:
+ case HANA_VARBINARY:
+ builder.dataType(PrimitiveByteArrayType.INSTANCE);
+ if (typeDefine.getLength() == null || typeDefine.getLength() == 0) {
+ builder.columnLength(MAX_BINARY_LENGTH);
+ } else {
+ builder.columnLength(typeDefine.getLength());
+ }
+ break;
+ case HANA_BOOLEAN:
+ builder.dataType(BasicType.BOOLEAN_TYPE);
+ break;
+ case HANA_VARCHAR:
+ case HANA_ALPHANUM:
+ case HANA_CLOB:
+ case HANA_NCLOB:
+ case HANA_TEXT:
+ case HANA_BINTEXT:
+ builder.dataType(BasicType.STRING_TYPE);
+ if (typeDefine.getLength() == null || typeDefine.getLength() == 0) {
+ builder.columnLength(MAX_LOB_LENGTH);
+ } else {
+ builder.columnLength(typeDefine.getLength());
+ }
+ break;
+ case HANA_NVARCHAR:
+ case HANA_SHORTTEXT:
+ builder.dataType(BasicType.STRING_TYPE);
+ builder.columnLength(TypeDefineUtils.charToByteLength(typeDefine.getLength(), 2));
Review Comment:
```suggestion
builder.columnLength(TypeDefineUtils.charTo4ByteLength(typeDefine.getLength()));
```
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@seatunnel.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [Feature][Connector-V2] Support jdbc hana catalog and type convertor [seatunnel]
Posted by "Hisoka-X (via GitHub)" <gi...@apache.org>.
Hisoka-X commented on code in PR #6950:
URL: https://github.com/apache/seatunnel/pull/6950#discussion_r1668576193
##########
seatunnel-connectors-v2/connector-jdbc/src/main/java/org/apache/seatunnel/connectors/seatunnel/jdbc/internal/dialect/saphana/SapHanaTypeConverter.java:
##########
@@ -0,0 +1,487 @@
+/*
+ * 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.catalog.Column;
+import org.apache.seatunnel.api.table.catalog.PhysicalColumn;
+import org.apache.seatunnel.api.table.converter.BasicTypeDefine;
+import org.apache.seatunnel.api.table.converter.TypeConverter;
+import org.apache.seatunnel.api.table.type.ArrayType;
+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.common.exception.CommonError;
+import org.apache.seatunnel.connectors.seatunnel.common.source.TypeDefineUtils;
+import org.apache.seatunnel.connectors.seatunnel.jdbc.internal.dialect.DatabaseIdentifier;
+
+import com.google.auto.service.AutoService;
+import lombok.extern.slf4j.Slf4j;
+
+import java.util.Arrays;
+import java.util.List;
+
+// reference
+// https://help.sap.com/docs/SAP_HANA_PLATFORM/4fe29514fd584807ac9f2a04f6754767/20a1569875191014b507cf392724b7eb.html?locale=en-US
+@Slf4j
+@AutoService(TypeConverter.class)
+public class SapHanaTypeConverter implements TypeConverter<BasicTypeDefine> {
+ // ============================data types=====================
+
+ // -------------------------binary-------------------------
+ public static final String HANA_BINARY = "BINARY";
+ public static final String HANA_VARBINARY = "VARBINARY";
+
+ // -------------------------boolean----------------------------
+ public static final String HANA_BOOLEAN = "BOOLEAN";
+
+ // -------------------------string----------------------------
+ public static final String HANA_VARCHAR = "VARCHAR";
+ public static final String HANA_NVARCHAR = "NVARCHAR";
+ public static final String HANA_ALPHANUM = "ALPHANUM";
+ public static final String HANA_SHORTTEXT = "SHORTTEXT";
+
+ // -------------------------datetime----------------------------
+ public static final String HANA_DATE = "DATE";
+ public static final String HANA_TIME = "TIME";
+ public static final String HANA_SECONDDATE = "SECONDDATE";
+ public static final String HANA_TIMESTAMP = "TIMESTAMP";
+
+ // -------------------------lob----------------------------
+ public static final String HANA_BLOB = "BLOB";
+ public static final String HANA_CLOB = "CLOB";
+ public static final String HANA_NCLOB = "NCLOB";
+ public static final String HANA_TEXT = "TEXT";
+ public static final String HANA_BINTEXT = "BINTEXT";
+
+ // -------------------------array----------------------------
+ public static final String HANA_ARRAY = "ARRAY";
+
+ // -------------------------number----------------------------
+ public static final String HANA_TINYINT = "TINYINT";
+ public static final String HANA_SMALLINT = "SMALLINT";
+ public static final String HANA_INTEGER = "INTEGER";
+ public static final String HANA_BIGINT = "BIGINT";
+ public static final String HANA_SMALLDECIMAL = "SMALLDECIMAL";
+ public static final String HANA_DECIMAL = "DECIMAL";
+ public static final String HANA_DOUBLE = "DOUBLE";
+ public static final String HANA_REAL = "REAL";
+
+ // -------------------------special----------------------------
+ public static final String HANA_ST_POINT = "ST_POINT";
+ public static final String HANA_ST_GEOMETRY = "ST_GEOMETRY";
+
+ public static final int MAX_PRECISION = 38;
+ public static final int DEFAULT_PRECISION = MAX_PRECISION;
+ public static final int MAX_SCALE = 6176;
+ public static final int MAX_SMALL_DECIMAL_SCALE = 368;
+ public static final int DEFAULT_SCALE = 0;
+ public static final int TIMESTAMP_DEFAULT_SCALE = 7;
+ public static final int MAX_TIMESTAMP_SCALE = 7;
+ public static final long MAX_BINARY_LENGTH = 5000;
+ public static final long MAX_LOB_LENGTH = Integer.MAX_VALUE;
+ public static final long MAX_NVARCHAR_LENGTH = 5000;
+
+ public static final List<String> shouldAppendLength =
+ Arrays.asList(
+ HANA_BINARY,
+ HANA_VARBINARY,
+ HANA_VARCHAR,
+ HANA_NVARCHAR,
+ HANA_ALPHANUM,
+ HANA_SHORTTEXT);
+
+ public static final SapHanaTypeConverter INSTANCE = new SapHanaTypeConverter();
+
+ @Override
+ public String identifier() {
+ return DatabaseIdentifier.SAP_HANA;
+ }
+
+ @Override
+ public Column convert(BasicTypeDefine typeDefine) {
+ PhysicalColumn.PhysicalColumnBuilder builder =
+ PhysicalColumn.builder()
+ .name(typeDefine.getName())
+ .sourceType(typeDefine.getColumnType())
+ .nullable(typeDefine.isNullable())
+ .defaultValue(typeDefine.getDefaultValue())
+ .comment(typeDefine.getComment());
+
+ String hanaType = typeDefine.getDataType().toUpperCase();
+ if (typeDefine.getColumnType().endsWith(" ARRAY")) {
+ typeDefine.setColumnType(typeDefine.getColumnType().replace(" ARRAY", ""));
+ typeDefine.setDataType(removeColumnSizeIfNeed(typeDefine.getColumnType()));
+ Column arrayColumn = convert(typeDefine);
+ SeaTunnelDataType<?> newType;
+ switch (arrayColumn.getDataType().getSqlType()) {
+ case STRING:
+ newType = ArrayType.STRING_ARRAY_TYPE;
+ break;
+ case BOOLEAN:
+ newType = ArrayType.BOOLEAN_ARRAY_TYPE;
+ break;
+ case TINYINT:
+ newType = ArrayType.BYTE_ARRAY_TYPE;
+ break;
+ case SMALLINT:
+ newType = ArrayType.SHORT_ARRAY_TYPE;
+ break;
+ case INT:
+ newType = ArrayType.INT_ARRAY_TYPE;
+ break;
+ case BIGINT:
+ newType = ArrayType.LONG_ARRAY_TYPE;
+ break;
+ case FLOAT:
+ newType = ArrayType.FLOAT_ARRAY_TYPE;
+ break;
+ case DOUBLE:
+ newType = ArrayType.DOUBLE_ARRAY_TYPE;
+ break;
+ case DATE:
+ newType = ArrayType.LOCAL_DATE_ARRAY_TYPE;
+ break;
+ case TIME:
+ newType = ArrayType.LOCAL_TIME_ARRAY_TYPE;
+ break;
+ case TIMESTAMP:
+ newType = ArrayType.LOCAL_DATE_TIME_ARRAY_TYPE;
+ break;
+ default:
+ throw CommonError.unsupportedDataType(
+ "SeaTunnel",
+ arrayColumn.getDataType().getSqlType().toString(),
+ typeDefine.getName());
+ }
+ return new PhysicalColumn(
+ arrayColumn.getName(),
+ newType,
+ arrayColumn.getColumnLength(),
+ arrayColumn.getScale(),
+ arrayColumn.isNullable(),
+ arrayColumn.getDefaultValue(),
+ arrayColumn.getComment(),
+ arrayColumn.getSourceType() + " ARRAY",
+ arrayColumn.getOptions());
+ }
+ switch (hanaType) {
+ case HANA_BINARY:
+ case HANA_VARBINARY:
+ builder.dataType(PrimitiveByteArrayType.INSTANCE);
+ if (typeDefine.getLength() == null || typeDefine.getLength() == 0) {
+ builder.columnLength(MAX_BINARY_LENGTH);
+ } else {
+ builder.columnLength(typeDefine.getLength());
+ }
+ break;
+ case HANA_BOOLEAN:
+ builder.dataType(BasicType.BOOLEAN_TYPE);
+ break;
+ case HANA_VARCHAR:
+ case HANA_ALPHANUM:
+ case HANA_CLOB:
+ case HANA_NCLOB:
+ case HANA_TEXT:
+ case HANA_BINTEXT:
+ builder.dataType(BasicType.STRING_TYPE);
+ if (typeDefine.getLength() == null || typeDefine.getLength() == 0) {
+ builder.columnLength(MAX_LOB_LENGTH);
+ } else {
+ builder.columnLength(typeDefine.getLength());
+ }
+ break;
+ case HANA_NVARCHAR:
+ case HANA_SHORTTEXT:
+ builder.dataType(BasicType.STRING_TYPE);
+ builder.columnLength(TypeDefineUtils.charToByteLength(typeDefine.getLength(), 2));
Review Comment:
addressed.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@seatunnel.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org