Copilot commented on code in PR #9574:
URL: https://github.com/apache/seatunnel/pull/9574#discussion_r2212877154
##########
seatunnel-connectors-v2/connector-redis/src/main/java/org/apache/seatunnel/connectors/seatunnel/redis/source/RedisSourceReader.java:
##########
@@ -91,101 +89,42 @@ public void internalPollNext(Collector<SeaTunnelRow>
output) throws Exception {
private void pollNext(List<String> keys, RedisDataType dataType,
Collector<SeaTunnelRow> output)
throws IOException {
+ RedisRecordReader redisRecordReader;
+ if (redisParameters.getReadKeyEnabled()) {
+ redisRecordReader =
+ new KeyedRecordReader(redisParameters,
deserializationSchema, redisClient);
+ } else
+ redisRecordReader =
+ new UnKeyedRecordReader(redisParameters,
deserializationSchema, redisClient);
Review Comment:
[nitpick] Missing braces around single-statement else clause. For
consistency and maintainability, add braces around the else block.
```suggestion
} else {
redisRecordReader =
new UnKeyedRecordReader(redisParameters,
deserializationSchema, redisClient);
}
```
##########
seatunnel-connectors-v2/connector-redis/src/main/java/org/apache/seatunnel/connectors/seatunnel/redis/source/KeyedRecordReader.java:
##########
@@ -0,0 +1,130 @@
+/*
+ * 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.redis.source;
+
+import org.apache.seatunnel.shade.com.fasterxml.jackson.databind.JsonNode;
+import
org.apache.seatunnel.shade.com.fasterxml.jackson.databind.node.ObjectNode;
+
+import org.apache.seatunnel.api.serialization.DeserializationSchema;
+import org.apache.seatunnel.api.source.Collector;
+import org.apache.seatunnel.api.table.type.SeaTunnelRow;
+import org.apache.seatunnel.common.exception.CommonError;
+import org.apache.seatunnel.common.utils.JsonUtils;
+import org.apache.seatunnel.connectors.seatunnel.redis.client.RedisClient;
+import org.apache.seatunnel.connectors.seatunnel.redis.config.RedisParameters;
+
+import lombok.extern.slf4j.Slf4j;
+
+import java.io.IOException;
+import java.util.List;
+import java.util.Set;
+
+@Slf4j
+public class KeyedRecordReader extends RedisRecordReader {
+
+ public KeyedRecordReader(
+ RedisParameters redisParameters,
+ DeserializationSchema<SeaTunnelRow> deserializationSchema,
+ RedisClient redisClient) {
+ super(redisParameters, deserializationSchema, redisClient);
+ }
+
+ @Override
+ public void pollZsetToNext(List<String> keys, Collector<SeaTunnelRow>
output)
+ throws IOException {
+ List<List<String>> zSetList = redisClient.batchGetZset(keys);
+ for (int i = 0; i < zSetList.size(); i++) {
+ for (String value : zSetList.get(i)) {
+ pollValueToNext(keys.get(i), value, output);
+ }
+ }
+ }
+
+ @Override
+ public void pollSetToNext(List<String> keys, Collector<SeaTunnelRow>
output)
+ throws IOException {
+ List<Set<String>> setList = redisClient.batchGetSet(keys);
+ for (int i = 0; i < setList.size(); i++) {
+ for (String value : setList.get(i)) {
+ pollValueToNext(keys.get(i), value, output);
+ }
+ }
+ }
+
+ @Override
+ public void pollListToNext(List<String> keys, Collector<SeaTunnelRow>
output)
+ throws IOException {
+ List<List<String>> valueList = redisClient.batchGetList(keys);
+ for (int i = 0; i < valueList.size(); i++) {
+ for (String value : valueList.get(i)) {
+ pollValueToNext(keys.get(i), value, output);
+ }
+ }
+ }
+
+ @Override
+ public void pollStringToNext(List<String> keys, Collector<SeaTunnelRow>
output)
+ throws IOException {
+ List<String> values = redisClient.batchGetString(keys);
+ for (int i = 0; i < values.size(); i++) {
+ pollValueToNext(keys.get(i), values.get(i), output);
+ }
+ }
+
+ private void pollValueToNext(String key, String value,
Collector<SeaTunnelRow> output)
+ throws IOException {
+ JsonNode node = JsonUtils.toJsonNode(value);
+ if (node.isTextual()) {
+ try {
+ node = JsonUtils.parseObject(node.textValue());
+ } catch (Exception e) {
+ // do nothing
Review Comment:
The catch block with '// do nothing' comment silently ignores parsing
errors. Consider logging the exception at debug level to aid troubleshooting
while maintaining the fallback behavior.
```suggestion
log.debug("Failed to parse JSON object from text value: {}",
node.textValue(), e);
```
--
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: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]