Copilot commented on code in PR #16435:
URL: https://github.com/apache/iotdb/pull/16435#discussion_r2357764594


##########
iotdb-core/datanode/src/main/java/org/apache/iotdb/db/pipe/source/dataregion/realtime/matcher/DataRegionSourceWithPattern.java:
##########
@@ -0,0 +1,59 @@
+/*
+ * 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.iotdb.db.pipe.source.dataregion.realtime.matcher;
+
+import org.apache.iotdb.commons.pipe.datastructure.pattern.TablePattern;
+import org.apache.iotdb.commons.pipe.datastructure.pattern.TreePattern;
+import 
org.apache.iotdb.db.pipe.source.dataregion.realtime.PipeRealtimeDataRegionSource;
+
+public class DataRegionSourceWithPattern {
+
+  private final PipeRealtimeDataRegionSource source;
+  private final TreePattern treePattern;
+  private final TablePattern tablePattern;
+
+  public DataRegionSourceWithPattern(final PipeRealtimeDataRegionSource 
source) {
+    this.source = source;
+    // TODO: handle multiple patterns
+    this.treePattern = source.getTreePatterns().get(0);

Review Comment:
   Potential IndexOutOfBoundsException if source.getTreePatterns() returns an 
empty list. Add bounds checking before accessing index 0.
   ```suggestion
       if (source.getTreePatterns() != null && 
!source.getTreePatterns().isEmpty()) {
         this.treePattern = source.getTreePatterns().get(0);
       } else {
         this.treePattern = null;
       }
   ```



##########
iotdb-core/node-commons/src/main/java/org/apache/iotdb/commons/pipe/datastructure/pattern/TreePattern.java:
##########
@@ -68,17 +70,24 @@ public boolean isRoot() {
    *
    * @return The interpreted {@link TreePattern} which is not {@code null}.
    */
-  public static TreePattern parsePipePatternFromSourceParameters(
+  public static List<TreePattern> parsePipePatternFromSourceParameters(
       final PipeParameters sourceParameters) {
     final boolean isTreeModelDataAllowedToBeCaptured =
         isTreeModelDataAllowToBeCaptured(sourceParameters);
 
+    final List<TreePattern> patterns = new ArrayList<>();
     final String path = sourceParameters.getStringByKeys(EXTRACTOR_PATH_KEY, 
SOURCE_PATH_KEY);
 
     // 1. If "source.path" is specified, it will be interpreted as an 
IoTDB-style path,
     // ignoring the other 2 parameters.
     if (path != null) {
-      return new IoTDBTreePattern(isTreeModelDataAllowedToBeCaptured, path);
+      // Support comma-separated multiple paths
+      for (final String singlePath : path.split(",")) {
+        if (!singlePath.trim().isEmpty()) {
+          patterns.add(new 
IoTDBTreePattern(isTreeModelDataAllowedToBeCaptured, singlePath.trim()));
+        }
+      }

Review Comment:
   The splitting logic on comma assumes no escaping mechanism for commas within 
paths. Consider using a more robust parsing approach or documenting that commas 
cannot be part of path names.



##########
iotdb-core/datanode/src/main/java/org/apache/iotdb/db/pipe/source/dataregion/realtime/matcher/CachedSchemaPatternMatcher.java:
##########
@@ -185,12 +189,16 @@ public Pair<Set<PipeRealtimeDataRegionSource>, 
Set<PipeRealtimeDataRegionSource>
     }
   }
 
-  private Set<PipeRealtimeDataRegionSource> findUnmatchedSources(
-      final Set<PipeRealtimeDataRegionSource> matchedSources) {
-    final Set<PipeRealtimeDataRegionSource> unmatchedSources = new HashSet<>();
+  private Set<DataRegionSourceWithPattern> findUnmatchedSources(
+      final Set<DataRegionSourceWithPattern> matchedSources) {
+    final Set<DataRegionSourceWithPattern> unmatchedSources = new HashSet<>();
     for (final PipeRealtimeDataRegionSource source : sources) {
-      if (!matchedSources.contains(source)) {
-        unmatchedSources.add(source);
+      // TODO: improve performance
+      if (!matchedSources.stream()
+          .map(DataRegionSourceWithPattern::getSource)
+          .collect(Collectors.toSet())
+          .contains(source)) {

Review Comment:
   Converting stream to Set for contains check is inefficient. Consider using 
anyMatch() or maintaining a Set<PipeRealtimeDataRegionSource> for faster 
lookups.



##########
iotdb-core/datanode/src/main/java/org/apache/iotdb/db/pipe/source/dataregion/historical/PipeHistoricalDataRegionTsFileAndDeletionSource.java:
##########
@@ -906,7 +913,7 @@ private Event supplyDeletionEvent(final DeletionResource 
deletionResource) {
             pipeName,
             creationTime,
             pipeTaskMeta,
-            treePattern,
+            treePatterns.get(0), // TODO

Review Comment:
   Potential IndexOutOfBoundsException if treePatterns is empty. Add bounds 
checking before accessing index 0.



##########
iotdb-core/datanode/src/main/java/org/apache/iotdb/db/pipe/source/dataregion/historical/PipeHistoricalDataRegionTsFileAndDeletionSource.java:
##########
@@ -849,7 +856,7 @@ private Event supplyTsFileEvent(final TsFileResource 
resource) {
             pipeName,
             creationTime,
             pipeTaskMeta,
-            treePattern,
+            treePatterns.get(0), // TODO

Review Comment:
   Potential IndexOutOfBoundsException if treePatterns is empty. Add bounds 
checking before accessing index 0.
   ```suggestion
               treePatterns.isEmpty() ? null : treePatterns.get(0), // Safe: 
pass null if empty
   ```



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

Reply via email to