github-advanced-security[bot] commented on code in PR #19462:
URL: https://github.com/apache/druid/pull/19462#discussion_r3237442588


##########
processing/src/main/java/org/apache/druid/timeline/ClusterGroupTuples.java:
##########
@@ -0,0 +1,224 @@
+/*
+ * 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.druid.timeline;
+
+import com.fasterxml.jackson.annotation.JsonCreator;
+import com.fasterxml.jackson.annotation.JsonInclude;
+import com.fasterxml.jackson.annotation.JsonProperty;
+import org.apache.druid.error.DruidException;
+import org.apache.druid.error.InvalidInput;
+import org.apache.druid.segment.VirtualColumns;
+import org.apache.druid.segment.column.ColumnType;
+import org.apache.druid.segment.column.RowSignature;
+
+import javax.annotation.Nullable;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.List;
+import java.util.Objects;
+
+/**
+ * Typed clustering tuples carried on {@link DataSegment#getClusterGroups()} 
for clustered base-table segments. Each
+ * entry in {@link #getTuples()} is one cluster group's clustering-column 
values, in the order declared by
+ * {@link #getClusteringColumns()}. Optionally carries the clustering {@link 
VirtualColumns} when the segment was
+ * clustered on a virtual-column expression, so that matching for things like 
partial load rules and query time
+ * segment pruning can make use of this information.
+ */
+public class ClusterGroupTuples
+{
+  private final RowSignature clusteringColumns;
+  private final List<List<Object>> tuples;
+  private final VirtualColumns virtualColumns;
+
+  @JsonCreator
+  public ClusterGroupTuples(
+      @JsonProperty("clusteringColumns") RowSignature clusteringColumns,
+      @JsonProperty("tuples") @Nullable List<List<Object>> tuples,
+      @JsonProperty("virtualColumns") @Nullable VirtualColumns virtualColumns
+  )
+  {
+    if (clusteringColumns == null || clusteringColumns.size() == 0) {
+      throw InvalidInput.exception("clusteringColumns must not be null or 
empty");
+    }
+    this.clusteringColumns = clusteringColumns;
+    this.virtualColumns = internVirtualColumns(virtualColumns);
+
+    final List<List<Object>> source = tuples == null ? Collections.emptyList() 
: tuples;
+    final int numCols = clusteringColumns.size();
+    final List<List<Object>> coerced = new ArrayList<>(source.size());
+    for (int t = 0; t < source.size(); t++) {
+      final List<Object> tuple = source.get(t);
+      if (tuple == null || tuple.size() != numCols) {
+        throw InvalidInput.exception(
+            "tuple[%s] has size [%s] but clusteringColumns size is [%s]",
+            t,
+            tuple == null ? "null" : tuple.size(),
+            numCols
+        );
+      }
+      final Object[] out = new Object[numCols];
+      for (int i = 0; i < numCols; i++) {
+        final String name = clusteringColumns.getColumnName(i);
+        final ColumnType type = clusteringColumns.getColumnType(i).orElseThrow(
+            () -> InvalidInput.exception("clusteringColumn[%s] has no declared 
type", name)
+        );
+        out[i] = coerceValue(name, type, tuple.get(i));
+      }
+      coerced.add(Collections.unmodifiableList(Arrays.asList(out)));
+    }
+    this.tuples = Collections.unmodifiableList(coerced);
+  }
+
+  /**
+   * Convenience constructor for callers that don't carry clustering virtual 
columns. Equivalent to passing
+   * {@code null} for the virtual columns argument.
+   */
+  public ClusterGroupTuples(RowSignature clusteringColumns, @Nullable 
List<List<Object>> tuples)
+  {
+    this(clusteringColumns, tuples, null);
+  }
+
+  @JsonProperty
+  public RowSignature getClusteringColumns()
+  {
+    return clusteringColumns;
+  }
+
+  @JsonProperty
+  public List<List<Object>> getTuples()

Review Comment:
   ## CodeQL / Exposing internal representation
   
   getTuples exposes the internal representation stored in field tuples. The 
value may be modified [after this call to getTuples](1).
   
   [Show more 
details](https://github.com/apache/druid/security/code-scanning/11221)



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


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to