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


##########
sql/src/main/java/org/apache/druid/sql/calcite/planner/DruidRelFieldTrimmer.java:
##########
@@ -0,0 +1,313 @@
+/*
+ * 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.planner;
+
+import com.google.common.collect.ImmutableList;
+import org.apache.calcite.plan.RelOptUtil;
+import org.apache.calcite.rel.RelHomogeneousShuttle;
+import org.apache.calcite.rel.RelNode;
+import org.apache.calcite.rel.core.CorrelationId;
+import org.apache.calcite.rel.core.TableScan;
+import org.apache.calcite.rel.logical.LogicalCorrelate;
+import org.apache.calcite.rel.type.RelDataType;
+import org.apache.calcite.rel.type.RelDataTypeField;
+import org.apache.calcite.rex.RexBuilder;
+import org.apache.calcite.rex.RexCorrelVariable;
+import org.apache.calcite.rex.RexFieldAccess;
+import org.apache.calcite.rex.RexNode;
+import org.apache.calcite.rex.RexPermuteInputsShuttle;
+import org.apache.calcite.rex.RexShuttle;
+import org.apache.calcite.rex.RexVisitor;
+import org.apache.calcite.sql.validate.SqlValidator;
+import org.apache.calcite.sql2rel.RelFieldTrimmer;
+import org.apache.calcite.tools.RelBuilder;
+import org.apache.calcite.util.ImmutableBitSet;
+import org.apache.calcite.util.mapping.IntPair;
+import org.apache.calcite.util.mapping.Mapping;
+import org.apache.calcite.util.mapping.MappingType;
+import org.apache.calcite.util.mapping.Mappings;
+import org.apache.druid.sql.calcite.rule.logical.LogicalUnnest;
+import org.checkerframework.checker.nullness.qual.Nullable;
+
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.List;
+import java.util.Set;
+
+public class DruidRelFieldTrimmer extends RelFieldTrimmer
+{
+  private final boolean trimTableScan;
+  private final RelBuilder relBuilder;
+
+  public DruidRelFieldTrimmer(@Nullable SqlValidator validator, RelBuilder 
relBuilder, boolean trimTableScan)
+  {
+    super(validator, relBuilder);
+    this.relBuilder = relBuilder;
+    this.trimTableScan = trimTableScan;
+  }
+
+  @Override
+  protected TrimResult dummyProject(int fieldCount, RelNode input)
+  {
+    return makeIdentityMapping(input);
+  }
+
+  protected TrimResult dummyProject(int fieldCount, RelNode input,

Review Comment:
   ## Missing Override annotation
   
   This method overrides [RelFieldTrimmer.dummyProject](1); it is advisable to 
add an Override annotation.
   
   [Show more 
details](https://github.com/apache/druid/security/code-scanning/4695)



##########
sql/src/main/java/org/apache/druid/sql/calcite/planner/DruidRelFieldTrimmer.java:
##########
@@ -0,0 +1,313 @@
+/*
+ * 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.planner;
+
+import com.google.common.collect.ImmutableList;
+import org.apache.calcite.plan.RelOptUtil;
+import org.apache.calcite.rel.RelHomogeneousShuttle;
+import org.apache.calcite.rel.RelNode;
+import org.apache.calcite.rel.core.CorrelationId;
+import org.apache.calcite.rel.core.TableScan;
+import org.apache.calcite.rel.logical.LogicalCorrelate;
+import org.apache.calcite.rel.type.RelDataType;
+import org.apache.calcite.rel.type.RelDataTypeField;
+import org.apache.calcite.rex.RexBuilder;
+import org.apache.calcite.rex.RexCorrelVariable;
+import org.apache.calcite.rex.RexFieldAccess;
+import org.apache.calcite.rex.RexNode;
+import org.apache.calcite.rex.RexPermuteInputsShuttle;
+import org.apache.calcite.rex.RexShuttle;
+import org.apache.calcite.rex.RexVisitor;
+import org.apache.calcite.sql.validate.SqlValidator;
+import org.apache.calcite.sql2rel.RelFieldTrimmer;
+import org.apache.calcite.tools.RelBuilder;
+import org.apache.calcite.util.ImmutableBitSet;
+import org.apache.calcite.util.mapping.IntPair;
+import org.apache.calcite.util.mapping.Mapping;
+import org.apache.calcite.util.mapping.MappingType;
+import org.apache.calcite.util.mapping.Mappings;
+import org.apache.druid.sql.calcite.rule.logical.LogicalUnnest;
+import org.checkerframework.checker.nullness.qual.Nullable;
+
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.List;
+import java.util.Set;
+
+public class DruidRelFieldTrimmer extends RelFieldTrimmer
+{
+  private final boolean trimTableScan;
+  private final RelBuilder relBuilder;
+
+  public DruidRelFieldTrimmer(@Nullable SqlValidator validator, RelBuilder 
relBuilder, boolean trimTableScan)
+  {
+    super(validator, relBuilder);
+    this.relBuilder = relBuilder;
+    this.trimTableScan = trimTableScan;
+  }
+
+  @Override
+  protected TrimResult dummyProject(int fieldCount, RelNode input)
+  {
+    return makeIdentityMapping(input);
+  }
+
+  protected TrimResult dummyProject(int fieldCount, RelNode input,
+      @Nullable RelNode originalRelNode)
+  {
+    if (fieldCount != 0 && trimTableScan) {
+      return super.dummyProject(fieldCount, input, originalRelNode);
+    }
+    // workaround to support fieldCount == 0 projections
+    final Mapping mapping = Mappings.create(MappingType.INVERSE_SURJECTION, 
fieldCount, 0);
+    if (input.getRowType().getFieldCount() == 0) {
+      // there is no need to do anything
+      return result(input, mapping);
+    }
+    relBuilder.push(input);
+    relBuilder.project(Collections.emptyList(), Collections.emptyList());
+    RelNode newProject = relBuilder.build();
+    if (originalRelNode != null) {
+      newProject = RelOptUtil.propagateRelHints(originalRelNode, newProject);
+    }
+    return result(newProject, mapping);
+  }
+
+  private TrimResult makeIdentityMapping(RelNode input)
+  {
+    Mapping mapping = 
Mappings.createIdentity(input.getRowType().getFieldCount());
+    return result(input, mapping);
+  }
+
+  public TrimResult trimFields(

Review Comment:
   ## Missing Override annotation
   
   This method overrides [RelFieldTrimmer.trimFields](1); it is advisable to 
add an Override annotation.
   
   [Show more 
details](https://github.com/apache/druid/security/code-scanning/4550)



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