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 2023/01/24 06:10:46 UTC

[GitHub] [incubator-seatunnel] Hisoka-X commented on a diff in pull request #3990: [Improve][Connector][PulsarSource]Improve pulsar deserialization

Hisoka-X commented on code in PR #3990:
URL: https://github.com/apache/incubator-seatunnel/pull/3990#discussion_r1084845437


##########
seatunnel-connectors-v2/connector-pulsar/src/main/java/org/apache/seatunnel/connectors/seatunnel/pulsar/source/PulsarSource.java:
##########
@@ -226,10 +234,37 @@ private void setPartitionDiscoverer(Config config) {
     }
 
     private void setDeserialization(Config config) {
-        String format = config.getString("format");
-        // TODO: format SPI
-        SeaTunnelRowType rowType = SeaTunnelSchema.buildWithConfig(config.getConfig(SeaTunnelSchema.SCHEMA.key())).getSeaTunnelRowType();
-        deserialization = (DeserializationSchema<T>) new JsonDeserializationSchema(false, false, rowType);
+        String schemaKey = SeaTunnelSchema.SCHEMA.key();
+        if (config.hasPath(schemaKey)) {
+            Config schema = config.getConfig(schemaKey);
+            SeaTunnelRowType rowType = SeaTunnelSchema.buildWithConfig(schema).getSeaTunnelRowType();
+            String format = DEFAULT_FORMAT;
+            if (config.hasPath(FORMAT.key())) {
+                format = config.getString(FORMAT.key());
+            }
+            if (DEFAULT_FORMAT.equals(format)) {
+                deserialization = (DeserializationSchema<T>) new JsonDeserializationSchema(false, false, rowType);
+            } else if (TEXT_FORMAT.equals(format)) {
+                String delimiter = DEFAULT_FIELD_DELIMITER;
+                if (config.hasPath(FIELD_DELIMITER.key())) {
+                    delimiter = config.getString(FIELD_DELIMITER.key());
+                }
+                deserialization = (DeserializationSchema<T>) TextDeserializationSchema.builder()
+                        .seaTunnelRowType(rowType)
+                        .delimiter(delimiter)
+                        .build();
+            } else {
+                // TODO: use format SPI
+                throw new SeaTunnelJsonFormatException(CommonErrorCode.UNSUPPORTED_DATA_TYPE,

Review Comment:
   Can't throw UNSUPPORTED_DATA_TYPE, CommonErrorCode.UNSUPPORTED_OPERATION maybe better.



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