blob: e9dec7bf2c1594e96ec5a29cd52e6899cd4a2f22 [file] [log] [blame]
<!DOCTYPE HTML>
<html lang="en">
<head>
<!-- Generated by javadoc (17) -->
<title>org.apache.calcite.sql.validate.implicit (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">
<meta name="generator" content="javadoc/PackageWriterImpl">
<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="package-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 class="nav-bar-cell1-rev">Package</li>
<li>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#package">Help</a></li>
</ul>
</div>
<div class="sub-nav">
<div>
<ul class="sub-nav-list">
<li>Package:&nbsp;</li>
<li><a href="#package-description">Description</a>&nbsp;|&nbsp;</li>
<li><a href="#related-package-summary">Related Packages</a>&nbsp;|&nbsp;</li>
<li><a href="#class-summary">Classes and Interfaces</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">
<div class="header">
<h1 title="Package org.apache.calcite.sql.validate.implicit" class="title">Package org.apache.calcite.sql.validate.implicit</h1>
</div>
<hr>
<div class="package-signature">package <span class="element-name">org.apache.calcite.sql.validate.implicit</span></div>
<section class="package-description" id="package-description">
<div class="block"><h2>SQL Implicit Type Cast</h2>
<h3>Work Flow</h3>
<p>This package contains rules for implicit type coercion, it works during
the process of SQL validation. The transformation entrance are all kinds of
checkers. i.e.
<a href="../../type/AssignableOperandTypeChecker.html" title="class in org.apache.calcite.sql.type"><code>AssignableOperandTypeChecker</code></a>,
<a href="../../type/ComparableOperandTypeChecker.html" title="class in org.apache.calcite.sql.type"><code>ComparableOperandTypeChecker</code></a>
<a href="../../type/CompositeOperandTypeChecker.html" title="class in org.apache.calcite.sql.type"><code>CompositeOperandTypeChecker</code></a>,
<a href="../../type/FamilyOperandTypeChecker.html" title="class in org.apache.calcite.sql.type"><code>FamilyOperandTypeChecker</code></a>,
<a href="../../type/SameOperandTypeChecker.html" title="class in org.apache.calcite.sql.type"><code>SameOperandTypeChecker</code></a>,
<a href="../../type/SetopOperandTypeChecker.html" title="class in org.apache.calcite.sql.type"><code>SetopOperandTypeChecker</code></a>.
<ul>
<li>
When user do validation for a <a href="../../SqlNode.html" title="class in org.apache.calcite.sql"><code>SqlNode</code></a>,
and the type coercion is turned on(default), the validator will check the
operands/return types of all kinds of operators, if the validation passes through,
the validator will just cache the data type (say RelDataType) for the
<a href="../../SqlNode.html" title="class in org.apache.calcite.sql"><code>SqlNode</code></a> it has validated;</li>
<li>If the validation fails, the validator will ask the
<a href="TypeCoercion.html" title="interface in org.apache.calcite.sql.validate.implicit"><code>TypeCoercion</code></a> about
if there can make implicit type coercion, if the coercion rules passed, the
<a href="TypeCoercion.html" title="interface in org.apache.calcite.sql.validate.implicit"><code>TypeCoercion</code></a> component
will replace the <a href="../../SqlNode.html" title="class in org.apache.calcite.sql"><code>SqlNode</code></a> with a casted one,
(the node may be an operand of an operator or a column field of a selected row).</li>
<li><a href="TypeCoercion.html" title="interface in org.apache.calcite.sql.validate.implicit"><code>TypeCoercion</code></a>
will then update the inferred type for the casted node and
the containing operator/row column type.</li>
<li>If the coercion rule fails again, the validator will just throw
the exception as is before.</li>
</ul>
<p>For some cases, although the validation passes, we still need the type coercion, e.g. for
expression 1 &gt; '1', Calcite will just return false without type coercion, we do type coercion
eagerly here: the result expression would be transformed to "1 &gt; cast('1' as int)" and
the result would be true.
<h3>Conversion SQL Contexts</h3>
<p>The supported conversion contexts are:
<a href="https://docs.google.com/document/d/1g2RUnLXyp_LjUlO-wbblKuP5hqEu3a_2Mt2k4dh6RwU/edit?usp=sharing">Conversion Expressions</a>
<p>Strategies for Finding Common Type:</p>
<ul>
<li>If the operator has expected data types, just take them as the desired one. i.e. the UDF.
</li>
<li>If there is no expected data type but data type families are registered, try to coerce
operand to the family's default data type, i.e. the STRING family will have a VARCHAR type.
</li>
<li>If neither expected data type nor families are specified, try to find the tightest common
type of the node types, i.e. INTEGER and DOUBLE will return DOUBLE, the numeric precision
does not lose for this case.</li>
<li>If no tightest common type is found, try to find a wider type, i.e. STRING and INT
will return int, we allow some precision loss when widening DECIMAL to fractional,
or promote to STRING.</li>
</ul>
<h3>Type Conversion Matrix</h3>
<p>See <a href="https://docs.google.com/spreadsheets/d/1GhleX5h5W8-kJKh7NMJ4vtoE78pwfaZRJl88ULX_MgU/edit?usp=sharing">CalciteImplicitCasts</a>.</div>
</section>
<section class="summary">
<ul class="summary-list">
<li>
<div id="related-package-summary">
<div class="caption"><span>Related Packages</span></div>
<div class="summary-table two-column-summary">
<div class="table-header col-first">Package</div>
<div class="table-header col-last">Description</div>
<div class="col-first even-row-color"><a href="../package-summary.html">org.apache.calcite.sql.validate</a></div>
<div class="col-last even-row-color">
<div class="block">SQL validation.</div>
</div>
</div>
</div>
</li>
<li>
<div id="class-summary">
<div class="table-tabs" role="tablist" aria-orientation="horizontal"><button id="class-summary-tab0" role="tab" aria-selected="true" aria-controls="class-summary.tabpanel" tabindex="0" onkeydown="switchTab(event)" onclick="show('class-summary', 'class-summary', 2)" class="active-table-tab">All Classes and Interfaces</button><button id="class-summary-tab1" role="tab" aria-selected="false" aria-controls="class-summary.tabpanel" tabindex="-1" onkeydown="switchTab(event)" onclick="show('class-summary', 'class-summary-tab1', 2)" class="table-tab">Interfaces</button><button id="class-summary-tab2" role="tab" aria-selected="false" aria-controls="class-summary.tabpanel" tabindex="-1" onkeydown="switchTab(event)" onclick="show('class-summary', 'class-summary-tab2', 2)" class="table-tab">Classes</button></div>
<div id="class-summary.tabpanel" role="tabpanel">
<div class="summary-table two-column-summary" aria-labelledby="class-summary-tab0">
<div class="table-header col-first">Class</div>
<div class="table-header col-last">Description</div>
<div class="col-first even-row-color class-summary class-summary-tab2"><a href="AbstractTypeCoercion.html" title="class in org.apache.calcite.sql.validate.implicit">AbstractTypeCoercion</a></div>
<div class="col-last even-row-color class-summary class-summary-tab2">
<div class="block">Base class for all the type coercion rules.</div>
</div>
<div class="col-first odd-row-color class-summary class-summary-tab1"><a href="TypeCoercion.html" title="interface in org.apache.calcite.sql.validate.implicit">TypeCoercion</a></div>
<div class="col-last odd-row-color class-summary class-summary-tab1">
<div class="block">Default strategies to coerce differing types that participate in
operations into compatible ones.</div>
</div>
<div class="col-first even-row-color class-summary class-summary-tab1"><a href="TypeCoercionFactory.html" title="interface in org.apache.calcite.sql.validate.implicit">TypeCoercionFactory</a></div>
<div class="col-last even-row-color class-summary class-summary-tab1">
<div class="block">Factory for <a href="TypeCoercion.html" title="interface in org.apache.calcite.sql.validate.implicit"><code>TypeCoercion</code></a> objects.</div>
</div>
<div class="col-first odd-row-color class-summary class-summary-tab2"><a href="TypeCoercionImpl.html" title="class in org.apache.calcite.sql.validate.implicit">TypeCoercionImpl</a></div>
<div class="col-last odd-row-color class-summary class-summary-tab2">
<div class="block">Default implementation of Calcite implicit type cast.</div>
</div>
<div class="col-first even-row-color class-summary class-summary-tab2"><a href="TypeCoercions.html" title="class in org.apache.calcite.sql.validate.implicit">TypeCoercions</a></div>
<div class="col-last even-row-color class-summary class-summary-tab2">
<div class="block">Factory class for type coercion instantiation of different sql dialects.</div>
</div>
</div>
</div>
</div>
</li>
</ul>
</section>
</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>