dybyte commented on code in PR #9574:
URL: https://github.com/apache/seatunnel/pull/9574#discussion_r2216318521
##########
seatunnel-connectors-v2/connector-redis/src/main/java/org/apache/seatunnel/connectors/seatunnel/redis/source/RedisSourceFactory.java:
##########
@@ -54,7 +54,9 @@ public OptionRule optionRule() {
RedisSourceOptions.HASH_KEY_PARSE_MODE,
RedisBaseOptions.AUTH,
RedisBaseOptions.USER,
- RedisBaseOptions.KEY)
+ RedisBaseOptions.KEY,
+ RedisSourceOptions.READ_KEY_ENABLED,
+ RedisSourceOptions.SINGLE_FIELD_NAME)
Review Comment:
Done. That said, I had a quick question:
I was looking at the code and noticed that the behavior of the KEY and
STRING types seems completely identical.
Is there a specific reason why the KEY type is separated out?
Was KEY perhaps introduced to semantically distinguish it from other types
that can hold multiple values?
##########
seatunnel-connectors-v2/connector-redis/src/main/java/org/apache/seatunnel/connectors/seatunnel/redis/source/KeyedRecordReader.java:
##########
@@ -0,0 +1,139 @@
+/*
+ * 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()) {
+ String text = node.textValue();
+ if (looksLikeJson(text)) {
+ try {
+ node = JsonUtils.parseObject(text);
+ } catch (Exception e) {
+ // do nothing
+ }
+ }
+ }
+
+ ObjectNode objectNode;
+ if (node instanceof ObjectNode) {
+ objectNode = (ObjectNode) node;
+ } else {
+ objectNode = JsonUtils.createObjectNode();
+ setValueInNode(objectNode, node);
+ }
+ objectNode.put("key", key);
Review Comment:
Done
--
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]