You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@seatunnel.apache.org by GitBox <gi...@apache.org> on 2022/09/15 18:11:40 UTC

[GitHub] [incubator-seatunnel] TyrantLucifer opened a new pull request, #2747: [Improve][Connector-V2] Imporve orc read strategy

TyrantLucifer opened a new pull request, #2747:
URL: https://github.com/apache/incubator-seatunnel/pull/2747

   <!--
   
   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/incubator-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
   
   close #2714
   
   <!-- Describe the purpose of this pull request. For example: This pull request adds checkstyle plugin.-->
   
   ## Check list
   
   * [x] Code changed are covered with tests, or it does not need tests for reason:
   * [ ] If any new Jar binary package adding in your PR, please add License Notice according
     [New License Guide](https://github.com/apache/incubator-seatunnel/blob/dev/docs/en/contribution/new-license.md)
   * [ ] If necessary, please update the documentation to describe the new feature. https://github.com/apache/incubator-seatunnel/tree/dev/docs
   


-- 
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


[GitHub] [incubator-seatunnel] TyrantLucifer commented on a diff in pull request #2747: [Improve][Connector-V2] Imporve orc read strategy

Posted by GitBox <gi...@apache.org>.
TyrantLucifer commented on code in PR #2747:
URL: https://github.com/apache/incubator-seatunnel/pull/2747#discussion_r974033584


##########
seatunnel-connectors-v2/connector-file/connector-file-base/src/main/java/org/apache/seatunnel/connectors/seatunnel/file/source/reader/OrcReadStrategy.java:
##########
@@ -163,6 +167,73 @@ boolean checkFileType(String path) {
         }
     }
 
