blob: 75a4437a1d577f367e566b9d9fdc9d680ac6bcb4 [file] [log] [blame]
<!DOCTYPE HTML>
<html lang="en">
<head>
<!-- Generated by javadoc (17) -->
<title>TypeCoercionImpl (Apache Calcite API)</title>
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<meta name="description" content="declaration: package: org.apache.calcite.sql.validate.implicit, class: TypeCoercionImpl">
<meta name="generator" content="javadoc/ClassWriterImpl">
<link rel="stylesheet" type="text/css" href="../../../../../../stylesheet.css" title="Style">
<link rel="stylesheet" type="text/css" href="../../../../../../script-dir/jquery-ui.min.css" title="Style">
<link rel="stylesheet" type="text/css" href="../../../../../../jquery-ui.overrides.css" title="Style">
<script type="text/javascript" src="../../../../../../script.js"></script>
<script type="text/javascript" src="../../../../../../script-dir/jquery-3.5.1.min.js"></script>
<script type="text/javascript" src="../../../../../../script-dir/jquery-ui.min.js"></script>
</head>
<body class="class-declaration-page">
<script type="text/javascript">var evenRowColor = "even-row-color";
var oddRowColor = "odd-row-color";
var tableTab = "table-tab";
var activeTableTab = "active-table-tab";
var pathtoroot = "../../../../../../";
loadScripts(document, 'script');</script>
<noscript>
<div>JavaScript is disabled on your browser.</div>
</noscript>
<div class="flex-box">
<header role="banner" class="flex-header">
<nav role="navigation">
<!-- ========= START OF TOP NAVBAR ======= -->
<div class="top-nav" id="navbar-top">
<div class="skip-nav"><a href="#skip-navbar-top" title="Skip navigation links">Skip navigation links</a></div>
<div class="about-language"><b>Apache Calcite</b></div>
<ul id="navbar-top-firstrow" class="nav-list" title="Navigation">
<li><a href="../../../../../../index.html">Overview</a></li>
<li><a href="package-summary.html">Package</a></li>
<li class="nav-bar-cell1-rev">Class</li>
<li><a href="package-tree.html">Tree</a></li>
<li><a href="../../../../../../deprecated-list.html">Deprecated</a></li>
<li><a href="../../../../../../index-all.html">Index</a></li>
<li><a href="../../../../../../help-doc.html#class">Help</a></li>
</ul>
</div>
<div class="sub-nav">
<div>
<ul class="sub-nav-list">
<li>Summary:&nbsp;</li>
<li>Nested&nbsp;|&nbsp;</li>
<li><a href="#field-summary">Field</a>&nbsp;|&nbsp;</li>
<li><a href="#constructor-summary">Constr</a>&nbsp;|&nbsp;</li>
<li><a href="#method-summary">Method</a></li>
</ul>
<ul class="sub-nav-list">
<li>Detail:&nbsp;</li>
<li>Field&nbsp;|&nbsp;</li>
<li><a href="#constructor-detail">Constr</a>&nbsp;|&nbsp;</li>
<li><a href="#method-detail">Method</a></li>
</ul>
</div>
<div class="nav-list-search"><label for="search-input">SEARCH:</label>
<input type="text" id="search-input" value="search" disabled="disabled">
<input type="reset" id="reset-button" value="reset" disabled="disabled">
</div>
</div>
<!-- ========= END OF TOP NAVBAR ========= -->
<span class="skip-nav" id="skip-navbar-top"></span></nav>
</header>
<div class="flex-content">
<main role="main">
<!-- ======== START OF CLASS DATA ======== -->
<div class="header">
<div class="sub-title"><span class="package-label-in-type">Package</span>&nbsp;<a href="package-summary.html">org.apache.calcite.sql.validate.implicit</a></div>
<h1 title="Class TypeCoercionImpl" class="title">Class TypeCoercionImpl</h1>
</div>
<div class="inheritance" title="Inheritance Tree"><a href="https://docs.oracle.com/en/java/javase/17/docs/api/java.base/java/lang/Object.html" title="class or interface in java.lang" class="external-link">java.lang.Object</a>
<div class="inheritance"><a href="AbstractTypeCoercion.html" title="class in org.apache.calcite.sql.validate.implicit">org.apache.calcite.sql.validate.implicit.AbstractTypeCoercion</a>
<div class="inheritance">org.apache.calcite.sql.validate.implicit.TypeCoercionImpl</div>
</div>
</div>
<section class="class-description" id="class-description">
<dl class="notes">
<dt>All Implemented Interfaces:</dt>
<dd><code><a href="TypeCoercion.html" title="interface in org.apache.calcite.sql.validate.implicit">TypeCoercion</a></code></dd>
</dl>
<hr>
<div class="type-signature"><span class="modifiers">public class </span><span class="element-name type-name-label">TypeCoercionImpl</span>
<span class="extends-implements">extends <a href="AbstractTypeCoercion.html" title="class in org.apache.calcite.sql.validate.implicit">AbstractTypeCoercion</a></span></div>
<div class="block">Default implementation of Calcite implicit type cast.</div>
</section>
<section class="summary">
<ul class="summary-list">
<!-- =========== FIELD SUMMARY =========== -->
<li>
<section class="field-summary" id="field-summary">
<h2>Field Summary</h2>
<div class="inherited-list">
<h3 id="fields-inherited-from-class-org.apache.calcite.sql.validate.implicit.AbstractTypeCoercion">Fields inherited from class&nbsp;org.apache.calcite.sql.validate.implicit.<a href="AbstractTypeCoercion.html" title="class in org.apache.calcite.sql.validate.implicit">AbstractTypeCoercion</a></h3>
<code><a href="AbstractTypeCoercion.html#factory">factory</a>, <a href="AbstractTypeCoercion.html#validator">validator</a></code></div>
</section>
</li>
<!-- ======== CONSTRUCTOR SUMMARY ======== -->
<li>
<section class="constructor-summary" id="constructor-summary">
<h2>Constructor Summary</h2>
<div class="caption"><span>Constructors</span></div>
<div class="summary-table two-column-summary">
<div class="table-header col-first">Constructor</div>
<div class="table-header col-last">Description</div>
<div class="col-constructor-name even-row-color"><code><a href="#%3Cinit%3E(org.apache.calcite.rel.type.RelDataTypeFactory,org.apache.calcite.sql.validate.SqlValidator)" class="member-name-link">TypeCoercionImpl</a><wbr>(<a href="../../../rel/type/RelDataTypeFactory.html" title="interface in org.apache.calcite.rel.type">RelDataTypeFactory</a>&nbsp;typeFactory,
<a href="../SqlValidator.html" title="interface in org.apache.calcite.sql.validate">SqlValidator</a>&nbsp;validator)</code></div>
<div class="col-last even-row-color">&nbsp;</div>
</div>
</section>
</li>
<!-- ========== METHOD SUMMARY =========== -->
<li>
<section class="method-summary" id="method-summary">
<h2>Method Summary</h2>
<div id="method-summary-table">
<div class="table-tabs" role="tablist" aria-orientation="horizontal"><button id="method-summary-table-tab0" role="tab" aria-selected="true" aria-controls="method-summary-table.tabpanel" tabindex="0" onkeydown="switchTab(event)" onclick="show('method-summary-table', 'method-summary-table', 3)" class="active-table-tab">All Methods</button><button id="method-summary-table-tab2" role="tab" aria-selected="false" aria-controls="method-summary-table.tabpanel" tabindex="-1" onkeydown="switchTab(event)" onclick="show('method-summary-table', 'method-summary-table-tab2', 3)" class="table-tab">Instance Methods</button><button id="method-summary-table-tab4" role="tab" aria-selected="false" aria-controls="method-summary-table.tabpanel" tabindex="-1" onkeydown="switchTab(event)" onclick="show('method-summary-table', 'method-summary-table-tab4', 3)" class="table-tab">Concrete Methods</button></div>
<div id="method-summary-table.tabpanel" role="tabpanel">
<div class="summary-table three-column-summary" aria-labelledby="method-summary-table-tab0">
<div class="table-header col-first">Modifier and Type</div>
<div class="table-header col-second">Method</div>
<div class="table-header col-last">Description</div>
<div class="col-first even-row-color method-summary-table method-summary-table-tab2 method-summary-table-tab4"><code>boolean</code></div>
<div class="col-second even-row-color method-summary-table method-summary-table-tab2 method-summary-table-tab4"><code><a href="#binaryArithmeticCoercion(org.apache.calcite.sql.SqlCallBinding)" class="member-name-link">binaryArithmeticCoercion</a><wbr>(<a href="../../SqlCallBinding.html" title="class in org.apache.calcite.sql">SqlCallBinding</a>&nbsp;binding)</code></div>
<div class="col-last even-row-color method-summary-table method-summary-table-tab2 method-summary-table-tab4">
<div class="block">Coerces operands in binary arithmetic expressions to NUMERIC types.</div>
</div>
<div class="col-first odd-row-color method-summary-table method-summary-table-tab2 method-summary-table-tab4"><code>protected boolean</code></div>
<div class="col-second odd-row-color method-summary-table method-summary-table-tab2 method-summary-table-tab4"><code><a href="#binaryArithmeticWithStrings(org.apache.calcite.sql.SqlCallBinding,org.apache.calcite.rel.type.RelDataType,org.apache.calcite.rel.type.RelDataType)" class="member-name-link">binaryArithmeticWithStrings</a><wbr>(<a href="../../SqlCallBinding.html" title="class in org.apache.calcite.sql">SqlCallBinding</a>&nbsp;binding,
<a href="../../../rel/type/RelDataType.html" title="interface in org.apache.calcite.rel.type">RelDataType</a>&nbsp;left,
<a href="../../../rel/type/RelDataType.html" title="interface in org.apache.calcite.rel.type">RelDataType</a>&nbsp;right)</code></div>
<div class="col-last odd-row-color method-summary-table method-summary-table-tab2 method-summary-table-tab4">
<div class="block">For NUMERIC and STRING operands, cast STRING to data type of the other operand.</div>
</div>
<div class="col-first even-row-color method-summary-table method-summary-table-tab2 method-summary-table-tab4"><code>boolean</code></div>
<div class="col-second even-row-color method-summary-table method-summary-table-tab2 method-summary-table-tab4"><code><a href="#binaryComparisonCoercion(org.apache.calcite.sql.SqlCallBinding)" class="member-name-link">binaryComparisonCoercion</a><wbr>(<a href="../../SqlCallBinding.html" title="class in org.apache.calcite.sql">SqlCallBinding</a>&nbsp;binding)</code></div>
<div class="col-last even-row-color method-summary-table method-summary-table-tab2 method-summary-table-tab4">
<div class="block">Coerces operands in binary comparison expressions.</div>
</div>
<div class="col-first odd-row-color method-summary-table method-summary-table-tab2 method-summary-table-tab4"><code>protected boolean</code></div>
<div class="col-second odd-row-color method-summary-table method-summary-table-tab2 method-summary-table-tab4"><code><a href="#booleanEquality(org.apache.calcite.sql.SqlCallBinding,org.apache.calcite.rel.type.RelDataType,org.apache.calcite.rel.type.RelDataType)" class="member-name-link">booleanEquality</a><wbr>(<a href="../../SqlCallBinding.html" title="class in org.apache.calcite.sql">SqlCallBinding</a>&nbsp;binding,
<a href="../../../rel/type/RelDataType.html" title="interface in org.apache.calcite.rel.type">RelDataType</a>&nbsp;left,
<a href="../../../rel/type/RelDataType.html" title="interface in org.apache.calcite.rel.type">RelDataType</a>&nbsp;right)</code></div>
<div class="col-last odd-row-color method-summary-table method-summary-table-tab2 method-summary-table-tab4">
<div class="block">Casts "BOOLEAN = NUMERIC" to "NUMERIC = NUMERIC".</div>
</div>
<div class="col-first even-row-color method-summary-table method-summary-table-tab2 method-summary-table-tab4"><code>boolean</code></div>
<div class="col-second even-row-color method-summary-table method-summary-table-tab2 method-summary-table-tab4"><code><a href="#builtinFunctionCoercion(org.apache.calcite.sql.SqlCallBinding,java.util.List,java.util.List)" class="member-name-link">builtinFunctionCoercion</a><wbr>(<a href="../../SqlCallBinding.html" title="class in org.apache.calcite.sql">SqlCallBinding</a>&nbsp;binding,
<a href="https://docs.oracle.com/en/java/javase/17/docs/api/java.base/java/util/List.html" title="class or interface in java.util" class="external-link">List</a>&lt;<a href="../../../rel/type/RelDataType.html" title="interface in org.apache.calcite.rel.type">RelDataType</a>&gt;&nbsp;operandTypes,
<a href="https://docs.oracle.com/en/java/javase/17/docs/api/java.base/java/util/List.html" title="class or interface in java.util" class="external-link">List</a>&lt;<a href="../../type/SqlTypeFamily.html" title="enum in org.apache.calcite.sql.type">SqlTypeFamily</a>&gt;&nbsp;expectedFamilies)</code></div>
<div class="col-last even-row-color method-summary-table method-summary-table-tab2 method-summary-table-tab4">
<div class="block">Type coercion with inferred type from passed in arguments and the
<a href="../../type/SqlTypeFamily.html" title="enum in org.apache.calcite.sql.type"><code>SqlTypeFamily</code></a> defined in the checkers, e.g.</div>
</div>
<div class="col-first odd-row-color method-summary-table method-summary-table-tab2 method-summary-table-tab4"><code>boolean</code></div>
<div class="col-second odd-row-color method-summary-table method-summary-table-tab2 method-summary-table-tab4"><code><a href="#caseWhenCoercion(org.apache.calcite.sql.SqlCallBinding)" class="member-name-link">caseWhenCoercion</a><wbr>(<a href="../../SqlCallBinding.html" title="class in org.apache.calcite.sql">SqlCallBinding</a>&nbsp;callBinding)</code></div>
<div class="col-last odd-row-color method-summary-table method-summary-table-tab2 method-summary-table-tab4">
<div class="block">CASE and COALESCE type coercion, collect all the branches types including then
operands and else operands to find a common type, then cast the operands to the common type
when needed.</div>
</div>
<div class="col-first even-row-color method-summary-table method-summary-table-tab2 method-summary-table-tab4"><code>protected @Nullable <a href="../../../rel/type/RelDataType.html" title="interface in org.apache.calcite.rel.type">RelDataType</a></code></div>
<div class="col-second even-row-color method-summary-table method-summary-table-tab2 method-summary-table-tab4"><code><a href="#commonTypeForComparison(java.util.List)" class="member-name-link">commonTypeForComparison</a><wbr>(<a href="https://docs.oracle.com/en/java/javase/17/docs/api/java.base/java/util/List.html" title="class or interface in java.util" class="external-link">List</a>&lt;<a href="../../../rel/type/RelDataType.html" title="interface in org.apache.calcite.rel.type">RelDataType</a>&gt;&nbsp;dataTypes)</code></div>
<div class="col-last even-row-color method-summary-table method-summary-table-tab2 method-summary-table-tab4">
<div class="block">Finds the common type for binary comparison
when the size of operands <code>dataTypes</code> is more than 2.</div>
</div>
<div class="col-first odd-row-color method-summary-table method-summary-table-tab2 method-summary-table-tab4"><code>protected boolean</code></div>
<div class="col-second odd-row-color method-summary-table method-summary-table-tab2 method-summary-table-tab4"><code><a href="#dateTimeStringEquality(org.apache.calcite.sql.SqlCallBinding,org.apache.calcite.rel.type.RelDataType,org.apache.calcite.rel.type.RelDataType)" class="member-name-link">dateTimeStringEquality</a><wbr>(<a href="../../SqlCallBinding.html" title="class in org.apache.calcite.sql">SqlCallBinding</a>&nbsp;binding,
<a href="../../../rel/type/RelDataType.html" title="interface in org.apache.calcite.rel.type">RelDataType</a>&nbsp;left,
<a href="../../../rel/type/RelDataType.html" title="interface in org.apache.calcite.rel.type">RelDataType</a>&nbsp;right)</code></div>
<div class="col-last odd-row-color method-summary-table method-summary-table-tab2 method-summary-table-tab4">
<div class="block">Datetime and STRING equality: cast STRING type to datetime type, SqlToRelConverter already
makes the conversion but we still keep this interface overridable
so user can have their custom implementation.</div>
</div>
<div class="col-first even-row-color method-summary-table method-summary-table-tab2 method-summary-table-tab4"><code>boolean</code></div>
<div class="col-second even-row-color method-summary-table method-summary-table-tab2 method-summary-table-tab4"><code><a href="#inOperationCoercion(org.apache.calcite.sql.SqlCallBinding)" class="member-name-link">inOperationCoercion</a><wbr>(<a href="../../SqlCallBinding.html" title="class in org.apache.calcite.sql">SqlCallBinding</a>&nbsp;binding)</code></div>
<div class="col-last even-row-color method-summary-table method-summary-table-tab2 method-summary-table-tab4">
<div class="block">Handles type coercion for IN operation with or without sub-query.</div>
</div>
<div class="col-first odd-row-color method-summary-table method-summary-table-tab2 method-summary-table-tab4"><code>boolean</code></div>
<div class="col-second odd-row-color method-summary-table method-summary-table-tab2 method-summary-table-tab4"><code><a href="#querySourceCoercion(org.apache.calcite.sql.validate.SqlValidatorScope,org.apache.calcite.rel.type.RelDataType,org.apache.calcite.rel.type.RelDataType,org.apache.calcite.sql.SqlNode)" class="member-name-link">querySourceCoercion</a><wbr>(@Nullable <a href="../SqlValidatorScope.html" title="interface in org.apache.calcite.sql.validate">SqlValidatorScope</a>&nbsp;scope,
<a href="../../../rel/type/RelDataType.html" title="interface in org.apache.calcite.rel.type">RelDataType</a>&nbsp;sourceRowType,
<a href="../../../rel/type/RelDataType.html" title="interface in org.apache.calcite.rel.type">RelDataType</a>&nbsp;targetRowType,
<a href="../../SqlNode.html" title="class in org.apache.calcite.sql">SqlNode</a>&nbsp;query)</code></div>
<div class="col-last odd-row-color method-summary-table method-summary-table-tab2 method-summary-table-tab4">
<div class="block">Coerces the source row expression to target type in an INSERT or UPDATE query.</div>
</div>
<div class="col-first even-row-color method-summary-table method-summary-table-tab2 method-summary-table-tab4"><code>boolean</code></div>
<div class="col-second even-row-color method-summary-table method-summary-table-tab2 method-summary-table-tab4"><code><a href="#rowTypeCoercion(org.apache.calcite.sql.validate.SqlValidatorScope,org.apache.calcite.sql.SqlNode,int,org.apache.calcite.rel.type.RelDataType)" class="member-name-link">rowTypeCoercion</a><wbr>(@Nullable <a href="../SqlValidatorScope.html" title="interface in org.apache.calcite.sql.validate">SqlValidatorScope</a>&nbsp;scope,
<a href="../../SqlNode.html" title="class in org.apache.calcite.sql">SqlNode</a>&nbsp;query,
int&nbsp;columnIndex,
<a href="../../../rel/type/RelDataType.html" title="interface in org.apache.calcite.rel.type">RelDataType</a>&nbsp;targetType)</code></div>
<div class="col-last even-row-color method-summary-table method-summary-table-tab2 method-summary-table-tab4">
<div class="block">Widen a SqlNode's field type to common type,
mainly used for set operations like UNION, INTERSECT and EXCEPT.</div>
</div>
<div class="col-first odd-row-color method-summary-table method-summary-table-tab2 method-summary-table-tab4"><code>boolean</code></div>
<div class="col-second odd-row-color method-summary-table method-summary-table-tab2 method-summary-table-tab4"><code><a href="#userDefinedFunctionCoercion(org.apache.calcite.sql.validate.SqlValidatorScope,org.apache.calcite.sql.SqlCall,org.apache.calcite.sql.SqlFunction)" class="member-name-link">userDefinedFunctionCoercion</a><wbr>(<a href="../SqlValidatorScope.html" title="interface in org.apache.calcite.sql.validate">SqlValidatorScope</a>&nbsp;scope,
<a href="../../SqlCall.html" title="class in org.apache.calcite.sql">SqlCall</a>&nbsp;call,
<a href="../../SqlFunction.html" title="class in org.apache.calcite.sql">SqlFunction</a>&nbsp;function)</code></div>
<div class="col-last odd-row-color method-summary-table method-summary-table-tab2 method-summary-table-tab4">
<div class="block">Type coercion for user-defined functions (UDFs).</div>
</div>
</div>
</div>
</div>
<div class="inherited-list">
<h3 id="methods-inherited-from-class-org.apache.calcite.sql.validate.implicit.AbstractTypeCoercion">Methods inherited from class&nbsp;org.apache.calcite.sql.validate.implicit.<a href="AbstractTypeCoercion.html" title="class in org.apache.calcite.sql.validate.implicit">AbstractTypeCoercion</a></h3>
<code><a href="AbstractTypeCoercion.html#coerceColumnType(org.apache.calcite.sql.validate.SqlValidatorScope,org.apache.calcite.sql.SqlNodeList,int,org.apache.calcite.rel.type.RelDataType)">coerceColumnType</a>, <a href="AbstractTypeCoercion.html#coerceOperandsType(org.apache.calcite.sql.validate.SqlValidatorScope,org.apache.calcite.sql.SqlCall,org.apache.calcite.rel.type.RelDataType)">coerceOperandsType</a>, <a href="AbstractTypeCoercion.html#coerceOperandType(org.apache.calcite.sql.validate.SqlValidatorScope,org.apache.calcite.sql.SqlCall,int,org.apache.calcite.rel.type.RelDataType)">coerceOperandType</a>, <a href="AbstractTypeCoercion.html#coerceStringToArray(org.apache.calcite.sql.SqlCall,org.apache.calcite.sql.SqlNode,int,org.apache.calcite.rel.type.RelDataType,org.apache.calcite.rel.type.RelDataType)">coerceStringToArray</a>, <a href="AbstractTypeCoercion.html#commonTypeForBinaryComparison(org.apache.calcite.rel.type.RelDataType,org.apache.calcite.rel.type.RelDataType)">commonTypeForBinaryComparison</a>, <a href="AbstractTypeCoercion.html#getTightestCommonType(org.apache.calcite.rel.type.RelDataType,org.apache.calcite.rel.type.RelDataType)">getTightestCommonType</a>, <a href="AbstractTypeCoercion.html#getWiderTypeFor(java.util.List,boolean)">getWiderTypeFor</a>, <a href="AbstractTypeCoercion.html#getWiderTypeForDecimal(org.apache.calcite.rel.type.RelDataType,org.apache.calcite.rel.type.RelDataType)">getWiderTypeForDecimal</a>, <a href="AbstractTypeCoercion.html#getWiderTypeForTwo(org.apache.calcite.rel.type.RelDataType,org.apache.calcite.rel.type.RelDataType,boolean)">getWiderTypeForTwo</a>, <a href="AbstractTypeCoercion.html#implicitCast(org.apache.calcite.rel.type.RelDataType,org.apache.calcite.sql.type.SqlTypeFamily)">implicitCast</a>, <a href="AbstractTypeCoercion.html#needToCast(org.apache.calcite.sql.validate.SqlValidatorScope,org.apache.calcite.sql.SqlNode,org.apache.calcite.rel.type.RelDataType)">needToCast</a>, <a href="AbstractTypeCoercion.html#updateInferredColumnType(org.apache.calcite.sql.validate.SqlValidatorScope,org.apache.calcite.sql.SqlNode,int,org.apache.calcite.rel.type.RelDataType)">updateInferredColumnType</a>, <a href="AbstractTypeCoercion.html#updateInferredType(org.apache.calcite.sql.SqlNode,org.apache.calcite.rel.type.RelDataType)">updateInferredType</a></code></div>
<div class="inherited-list">
<h3 id="methods-inherited-from-class-java.lang.Object">Methods inherited from class&nbsp;java.lang.<a href="https://docs.oracle.com/en/java/javase/17/docs/api/java.base/java/lang/Object.html" title="class or interface in java.lang" class="external-link">Object</a></h3>
<code><a href="https://docs.oracle.com/en/java/javase/17/docs/api/java.base/java/lang/Object.html#clone()" title="class or interface in java.lang" class="external-link">clone</a>, <a href="https://docs.oracle.com/en/java/javase/17/docs/api/java.base/java/lang/Object.html#equals(java.lang.Object)" title="class or interface in java.lang" class="external-link">equals</a>, <a href="https://docs.oracle.com/en/java/javase/17/docs/api/java.base/java/lang/Object.html#finalize()" title="class or interface in java.lang" class="external-link">finalize</a>, <a href="https://docs.oracle.com/en/java/javase/17/docs/api/java.base/java/lang/Object.html#getClass()" title="class or interface in java.lang" class="external-link">getClass</a>, <a href="https://docs.oracle.com/en/java/javase/17/docs/api/java.base/java/lang/Object.html#hashCode()" title="class or interface in java.lang" class="external-link">hashCode</a>, <a href="https://docs.oracle.com/en/java/javase/17/docs/api/java.base/java/lang/Object.html#notify()" title="class or interface in java.lang" class="external-link">notify</a>, <a href="https://docs.oracle.com/en/java/javase/17/docs/api/java.base/java/lang/Object.html#notifyAll()" title="class or interface in java.lang" class="external-link">notifyAll</a>, <a href="https://docs.oracle.com/en/java/javase/17/docs/api/java.base/java/lang/Object.html#toString()" title="class or interface in java.lang" class="external-link">toString</a>, <a href="https://docs.oracle.com/en/java/javase/17/docs/api/java.base/java/lang/Object.html#wait()" title="class or interface in java.lang" class="external-link">wait</a>, <a href="https://docs.oracle.com/en/java/javase/17/docs/api/java.base/java/lang/Object.html#wait(long)" title="class or interface in java.lang" class="external-link">wait</a>, <a href="https://docs.oracle.com/en/java/javase/17/docs/api/java.base/java/lang/Object.html#wait(long,int)" title="class or interface in java.lang" class="external-link">wait</a></code></div>
</section>
</li>
</ul>
</section>
<section class="details">
<ul class="details-list">
<!-- ========= CONSTRUCTOR DETAIL ======== -->
<li>
<section class="constructor-details" id="constructor-detail">
<h2>Constructor Details</h2>
<ul class="member-list">
<li>
<section class="detail" id="&lt;init&gt;(org.apache.calcite.rel.type.RelDataTypeFactory,org.apache.calcite.sql.validate.SqlValidator)">
<h3>TypeCoercionImpl</h3>
<div class="member-signature"><span class="modifiers">public</span>&nbsp;<span class="element-name">TypeCoercionImpl</span><wbr><span class="parameters">(<a href="../../../rel/type/RelDataTypeFactory.html" title="interface in org.apache.calcite.rel.type">RelDataTypeFactory</a>&nbsp;typeFactory,
<a href="../SqlValidator.html" title="interface in org.apache.calcite.sql.validate">SqlValidator</a>&nbsp;validator)</span></div>
</section>
</li>
</ul>
</section>
</li>
<!-- ============ METHOD DETAIL ========== -->
<li>
<section class="method-details" id="method-detail">
<h2>Method Details</h2>
<ul class="member-list">
<li>
<section class="detail" id="rowTypeCoercion(org.apache.calcite.sql.validate.SqlValidatorScope,org.apache.calcite.sql.SqlNode,int,org.apache.calcite.rel.type.RelDataType)">
<h3>rowTypeCoercion</h3>
<div class="member-signature"><span class="modifiers">public</span>&nbsp;<span class="return-type">boolean</span>&nbsp;<span class="element-name">rowTypeCoercion</span><wbr><span class="parameters">(@Nullable <a href="../SqlValidatorScope.html" title="interface in org.apache.calcite.sql.validate">SqlValidatorScope</a>&nbsp;scope,
<a href="../../SqlNode.html" title="class in org.apache.calcite.sql">SqlNode</a>&nbsp;query,
int&nbsp;columnIndex,
<a href="../../../rel/type/RelDataType.html" title="interface in org.apache.calcite.rel.type">RelDataType</a>&nbsp;targetType)</span></div>
<div class="block">Widen a SqlNode's field type to common type,
mainly used for set operations like UNION, INTERSECT and EXCEPT.
<p>Rules:
<pre>
type1, type2 type3 select a, b, c from t1
\ \ \
type4 type5 type6 UNION
/ / /
type7 type8 type9 select d, e, f from t2
</pre>
For struct type (type1, type2, type3) union type (type4, type5, type6),
infer the first result column type type7 as the wider type of type1 and type4,
the second column type as the wider type of type2 and type5 and so on.</div>
<dl class="notes">
<dt>Parameters:</dt>
<dd><code>scope</code> - Validator scope</dd>
<dd><code>query</code> - Query node to update the field type for</dd>
<dd><code>columnIndex</code> - Target column index</dd>
<dd><code>targetType</code> - Target type to cast to</dd>
</dl>
</section>
</li>
<li>
<section class="detail" id="binaryArithmeticCoercion(org.apache.calcite.sql.SqlCallBinding)">
<h3>binaryArithmeticCoercion</h3>
<div class="member-signature"><span class="modifiers">public</span>&nbsp;<span class="return-type">boolean</span>&nbsp;<span class="element-name">binaryArithmeticCoercion</span><wbr><span class="parameters">(<a href="../../SqlCallBinding.html" title="class in org.apache.calcite.sql">SqlCallBinding</a>&nbsp;binding)</span></div>
<div class="block">Coerces operands in binary arithmetic expressions to NUMERIC types.
<p>For binary arithmetic operators like [+, -, *, /, %]:
If the operand is VARCHAR,
coerce it to data type of the other operand if its data type is NUMERIC;
If the other operand is DECIMAL,
coerce the STRING operand to max precision/scale DECIMAL.</div>
</section>
</li>
<li>
<section class="detail" id="binaryArithmeticWithStrings(org.apache.calcite.sql.SqlCallBinding,org.apache.calcite.rel.type.RelDataType,org.apache.calcite.rel.type.RelDataType)">
<h3>binaryArithmeticWithStrings</h3>
<div class="member-signature"><span class="modifiers">protected</span>&nbsp;<span class="return-type">boolean</span>&nbsp;<span class="element-name">binaryArithmeticWithStrings</span><wbr><span class="parameters">(<a href="../../SqlCallBinding.html" title="class in org.apache.calcite.sql">SqlCallBinding</a>&nbsp;binding,
<a href="../../../rel/type/RelDataType.html" title="interface in org.apache.calcite.rel.type">RelDataType</a>&nbsp;left,
<a href="../../../rel/type/RelDataType.html" title="interface in org.apache.calcite.rel.type">RelDataType</a>&nbsp;right)</span></div>
<div class="block">For NUMERIC and STRING operands, cast STRING to data type of the other operand.</div>
</section>
</li>
<li>
<section class="detail" id="binaryComparisonCoercion(org.apache.calcite.sql.SqlCallBinding)">
<h3>binaryComparisonCoercion</h3>
<div class="member-signature"><span class="modifiers">public</span>&nbsp;<span class="return-type">boolean</span>&nbsp;<span class="element-name">binaryComparisonCoercion</span><wbr><span class="parameters">(<a href="../../SqlCallBinding.html" title="class in org.apache.calcite.sql">SqlCallBinding</a>&nbsp;binding)</span></div>
<div class="block">Coerces operands in binary comparison expressions.
<p>Rules:</p>
<ul>
<li>For EQUALS(=) operator: 1. If operands are BOOLEAN and NUMERIC, evaluate
`1=true` and `0=false` all to be true; 2. If operands are datetime and string,
do nothing because the SqlToRelConverter already makes the type coercion;</li>
<li>For binary comparison [=, &gt;, &gt;=, &lt;, &lt;=]: try to find the
common type, i.e. "1 &gt; '1'" will be converted to "1 &gt; 1";</li>
<li>For BETWEEN operator, find the common comparison data type of all the operands,
the common type is deduced from left to right, i.e. for expression "A between B and C",
finds common comparison type D between A and B
then common comparison type E between D and C as the final common type.</li>
</ul></div>
</section>
</li>
<li>
<section class="detail" id="commonTypeForComparison(java.util.List)">
<h3>commonTypeForComparison</h3>
<div class="member-signature"><span class="modifiers">protected</span>&nbsp;<span class="return-type">@Nullable <a href="../../../rel/type/RelDataType.html" title="interface in org.apache.calcite.rel.type">RelDataType</a></span>&nbsp;<span class="element-name">commonTypeForComparison</span><wbr><span class="parameters">(<a href="https://docs.oracle.com/en/java/javase/17/docs/api/java.base/java/util/List.html" title="class or interface in java.util" class="external-link">List</a>&lt;<a href="../../../rel/type/RelDataType.html" title="interface in org.apache.calcite.rel.type">RelDataType</a>&gt;&nbsp;dataTypes)</span></div>
<div class="block">Finds the common type for binary comparison
when the size of operands <code>dataTypes</code> is more than 2.
If there are N(more than 2) operands,
finds the common type between two operands from left to right:
<p>Rules:</p>
<pre>
type1 type2 type3
| | |
+- type4 -+ |
| |
+--- type5 ---+
</pre>
For operand data types (type1, type2, type3), deduce the common type type4
from type1 and type2, then common type type5 from type4 and type3.</div>
</section>
</li>
<li>
<section class="detail" id="dateTimeStringEquality(org.apache.calcite.sql.SqlCallBinding,org.apache.calcite.rel.type.RelDataType,org.apache.calcite.rel.type.RelDataType)">
<h3>dateTimeStringEquality</h3>
<div class="member-signature"><span class="modifiers">protected</span>&nbsp;<span class="return-type">boolean</span>&nbsp;<span class="element-name">dateTimeStringEquality</span><wbr><span class="parameters">(<a href="../../SqlCallBinding.html" title="class in org.apache.calcite.sql">SqlCallBinding</a>&nbsp;binding,
<a href="../../../rel/type/RelDataType.html" title="interface in org.apache.calcite.rel.type">RelDataType</a>&nbsp;left,
<a href="../../../rel/type/RelDataType.html" title="interface in org.apache.calcite.rel.type">RelDataType</a>&nbsp;right)</span></div>
<div class="block">Datetime and STRING equality: cast STRING type to datetime type, SqlToRelConverter already
makes the conversion but we still keep this interface overridable
so user can have their custom implementation.</div>
</section>
</li>
<li>
<section class="detail" id="booleanEquality(org.apache.calcite.sql.SqlCallBinding,org.apache.calcite.rel.type.RelDataType,org.apache.calcite.rel.type.RelDataType)">
<h3>booleanEquality</h3>
<div class="member-signature"><span class="modifiers">protected</span>&nbsp;<span class="return-type">boolean</span>&nbsp;<span class="element-name">booleanEquality</span><wbr><span class="parameters">(<a href="../../SqlCallBinding.html" title="class in org.apache.calcite.sql">SqlCallBinding</a>&nbsp;binding,
<a href="../../../rel/type/RelDataType.html" title="interface in org.apache.calcite.rel.type">RelDataType</a>&nbsp;left,
<a href="../../../rel/type/RelDataType.html" title="interface in org.apache.calcite.rel.type">RelDataType</a>&nbsp;right)</span></div>
<div class="block">Casts "BOOLEAN = NUMERIC" to "NUMERIC = NUMERIC". Expressions like 1=`expr` and
0=`expr` can be simplified to `expr` and `not expr`, but this better happens
in <a href="../../../rex/RexSimplify.html" title="class in org.apache.calcite.rex"><code>RexSimplify</code></a>.
<p>There are 2 cases that need type coercion here:
<ol>
<li>Case1: `boolean expr1` = 1 or `boolean expr1` = 0, replace the numeric literal with
`true` or `false` boolean literal.</li>
<li>Case2: `boolean expr1` = `numeric expr2`, replace expr1 to `1` or `0` numeric
literal.</li>
</ol>
For case2, wrap the operand in a cast operator, during sql-to-rel conversion
we would convert expression `cast(expr1 as right)` to `case when expr1 then 1 else 0.`</div>
</section>
</li>
<li>
<section class="detail" id="caseWhenCoercion(org.apache.calcite.sql.SqlCallBinding)">
<h3>caseWhenCoercion</h3>
<div class="member-signature"><span class="modifiers">public</span>&nbsp;<span class="return-type">boolean</span>&nbsp;<span class="element-name">caseWhenCoercion</span><wbr><span class="parameters">(<a href="../../SqlCallBinding.html" title="class in org.apache.calcite.sql">SqlCallBinding</a>&nbsp;callBinding)</span></div>
<div class="block">CASE and COALESCE type coercion, collect all the branches types including then
operands and else operands to find a common type, then cast the operands to the common type
when needed.</div>
</section>
</li>
<li>
<section class="detail" id="inOperationCoercion(org.apache.calcite.sql.SqlCallBinding)">
<h3>inOperationCoercion</h3>
<div class="member-signature"><span class="modifiers">public</span>&nbsp;<span class="return-type">boolean</span>&nbsp;<span class="element-name">inOperationCoercion</span><wbr><span class="parameters">(<a href="../../SqlCallBinding.html" title="class in org.apache.calcite.sql">SqlCallBinding</a>&nbsp;binding)</span></div>
<div class="block">Handles type coercion for IN operation with or without sub-query.
<p>See <a href="TypeCoercionImpl.html" title="class in org.apache.calcite.sql.validate.implicit"><code>TypeCoercionImpl</code></a> for default strategies.
<p>STRATEGIES
<p>With(Without) sub-query:
<ul>
<li>With sub-query: find the common type through comparing the left hand
side (LHS) expression types with corresponding right hand side (RHS)
expression derived from the sub-query expression's row type. Wrap the
fields of the LHS and RHS in CAST operators if it is needed.
<li>Without sub-query: convert the nodes of the RHS to the common type by
checking all the argument types and find out the minimum common type that
all the arguments can be cast to.
</ul>
<p>How to find the common type:
<ul>
<li>For both struct sql types (LHS and RHS), find the common type of every
LHS and RHS fields pair:
<pre>
(field1, field2, field3) (field4, field5, field6)
| | | | | |
+--------+---type1----------+ | |
| | | |
+-------+----type2---------+ |
| |
+-------------type3--------+
</pre>
<li>For both basic sql types(LHS and RHS),
find the common type of LHS and RHS nodes.
</ul></div>
</section>
</li>
<li>
<section class="detail" id="builtinFunctionCoercion(org.apache.calcite.sql.SqlCallBinding,java.util.List,java.util.List)">
<h3>builtinFunctionCoercion</h3>
<div class="member-signature"><span class="modifiers">public</span>&nbsp;<span class="return-type">boolean</span>&nbsp;<span class="element-name">builtinFunctionCoercion</span><wbr><span class="parameters">(<a href="../../SqlCallBinding.html" title="class in org.apache.calcite.sql">SqlCallBinding</a>&nbsp;binding,
<a href="https://docs.oracle.com/en/java/javase/17/docs/api/java.base/java/util/List.html" title="class or interface in java.util" class="external-link">List</a>&lt;<a href="../../../rel/type/RelDataType.html" title="interface in org.apache.calcite.rel.type">RelDataType</a>&gt;&nbsp;operandTypes,
<a href="https://docs.oracle.com/en/java/javase/17/docs/api/java.base/java/util/List.html" title="class or interface in java.util" class="external-link">List</a>&lt;<a href="../../type/SqlTypeFamily.html" title="enum in org.apache.calcite.sql.type">SqlTypeFamily</a>&gt;&nbsp;expectedFamilies)</span></div>
<div class="block"><span class="descfrm-type-label">Description copied from interface:&nbsp;<code><a href="TypeCoercion.html#builtinFunctionCoercion(org.apache.calcite.sql.SqlCallBinding,java.util.List,java.util.List)">TypeCoercion</a></code></span></div>
<div class="block">Type coercion with inferred type from passed in arguments and the
<a href="../../type/SqlTypeFamily.html" title="enum in org.apache.calcite.sql.type"><code>SqlTypeFamily</code></a> defined in the checkers, e.g. the
<a href="../../type/FamilyOperandTypeChecker.html" title="class in org.apache.calcite.sql.type"><code>FamilyOperandTypeChecker</code></a>.
<p>Caution that we do not cast from NUMERIC if desired type family is also
<a href="../../type/SqlTypeFamily.html#NUMERIC"><code>SqlTypeFamily.NUMERIC</code></a>.
<p>If the <a href="../../type/FamilyOperandTypeChecker.html" title="class in org.apache.calcite.sql.type"><code>FamilyOperandTypeChecker</code></a>s are
subsumed in a
<a href="../../type/CompositeOperandTypeChecker.html" title="class in org.apache.calcite.sql.type"><code>CompositeOperandTypeChecker</code></a>, check them
based on their combination order. i.e. If we allow a NUMERIC_NUMERIC OR
STRING_NUMERIC family combination and are with arguments (op1: VARCHAR(20), op2: BOOLEAN),
try to coerce both op1 and op2 to NUMERIC if the type coercion rules allow it,
or else try to coerce op2 to NUMERIC and keep op1 the type as it is.
<p>This is also very interrelated to the composition predicate for the
checkers: if the predicate is AND, we would fail fast if the first family
type coercion fails.</div>
<dl class="notes">
<dt>Parameters:</dt>
<dd><code>binding</code> - Call binding</dd>
<dd><code>operandTypes</code> - Types of the operands passed in</dd>
<dd><code>expectedFamilies</code> - Expected SqlTypeFamily list by user specified</dd>
</dl>
</section>
</li>
<li>
<section class="detail" id="userDefinedFunctionCoercion(org.apache.calcite.sql.validate.SqlValidatorScope,org.apache.calcite.sql.SqlCall,org.apache.calcite.sql.SqlFunction)">
<h3>userDefinedFunctionCoercion</h3>
<div class="member-signature"><span class="modifiers">public</span>&nbsp;<span class="return-type">boolean</span>&nbsp;<span class="element-name">userDefinedFunctionCoercion</span><wbr><span class="parameters">(<a href="../SqlValidatorScope.html" title="interface in org.apache.calcite.sql.validate">SqlValidatorScope</a>&nbsp;scope,
<a href="../../SqlCall.html" title="class in org.apache.calcite.sql">SqlCall</a>&nbsp;call,
<a href="../../SqlFunction.html" title="class in org.apache.calcite.sql">SqlFunction</a>&nbsp;function)</span></div>
<div class="block">Type coercion for user-defined functions (UDFs).</div>
</section>
</li>
<li>
<section class="detail" id="querySourceCoercion(org.apache.calcite.sql.validate.SqlValidatorScope,org.apache.calcite.rel.type.RelDataType,org.apache.calcite.rel.type.RelDataType,org.apache.calcite.sql.SqlNode)">
<h3>querySourceCoercion</h3>
<div class="member-signature"><span class="modifiers">public</span>&nbsp;<span class="return-type">boolean</span>&nbsp;<span class="element-name">querySourceCoercion</span><wbr><span class="parameters">(@Nullable <a href="../SqlValidatorScope.html" title="interface in org.apache.calcite.sql.validate">SqlValidatorScope</a>&nbsp;scope,
<a href="../../../rel/type/RelDataType.html" title="interface in org.apache.calcite.rel.type">RelDataType</a>&nbsp;sourceRowType,
<a href="../../../rel/type/RelDataType.html" title="interface in org.apache.calcite.rel.type">RelDataType</a>&nbsp;targetRowType,
<a href="../../SqlNode.html" title="class in org.apache.calcite.sql">SqlNode</a>&nbsp;query)</span></div>
<div class="block"><span class="descfrm-type-label">Description copied from interface:&nbsp;<code><a href="TypeCoercion.html#querySourceCoercion(org.apache.calcite.sql.validate.SqlValidatorScope,org.apache.calcite.rel.type.RelDataType,org.apache.calcite.rel.type.RelDataType,org.apache.calcite.sql.SqlNode)">TypeCoercion</a></code></span></div>
<div class="block">Coerces the source row expression to target type in an INSERT or UPDATE query.
<p>If the source and target fields in the same ordinal do not equal sans nullability,
try to coerce the source field to target field type.</div>
<dl class="notes">
<dt>Parameters:</dt>
<dd><code>scope</code> - Source scope</dd>
<dd><code>sourceRowType</code> - Source row type</dd>
<dd><code>targetRowType</code> - Target row type</dd>
<dd><code>query</code> - The query, either an INSERT or UPDATE</dd>
</dl>
</section>
</li>
</ul>
</section>
</li>
</ul>
</section>
<!-- ========= END OF CLASS DATA ========= -->
</main>
<footer role="contentinfo">
<hr>
<p class="legal-copy"><small>Copyright &copy; 2012-2023 Apache Software Foundation. All Rights Reserved.</small></p>
</footer>
</div>
</div>
</body>
</html>