hsyuan commented on a change in pull request #706: [CALCITE-2302] Implicit type 
cast support
URL: https://github.com/apache/calcite/pull/706#discussion_r309923231
 
 

 ##########
 File path: 
core/src/main/java/org/apache/calcite/sql/validate/implicit/AbstractTypeCoercion.java
 ##########
 @@ -0,0 +1,647 @@
+/*
+ * 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.calcite.sql.validate.implicit;
+
+import org.apache.calcite.rel.type.DynamicRecordType;
+import org.apache.calcite.rel.type.RelDataType;
+import org.apache.calcite.rel.type.RelDataTypeFactory;
+import org.apache.calcite.rel.type.RelDataTypeField;
+import org.apache.calcite.sql.SqlCall;
+import org.apache.calcite.sql.SqlCollation;
+import org.apache.calcite.sql.SqlIdentifier;
+import org.apache.calcite.sql.SqlKind;
+import org.apache.calcite.sql.SqlNode;
+import org.apache.calcite.sql.SqlNodeList;
+import org.apache.calcite.sql.fun.SqlStdOperatorTable;
+import org.apache.calcite.sql.parser.SqlParserPos;
+import org.apache.calcite.sql.type.SqlTypeAssignmentRules;
+import org.apache.calcite.sql.type.SqlTypeFamily;
+import org.apache.calcite.sql.type.SqlTypeName;
+import org.apache.calcite.sql.type.SqlTypeUtil;
+import org.apache.calcite.sql.validate.SqlValidator;
+import org.apache.calcite.sql.validate.SqlValidatorNamespace;
+import org.apache.calcite.sql.validate.SqlValidatorScope;
+import org.apache.calcite.util.Pair;
+import org.apache.calcite.util.Util;
+
+import com.google.common.collect.ImmutableList;
+
+import java.nio.charset.Charset;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Map;
+import java.util.Objects;
+
+/**
+ * Base class for all the type coercion rules. If you want to have a custom 
type coercion rules,
+ * inheriting this class is not necessary, but would have some convenient tool 
methods.
+ *
+ * <p>We make tool methods: {@link #coerceIthOperandTo}, {@link 
#coerceIthColumnTo},
+ * {@link #needToCast}, {@link #updateInferredRowType},
+ * {@link #updateInferredTypeFor}, {@link #updateInferredRowType}
+ * all overridable by derived classes, you can define system specific type 
coercion logic.
+ *
+ * <p>Caution that these methods may modify the {@link SqlNode} tree, you 
should know what the
+ * effect is when using these methods to customize your type coercion 
rules.</p>
+ *
+ * <p>This class also defines the default implementation of the type widening 
strategies, see
+ * {@link TypeCoercion} doc and methods: {@link #getTightestCommonType}, 
{@link #getWiderTypeFor},
+ * {@link #getWiderTypeForTwo}, {@link #getWiderTypeForDecimal},
+ * {@link #commonTypeForBinaryComparison} for the detail strategies.</p>
+ */
+public abstract class AbstractTypeCoercion implements TypeCoercion {
+  protected SqlValidator validator;
+  protected RelDataTypeFactory factory;
+
+  //~ Constructors -----------------------------------------------------------
+
+  AbstractTypeCoercion(SqlValidator validator) {
+    Objects.requireNonNull(validator);
+    this.validator = validator;
+    this.factory = validator.getTypeFactory();
+  }
+
+  //~ Methods ----------------------------------------------------------------
+
+  public RelDataTypeFactory getFactory() {
+    return this.factory;
+  }
+
+  public SqlValidator getValidator() {
+    return this.validator;
+  }
+
+  /**
+   * Cast ith operand to target type, we do this base on the fact that
+   * validate happens before type coercion.
+   */
+  protected boolean coerceIthOperandTo(
 
 Review comment:
   I don't think `ith` is needed in the method name

----------------------------------------------------------------
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.
 
For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


With regards,
Apache Git Services

Reply via email to