+    private SeaTunnelDataType<?> orcDataType2SeaTunnelDataType(TypeDescription typeDescription) {
+        switch (typeDescription.getCategory()) {
+            case BOOLEAN:
+                return BasicType.BOOLEAN_TYPE;
+            case INT:
+                return BasicType.INT_TYPE;
+            case BYTE:
+            case SHORT:

Review Comment:
   Becase these types in orc are saved in `LongVector`, so when we read these types using java api it is a `Long` object.



-- 
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


[GitHub] [incubator-seatunnel] hailin0 commented on a diff in pull request #2747: [Improve][Connector-V2] Imporve orc read strategy

Posted by GitBox <gi...@apache.org>.
hailin0 commented on code in PR #2747:
URL: https://github.com/apache/incubator-seatunnel/pull/2747#discussion_r973999548


##########
seatunnel-connectors-v2/connector-file/connector-file-base/src/main/java/org/apache/seatunnel/connectors/seatunnel/file/source/reader/OrcReadStrategy.java:
##########
@@ -163,6 +167,73 @@ boolean checkFileType(String path) {
         }
     }
 
+    private SeaTunnelDataType<?> orcDataType2SeaTunnelDataType(TypeDescription typeDescription) {
+        switch (typeDescription.getCategory()) {
+            case BOOLEAN:
+                return BasicType.BOOLEAN_TYPE;
+            case INT:
+                return BasicType.INT_TYPE;
+            case BYTE:
+            case SHORT:
+            case LONG:
+                return BasicType.LONG_TYPE;
+            case FLOAT:

Review Comment:
   Why not use :
   ```java
   case FLOAT:
       return BasicType.FLOAT_TYPE
   ```



-- 
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


[GitHub] [incubator-seatunnel] EricJoy2048 commented on pull request #2747: [Improve][Connector-V2] Imporve orc read strategy

Posted by GitBox <gi...@apache.org>.
EricJoy2048 commented on PR #2747:
URL: https://github.com/apache/incubator-seatunnel/pull/2747#issuecomment-1252152538

   @CalvinKirs  PTAL


-- 
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


[GitHub] [incubator-seatunnel] CalvinKirs merged pull request #2747: [Improve][Connector-V2] Imporve orc read strategy

Posted by GitBox <gi...@apache.org>.
CalvinKirs merged PR #2747:
URL: https://github.com/apache/incubator-seatunnel/pull/2747


-- 
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


[GitHub] [incubator-seatunnel] hailin0 commented on a diff in pull request #2747: [Improve][Connector-V2] Imporve orc read strategy

Posted by GitBox <gi...@apache.org>.
hailin0 commented on code in PR #2747:
URL: https://github.com/apache/incubator-seatunnel/pull/2747#discussion_r974000489


##########
seatunnel-connectors-v2/connector-file/connector-file-base/src/main/java/org/apache/seatunnel/connectors/seatunnel/file/source/reader/OrcReadStrategy.java:
##########
@@ -163,6 +167,73 @@ boolean checkFileType(String path) {
         }
     }
 
+    private SeaTunnelDataType<?> orcDataType2SeaTunnelDataType(TypeDescription typeDescription) {
+        switch (typeDescription.getCategory()) {
+            case BOOLEAN:
+                return BasicType.BOOLEAN_TYPE;
+            case INT:
+                return BasicType.INT_TYPE;
+            case BYTE:
+            case SHORT:
+            case LONG:
+                return BasicType.LONG_TYPE;
+            case FLOAT:
+            case DOUBLE:
+                return BasicType.DOUBLE_TYPE;
+            case STRING:
+            case BINARY:

Review Comment:
   
   Why not use :
   ```java
   case BINARY:
       return PrimitiveByteArrayType.INSTANCE
   ```



-- 
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


[GitHub] [incubator-seatunnel] TyrantLucifer commented on a diff in pull request #2747: [Improve][Connector-V2] Imporve orc read strategy

Posted by GitBox <gi...@apache.org>.
TyrantLucifer commented on code in PR #2747:
URL: https://github.com/apache/incubator-seatunnel/pull/2747#discussion_r974033957


##########
seatunnel-connectors-v2/connector-file/connector-file-base/src/main/java/org/apache/seatunnel/connectors/seatunnel/file/source/reader/OrcReadStrategy.java:
##########
@@ -163,6 +167,73 @@ boolean checkFileType(String path) {
         }
     }
 
+    private SeaTunnelDataType<?> orcDataType2SeaTunnelDataType(TypeDescription typeDescription) {
+        switch (typeDescription.getCategory()) {
+            case BOOLEAN:
+                return BasicType.BOOLEAN_TYPE;
+            case INT:
+                return BasicType.INT_TYPE;
+            case BYTE:
+            case SHORT:
+            case LONG:
+                return BasicType.LONG_TYPE;
+            case FLOAT:

Review Comment:
   Becase these types in orc are saved in `DoubleVector`, so when we read these types using java api it is a `Double` object.



-- 
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


[GitHub] [incubator-seatunnel] hailin0 commented on a diff in pull request #2747: [Improve][Connector-V2] Imporve orc read strategy

Posted by GitBox <gi...@apache.org>.
hailin0 commented on code in PR #2747:
URL: https://github.com/apache/incubator-seatunnel/pull/2747#discussion_r973999253


##########
seatunnel-connectors-v2/connector-file/connector-file-base/src/main/java/org/apache/seatunnel/connectors/seatunnel/file/source/reader/OrcReadStrategy.java:
##########
@@ -163,6 +167,73 @@ boolean checkFileType(String path) {
         }
     }
 
+    private SeaTunnelDataType<?> orcDataType2SeaTunnelDataType(TypeDescription typeDescription) {
+        switch (typeDescription.getCategory()) {
+            case BOOLEAN:
+                return BasicType.BOOLEAN_TYPE;
+            case INT:
+                return BasicType.INT_TYPE;
+            case BYTE:
+            case SHORT:

Review Comment:
   Why not use `TINYINT`、`SMALLINT`?



##########
seatunnel-connectors-v2/connector-file/connector-file-base/src/main/java/org/apache/seatunnel/connectors/seatunnel/file/source/reader/OrcReadStrategy.java:
##########
@@ -163,6 +167,73 @@ boolean checkFileType(String path) {
         }
     }
 
+    private SeaTunnelDataType<?> orcDataType2SeaTunnelDataType(TypeDescription typeDescription) {
+        switch (typeDescription.getCategory()) {
+            case BOOLEAN:
+                return BasicType.BOOLEAN_TYPE;
+            case INT:
+                return BasicType.INT_TYPE;
+            case BYTE:
+            case SHORT:
+            case LONG:
+                return BasicType.LONG_TYPE;
+            case FLOAT:

Review Comment:
   Why not use `FLOAT`?



##########
seatunnel-connectors-v2/connector-file/connector-file-base/src/main/java/org/apache/seatunnel/connectors/seatunnel/file/source/reader/OrcReadStrategy.java:
##########
@@ -163,6 +167,73 @@ boolean checkFileType(String path) {
         }
     }
 
+    private SeaTunnelDataType<?> orcDataType2SeaTunnelDataType(TypeDescription typeDescription) {
+        switch (typeDescription.getCategory()) {
+            case BOOLEAN:
+                return BasicType.BOOLEAN_TYPE;
+            case INT:
+                return BasicType.INT_TYPE;
+            case BYTE:
+            case SHORT:
+            case LONG:
+                return BasicType.LONG_TYPE;
+            case FLOAT:
+            case DOUBLE:
+                return BasicType.DOUBLE_TYPE;
+            case STRING:
+            case BINARY:
+            case VARCHAR:
+            case CHAR:
+                return BasicType.STRING_TYPE;
+            case DATE:
+                return LocalTimeType.LOCAL_DATE_TYPE;
+            case TIMESTAMP:
+                return LocalTimeType.LOCAL_DATE_TIME_TYPE;
+            case DECIMAL:
+                int precision = typeDescription.getPrecision();
+                int scale = typeDescription.getScale();
+                return new DecimalType(precision, scale);
+            case LIST:
+                TypeDescription listType = typeDescription.getChildren().get(0);
+                SeaTunnelDataType<?> seaTunnelDataType = orcDataType2SeaTunnelDataType(listType);
+                if (BasicType.STRING_TYPE.equals(seaTunnelDataType)) {
+                    return ArrayType.STRING_ARRAY_TYPE;
+                } else if (BasicType.BOOLEAN_TYPE.equals(seaTunnelDataType)) {
+                    return ArrayType.BOOLEAN_ARRAY_TYPE;
+                } else if (BasicType.BYTE_TYPE.equals(seaTunnelDataType)) {
+                    return ArrayType.BYTE_ARRAY_TYPE;
+                } else if (BasicType.SHORT_TYPE.equals(seaTunnelDataType)) {
+                    return ArrayType.SHORT_ARRAY_TYPE;
+                } else if (BasicType.INT_TYPE.equals(seaTunnelDataType)) {
+                    return ArrayType.INT_ARRAY_TYPE;
+                } else if (BasicType.LONG_TYPE.equals(seaTunnelDataType)) {
+                    return ArrayType.LONG_ARRAY_TYPE;
+                } else if (BasicType.FLOAT_TYPE.equals(seaTunnelDataType)) {
+                    return ArrayType.FLOAT_ARRAY_TYPE;
+                } else if (BasicType.DOUBLE_TYPE.equals(seaTunnelDataType)) {
+                    return ArrayType.DOUBLE_ARRAY_TYPE;
+                }
+                String errorMsg = String.format("SeaTunnel array type not supported this genericType [%s] yet", seaTunnelDataType);
+                throw new RuntimeException(errorMsg);

Review Comment:
   Use `switch (seaTunnelDataType.getSqlType())`?



##########
seatunnel-connectors-v2/connector-file/connector-file-base/src/main/java/org/apache/seatunnel/connectors/seatunnel/file/source/reader/OrcReadStrategy.java:
##########
@@ -163,6 +167,73 @@ boolean checkFileType(String path) {
         }
     }
 
+    private SeaTunnelDataType<?> orcDataType2SeaTunnelDataType(TypeDescription typeDescription) {
+        switch (typeDescription.getCategory()) {
+            case BOOLEAN:
+                return BasicType.BOOLEAN_TYPE;
+            case INT:
+                return BasicType.INT_TYPE;
+            case BYTE:
+            case SHORT:
+            case LONG:
+                return BasicType.LONG_TYPE;
+            case FLOAT:
+            case DOUBLE:
+                return BasicType.DOUBLE_TYPE;
+            case STRING:
+            case BINARY:

Review Comment:
   why not use  seatunnel `BYTES`?



##########
seatunnel-connectors-v2/connector-file/connector-file-base/src/main/java/org/apache/seatunnel/connectors/seatunnel/file/source/reader/OrcReadStrategy.java:
##########
@@ -163,6 +167,73 @@ boolean checkFileType(String path) {
         }
     }
 
+    private SeaTunnelDataType<?> orcDataType2SeaTunnelDataType(TypeDescription typeDescription) {
+        switch (typeDescription.getCategory()) {
+            case BOOLEAN:
+                return BasicType.BOOLEAN_TYPE;
+            case INT:
+                return BasicType.INT_TYPE;
+            case BYTE:
+            case SHORT:
+            case LONG:
+                return BasicType.LONG_TYPE;
+            case FLOAT:
+            case DOUBLE:
+                return BasicType.DOUBLE_TYPE;
+            case STRING:
+            case BINARY:
+            case VARCHAR:
+            case CHAR:
+                return BasicType.STRING_TYPE;
+            case DATE:
+                return LocalTimeType.LOCAL_DATE_TYPE;
+            case TIMESTAMP:
+                return LocalTimeType.LOCAL_DATE_TIME_TYPE;
+            case DECIMAL:
+                int precision = typeDescription.getPrecision();
+                int scale = typeDescription.getScale();
+                return new DecimalType(precision, scale);
+            case LIST:
+                TypeDescription listType = typeDescription.getChildren().get(0);
+                SeaTunnelDataType<?> seaTunnelDataType = orcDataType2SeaTunnelDataType(listType);
+                if (BasicType.STRING_TYPE.equals(seaTunnelDataType)) {
+                    return ArrayType.STRING_ARRAY_TYPE;
+                } else if (BasicType.BOOLEAN_TYPE.equals(seaTunnelDataType)) {
+                    return ArrayType.BOOLEAN_ARRAY_TYPE;
+                } else if (BasicType.BYTE_TYPE.equals(seaTunnelDataType)) {
+                    return ArrayType.BYTE_ARRAY_TYPE;
+                } else if (BasicType.SHORT_TYPE.equals(seaTunnelDataType)) {
+                    return ArrayType.SHORT_ARRAY_TYPE;
+                } else if (BasicType.INT_TYPE.equals(seaTunnelDataType)) {
+                    return ArrayType.INT_ARRAY_TYPE;
+                } else if (BasicType.LONG_TYPE.equals(seaTunnelDataType)) {
+                    return ArrayType.LONG_ARRAY_TYPE;
+                } else if (BasicType.FLOAT_TYPE.equals(seaTunnelDataType)) {
+                    return ArrayType.FLOAT_ARRAY_TYPE;
+                } else if (BasicType.DOUBLE_TYPE.equals(seaTunnelDataType)) {
+                    return ArrayType.DOUBLE_ARRAY_TYPE;
+                }
+                String errorMsg = String.format("SeaTunnel array type not supported this genericType [%s] yet", seaTunnelDataType);
+                throw new RuntimeException(errorMsg);
+            case MAP:
+                TypeDescription keyType = typeDescription.getChildren().get(0);
+                TypeDescription valueType = typeDescription.getChildren().get(1);
+                return new MapType<>(orcDataType2SeaTunnelDataType(keyType), orcDataType2SeaTunnelDataType(valueType));
+            case STRUCT:
+                List<TypeDescription> children = typeDescription.getChildren();
+                String[] fieldNames = typeDescription.getFieldNames().toArray(new String[0]);
+                SeaTunnelDataType<?>[] fieldTypes = children.stream().map(this::orcDataType2SeaTunnelDataType).toArray(SeaTunnelDataType<?>[]::new);
+                return new SeaTunnelRowType(fieldNames, fieldTypes);
+            case UNION:
+                // TODO: How to explain this type using SeaTunnel data type
+                throw new RuntimeException("SeaTunnel not supported orc [union] type yet");
+            default:
+                // do nothing
+                // never get in there
+                return null;

Review Comment:
   You will get unexpected results if the orc is upgraded, so log error message and throw exception



-- 
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