gortiz commented on code in PR #12475:
URL: https://github.com/apache/pinot/pull/12475#discussion_r1507187948


##########
pinot-query-planner/src/main/java/org/apache/pinot/query/validate/BytesCastVisitor.java:
##########
@@ -0,0 +1,73 @@
+/**
+ * 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.pinot.query.validate;
+
+import com.google.common.base.Preconditions;
+import java.util.List;
+import org.apache.calcite.rel.type.RelDataType;
+import org.apache.calcite.sql.SqlCall;
+import org.apache.calcite.sql.SqlCharStringLiteral;
+import org.apache.calcite.sql.SqlDataTypeSpec;
+import org.apache.calcite.sql.SqlNode;
+import org.apache.calcite.sql.fun.SqlCastFunction;
+import org.apache.calcite.sql.parser.SqlParserPos;
+import org.apache.calcite.sql.type.SqlTypeUtil;
+import org.apache.calcite.sql.util.SqlBasicVisitor;
+import org.apache.calcite.sql.validate.SqlValidator;
+import org.apache.calcite.util.Static;
+
+
+public class BytesCastVisitor extends SqlBasicVisitor<Void> {
+
+  private final SqlValidator _originalValidator;
+
+  public BytesCastVisitor(SqlValidator originalValidator) {
+    _originalValidator = originalValidator;
+  }
+
+  @SuppressWarnings("checkstyle:WhitespaceAround")
+  @Override
+  public Void visit(SqlCall call) {
+    if (call.getOperator() instanceof SqlCastFunction) {
+      List<SqlNode> operands = call.getOperandList();
+      SqlNode sqlNode = operands.get(1);
+      Preconditions.checkState(sqlNode instanceof SqlDataTypeSpec);
+      RelDataType toType = ((SqlDataTypeSpec) 
sqlNode).deriveType(_originalValidator);
+      if (!SqlTypeUtil.isBinary(toType)) {
+        return super.visit(call);

Review Comment:
   It is not the same, right?
   
   `return null` just aborts the execution here while `return 
super.visit(call)` does in fact return the same value, but has the desired side 
effect of visiting the operators.
   
   For example, an expression like: `CAST (someOperation(CAST ('someliteral' as 
BINARY)) as STRING)` will be converted into:
   1. CAST
      1. someOperation
          1.  CAST
              1. 'someliteral'
              2. BINARY
      2. STRING
   
   In case we changed this line to `return null` we won't be able to detect the 
inner cast to BINARY because we would just abort the visitor once the first 
CAST to STRING was detected.



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

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


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

Reply via email to