Copilot commented on code in PR #18087:
URL: https://github.com/apache/druid/pull/18087#discussion_r2203060053


##########
processing/src/main/java/org/apache/druid/query/QueryContexts.java:
##########
@@ -120,14 +193,25 @@ public class QueryContexts
 
   // Unique identifier for the query, that is used to map the global shared 
resources (specifically merge buffers) to the
   // query's runtime
-  public static final String QUERY_RESOURCE_ID = "queryResourceId";
+  public static final SettingEntry<String> QUERY_RESOURCE_ID = 
SettingEntry.newStringEntry()
+                                                                           
.name("queryResourceId")
+                                                                           
.defaultValue(null)
+                                                                           
.description(
+                                                                               
"Unique identifier for the query, that is used to map the global shared 
resources (specifically merge buffers) to the query's runtime")
+                                                                           
.register(QueryContextParameterRegistry.getInstance());
 
   // SQL query context keys
-  public static final String CTX_SQL_QUERY_ID = BaseQuery.SQL_QUERY_ID;
+  public static final String CTX_SQL_QUERY_ID = SQL_QUERY_ID.name;

Review Comment:
   [nitpick] The `CTX_SQL_QUERY_ID` constant duplicates the value of 
`SQL_QUERY_ID.name`. Consider removing this redundant constant and using 
`SQL_QUERY_ID.name` directly to reduce duplication.
   ```suggestion
   
   ```



##########
sql/src/main/java/org/apache/druid/sql/calcite/schema/QueryContextParameterTable.java:
##########
@@ -0,0 +1,123 @@
+/*
+ * 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.sql.calcite.schema;
+
+
+import org.apache.calcite.DataContext;
+import org.apache.calcite.linq4j.DefaultEnumerable;
+import org.apache.calcite.linq4j.Enumerable;
+import org.apache.calcite.linq4j.Enumerator;
+import org.apache.calcite.rel.type.RelDataType;
+import org.apache.calcite.rel.type.RelDataTypeFactory;
+import org.apache.calcite.schema.ScannableTable;
+import org.apache.calcite.schema.impl.AbstractTable;
+import org.apache.druid.query.QueryContextParameterRegistry;
+import org.apache.druid.segment.column.ColumnType;
+import org.apache.druid.segment.column.RowSignature;
+import org.apache.druid.setting.SettingEntry;
+import org.apache.druid.sql.calcite.table.RowSignatures;
+
+import java.util.Iterator;
+
+public class QueryContextParameterTable extends AbstractTable implements 
ScannableTable
+{
+  static final String TABLE_NAME = "query_context_parameters";
+
+  static final RowSignature ROW_SIGNATURE = RowSignature
+      .builder()
+      .add("name", ColumnType.STRING)
+      .add("type", ColumnType.STRING)
+      .add("min", ColumnType.STRING)
+      .add("max", ColumnType.STRING)
+      .add("default_value", ColumnType.STRING)
+      .add("scope", ColumnType.STRING)
+      .add("deprecated", ColumnType.LONG)
+      .add("description", ColumnType.STRING)
+      .build();
+
+  @Override
+  public RelDataType getRowType(RelDataTypeFactory typeFactory)
+  {
+    return RowSignatures.toRelDataType(ROW_SIGNATURE, typeFactory);
+  }
+
+  @Override
+  public Enumerable<Object[]> scan(DataContext root)
+  {
+    return new DataEnumerable(QueryContextParameterRegistry.getInstance()
+                                                           .getParameters()
+                                                           .iterator());
+  }
+
+  static class DataEnumerable extends DefaultEnumerable<Object[]>
+  {
+    private final Iterator<SettingEntry<?>> it;
+
+    DataEnumerable(Iterator<SettingEntry<?>> settingIterator)
+    {
+      this.it = settingIterator;
+    }
+
+    @Override
+    public Iterator<Object[]> iterator()
+    {
+      throw new UnsupportedOperationException("Do not use iterator(), it 
cannot be closed.");
+    }
+
+    @Override
+    public Enumerator<Object[]> enumerator()
+    {
+      return new Enumerator<>()
+      {
+        @Override
+        public Object[] current()
+        {
+          final SettingEntry<?> entry = it.next();
+          return new Object[]{
+              entry.name,
+              entry.type.getSimpleName(),
+              entry.min == null ? null : entry.min.toString(),
+              entry.max == null ? null : entry.max.toString(),
+              entry.defaultValue == null ? null : 
entry.defaultValue.toString(),
+              entry.scope,
+              entry.deprecated ? 1L : 0L,
+              entry.description
+          };
+        }
+
+        @Override
+        public boolean moveNext()
+        {
+          return it.hasNext();

Review Comment:
   [nitpick] The Enumerator advances the iterator in `current()` instead of 
`moveNext()`, which violates the usual enumerator contract and can lead to 
unexpected behavior. Consider moving the `it.next()` call into `moveNext()` and 
storing the current entry for `current()` to return.
   ```suggestion
           private SettingEntry<?> currentEntry;
   
           @Override
           public Object[] current()
           {
             return new Object[]{
                 currentEntry.name,
                 currentEntry.type.getSimpleName(),
                 currentEntry.min == null ? null : currentEntry.min.toString(),
                 currentEntry.max == null ? null : currentEntry.max.toString(),
                 currentEntry.defaultValue == null ? null : 
currentEntry.defaultValue.toString(),
                 currentEntry.scope,
                 currentEntry.deprecated ? 1L : 0L,
                 currentEntry.description
             };
           }
   
           @Override
           public boolean moveNext()
           {
             if (it.hasNext()) {
               currentEntry = it.next();
               return true;
             }
             return false;
   ```



-- 
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-unsubscr...@druid.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscr...@druid.apache.org
For additional commands, e-mail: commits-h...@druid.apache.org

Reply via email to