| <!DOCTYPE HTML> |
| <!-- NewPage --> |
| <html lang="en"> |
| <head> |
| <!-- Generated by javadoc --> |
| <title>org.apache.calcite.sql.validate.implicit (Apache Calcite API)</title> |
| <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> |
| <link rel="stylesheet" type="text/css" href="../../../../../../stylesheet.css" title="Style"> |
| <link rel="stylesheet" type="text/css" href="../../../../../../jquery/jquery-ui.css" title="Style"> |
| <script type="text/javascript" src="../../../../../../script.js"></script> |
| <script type="text/javascript" src="../../../../../../jquery/jszip/dist/jszip.min.js"></script> |
| <script type="text/javascript" src="../../../../../../jquery/jszip-utils/dist/jszip-utils.min.js"></script> |
| <!--[if IE]> |
| <script type="text/javascript" src="../../../../../../jquery/jszip-utils/dist/jszip-utils-ie.min.js"></script> |
| <![endif]--> |
| <script type="text/javascript" src="../../../../../../jquery/jquery-3.3.1.js"></script> |
| <script type="text/javascript" src="../../../../../../jquery/jquery-migrate-3.0.1.js"></script> |
| <script type="text/javascript" src="../../../../../../jquery/jquery-ui.js"></script> |
| </head> |
| <body> |
| <script type="text/javascript"><!-- |
| try { |
| if (location.href.indexOf('is-external=true') == -1) { |
| parent.document.title="org.apache.calcite.sql.validate.implicit (Apache Calcite API)"; |
| } |
| } |
| catch(err) { |
| } |
| //--> |
| var pathtoroot = "../../../../../../"; |
| var useModuleDirectories = true; |
| loadScripts(document, 'script');</script> |
| <noscript> |
| <div>JavaScript is disabled on your browser.</div> |
| </noscript> |
| <header role="banner"> |
| <nav role="navigation"> |
| <div class="fixedNav"> |
| <!-- ========= START OF TOP NAVBAR ======= --> |
| <div class="topNav"><a id="navbar.top"> |
| <!-- --> |
| </a> |
| <div class="skipNav"><a href="#skip.navbar.top" title="Skip navigation links">Skip navigation links</a></div> |
| <a id="navbar.top.firstrow"> |
| <!-- --> |
| </a> |
| <ul class="navList" title="Navigation"> |
| <li><a href="../../../../../../index.html">Overview</a></li> |
| <li class="navBarCell1Rev">Package</li> |
| <li>Class</li> |
| <li><a href="package-use.html">Use</a></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">Help</a></li> |
| </ul> |
| </div> |
| <div class="subNav"> |
| <ul class="navList" id="allclasses_navbar_top"> |
| <li><a href="../../../../../../allclasses.html">All Classes</a></li> |
| </ul> |
| <ul class="navListSearch"> |
| <li><label for="search">SEARCH:</label> |
| <input type="text" id="search" value="search" disabled="disabled"> |
| <input type="reset" id="reset" value="reset" disabled="disabled"> |
| </li> |
| </ul> |
| <div> |
| <script type="text/javascript"><!-- |
| allClassesLink = document.getElementById("allclasses_navbar_top"); |
| if(window==top) { |
| allClassesLink.style.display = "block"; |
| } |
| else { |
| allClassesLink.style.display = "none"; |
| } |
| //--> |
| </script> |
| <noscript> |
| <div>JavaScript is disabled on your browser.</div> |
| </noscript> |
| </div> |
| <a id="skip.navbar.top"> |
| <!-- --> |
| </a></div> |
| <!-- ========= END OF TOP NAVBAR ========= --> |
| </div> |
| <div class="navPadding"> </div> |
| <script type="text/javascript"><!-- |
| $('.navPadding').css('padding-top', $('.fixedNav').css("height")); |
| //--> |
| </script> |
| </nav> |
| </header> |
| <main role="main"> |
| <div class="header"> |
| <h1 title="Package" class="title">Package org.apache.calcite.sql.validate.implicit</h1> |
| </div> |
| <div class="contentContainer"> |
| <section role="region"><a id="package.description"> |
| <!-- --> |
| </a> |
| <div class="block">Sql implicit type cast. |
| <h2>Work Flow</h2> |
| 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 > '1', Calcite will just return false without type coercion, we do type coercion |
| eagerly here: the result expression would be transformed to "1 > cast('1' as int)" and |
| the result would be true. |
| |
| <h2>Conversion Expressions</h2> |
| 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. int and double will return double, the numeric precision does not |
| lose for this case.</li> |
| <li>If no tightest common type 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 type.</li> |
| </ul> |
| |
| <h2>Types Conversion Matrix</h2> |
| See <a href="https://docs.google.com/spreadsheets/d/1GhleX5h5W8-kJKh7NMJ4vtoE78pwfaZRJl88ULX_MgU/edit?usp=sharing">CalciteImplicitCasts</a></div> |
| </section> |
| <ul class="blockList"> |
| <li class="blockList"> |
| <table class="typeSummary"> |
| <caption><span>Interface Summary</span><span class="tabEnd"> </span></caption> |
| <tr> |
| <th class="colFirst" scope="col">Interface</th> |
| <th class="colLast" scope="col">Description</th> |
| </tr> |
| <tbody> |
| <tr class="altColor"> |
| <th class="colFirst" scope="row"><a href="TypeCoercion.html" title="interface in org.apache.calcite.sql.validate.implicit">TypeCoercion</a></th> |
| <td class="colLast"> |
| <div class="block">Default Strategies to coerce differing types that participate in |
| operations into compatible ones.</div> |
| </td> |
| </tr> |
| </tbody> |
| </table> |
| </li> |
| <li class="blockList"> |
| <table class="typeSummary"> |
| <caption><span>Class Summary</span><span class="tabEnd"> </span></caption> |
| <tr> |
| <th class="colFirst" scope="col">Class</th> |
| <th class="colLast" scope="col">Description</th> |
| </tr> |
| <tbody> |
| <tr class="altColor"> |
| <th class="colFirst" scope="row"><a href="AbstractTypeCoercion.html" title="class in org.apache.calcite.sql.validate.implicit">AbstractTypeCoercion</a></th> |
| <td class="colLast"> |
| <div class="block">Base class for all the type coercion rules.</div> |
| </td> |
| </tr> |
| <tr class="rowColor"> |
| <th class="colFirst" scope="row"><a href="TypeCoercionImpl.html" title="class in org.apache.calcite.sql.validate.implicit">TypeCoercionImpl</a></th> |
| <td class="colLast"> |
| <div class="block">Default implementation of Calcite implicit type cast.</div> |
| </td> |
| </tr> |
| <tr class="altColor"> |
| <th class="colFirst" scope="row"><a href="TypeCoercions.html" title="class in org.apache.calcite.sql.validate.implicit">TypeCoercions</a></th> |
| <td class="colLast"> |
| <div class="block">Factory class for type coercion instantiation of different sql dialects.</div> |
| </td> |
| </tr> |
| </tbody> |
| </table> |
| </li> |
| </ul> |
| </div> |
| </main> |
| <footer role="contentinfo"> |
| <nav role="navigation"> |
| <!-- ======= START OF BOTTOM NAVBAR ====== --> |
| <div class="bottomNav"><a id="navbar.bottom"> |
| <!-- --> |
| </a> |
| <div class="skipNav"><a href="#skip.navbar.bottom" title="Skip navigation links">Skip navigation links</a></div> |
| <a id="navbar.bottom.firstrow"> |
| <!-- --> |
| </a> |
| <ul class="navList" title="Navigation"> |
| <li><a href="../../../../../../index.html">Overview</a></li> |
| <li class="navBarCell1Rev">Package</li> |
| <li>Class</li> |
| <li><a href="package-use.html">Use</a></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">Help</a></li> |
| </ul> |
| </div> |
| <div class="subNav"> |
| <ul class="navList" id="allclasses_navbar_bottom"> |
| <li><a href="../../../../../../allclasses.html">All Classes</a></li> |
| </ul> |
| <div> |
| <script type="text/javascript"><!-- |
| allClassesLink = document.getElementById("allclasses_navbar_bottom"); |
| if(window==top) { |
| allClassesLink.style.display = "block"; |
| } |
| else { |
| allClassesLink.style.display = "none"; |
| } |
| //--> |
| </script> |
| <noscript> |
| <div>JavaScript is disabled on your browser.</div> |
| </noscript> |
| </div> |
| <a id="skip.navbar.bottom"> |
| <!-- --> |
| </a></div> |
| <!-- ======== END OF BOTTOM NAVBAR ======= --> |
| </nav> |
| <p class="legalCopy"><small>Copyright © 2012–2019 <a href="https://www.apache.org/">The Apache Software Foundation</a>. All rights reserved.</small></p> |
| </footer> |
| </body> |
| </html> |