blob: 49cd77d83b25271938f5a441cb7567f11f83c512 [file] [log] [blame]
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="shortcut icon" href="/favicon.ico" type="image/x-icon">
<link rel="icon" href="/favicon.ico" type="image/x-icon">
<title>Storm SQL language</title>
<!-- Bootstrap core CSS -->
<link href="/assets/css/bootstrap.min.css" rel="stylesheet">
<!-- Bootstrap theme -->
<link href="/assets/css/bootstrap-theme.min.css" rel="stylesheet">
<!-- Custom styles for this template -->
<link rel="stylesheet" href="http://fortawesome.github.io/Font-Awesome/assets/font-awesome/css/font-awesome.css">
<link href="/css/style.css" rel="stylesheet">
<link href="/assets/css/owl.theme.css" rel="stylesheet">
<link href="/assets/css/owl.carousel.css" rel="stylesheet">
<script type="text/javascript" src="/assets/js/jquery.min.js"></script>
<script type="text/javascript" src="/assets/js/bootstrap.min.js"></script>
<script type="text/javascript" src="/assets/js/owl.carousel.min.js"></script>
<script type="text/javascript" src="/assets/js/storm.js"></script>
<!-- Just for debugging purposes. Don't actually copy these 2 lines! -->
<!--[if lt IE 9]><script src="../../assets/js/ie8-responsive-file-warning.js"></script><![endif]-->
<!-- HTML5 shim and Respond.js for IE8 support of HTML5 elements and media queries -->
<!--[if lt IE 9]>
<script src="https://oss.maxcdn.com/html5shiv/3.7.2/html5shiv.min.js"></script>
<script src="https://oss.maxcdn.com/respond/1.4.2/respond.min.js"></script>
<![endif]-->
</head>
<body>
<header>
<div class="container-fluid">
<div class="row">
<div class="col-md-5">
<a href="/index.html"><img src="/images/logo.png" class="logo" /></a>
</div>
<div class="col-md-5">
<h1>Version: 2.3.0</h1>
</div>
<div class="col-md-2">
<a href="/downloads.html" class="btn-std btn-block btn-download">Download</a>
</div>
</div>
</div>
</header>
<!--Header End-->
<!--Navigation Begin-->
<div class="navbar" role="banner">
<div class="container-fluid">
<div class="navbar-header">
<button class="navbar-toggle" type="button" data-toggle="collapse" data-target=".bs-navbar-collapse">
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
</div>
<nav class="collapse navbar-collapse bs-navbar-collapse" role="navigation">
<ul class="nav navbar-nav">
<li><a href="/index.html" id="home">Home</a></li>
<li><a href="/getting-help.html" id="getting-help">Getting Help</a></li>
<li><a href="/about/integrates.html" id="project-info">Project Information</a></li>
<li class="dropdown">
<a href="#" class="dropdown-toggle" data-toggle="dropdown" id="documentation">Documentation <b class="caret"></b></a>
<ul class="dropdown-menu">
<li><a href="/releases/2.3.0/index.html">2.3.0</a></li>
<li><a href="/releases/2.2.0/index.html">2.2.0</a></li>
<li><a href="/releases/2.1.0/index.html">2.1.0</a></li>
<li><a href="/releases/2.0.0/index.html">2.0.0</a></li>
<li><a href="/releases/1.2.3/index.html">1.2.3</a></li>
</ul>
</li>
<li><a href="/talksAndVideos.html">Talks and Slideshows</a></li>
<li class="dropdown">
<a href="#" class="dropdown-toggle" data-toggle="dropdown" id="contribute">Community <b class="caret"></b></a>
<ul class="dropdown-menu">
<li><a href="/contribute/Contributing-to-Storm.html">Contributing</a></li>
<li><a href="/contribute/People.html">People</a></li>
<li><a href="/contribute/BYLAWS.html">ByLaws</a></li>
</ul>
</li>
<li><a href="/2021/09/27/storm230-released.html" id="news">News</a></li>
</ul>
</nav>
</div>
</div>
<div class="container-fluid">
<h1 class="page-title">Storm SQL language</h1>
<div class="row">
<div class="col-md-12">
<!-- Documentation -->
<p class="post-meta"></p>
<div class="documentation-content"><p>Storm SQL uses Apache Calcite to parse and evaluate the SQL statements.
Storm SQL also adopts Rex compiler from Calcite, so Storm SQL is expected to handle SQL dialect recognized by Calcite&#39;s default SQL parser. </p>
<p>The page is based on Calcite SQL reference on website, and removes the area Storm SQL doesn&#39;t support, and also adds the area Storm SQL supports.</p>
<p>Please read <a href="storm-sql.html">Storm SQL integration</a> page first to see what features Storm SQL supports. </p>
<h2 id="grammar">Grammar</h2>
<p>Calcite provides broader SQL Grammar. But Storm SQL is not a database system and handles streaming data, so only subset of grammar is supported.
Storm SQL doesn&#39;t redefine SQL Grammar and just utilize the parser Calcite provided, so SQL statements are still parsed based on Calcite&#39;s SQL Grammar. </p>
<p>SQL grammar in <a href="http://en.wikipedia.org/wiki/Backus%E2%80%93Naur_Form">BNF</a>-like form.</p>
<figure class="highlight"><pre><code class="language-sql" data-lang="sql"><span class="k">statement</span><span class="p">:</span>
<span class="n">setStatement</span>
<span class="o">|</span> <span class="n">resetStatement</span>
<span class="o">|</span> <span class="k">explain</span>
<span class="o">|</span> <span class="k">describe</span>
<span class="o">|</span> <span class="k">insert</span>
<span class="o">|</span> <span class="k">update</span>
<span class="o">|</span> <span class="n">merge</span>
<span class="o">|</span> <span class="k">delete</span>
<span class="o">|</span> <span class="n">query</span>
<span class="n">setStatement</span><span class="p">:</span>
<span class="p">[</span> <span class="k">ALTER</span> <span class="p">(</span> <span class="k">SYSTEM</span> <span class="o">|</span> <span class="k">SESSION</span> <span class="p">)</span> <span class="p">]</span> <span class="k">SET</span> <span class="n">identifier</span> <span class="s1">'='</span> <span class="n">expression</span>
<span class="n">resetStatement</span><span class="p">:</span>
<span class="p">[</span> <span class="k">ALTER</span> <span class="p">(</span> <span class="k">SYSTEM</span> <span class="o">|</span> <span class="k">SESSION</span> <span class="p">)</span> <span class="p">]</span> <span class="k">RESET</span> <span class="n">identifier</span>
<span class="o">|</span> <span class="p">[</span> <span class="k">ALTER</span> <span class="p">(</span> <span class="k">SYSTEM</span> <span class="o">|</span> <span class="k">SESSION</span> <span class="p">)</span> <span class="p">]</span> <span class="k">RESET</span> <span class="k">ALL</span>
<span class="k">explain</span><span class="p">:</span>
<span class="k">EXPLAIN</span> <span class="n">PLAN</span>
<span class="p">[</span> <span class="k">WITH</span> <span class="k">TYPE</span> <span class="o">|</span> <span class="k">WITH</span> <span class="k">IMPLEMENTATION</span> <span class="o">|</span> <span class="k">WITHOUT</span> <span class="k">IMPLEMENTATION</span> <span class="p">]</span>
<span class="p">[</span> <span class="k">EXCLUDING</span> <span class="n">ATTRIBUTES</span> <span class="o">|</span> <span class="k">INCLUDING</span> <span class="p">[</span> <span class="k">ALL</span> <span class="p">]</span> <span class="n">ATTRIBUTES</span> <span class="p">]</span>
<span class="k">FOR</span> <span class="p">(</span> <span class="n">query</span> <span class="o">|</span> <span class="k">insert</span> <span class="o">|</span> <span class="k">update</span> <span class="o">|</span> <span class="n">merge</span> <span class="o">|</span> <span class="k">delete</span> <span class="p">)</span>
<span class="k">describe</span><span class="p">:</span>
<span class="k">DESCRIBE</span> <span class="k">DATABASE</span> <span class="n">databaseName</span>
<span class="o">|</span> <span class="k">DESCRIBE</span> <span class="k">CATALOG</span> <span class="p">[</span> <span class="n">databaseName</span> <span class="p">.</span> <span class="p">]</span> <span class="n">catalogName</span>
<span class="o">|</span> <span class="k">DESCRIBE</span> <span class="k">SCHEMA</span> <span class="p">[</span> <span class="p">[</span> <span class="n">databaseName</span> <span class="p">.</span> <span class="p">]</span> <span class="n">catalogName</span> <span class="p">]</span> <span class="p">.</span> <span class="n">schemaName</span>
<span class="o">|</span> <span class="k">DESCRIBE</span> <span class="p">[</span> <span class="k">TABLE</span> <span class="p">]</span> <span class="p">[</span> <span class="p">[</span> <span class="p">[</span> <span class="n">databaseName</span> <span class="p">.</span> <span class="p">]</span> <span class="n">catalogName</span> <span class="p">.</span> <span class="p">]</span> <span class="n">schemaName</span> <span class="p">.</span> <span class="p">]</span> <span class="n">tableName</span> <span class="p">[</span> <span class="n">columnName</span> <span class="p">]</span>
<span class="o">|</span> <span class="k">DESCRIBE</span> <span class="p">[</span> <span class="k">STATEMENT</span> <span class="p">]</span> <span class="p">(</span> <span class="n">query</span> <span class="o">|</span> <span class="k">insert</span> <span class="o">|</span> <span class="k">update</span> <span class="o">|</span> <span class="n">merge</span> <span class="o">|</span> <span class="k">delete</span> <span class="p">)</span>
<span class="k">insert</span><span class="p">:</span>
<span class="p">(</span> <span class="k">INSERT</span> <span class="o">|</span> <span class="n">UPSERT</span> <span class="p">)</span> <span class="k">INTO</span> <span class="n">tablePrimary</span>
<span class="p">[</span> <span class="s1">'('</span> <span class="k">column</span> <span class="p">[,</span> <span class="k">column</span> <span class="p">]</span><span class="o">*</span> <span class="s1">')'</span> <span class="p">]</span>
<span class="n">query</span>
<span class="k">update</span><span class="p">:</span>
<span class="k">UPDATE</span> <span class="n">tablePrimary</span>
<span class="k">SET</span> <span class="n">assign</span> <span class="p">[,</span> <span class="n">assign</span> <span class="p">]</span><span class="o">*</span>
<span class="p">[</span> <span class="k">WHERE</span> <span class="n">booleanExpression</span> <span class="p">]</span>
<span class="n">assign</span><span class="p">:</span>
<span class="n">identifier</span> <span class="s1">'='</span> <span class="n">expression</span>
<span class="n">merge</span><span class="p">:</span>
<span class="n">MERGE</span> <span class="k">INTO</span> <span class="n">tablePrimary</span> <span class="p">[</span> <span class="p">[</span> <span class="k">AS</span> <span class="p">]</span> <span class="k">alias</span> <span class="p">]</span>
<span class="k">USING</span> <span class="n">tablePrimary</span>
<span class="k">ON</span> <span class="n">booleanExpression</span>
<span class="p">[</span> <span class="k">WHEN</span> <span class="n">MATCHED</span> <span class="k">THEN</span> <span class="k">UPDATE</span> <span class="k">SET</span> <span class="n">assign</span> <span class="p">[,</span> <span class="n">assign</span> <span class="p">]</span><span class="o">*</span> <span class="p">]</span>
<span class="p">[</span> <span class="k">WHEN</span> <span class="k">NOT</span> <span class="n">MATCHED</span> <span class="k">THEN</span> <span class="k">INSERT</span> <span class="k">VALUES</span> <span class="s1">'('</span> <span class="n">value</span> <span class="p">[</span> <span class="p">,</span> <span class="n">value</span> <span class="p">]</span><span class="o">*</span> <span class="s1">')'</span> <span class="p">]</span>
<span class="k">delete</span><span class="p">:</span>
<span class="k">DELETE</span> <span class="k">FROM</span> <span class="n">tablePrimary</span> <span class="p">[</span> <span class="p">[</span> <span class="k">AS</span> <span class="p">]</span> <span class="k">alias</span> <span class="p">]</span>
<span class="p">[</span> <span class="k">WHERE</span> <span class="n">booleanExpression</span> <span class="p">]</span>
<span class="n">query</span><span class="p">:</span>
<span class="k">values</span>
<span class="o">|</span> <span class="k">WITH</span> <span class="n">withItem</span> <span class="p">[</span> <span class="p">,</span> <span class="n">withItem</span> <span class="p">]</span><span class="o">*</span> <span class="n">query</span>
<span class="o">|</span> <span class="err">{</span>
<span class="k">select</span>
<span class="o">|</span> <span class="n">selectWithoutFrom</span>
<span class="o">|</span> <span class="n">query</span> <span class="k">UNION</span> <span class="p">[</span> <span class="k">ALL</span> <span class="p">]</span> <span class="n">query</span>
<span class="o">|</span> <span class="n">query</span> <span class="k">EXCEPT</span> <span class="n">query</span>
<span class="o">|</span> <span class="n">query</span> <span class="k">INTERSECT</span> <span class="n">query</span>
<span class="err">}</span>
<span class="p">[</span> <span class="k">ORDER</span> <span class="k">BY</span> <span class="n">orderItem</span> <span class="p">[,</span> <span class="n">orderItem</span> <span class="p">]</span><span class="o">*</span> <span class="p">]</span>
<span class="p">[</span> <span class="k">LIMIT</span> <span class="err">{</span> <span class="k">count</span> <span class="o">|</span> <span class="k">ALL</span> <span class="err">}</span> <span class="p">]</span>
<span class="p">[</span> <span class="k">OFFSET</span> <span class="k">start</span> <span class="err">{</span> <span class="k">ROW</span> <span class="o">|</span> <span class="k">ROWS</span> <span class="err">}</span> <span class="p">]</span>
<span class="p">[</span> <span class="k">FETCH</span> <span class="err">{</span> <span class="k">FIRST</span> <span class="o">|</span> <span class="k">NEXT</span> <span class="err">}</span> <span class="p">[</span> <span class="k">count</span> <span class="p">]</span> <span class="err">{</span> <span class="k">ROW</span> <span class="o">|</span> <span class="k">ROWS</span> <span class="err">}</span> <span class="p">]</span>
<span class="n">withItem</span><span class="p">:</span>
<span class="n">name</span>
<span class="p">[</span> <span class="s1">'('</span> <span class="k">column</span> <span class="p">[,</span> <span class="k">column</span> <span class="p">]</span><span class="o">*</span> <span class="s1">')'</span> <span class="p">]</span>
<span class="k">AS</span> <span class="s1">'('</span> <span class="n">query</span> <span class="s1">')'</span>
<span class="n">orderItem</span><span class="p">:</span>
<span class="n">expression</span> <span class="p">[</span> <span class="k">ASC</span> <span class="o">|</span> <span class="k">DESC</span> <span class="p">]</span> <span class="p">[</span> <span class="n">NULLS</span> <span class="k">FIRST</span> <span class="o">|</span> <span class="n">NULLS</span> <span class="k">LAST</span> <span class="p">]</span>
<span class="k">select</span><span class="p">:</span>
<span class="k">SELECT</span> <span class="p">[</span> <span class="n">STREAM</span> <span class="p">]</span> <span class="p">[</span> <span class="k">ALL</span> <span class="o">|</span> <span class="k">DISTINCT</span> <span class="p">]</span>
<span class="err">{</span> <span class="o">*</span> <span class="o">|</span> <span class="n">projectItem</span> <span class="p">[,</span> <span class="n">projectItem</span> <span class="p">]</span><span class="o">*</span> <span class="err">}</span>
<span class="k">FROM</span> <span class="n">tableExpression</span>
<span class="p">[</span> <span class="k">WHERE</span> <span class="n">booleanExpression</span> <span class="p">]</span>
<span class="p">[</span> <span class="k">GROUP</span> <span class="k">BY</span> <span class="err">{</span> <span class="n">groupItem</span> <span class="p">[,</span> <span class="n">groupItem</span> <span class="p">]</span><span class="o">*</span> <span class="err">}</span> <span class="p">]</span>
<span class="p">[</span> <span class="k">HAVING</span> <span class="n">booleanExpression</span> <span class="p">]</span>
<span class="p">[</span> <span class="n">WINDOW</span> <span class="n">windowName</span> <span class="k">AS</span> <span class="n">windowSpec</span> <span class="p">[,</span> <span class="n">windowName</span> <span class="k">AS</span> <span class="n">windowSpec</span> <span class="p">]</span><span class="o">*</span> <span class="p">]</span>
<span class="n">selectWithoutFrom</span><span class="p">:</span>
<span class="k">SELECT</span> <span class="p">[</span> <span class="k">ALL</span> <span class="o">|</span> <span class="k">DISTINCT</span> <span class="p">]</span>
<span class="err">{</span> <span class="o">*</span> <span class="o">|</span> <span class="n">projectItem</span> <span class="p">[,</span> <span class="n">projectItem</span> <span class="p">]</span><span class="o">*</span> <span class="err">}</span>
<span class="n">projectItem</span><span class="p">:</span>
<span class="n">expression</span> <span class="p">[</span> <span class="p">[</span> <span class="k">AS</span> <span class="p">]</span> <span class="n">columnAlias</span> <span class="p">]</span>
<span class="o">|</span> <span class="n">tableAlias</span> <span class="p">.</span> <span class="o">*</span>
<span class="n">tableExpression</span><span class="p">:</span>
<span class="n">tableReference</span> <span class="p">[,</span> <span class="n">tableReference</span> <span class="p">]</span><span class="o">*</span>
<span class="o">|</span> <span class="n">tableExpression</span> <span class="p">[</span> <span class="k">NATURAL</span> <span class="p">]</span> <span class="p">[</span> <span class="k">LEFT</span> <span class="o">|</span> <span class="k">RIGHT</span> <span class="o">|</span> <span class="k">FULL</span> <span class="p">]</span> <span class="k">JOIN</span> <span class="n">tableExpression</span> <span class="p">[</span> <span class="n">joinCondition</span> <span class="p">]</span>
<span class="n">joinCondition</span><span class="p">:</span>
<span class="k">ON</span> <span class="n">booleanExpression</span>
<span class="o">|</span> <span class="k">USING</span> <span class="s1">'('</span> <span class="k">column</span> <span class="p">[,</span> <span class="k">column</span> <span class="p">]</span><span class="o">*</span> <span class="s1">')'</span>
<span class="n">tableReference</span><span class="p">:</span>
<span class="n">tablePrimary</span>
<span class="p">[</span> <span class="p">[</span> <span class="k">AS</span> <span class="p">]</span> <span class="k">alias</span> <span class="p">[</span> <span class="s1">'('</span> <span class="n">columnAlias</span> <span class="p">[,</span> <span class="n">columnAlias</span> <span class="p">]</span><span class="o">*</span> <span class="s1">')'</span> <span class="p">]</span> <span class="p">]</span>
<span class="n">tablePrimary</span><span class="p">:</span>
<span class="p">[</span> <span class="p">[</span> <span class="n">catalogName</span> <span class="p">.</span> <span class="p">]</span> <span class="n">schemaName</span> <span class="p">.</span> <span class="p">]</span> <span class="n">tableName</span>
<span class="s1">'('</span> <span class="k">TABLE</span> <span class="p">[</span> <span class="p">[</span> <span class="n">catalogName</span> <span class="p">.</span> <span class="p">]</span> <span class="n">schemaName</span> <span class="p">.</span> <span class="p">]</span> <span class="n">tableName</span> <span class="s1">')'</span>
<span class="o">|</span> <span class="p">[</span> <span class="k">LATERAL</span> <span class="p">]</span> <span class="s1">'('</span> <span class="n">query</span> <span class="s1">')'</span>
<span class="o">|</span> <span class="k">UNNEST</span> <span class="s1">'('</span> <span class="n">expression</span> <span class="s1">')'</span> <span class="p">[</span> <span class="k">WITH</span> <span class="k">ORDINALITY</span> <span class="p">]</span>
<span class="o">|</span> <span class="p">[</span> <span class="k">LATERAL</span> <span class="p">]</span> <span class="k">TABLE</span> <span class="s1">'('</span> <span class="p">[</span> <span class="k">SPECIFIC</span> <span class="p">]</span> <span class="n">functionName</span> <span class="s1">'('</span> <span class="n">expression</span> <span class="p">[,</span> <span class="n">expression</span> <span class="p">]</span><span class="o">*</span> <span class="s1">')'</span> <span class="s1">')'</span>
<span class="k">values</span><span class="p">:</span>
<span class="k">VALUES</span> <span class="n">expression</span> <span class="p">[,</span> <span class="n">expression</span> <span class="p">]</span><span class="o">*</span>
<span class="n">groupItem</span><span class="p">:</span>
<span class="n">expression</span>
<span class="o">|</span> <span class="s1">'('</span> <span class="s1">')'</span>
<span class="o">|</span> <span class="s1">'('</span> <span class="n">expression</span> <span class="p">[,</span> <span class="n">expression</span> <span class="p">]</span><span class="o">*</span> <span class="s1">')'</span>
<span class="o">|</span> <span class="k">CUBE</span> <span class="s1">'('</span> <span class="n">expression</span> <span class="p">[,</span> <span class="n">expression</span> <span class="p">]</span><span class="o">*</span> <span class="s1">')'</span>
<span class="o">|</span> <span class="k">ROLLUP</span> <span class="s1">'('</span> <span class="n">expression</span> <span class="p">[,</span> <span class="n">expression</span> <span class="p">]</span><span class="o">*</span> <span class="s1">')'</span>
<span class="o">|</span> <span class="k">GROUPING</span> <span class="k">SETS</span> <span class="s1">'('</span> <span class="n">groupItem</span> <span class="p">[,</span> <span class="n">groupItem</span> <span class="p">]</span><span class="o">*</span> <span class="s1">')'</span>
<span class="n">windowRef</span><span class="p">:</span>
<span class="n">windowName</span>
<span class="o">|</span> <span class="n">windowSpec</span>
<span class="n">windowSpec</span><span class="p">:</span>
<span class="p">[</span> <span class="n">windowName</span> <span class="p">]</span>
<span class="s1">'('</span>
<span class="p">[</span> <span class="k">ORDER</span> <span class="k">BY</span> <span class="n">orderItem</span> <span class="p">[,</span> <span class="n">orderItem</span> <span class="p">]</span><span class="o">*</span> <span class="p">]</span>
<span class="p">[</span> <span class="n">PARTITION</span> <span class="k">BY</span> <span class="n">expression</span> <span class="p">[,</span> <span class="n">expression</span> <span class="p">]</span><span class="o">*</span> <span class="p">]</span>
<span class="p">[</span>
<span class="n">RANGE</span> <span class="n">numericOrIntervalExpression</span> <span class="err">{</span> <span class="n">PRECEDING</span> <span class="o">|</span> <span class="n">FOLLOWING</span> <span class="err">}</span>
<span class="o">|</span> <span class="k">ROWS</span> <span class="n">numericExpression</span> <span class="err">{</span> <span class="n">PRECEDING</span> <span class="o">|</span> <span class="n">FOLLOWING</span> <span class="err">}</span>
<span class="p">]</span>
<span class="s1">')'</span></code></pre></figure>
<p>In <em>merge</em>, at least one of the WHEN MATCHED and WHEN NOT MATCHED clauses must
be present.</p>
<p>In <em>orderItem</em>, if <em>expression</em> is a positive integer <em>n</em>, it denotes
the <em>n</em>th item in the SELECT clause.</p>
<p>An aggregate query is a query that contains a GROUP BY or a HAVING
clause, or aggregate functions in the SELECT clause. In the SELECT,
HAVING and ORDER BY clauses of an aggregate query, all expressions
must be constant within the current group (that is, grouping constants
as defined by the GROUP BY clause, or constants), or aggregate
functions, or a combination of constants and aggregate
functions. Aggregate and grouping functions may only appear in an
aggregate query, and only in a SELECT, HAVING or ORDER BY clause.</p>
<p>A scalar sub-query is a sub-query used as an expression.
If the sub-query returns no rows, the value is NULL; if it
returns more than one row, it is an error.</p>
<p>IN, EXISTS and scalar sub-queries can occur
in any place where an expression can occur (such as the SELECT clause,
WHERE clause, ON clause of a JOIN, or as an argument to an aggregate
function).</p>
<p>An IN, EXISTS or scalar sub-query may be correlated; that is, it
may refer to tables in the FROM clause of an enclosing query.</p>
<p><em>selectWithoutFrom</em> is equivalent to VALUES,
but is not standard SQL and is only allowed in certain
<a href="https://calcite.apache.org/apidocs/org/apache/calcite/sql/validate/SqlConformance.html#isFromRequired--">conformance levels</a>.</p>
<h2 id="keywords">Keywords</h2>
<p>The following is a list of SQL keywords. This list is also from Calcite SQL reference.
Reserved keywords are <strong>bold</strong>.</p>
<p>A,
<strong>ABS</strong>,
ABSOLUTE,
ACTION,
ADA,
ADD,
ADMIN,
AFTER,
<strong>ALL</strong>,
<strong>ALLOCATE</strong>,
<strong>ALLOW</strong>,
<strong>ALTER</strong>,
ALWAYS,
<strong>AND</strong>,
<strong>ANY</strong>,
<strong>ARE</strong>,
<strong>ARRAY</strong>,
<strong>AS</strong>,
ASC,
<strong>ASENSITIVE</strong>,
ASSERTION,
ASSIGNMENT,
<strong>ASYMMETRIC</strong>,
<strong>AT</strong>,
<strong>ATOMIC</strong>,
ATTRIBUTE,
ATTRIBUTES,
<strong>AUTHORIZATION</strong>,
<strong>AVG</strong>,
BEFORE,
<strong>BEGIN</strong>,
BERNOULLI,
<strong>BETWEEN</strong>,
<strong>BIGINT</strong>,
<strong>BINARY</strong>,
<strong>BIT</strong>,
<strong>BLOB</strong>,
<strong>BOOLEAN</strong>,
<strong>BOTH</strong>,
BREADTH,
<strong>BY</strong>,
C,
<strong>CALL</strong>,
<strong>CALLED</strong>,
<strong>CARDINALITY</strong>,
CASCADE,
<strong>CASCADED</strong>,
<strong>CASE</strong>,
<strong>CAST</strong>,
CATALOG,
CATALOG_NAME,
<strong>CEIL</strong>,
<strong>CEILING</strong>,
CENTURY,
CHAIN,
<strong>CHAR</strong>,
<strong>CHARACTER</strong>,
CHARACTERISTICTS,
CHARACTERS,
<strong>CHARACTER_LENGTH</strong>,
CHARACTER_SET_CATALOG,
CHARACTER_SET_NAME,
CHARACTER_SET_SCHEMA,
<strong>CHAR_LENGTH</strong>,
<strong>CHECK</strong>,
CLASS_ORIGIN,
<strong>CLOB</strong>,
<strong>CLOSE</strong>,
<strong>COALESCE</strong>,
COBOL,
<strong>COLLATE</strong>,
COLLATION,
COLLATION_CATALOG,
COLLATION_NAME,
COLLATION_SCHEMA,
<strong>COLLECT</strong>,
<strong>COLUMN</strong>,
COLUMN_NAME,
COMMAND_FUNCTION,
COMMAND_FUNCTION_CODE,
<strong>COMMIT</strong>,
COMMITTED,
<strong>CONDITION</strong>,
CONDITION_NUMBER,
<strong>CONNECT</strong>,
CONNECTION,
CONNECTION_NAME,
<strong>CONSTRAINT</strong>,
CONSTRAINTS,
CONSTRAINT_CATALOG,
CONSTRAINT_NAME,
CONSTRAINT_SCHEMA,
CONSTRUCTOR,
CONTAINS,
CONTINUE,
<strong>CONVERT</strong>,
<strong>CORR</strong>,
<strong>CORRESPONDING</strong>,
<strong>COUNT</strong>,
<strong>COVAR_POP</strong>,
<strong>COVAR_SAMP</strong>,
<strong>CREATE</strong>,
<strong>CROSS</strong>,
<strong>CUBE</strong>,
<strong>CUME_DIST</strong>,
<strong>CURRENT</strong>,
<strong>CURRENT_CATALOG</strong>,
<strong>CURRENT_DATE</strong>,
<strong>CURRENT_DEFAULT_TRANSFORM_GROUP</strong>,
<strong>CURRENT_PATH</strong>,
<strong>CURRENT_ROLE</strong>,
<strong>CURRENT_SCHEMA</strong>,
<strong>CURRENT_TIME</strong>,
<strong>CURRENT_TIMESTAMP</strong>,
<strong>CURRENT_TRANSFORM_GROUP_FOR_TYPE</strong>,
<strong>CURRENT_USER</strong>,
<strong>CURSOR</strong>,
CURSOR_NAME,
<strong>CYCLE</strong>,
DATA,
DATABASE,
<strong>DATE</strong>,
DATETIME_INTERVAL_CODE,
DATETIME_INTERVAL_PRECISION,
<strong>DAY</strong>,
<strong>DEALLOCATE</strong>,
<strong>DEC</strong>,
DECADE,
<strong>DECIMAL</strong>,
<strong>DECLARE</strong>,
<strong>DEFAULT</strong>,
DEFAULTS,
DEFERRABLE,
DEFERRED,
DEFINED,
DEFINER,
DEGREE,
<strong>DELETE</strong>,
<strong>DENSE_RANK</strong>,
DEPTH,
<strong>DEREF</strong>,
DERIVED,
DESC,
<strong>DESCRIBE</strong>,
DESCRIPTION,
DESCRIPTOR,
<strong>DETERMINISTIC</strong>,
DIAGNOSTICS,
<strong>DISALLOW</strong>,
<strong>DISCONNECT</strong>,
DISPATCH,
<strong>DISTINCT</strong>,
DOMAIN,
<strong>DOUBLE</strong>,
DOW,
DOY,
<strong>DROP</strong>,
<strong>DYNAMIC</strong>,
DYNAMIC_FUNCTION,
DYNAMIC_FUNCTION_CODE,
<strong>EACH</strong>,
<strong>ELEMENT</strong>,
<strong>ELSE</strong>,
<strong>END</strong>,
<strong>END-EXEC</strong>,
EPOCH,
EQUALS,
<strong>ESCAPE</strong>,
<strong>EVERY</strong>,
<strong>EXCEPT</strong>,
EXCEPTION,
EXCLUDE,
EXCLUDING,
<strong>EXEC</strong>,
<strong>EXECUTE</strong>,
<strong>EXISTS</strong>,
<strong>EXP</strong>,
<strong>EXPLAIN</strong>,
<strong>EXTEND</strong>,
<strong>EXTERNAL</strong>,
<strong>EXTRACT</strong>,
<strong>FALSE</strong>,
<strong>FETCH</strong>,
<strong>FILTER</strong>,
FINAL,
FIRST,
<strong>FIRST_VALUE</strong>,
<strong>FLOAT</strong>,
<strong>FLOOR</strong>,
FOLLOWING,
<strong>FOR</strong>,
<strong>FOREIGN</strong>,
FORTRAN,
FOUND,
FRAC_SECOND,
<strong>FREE</strong>,
<strong>FROM</strong>,
<strong>FULL</strong>,
<strong>FUNCTION</strong>,
<strong>FUSION</strong>,
G,
GENERAL,
GENERATED,
<strong>GET</strong>,
<strong>GLOBAL</strong>,
GO,
GOTO,
<strong>GRANT</strong>,
GRANTED,
<strong>GROUP</strong>,
<strong>GROUPING</strong>,
<strong>HAVING</strong>,
HIERARCHY,
<strong>HOLD</strong>,
<strong>HOUR</strong>,
<strong>IDENTITY</strong>,
IMMEDIATE,
IMPLEMENTATION,
<strong>IMPORT</strong>,
<strong>IN</strong>,
INCLUDING,
INCREMENT,
<strong>INDICATOR</strong>,
INITIALLY,
<strong>INNER</strong>,
<strong>INOUT</strong>,
INPUT,
<strong>INSENSITIVE</strong>,
<strong>INSERT</strong>,
INSTANCE,
INSTANTIABLE,
<strong>INT</strong>,
<strong>INTEGER</strong>,
<strong>INTERSECT</strong>,
<strong>INTERSECTION</strong>,
<strong>INTERVAL</strong>,
<strong>INTO</strong>,
INVOKER,
<strong>IS</strong>,
ISOLATION,
JAVA,
<strong>JOIN</strong>,
K,
KEY,
KEY_MEMBER,
KEY_TYPE,
LABEL,
<strong>LANGUAGE</strong>,
<strong>LARGE</strong>,
LAST,
<strong>LAST_VALUE</strong>,
<strong>LATERAL</strong>,
<strong>LEADING</strong>,
<strong>LEFT</strong>,
LENGTH,
LEVEL,
LIBRARY,
<strong>LIKE</strong>,
<strong>LIMIT</strong>,
<strong>LN</strong>,
<strong>LOCAL</strong>,
<strong>LOCALTIME</strong>,
<strong>LOCALTIMESTAMP</strong>,
LOCATOR,
<strong>LOWER</strong>,
M,
MAP,
<strong>MATCH</strong>,
MATCHED,
<strong>MAX</strong>,
MAXVALUE,
<strong>MEMBER</strong>,
<strong>MERGE</strong>,
MESSAGE_LENGTH,
MESSAGE_OCTET_LENGTH,
MESSAGE_TEXT,
<strong>METHOD</strong>,
MICROSECOND,
MILLENNIUM,
<strong>MIN</strong>,
<strong>MINUTE</strong>,
MINVALUE,
<strong>MOD</strong>,
<strong>MODIFIES</strong>,
<strong>MODULE</strong>,
<strong>MONTH</strong>,
MORE,
<strong>MULTISET</strong>,
MUMPS,
NAME,
NAMES,
<strong>NATIONAL</strong>,
<strong>NATURAL</strong>,
<strong>NCHAR</strong>,
<strong>NCLOB</strong>,
NESTING,
<strong>NEW</strong>,
<strong>NEXT</strong>,
<strong>NO</strong>,
<strong>NONE</strong>,
<strong>NORMALIZE</strong>,
NORMALIZED,
<strong>NOT</strong>,
<strong>NULL</strong>,
NULLABLE,
<strong>NULLIF</strong>,
NULLS,
NUMBER,
<strong>NUMERIC</strong>,
OBJECT,
OCTETS,
<strong>OCTET_LENGTH</strong>,
<strong>OF</strong>,
<strong>OFFSET</strong>,
<strong>OLD</strong>,
<strong>ON</strong>,
<strong>ONLY</strong>,
<strong>OPEN</strong>,
OPTION,
OPTIONS,
<strong>OR</strong>,
<strong>ORDER</strong>,
ORDERING,
ORDINALITY,
OTHERS,
<strong>OUT</strong>,
<strong>OUTER</strong>,
OUTPUT,
<strong>OVER</strong>,
<strong>OVERLAPS</strong>,
<strong>OVERLAY</strong>,
OVERRIDING,
PAD,
<strong>PARAMETER</strong>,
PARAMETER_MODE,
PARAMETER_NAME,
PARAMETER_ORDINAL_POSITION,
PARAMETER_SPECIFIC_CATALOG,
PARAMETER_SPECIFIC_NAME,
PARAMETER_SPECIFIC_SCHEMA,
PARTIAL,
<strong>PARTITION</strong>,
PASCAL,
PASSTHROUGH,
PATH,
<strong>PERCENTILE_CONT</strong>,
<strong>PERCENTILE_DISC</strong>,
<strong>PERCENT_RANK</strong>,
PLACING,
PLAN,
PLI,
<strong>POSITION</strong>,
<strong>POWER</strong>,
PRECEDING,
<strong>PRECISION</strong>,
<strong>PREPARE</strong>,
PRESERVE,
<strong>PRIMARY</strong>,
PRIOR,
PRIVILEGES,
<strong>PROCEDURE</strong>,
PUBLIC,
QUARTER,
<strong>RANGE</strong>,
<strong>RANK</strong>,
READ,
<strong>READS</strong>,
<strong>REAL</strong>,
<strong>RECURSIVE</strong>,
<strong>REF</strong>,
<strong>REFERENCES</strong>,
<strong>REFERENCING</strong>,
<strong>REGR_AVGX</strong>,
<strong>REGR_AVGY</strong>,
<strong>REGR_COUNT</strong>,
<strong>REGR_INTERCEPT</strong>,
<strong>REGR_R2</strong>,
<strong>REGR_SLOPE</strong>,
<strong>REGR_SXX</strong>,
<strong>REGR_SXY</strong>,
<strong>REGR_SYY</strong>,
RELATIVE,
<strong>RELEASE</strong>,
REPEATABLE,
<strong>RESET</strong>,
RESTART,
RESTRICT,
<strong>RESULT</strong>,
<strong>RETURN</strong>,
RETURNED_CARDINALITY,
RETURNED_LENGTH,
RETURNED_OCTET_LENGTH,
RETURNED_SQLSTATE,
<strong>RETURNS</strong>,
<strong>REVOKE</strong>,
<strong>RIGHT</strong>,
ROLE,
<strong>ROLLBACK</strong>,
<strong>ROLLUP</strong>,
ROUTINE,
ROUTINE_CATALOG,
ROUTINE_NAME,
ROUTINE_SCHEMA,
<strong>ROW</strong>,
<strong>ROWS</strong>,
ROW_COUNT,
<strong>ROW_NUMBER</strong>,
<strong>SAVEPOINT</strong>,
SCALE,
SCHEMA,
SCHEMA_NAME,
<strong>SCOPE</strong>,
SCOPE_CATALOGS,
SCOPE_NAME,
SCOPE_SCHEMA,
<strong>SCROLL</strong>,
<strong>SEARCH</strong>,
<strong>SECOND</strong>,
SECTION,
SECURITY,
<strong>SELECT</strong>,
SELF,
<strong>SENSITIVE</strong>,
SEQUENCE,
SERIALIZABLE,
SERVER,
SERVER_NAME,
SESSION,
<strong>SESSION_USER</strong>,
<strong>SET</strong>,
SETS,
<strong>SIMILAR</strong>,
SIMPLE,
SIZE,
<strong>SMALLINT</strong>,
<strong>SOME</strong>,
SOURCE,
SPACE,
<strong>SPECIFIC</strong>,
<strong>SPECIFICTYPE</strong>,
SPECIFIC_NAME,
<strong>SQL</strong>,
<strong>SQLEXCEPTION</strong>,
<strong>SQLSTATE</strong>,
<strong>SQLWARNING</strong>,
SQL_TSI_DAY,
SQL_TSI_FRAC_SECOND,
SQL_TSI_HOUR,
SQL_TSI_MICROSECOND,
SQL_TSI_MINUTE,
SQL_TSI_MONTH,
SQL_TSI_QUARTER,
SQL_TSI_SECOND,
SQL_TSI_WEEK,
SQL_TSI_YEAR,
<strong>SQRT</strong>,
<strong>START</strong>,
STATE,
STATEMENT,
<strong>STATIC</strong>,
<strong>STDDEV_POP</strong>,
<strong>STDDEV_SAMP</strong>,
<strong>STREAM</strong>,
STRUCTURE,
STYLE,
SUBCLASS_ORIGIN,
<strong>SUBMULTISET</strong>,
SUBSTITUTE,
<strong>SUBSTRING</strong>,
<strong>SUM</strong>,
<strong>SYMMETRIC</strong>,
<strong>SYSTEM</strong>,
<strong>SYSTEM_USER</strong>,
<strong>TABLE</strong>,
<strong>TABLESAMPLE</strong>,
TABLE_NAME,
TEMPORARY,
<strong>THEN</strong>,
TIES,
<strong>TIME</strong>,
<strong>TIMESTAMP</strong>,
TIMESTAMPADD,
TIMESTAMPDIFF,
<strong>TIMEZONE_HOUR</strong>,
<strong>TIMEZONE_MINUTE</strong>,
<strong>TINYINT</strong>,
<strong>TO</strong>,
TOP_LEVEL_COUNT,
<strong>TRAILING</strong>,
TRANSACTION,
TRANSACTIONS_ACTIVE,
TRANSACTIONS_COMMITTED,
TRANSACTIONS_ROLLED_BACK,
TRANSFORM,
TRANSFORMS,
<strong>TRANSLATE</strong>,
<strong>TRANSLATION</strong>,
<strong>TREAT</strong>,
<strong>TRIGGER</strong>,
TRIGGER_CATALOG,
TRIGGER_NAME,
TRIGGER_SCHEMA,
<strong>TRIM</strong>,
<strong>TRUE</strong>,
TYPE,
<strong>UESCAPE</strong>,
UNBOUNDED,
UNCOMMITTED,
UNDER,
<strong>UNION</strong>,
<strong>UNIQUE</strong>,
<strong>UNKNOWN</strong>,
UNNAMED,
<strong>UNNEST</strong>,
<strong>UPDATE</strong>,
<strong>UPPER</strong>,
<strong>UPSERT</strong>,
USAGE,
<strong>USER</strong>,
USER_DEFINED_TYPE_CATALOG,
USER_DEFINED_TYPE_CODE,
USER_DEFINED_TYPE_NAME,
USER_DEFINED_TYPE_SCHEMA,
<strong>USING</strong>,
<strong>VALUE</strong>,
<strong>VALUES</strong>,
<strong>VARBINARY</strong>,
<strong>VARCHAR</strong>,
<strong>VARYING</strong>,
<strong>VAR_POP</strong>,
<strong>VAR_SAMP</strong>,
VERSION,
VIEW,
WEEK,
<strong>WHEN</strong>,
<strong>WHENEVER</strong>,
<strong>WHERE</strong>,
<strong>WIDTH_BUCKET</strong>,
<strong>WINDOW</strong>,
<strong>WITH</strong>,
<strong>WITHIN</strong>,
<strong>WITHOUT</strong>,
WORK,
WRAPPER,
WRITE,
XML,
<strong>YEAR</strong>,
ZONE.</p>
<h2 id="identifiers">Identifiers</h2>
<p>Identifiers are the names of tables, columns and other metadata
elements used in a SQL query.</p>
<p>Unquoted identifiers, such as emp, must start with a letter and can
only contain letters, digits, and underscores. They are implicitly
converted to upper case.</p>
<p>Quoted identifiers, such as <code>&quot;Employee Name&quot;</code>, start and end with
double quotes. They may contain virtually any character, including
spaces and other punctuation. If you wish to include a double quote
in an identifier, use another double quote to escape it, like this:
<code>&quot;An employee called &quot;&quot;Fred&quot;&quot;.&quot;</code>.</p>
<p>In Calcite, matching identifiers to the name of the referenced object is
case-sensitive. But remember that unquoted identifiers are implicitly
converted to upper case before matching, and if the object it refers
to was created using an unquoted identifier for its name, then its
name will have been converted to upper case also.</p>
<h2 id="data-types">Data types</h2>
<h3 id="scalar-types">Scalar types</h3>
<table><thead>
<tr>
<th style="text-align: left">Data type</th>
<th style="text-align: left">Description</th>
<th style="text-align: left">Range and examples</th>
</tr>
</thead><tbody>
<tr>
<td style="text-align: left">BOOLEAN</td>
<td style="text-align: left">Logical values</td>
<td style="text-align: left">Values: TRUE, FALSE, UNKNOWN</td>
</tr>
<tr>
<td style="text-align: left">TINYINT</td>
<td style="text-align: left">1 byte signed integer</td>
<td style="text-align: left">Range is -255 to 256</td>
</tr>
<tr>
<td style="text-align: left">SMALLINT</td>
<td style="text-align: left">2 byte signed integer</td>
<td style="text-align: left">Range is -32768 to 32767</td>
</tr>
<tr>
<td style="text-align: left">INTEGER, INT</td>
<td style="text-align: left">4 byte signed integer</td>
<td style="text-align: left">Range is -2147483648 to 2147483647</td>
</tr>
<tr>
<td style="text-align: left">BIGINT</td>
<td style="text-align: left">8 byte signed integer</td>
<td style="text-align: left">Range is -9223372036854775808 to 9223372036854775807</td>
</tr>
<tr>
<td style="text-align: left">DECIMAL(p, s)</td>
<td style="text-align: left">Fixed point</td>
<td style="text-align: left">Example: 123.45 is a DECIMAL(5, 2) value.</td>
</tr>
<tr>
<td style="text-align: left">NUMERIC</td>
<td style="text-align: left">Fixed point</td>
<td style="text-align: left"></td>
</tr>
<tr>
<td style="text-align: left">REAL, FLOAT</td>
<td style="text-align: left">4 byte floating point</td>
<td style="text-align: left">6 decimal digits precision</td>
</tr>
<tr>
<td style="text-align: left">DOUBLE</td>
<td style="text-align: left">8 byte floating point</td>
<td style="text-align: left">15 decimal digits precision</td>
</tr>
<tr>
<td style="text-align: left">CHAR(n), CHARACTER(n)</td>
<td style="text-align: left">Fixed-width character string</td>
<td style="text-align: left">&#39;Hello&#39;, &#39;&#39; (empty string), _latin1&#39;Hello&#39;, n&#39;Hello&#39;, _UTF16&#39;Hello&#39;, &#39;Hello&#39; &#39;there&#39; (literal split into multiple parts)</td>
</tr>
<tr>
<td style="text-align: left">VARCHAR(n), CHARACTER VARYING(n)</td>
<td style="text-align: left">Variable-length character string</td>
<td style="text-align: left">As CHAR(n)</td>
</tr>
<tr>
<td style="text-align: left">BINARY(n)</td>
<td style="text-align: left">Fixed-width binary string</td>
<td style="text-align: left">x&#39;45F0AB&#39;, x&#39;&#39; (empty binary string), x&#39;AB&#39; &#39;CD&#39; (multi-part binary string literal)</td>
</tr>
<tr>
<td style="text-align: left">VARBINARY(n), BINARY VARYING(n)</td>
<td style="text-align: left">Variable-length binary string</td>
<td style="text-align: left">As BINARY(n)</td>
</tr>
<tr>
<td style="text-align: left">DATE</td>
<td style="text-align: left">Date</td>
<td style="text-align: left">Example: DATE &#39;1969-07-20&#39;</td>
</tr>
<tr>
<td style="text-align: left">TIME</td>
<td style="text-align: left">Time of day</td>
<td style="text-align: left">Example: TIME &#39;20:17:40&#39;</td>
</tr>
<tr>
<td style="text-align: left">TIMESTAMP [ WITHOUT TIME ZONE ]</td>
<td style="text-align: left">Date and time</td>
<td style="text-align: left">Example: TIMESTAMP &#39;1969-07-20 20:17:40&#39;</td>
</tr>
<tr>
<td style="text-align: left">TIMESTAMP WITH TIME ZONE</td>
<td style="text-align: left">Date and time with time zone</td>
<td style="text-align: left">Example: TIMESTAMP &#39;1969-07-20 20:17:40 America/Los Angeles&#39;</td>
</tr>
<tr>
<td style="text-align: left">INTERVAL timeUnit [ TO timeUnit ]</td>
<td style="text-align: left">Date time interval</td>
<td style="text-align: left">Examples: INTERVAL &#39;1:5&#39; YEAR TO MONTH, INTERVAL &#39;45&#39; DAY</td>
</tr>
<tr>
<td style="text-align: left">Anchored interval</td>
<td style="text-align: left">Date time interval</td>
<td style="text-align: left">Example: (DATE &#39;1969-07-20&#39;, DATE &#39;1972-08-29&#39;)</td>
</tr>
</tbody></table>
<p>Where:</p>
<figure class="highlight"><pre><code class="language-sql" data-lang="sql"><span class="n">timeUnit</span><span class="p">:</span>
<span class="n">MILLENNIUM</span> <span class="o">|</span> <span class="n">CENTURY</span> <span class="o">|</span> <span class="n">DECADE</span> <span class="o">|</span> <span class="k">YEAR</span> <span class="o">|</span> <span class="n">QUARTER</span> <span class="o">|</span> <span class="k">MONTH</span> <span class="o">|</span> <span class="n">WEEK</span> <span class="o">|</span> <span class="n">DOY</span> <span class="o">|</span> <span class="n">DOW</span> <span class="o">|</span> <span class="k">DAY</span> <span class="o">|</span> <span class="n">HOUR</span> <span class="o">|</span> <span class="k">MINUTE</span> <span class="o">|</span> <span class="k">SECOND</span> <span class="o">|</span> <span class="n">EPOCH</span></code></pre></figure>
<p>Note:</p>
<ul>
<li>DATE, TIME and TIMESTAMP have no time zone. There is not even an implicit
time zone, such as UTC (as in Java) or the local time zone. It is left to
the user or application to supply a time zone.</li>
</ul>
<h3 id="non-scalar-types">Non-scalar types</h3>
<table><thead>
<tr>
<th style="text-align: left">Type</th>
<th style="text-align: left">Description</th>
</tr>
</thead><tbody>
<tr>
<td style="text-align: left">ANY</td>
<td style="text-align: left">A value of an unknown type</td>
</tr>
<tr>
<td style="text-align: left">ROW</td>
<td style="text-align: left">Row with 1 or more columns</td>
</tr>
<tr>
<td style="text-align: left">MAP</td>
<td style="text-align: left">Collection of keys mapped to values</td>
</tr>
<tr>
<td style="text-align: left">MULTISET</td>
<td style="text-align: left">Unordered collection that may contain duplicates</td>
</tr>
<tr>
<td style="text-align: left">ARRAY</td>
<td style="text-align: left">Ordered, contiguous collection that may contain duplicates</td>
</tr>
<tr>
<td style="text-align: left">CURSOR</td>
<td style="text-align: left">Cursor over the result of executing a query</td>
</tr>
</tbody></table>
<h2 id="operators-and-functions">Operators and functions</h2>
<h3 id="operator-precedence">Operator precedence</h3>
<p>The operator precedence and associativity, highest to lowest.</p>
<table><thead>
<tr>
<th style="text-align: left">Operator</th>
<th style="text-align: left">Associativity</th>
</tr>
</thead><tbody>
<tr>
<td style="text-align: left">.</td>
<td style="text-align: left">left</td>
</tr>
<tr>
<td style="text-align: left">[ ] (array element)</td>
<td style="text-align: left">left</td>
</tr>
<tr>
<td style="text-align: left">+ - (unary plus, minus)</td>
<td style="text-align: left">right</td>
</tr>
<tr>
<td style="text-align: left">* /</td>
<td style="text-align: left">left</td>
</tr>
<tr>
<td style="text-align: left">+ -</td>
<td style="text-align: left">left</td>
</tr>
<tr>
<td style="text-align: left">BETWEEN, IN, LIKE, SIMILAR</td>
<td style="text-align: left">-</td>
</tr>
<tr>
<td style="text-align: left">&lt; &gt; = &lt;= &gt;= &lt;&gt; !=</td>
<td style="text-align: left">left</td>
</tr>
<tr>
<td style="text-align: left">IS NULL, IS FALSE, IS NOT TRUE etc.</td>
<td style="text-align: left">-</td>
</tr>
<tr>
<td style="text-align: left">NOT</td>
<td style="text-align: left">right</td>
</tr>
<tr>
<td style="text-align: left">AND</td>
<td style="text-align: left">left</td>
</tr>
<tr>
<td style="text-align: left">OR</td>
<td style="text-align: left">left</td>
</tr>
</tbody></table>
<h3 id="comparison-operators">Comparison operators</h3>
<table><thead>
<tr>
<th style="text-align: left">Operator syntax</th>
<th style="text-align: left">Description</th>
</tr>
</thead><tbody>
<tr>
<td style="text-align: left">value1 = value2</td>
<td style="text-align: left">Equals</td>
</tr>
<tr>
<td style="text-align: left">value1 &lt;&gt; value2</td>
<td style="text-align: left">Not equal</td>
</tr>
<tr>
<td style="text-align: left">value1 != value2</td>
<td style="text-align: left">Not equal (only available at some conformance levels)</td>
</tr>
<tr>
<td style="text-align: left">value1 &gt; value2</td>
<td style="text-align: left">Greater than</td>
</tr>
<tr>
<td style="text-align: left">value1 &gt;= value2</td>
<td style="text-align: left">Greater than or equal</td>
</tr>
<tr>
<td style="text-align: left">value1 &lt; value2</td>
<td style="text-align: left">Less than</td>
</tr>
<tr>
<td style="text-align: left">value1 &lt;= value2</td>
<td style="text-align: left">Less than or equal</td>
</tr>
<tr>
<td style="text-align: left">value IS NULL</td>
<td style="text-align: left">Whether <em>value</em> is null</td>
</tr>
<tr>
<td style="text-align: left">value IS NOT NULL</td>
<td style="text-align: left">Whether <em>value</em> is not null</td>
</tr>
<tr>
<td style="text-align: left">value1 IS DISTINCT FROM value2</td>
<td style="text-align: left">Whether two values are not equal, treating null values as the same</td>
</tr>
<tr>
<td style="text-align: left">value1 IS NOT DISTINCT FROM value2</td>
<td style="text-align: left">Whether two values are equal, treating null values as the same</td>
</tr>
<tr>
<td style="text-align: left">value1 BETWEEN value2 AND value3</td>
<td style="text-align: left">Whether <em>value1</em> is greater than or equal to <em>value2</em> and less than or equal to <em>value3</em></td>
</tr>
<tr>
<td style="text-align: left">value1 NOT BETWEEN value2 AND value3</td>
<td style="text-align: left">Whether <em>value1</em> is less than <em>value2</em> or greater than <em>value3</em></td>
</tr>
<tr>
<td style="text-align: left">string1 LIKE string2 [ ESCAPE string3 ]</td>
<td style="text-align: left">Whether <em>string1</em> matches pattern <em>string2</em></td>
</tr>
<tr>
<td style="text-align: left">string1 NOT LIKE string2 [ ESCAPE string3 ]</td>
<td style="text-align: left">Whether <em>string1</em> does not match pattern <em>string2</em></td>
</tr>
<tr>
<td style="text-align: left">string1 SIMILAR TO string2 [ ESCAPE string3 ]</td>
<td style="text-align: left">Whether <em>string1</em> matches regular expression <em>string2</em></td>
</tr>
<tr>
<td style="text-align: left">string1 NOT SIMILAR TO string2 [ ESCAPE string3 ]</td>
<td style="text-align: left">Whether <em>string1</em> does not match regular expression <em>string2</em></td>
</tr>
<tr>
<td style="text-align: left">value IN (value [, value]* )</td>
<td style="text-align: left">Whether <em>value</em> is equal to a value in a list</td>
</tr>
<tr>
<td style="text-align: left">value NOT IN (value [, value]* )</td>
<td style="text-align: left">Whether <em>value</em> is not equal to every value in a list</td>
</tr>
</tbody></table>
<p>Not supported yet on Storm SQL:</p>
<table><thead>
<tr>
<th style="text-align: left">Operator syntax</th>
<th style="text-align: left">Description</th>
</tr>
</thead><tbody>
<tr>
<td style="text-align: left">value IN (sub-query)</td>
<td style="text-align: left">Whether <em>value</em> is equal to a row returned by <em>sub-query</em></td>
</tr>
<tr>
<td style="text-align: left">value NOT IN (sub-query)</td>
<td style="text-align: left">Whether <em>value</em> is not equal to every row returned by <em>sub-query</em></td>
</tr>
<tr>
<td style="text-align: left">EXISTS (sub-query)</td>
<td style="text-align: left">Whether <em>sub-query</em> returns at least one row</td>
</tr>
</tbody></table>
<p>Storm SQL doesn&#39;t support sub-query yet, so above operators don&#39;t work properly. This will be addressed in near future. </p>
<h3 id="logical-operators">Logical operators</h3>
<table><thead>
<tr>
<th style="text-align: left">Operator syntax</th>
<th style="text-align: left">Description</th>
</tr>
</thead><tbody>
<tr>
<td style="text-align: left">boolean1 OR boolean2</td>
<td style="text-align: left">Whether <em>boolean1</em> is TRUE or <em>boolean2</em> is TRUE</td>
</tr>
<tr>
<td style="text-align: left">boolean1 AND boolean2</td>
<td style="text-align: left">Whether <em>boolean1</em> and <em>boolean2</em> are both TRUE</td>
</tr>
<tr>
<td style="text-align: left">NOT boolean</td>
<td style="text-align: left">Whether <em>boolean</em> is not TRUE; returns UNKNOWN if <em>boolean</em> is UNKNOWN</td>
</tr>
<tr>
<td style="text-align: left">boolean IS FALSE</td>
<td style="text-align: left">Whether <em>boolean</em> is FALSE; returns FALSE if <em>boolean</em> is UNKNOWN</td>
</tr>
<tr>
<td style="text-align: left">boolean IS NOT FALSE</td>
<td style="text-align: left">Whether <em>boolean</em> is not FALSE; returns TRUE if <em>boolean</em> is UNKNOWN</td>
</tr>
<tr>
<td style="text-align: left">boolean IS TRUE</td>
<td style="text-align: left">Whether <em>boolean</em> is TRUE; returns FALSE if <em>boolean</em> is UNKNOWN</td>
</tr>
<tr>
<td style="text-align: left">boolean IS NOT TRUE</td>
<td style="text-align: left">Whether <em>boolean</em> is not TRUE; returns TRUE if <em>boolean</em> is UNKNOWN</td>
</tr>
<tr>
<td style="text-align: left">boolean IS UNKNOWN</td>
<td style="text-align: left">Whether <em>boolean</em> is UNKNOWN</td>
</tr>
<tr>
<td style="text-align: left">boolean IS NOT UNKNOWN</td>
<td style="text-align: left">Whether <em>boolean</em> is not UNKNOWN</td>
</tr>
</tbody></table>
<h3 id="arithmetic-operators-and-functions">Arithmetic operators and functions</h3>
<table><thead>
<tr>
<th style="text-align: left">Operator syntax</th>
<th style="text-align: left">Description</th>
</tr>
</thead><tbody>
<tr>
<td style="text-align: left">+ numeric</td>
<td style="text-align: left">Returns <em>numeric</em></td>
</tr>
<tr>
<td style="text-align: left">:- numeric</td>
<td style="text-align: left">Returns negative <em>numeric</em></td>
</tr>
<tr>
<td style="text-align: left">numeric1 + numeric2</td>
<td style="text-align: left">Returns <em>numeric1</em> plus <em>numeric2</em></td>
</tr>
<tr>
<td style="text-align: left">numeric1 - numeric2</td>
<td style="text-align: left">Returns <em>numeric1</em> minus <em>numeric2</em></td>
</tr>
<tr>
<td style="text-align: left">numeric1 * numeric2</td>
<td style="text-align: left">Returns <em>numeric1</em> multiplied by <em>numeric2</em></td>
</tr>
<tr>
<td style="text-align: left">numeric1 / numeric2</td>
<td style="text-align: left">Returns <em>numeric1</em> divided by <em>numeric2</em></td>
</tr>
<tr>
<td style="text-align: left">POWER(numeric1, numeric2)</td>
<td style="text-align: left">Returns <em>numeric1</em> raised to the power of <em>numeric2</em></td>
</tr>
<tr>
<td style="text-align: left">ABS(numeric)</td>
<td style="text-align: left">Returns the absolute value of <em>numeric</em></td>
</tr>
<tr>
<td style="text-align: left">MOD(numeric, numeric)</td>
<td style="text-align: left">Returns the remainder (modulus) of <em>numeric1</em> divided by <em>numeric2</em>. The result is negative only if <em>numeric1</em> is negative</td>
</tr>
<tr>
<td style="text-align: left">SQRT(numeric)</td>
<td style="text-align: left">Returns the square root of <em>numeric</em></td>
</tr>
<tr>
<td style="text-align: left">LN(numeric)</td>
<td style="text-align: left">Returns the natural logarithm (base <em>e</em>) of <em>numeric</em></td>
</tr>
<tr>
<td style="text-align: left">LOG10(numeric)</td>
<td style="text-align: left">Returns the base 10 logarithm of <em>numeric</em></td>
</tr>
<tr>
<td style="text-align: left">EXP(numeric)</td>
<td style="text-align: left">Returns <em>e</em> raised to the power of <em>numeric</em></td>
</tr>
<tr>
<td style="text-align: left">CEIL(numeric)</td>
<td style="text-align: left">Rounds <em>numeric</em> up, and returns the smallest number that is greater than or equal to <em>numeric</em></td>
</tr>
<tr>
<td style="text-align: left">FLOOR(numeric)</td>
<td style="text-align: left">Rounds <em>numeric</em> down, and returns the largest number that is less than or equal to <em>numeric</em></td>
</tr>
</tbody></table>
<h3 id="character-string-operators-and-functions">Character string operators and functions</h3>
<table><thead>
<tr>
<th style="text-align: left">Operator syntax</th>
<th style="text-align: left">Description</th>
</tr>
</thead><tbody>
<tr>
<td style="text-align: left">string &#124;&#124; string</td>
<td style="text-align: left">Concatenates two character strings.</td>
</tr>
<tr>
<td style="text-align: left">CHAR_LENGTH(string)</td>
<td style="text-align: left">Returns the number of characters in a character string</td>
</tr>
<tr>
<td style="text-align: left">CHARACTER_LENGTH(string)</td>
<td style="text-align: left">As CHAR_LENGTH(<em>string</em>)</td>
</tr>
<tr>
<td style="text-align: left">UPPER(string)</td>
<td style="text-align: left">Returns a character string converted to upper case</td>
</tr>
<tr>
<td style="text-align: left">LOWER(string)</td>
<td style="text-align: left">Returns a character string converted to lower case</td>
</tr>
<tr>
<td style="text-align: left">POSITION(string1 IN string2)</td>
<td style="text-align: left">Returns the position of the first occurrence of <em>string1</em> in <em>string2</em></td>
</tr>
<tr>
<td style="text-align: left">TRIM( { BOTH &#124; LEADING &#124; TRAILING } string1 FROM string2)</td>
<td style="text-align: left">Removes the longest string containing only the characters in <em>string1</em> from the start/end/both ends of <em>string1</em></td>
</tr>
<tr>
<td style="text-align: left">OVERLAY(string1 PLACING string2 FROM integer [ FOR integer2 ])</td>
<td style="text-align: left">Replaces a substring of <em>string1</em> with <em>string2</em></td>
</tr>
<tr>
<td style="text-align: left">SUBSTRING(string FROM integer)</td>
<td style="text-align: left">Returns a substring of a character string starting at a given point.</td>
</tr>
<tr>
<td style="text-align: left">SUBSTRING(string FROM integer FOR integer)</td>
<td style="text-align: left">Returns a substring of a character string starting at a given point with a given length.</td>
</tr>
<tr>
<td style="text-align: left">INITCAP(string)</td>
<td style="text-align: left">Returns <em>string</em> with the first letter of each word converter to upper case and the rest to lower case. Words are sequences of alphanumeric characters separated by non-alphanumeric characters.</td>
</tr>
</tbody></table>
<p>Not implemented:</p>
<ul>
<li>SUBSTRING(string FROM regexp FOR regexp)</li>
</ul>
<h3 id="binary-string-operators-and-functions">Binary string operators and functions</h3>
<table><thead>
<tr>
<th style="text-align: left">Operator syntax</th>
<th style="text-align: left">Description</th>
</tr>
</thead><tbody>
<tr>
<td style="text-align: left">binary &#124;&#124; binary</td>
<td style="text-align: left">Concatenates two binary strings.</td>
</tr>
<tr>
<td style="text-align: left">POSITION(binary1 IN binary2)</td>
<td style="text-align: left">Returns the position of the first occurrence of <em>binary1</em> in <em>binary2</em></td>
</tr>
<tr>
<td style="text-align: left">OVERLAY(binary1 PLACING binary2 FROM integer [ FOR integer2 ])</td>
<td style="text-align: left">Replaces a substring of <em>binary1</em> with <em>binary2</em></td>
</tr>
</tbody></table>
<p>Known bugs:</p>
<table><thead>
<tr>
<th style="text-align: left">Operator syntax</th>
<th style="text-align: left">Description</th>
</tr>
</thead><tbody>
<tr>
<td style="text-align: left">SUBSTRING(binary FROM integer)</td>
<td style="text-align: left">Returns a substring of <em>binary</em> starting at a given point</td>
</tr>
<tr>
<td style="text-align: left">SUBSTRING(binary FROM integer FOR integer)</td>
<td style="text-align: left">Returns a substring of <em>binary</em> starting at a given point with a given length</td>
</tr>
</tbody></table>
<p>Calcite 1.9.0 has bugs on binary SUBSTRING functions which throws exception while compiling SQL statements. This can be fixed to higher version of Calcite.</p>
<h3 id="date-time-functions">Date/time functions</h3>
<table><thead>
<tr>
<th style="text-align: left">Operator syntax</th>
<th style="text-align: left">Description</th>
</tr>
</thead><tbody>
<tr>
<td style="text-align: left">EXTRACT(timeUnit FROM datetime)</td>
<td style="text-align: left">Extracts and returns the value of a specified datetime field from a datetime value expression</td>
</tr>
<tr>
<td style="text-align: left">FLOOR(datetime TO timeUnit)</td>
<td style="text-align: left">Rounds <em>datetime</em> down to <em>timeUnit</em></td>
</tr>
<tr>
<td style="text-align: left">CEIL(datetime TO timeUnit)</td>
<td style="text-align: left">Rounds <em>datetime</em> up to <em>timeUnit</em></td>
</tr>
</tbody></table>
<p>Not implemented:</p>
<ul>
<li>EXTRACT(timeUnit FROM interval)</li>
<li>CEIL(interval)</li>
<li>FLOOR(interval)</li>
<li>datetime - datetime timeUnit [ TO timeUnit ]</li>
<li>interval OVERLAPS interval</li>
<li>+ interval</li>
<li>- interval</li>
<li>interval + interval</li>
<li>interval - interval</li>
<li>interval / interval</li>
<li>datetime + interval</li>
<li>datetime - interval</li>
</ul>
<p>Note on Storm SQL:</p>
<table><thead>
<tr>
<th style="text-align: left">Operator syntax</th>
<th style="text-align: left">Description</th>
</tr>
</thead><tbody>
<tr>
<td style="text-align: left">LOCALTIME</td>
<td style="text-align: left">Returns the current date and time in the session time zone in a value of datatype TIME</td>
</tr>
<tr>
<td style="text-align: left">LOCALTIME(precision)</td>
<td style="text-align: left">Returns the current date and time in the session time zone in a value of datatype TIME, with <em>precision</em> digits of precision</td>
</tr>
<tr>
<td style="text-align: left">LOCALTIMESTAMP</td>
<td style="text-align: left">Returns the current date and time in the session time zone in a value of datatype TIMESTAMP</td>
</tr>
<tr>
<td style="text-align: left">LOCALTIMESTAMP(precision)</td>
<td style="text-align: left">Returns the current date and time in the session time zone in a value of datatype TIMESTAMP, with <em>precision</em> digits of precision</td>
</tr>
<tr>
<td style="text-align: left">CURRENT_TIME</td>
<td style="text-align: left">Returns the current time in the session time zone, in a value of datatype TIMESTAMP WITH TIME ZONE</td>
</tr>
<tr>
<td style="text-align: left">CURRENT_DATE</td>
<td style="text-align: left">Returns the current date in the session time zone, in a value of datatype DATE</td>
</tr>
<tr>
<td style="text-align: left">CURRENT_TIMESTAMP</td>
<td style="text-align: left">Returns the current date and time in the session time zone, in a value of datatype TIMESTAMP WITH TIME ZONE</td>
</tr>
</tbody></table>
<p>SQL standard states that above operators should return the same value while evaluating query.
Storm SQL converts each query to Trident topology and run, so technically current date / time should be fixed while evaluating SQL statement.
Because of this limitation, current date / time will be fixed while creating Trident topology, and these operators should return the same value in the lifecycle of topology.</p>
<h3 id="system-functions">System functions</h3>
<p>Not supported yet on Storm SQL:</p>
<table><thead>
<tr>
<th style="text-align: left">Operator syntax</th>
<th style="text-align: left">Description</th>
</tr>
</thead><tbody>
<tr>
<td style="text-align: left">USER</td>
<td style="text-align: left">Equivalent to CURRENT_USER</td>
</tr>
<tr>
<td style="text-align: left">CURRENT_USER</td>
<td style="text-align: left">User name of current execution context</td>
</tr>
<tr>
<td style="text-align: left">SESSION_USER</td>
<td style="text-align: left">Session user name</td>
</tr>
<tr>
<td style="text-align: left">SYSTEM_USER</td>
<td style="text-align: left">Returns the name of the current data store user as identified by the operating system</td>
</tr>
<tr>
<td style="text-align: left">CURRENT_PATH</td>
<td style="text-align: left">Returns a character string representing the current lookup scope for references to user-defined routines and types</td>
</tr>
<tr>
<td style="text-align: left">CURRENT_ROLE</td>
<td style="text-align: left">Returns the current active role</td>
</tr>
</tbody></table>
<p>These operators are not making sense of Storm SQL&#39;s runtime, so it may be never supported unless we find out proper semantics. </p>
<h3 id="conditional-functions-and-operators">Conditional functions and operators</h3>
<table><thead>
<tr>
<th style="text-align: left">Operator syntax</th>
<th style="text-align: left">Description</th>
</tr>
</thead><tbody>
<tr>
<td style="text-align: left">CASE value<br/>WHEN value1 [, value11 ]* THEN result1<br/>[ WHEN valueN [, valueN1 ]* THEN resultN ]*<br/>[ ELSE resultZ ]<br/> END</td>
<td style="text-align: left">Simple case</td>
</tr>
<tr>
<td style="text-align: left">CASE<br/>WHEN condition1 THEN result1<br/>[ WHEN conditionN THEN resultN ]*<br/>[ ELSE resultZ ]<br/>END</td>
<td style="text-align: left">Searched case</td>
</tr>
<tr>
<td style="text-align: left">NULLIF(value, value)</td>
<td style="text-align: left">Returns NULL if the values are the same.<br/><br/>For example, <code>NULLIF(5, 5)</code> returns NULL; <code>NULLIF(5, 0)</code> returns 5.</td>
</tr>
<tr>
<td style="text-align: left">COALESCE(value, value [, value ]* )</td>
<td style="text-align: left">Provides a value if the first value is null.<br/><br/>For example, <code>COALESCE(NULL, 5)</code> returns 5.</td>
</tr>
</tbody></table>
<h3 id="type-conversion">Type conversion</h3>
<table><thead>
<tr>
<th style="text-align: left">Operator syntax</th>
<th style="text-align: left">Description</th>
</tr>
</thead><tbody>
<tr>
<td style="text-align: left">CAST(value AS type)</td>
<td style="text-align: left">Converts a value to a given type.</td>
</tr>
</tbody></table>
<h3 id="value-constructors">Value constructors</h3>
<table><thead>
<tr>
<th style="text-align: left">Operator syntax</th>
<th style="text-align: left">Description</th>
</tr>
</thead><tbody>
<tr>
<td style="text-align: left">ROW (value [, value]* )</td>
<td style="text-align: left">Creates a row from a list of values.</td>
</tr>
<tr>
<td style="text-align: left">(value [, value]* )</td>
<td style="text-align: left">Creates a row from a list of values.</td>
</tr>
<tr>
<td style="text-align: left">map &#39;[&#39; key &#39;]&#39;</td>
<td style="text-align: left">Returns the element of a map with a particular key.</td>
</tr>
<tr>
<td style="text-align: left">array &#39;[&#39; index &#39;]&#39;</td>
<td style="text-align: left">Returns the element at a particular location in an array.</td>
</tr>
<tr>
<td style="text-align: left">ARRAY &#39;[&#39; value [, value ]* &#39;]&#39;</td>
<td style="text-align: left">Creates an array from a list of values.</td>
</tr>
<tr>
<td style="text-align: left">MAP &#39;[&#39; key, value [, key, value ]* &#39;]&#39;</td>
<td style="text-align: left">Creates a map from a list of key-value pairs.</td>
</tr>
</tbody></table>
<h3 id="collection-functions">Collection functions</h3>
<table><thead>
<tr>
<th style="text-align: left">Operator syntax</th>
<th style="text-align: left">Description</th>
</tr>
</thead><tbody>
<tr>
<td style="text-align: left">ELEMENT(value)</td>
<td style="text-align: left">Returns the sole element of a array or multiset; null if the collection is empty; throws if it has more than one element.</td>
</tr>
<tr>
<td style="text-align: left">CARDINALITY(value)</td>
<td style="text-align: left">Returns the number of elements in an array or multiset.</td>
</tr>
</tbody></table>
<p>See also: UNNEST relational operator converts a collection to a relation.</p>
<h3 id="jdbc-function-escape">JDBC function escape</h3>
<h4 id="numeric">Numeric</h4>
<table><thead>
<tr>
<th style="text-align: left">Operator syntax</th>
<th style="text-align: left">Description</th>
</tr>
</thead><tbody>
<tr>
<td style="text-align: left">{fn ABS(numeric)}</td>
<td style="text-align: left">Returns the absolute value of <em>numeric</em></td>
</tr>
<tr>
<td style="text-align: left">{fn EXP(numeric)}</td>
<td style="text-align: left">Returns <em>e</em> raised to the power of <em>numeric</em></td>
</tr>
<tr>
<td style="text-align: left">{fn LOG(numeric)}</td>
<td style="text-align: left">Returns the natural logarithm (base <em>e</em>) of <em>numeric</em></td>
</tr>
<tr>
<td style="text-align: left">{fn LOG10(numeric)}</td>
<td style="text-align: left">Returns the base-10 logarithm of <em>numeric</em></td>
</tr>
<tr>
<td style="text-align: left">{fn MOD(numeric1, numeric2)}</td>
<td style="text-align: left">Returns the remainder (modulus) of <em>numeric1</em> divided by <em>numeric2</em>. The result is negative only if <em>numeric1</em> is negative</td>
</tr>
<tr>
<td style="text-align: left">{fn POWER(numeric1, numeric2)}</td>
<td style="text-align: left">Returns <em>numeric1</em> raised to the power of <em>numeric2</em></td>
</tr>
</tbody></table>
<p>Not implemented:</p>
<ul>
<li>{fn ACOS(numeric)} - Returns the arc cosine of <em>numeric</em></li>
<li>{fn ASIN(numeric)} - Returns the arc sine of <em>numeric</em></li>
<li>{fn ATAN(numeric)} - Returns the arc tangent of <em>numeric</em></li>
<li>{fn ATAN2(numeric, numeric)}</li>
<li>{fn CEILING(numeric)} - Rounds <em>numeric</em> up, and returns the smallest number that is greater than or equal to <em>numeric</em></li>
<li>{fn COS(numeric)} - Returns the cosine of <em>numeric</em></li>
<li>{fn COT(numeric)}</li>
<li>{fn DEGREES(numeric)} - Converts <em>numeric</em> from radians to degrees</li>
<li>{fn FLOOR(numeric)} - Rounds <em>numeric</em> down, and returns the largest number that is less than or equal to <em>numeric</em></li>
<li>{fn PI()} - Returns a value that is closer than any other value to <em>pi</em></li>
<li>{fn RADIANS(numeric)} - Converts <em>numeric</em> from degrees to radians</li>
<li>{fn RAND(numeric)}</li>
<li>{fn ROUND(numeric, numeric)}</li>
<li>{fn SIGN(numeric)}</li>
<li>{fn SIN(numeric)} - Returns the sine of <em>numeric</em></li>
<li>{fn SQRT(numeric)} - Returns the square root of <em>numeric</em></li>
<li>{fn TAN(numeric)} - Returns the tangent of <em>numeric</em></li>
<li>{fn TRUNCATE(numeric, numeric)}</li>
</ul>
<h4 id="string">String</h4>
<table><thead>
<tr>
<th style="text-align: left">Operator syntax</th>
<th style="text-align: left">Description</th>
</tr>
</thead><tbody>
<tr>
<td style="text-align: left">{fn CONCAT(character, character)}</td>
<td style="text-align: left">Returns the concatenation of character strings</td>
</tr>
<tr>
<td style="text-align: left">{fn LOCATE(string1, string2)}</td>
<td style="text-align: left">Returns the position in <em>string2</em> of the first occurrence of <em>string1</em>. Searches from the beginning of the second CharacterExpression, unless the startIndex parameter is specified.</td>
</tr>
<tr>
<td style="text-align: left">{fn INSERT(string1, start, length, string2)}</td>
<td style="text-align: left">Inserts <em>string2</em> into a slot in <em>string1</em></td>
</tr>
<tr>
<td style="text-align: left">{fn LCASE(string)}</td>
<td style="text-align: left">Returns a string in which all alphabetic characters in <em>string</em> have been converted to lower case</td>
</tr>
<tr>
<td style="text-align: left">{fn LENGTH(string)}</td>
<td style="text-align: left">Returns the number of characters in a string</td>
</tr>
<tr>
<td style="text-align: left">{fn SUBSTRING(string, offset, length)}</td>
<td style="text-align: left">Returns a character string that consists of <em>length</em> characters from <em>string</em> starting at the <em>offset</em> position</td>
</tr>
<tr>
<td style="text-align: left">{fn UCASE(string)}</td>
<td style="text-align: left">Returns a string in which all alphabetic characters in <em>string</em> have been converted to upper case</td>
</tr>
</tbody></table>
<p>Known bugs:</p>
<table><thead>
<tr>
<th style="text-align: left">Operator syntax</th>
<th style="text-align: left">Description</th>
</tr>
</thead><tbody>
<tr>
<td style="text-align: left">{fn LOCATE(string1, string2 [, integer])}</td>
<td style="text-align: left">Returns the position in <em>string2</em> of the first occurrence of <em>string1</em>. Searches from the beginning of <em>string2</em>, unless <em>integer</em> is specified.</td>
</tr>
<tr>
<td style="text-align: left">{fn LTRIM(string)}</td>
<td style="text-align: left">Returns <em>string</em> with leading space characters removed</td>
</tr>
<tr>
<td style="text-align: left">{fn RTRIM(string)}</td>
<td style="text-align: left">Returns <em>string</em> with trailing space characters removed</td>
</tr>
</tbody></table>
<p>Calcite 1.9.0 throws exception on {fn LOCATE} with position parameter, {fn LTRIM} and {fn RTRIM} while compiling SQL statement.
This can be fixed to higher version of Calcite.</p>
<p>Not implemented:</p>
<ul>
<li>{fn ASCII(string)} - Convert a single-character string to the corresponding ASCII code, an integer between 0 and 255</li>
<li>{fn CHAR(string)}</li>
<li>{fn DIFFERENCE(string, string)}</li>
<li>{fn LEFT(string, integer)}</li>
<li>{fn REPEAT(string, integer)}</li>
<li>{fn REPLACE(string, string, string)}</li>
<li>{fn RIGHT(string, integer)}</li>
<li>{fn SOUNDEX(string)}</li>
<li>{fn SPACE(integer)}</li>
</ul>
<h4 id="date-time">Date/time</h4>
<table><thead>
<tr>
<th style="text-align: left">Operator syntax</th>
<th style="text-align: left">Description</th>
</tr>
</thead><tbody>
<tr>
<td style="text-align: left">{fn CURDATE()}</td>
<td style="text-align: left">Equivalent to <code>CURRENT_DATE</code></td>
</tr>
<tr>
<td style="text-align: left">{fn CURTIME()}</td>
<td style="text-align: left">Equivalent to <code>LOCALTIME</code></td>
</tr>
<tr>
<td style="text-align: left">{fn NOW()}</td>
<td style="text-align: left">Equivalent to <code>LOCALTIMESTAMP</code></td>
</tr>
<tr>
<td style="text-align: left">{fn QUARTER(date)}</td>
<td style="text-align: left">Equivalent to <code>EXTRACT(QUARTER FROM date)</code>. Returns an integer between 1 and 4.</td>
</tr>
<tr>
<td style="text-align: left">{fn TIMESTAMPADD(timeUnit, count, timestamp)}</td>
<td style="text-align: left">Adds an interval of <em>count</em> *timeUnit*s to a timestamp</td>
</tr>
<tr>
<td style="text-align: left">{fn TIMESTAMPDIFF(timeUnit, timestamp1, timestamp2)}</td>
<td style="text-align: left">Subtracts <em>timestamp1</em> from <em>timestamp2</em> and returns the result in *timeUnit*s</td>
</tr>
</tbody></table>
<p>Not implemented:</p>
<ul>
<li>{fn DAYNAME(date)}</li>
<li>{fn DAYOFMONTH(date)}</li>
<li>{fn DAYOFWEEK(date)}</li>
<li>{fn DAYOFYEAR(date)}</li>
<li>{fn HOUR(time)}</li>
<li>{fn MINUTE(time)}</li>
<li>{fn MONTH(date)}</li>
<li>{fn MONTHNAME(date)}</li>
<li>{fn SECOND(time)}</li>
<li>{fn WEEK(date)}</li>
<li>{fn YEAR(date)}</li>
</ul>
<h4 id="system">System</h4>
<p>Not implemented:</p>
<ul>
<li>{fn DATABASE()}</li>
<li>{fn IFNULL(value, value)}</li>
<li>{fn USER(value, value)}</li>
<li>{fn CONVERT(value, type)}</li>
</ul>
<h3 id="aggregate-functions">Aggregate functions</h3>
<p>Storm SQL doesn&#39;t support aggregation yet.</p>
<h3 id="window-functions">Window functions</h3>
<p>Storm SQL doesn&#39;t support windowing yet.</p>
<h3 id="grouping-functions">Grouping functions</h3>
<p>Storm SQL doesn&#39;t support grouping functions.</p>
<h3 id="user-defined-functions">User-defined functions</h3>
<p>Users can define user defined function (scalar) using <code>CREATE FUNCTION</code> statement.
For example, the following statement defines <code>MYPLUS</code> function which uses <code>org.apache.storm.sql.TestUtils$MyPlus</code> class.</p>
<div class="highlight"><pre><code class="language-" data-lang="">CREATE FUNCTION MYPLUS AS 'org.apache.storm.sql.TestUtils$MyPlus'
</code></pre></div>
<p>Storm SQL determines whether the function as scalar or aggregate by checking which methods are defined.
If the class defines <code>evaluate</code> method, Storm SQL treats the function as <code>scalar</code>.</p>
<p>Example of class for scalar function is here:</p>
<div class="highlight"><pre><code class="language-" data-lang=""> public class MyPlus {
public static Integer evaluate(Integer x, Integer y) {
return x + y;
}
}
</code></pre></div>
<p>Please note that users should use <code>--jars</code> or <code>--artifacts</code> while running Storm SQL runner to make sure UDFs are available in classpath. </p>
<h2 id="external-data-sources">External Data Sources</h2>
<h3 id="specifying-external-data-sources">Specifying External Data Sources</h3>
<p>In StormSQL data is represented by external tables. Users can specify data sources using the <code>CREATE EXTERNAL TABLE</code> statement. The syntax of <code>CREATE EXTERNAL TABLE</code> closely follows the one defined in <a href="https://cwiki.apache.org/confluence/display/Hive/LanguageManual+DDL">Hive Data Definition Language</a>:</p>
<div class="highlight"><pre><code class="language-" data-lang="">CREATE EXTERNAL TABLE table_name field_list
[ STORED AS
INPUTFORMAT input_format_classname
OUTPUTFORMAT output_format_classname
]
LOCATION location
[ TBLPROPERTIES tbl_properties ]
[ AS select_stmt ]
</code></pre></div>
<p>Default input format and output format are JSON. We will introduce <code>supported formats</code> from further section.</p>
<p>For example, the following statement specifies a Kafka spout and sink:</p>
<div class="highlight"><pre><code class="language-" data-lang="">CREATE EXTERNAL TABLE FOO (ID INT PRIMARY KEY) LOCATION 'kafka://test?bootstrap-hosts=localhost:9092' TBLPROPERTIES '{"producer":{"acks":"1","key.serializer":"org.apache.storm.kafka.IntSerializer"}}'
</code></pre></div>
<p>Please note that users should use <code>--jars</code> or <code>--artifacts</code> while running Storm SQL runner to make sure UDFs are available in classpath. </p>
<h3 id="plugging-in-external-data-sources">Plugging in External Data Sources</h3>
<p>Users plug in external data sources through implementing the <code>ISqlTridentDataSource</code> interface and registers them using the mechanisms of Java&#39;s service loader. The external data source will be chosen based on the scheme of the URI of the tables. Please refer to the implementation of <code>storm-sql-kafka</code> for more details.</p>
<h3 id="supported-formats">Supported Formats</h3>
<table><thead>
<tr>
<th style="text-align: left">Format</th>
<th style="text-align: left">Input format class</th>
<th style="text-align: left">Output format class</th>
<th style="text-align: left">Requires properties</th>
</tr>
</thead><tbody>
<tr>
<td style="text-align: left">JSON</td>
<td style="text-align: left">org.apache.storm.sql.runtime.serde.json.JsonScheme</td>
<td style="text-align: left">org.apache.storm.sql.runtime.serde.json.JsonSerializer</td>
<td style="text-align: left">No</td>
</tr>
<tr>
<td style="text-align: left">Avro</td>
<td style="text-align: left">org.apache.storm.sql.runtime.serde.avro.AvroScheme</td>
<td style="text-align: left">org.apache.storm.sql.runtime.serde.avro.AvroSerializer</td>
<td style="text-align: left">Yes</td>
</tr>
<tr>
<td style="text-align: left">CSV</td>
<td style="text-align: left">org.apache.storm.sql.runtime.serde.csv.CsvScheme</td>
<td style="text-align: left">org.apache.storm.sql.runtime.serde.csv.CsvSerializer</td>
<td style="text-align: left">No</td>
</tr>
<tr>
<td style="text-align: left">TSV</td>
<td style="text-align: left">org.apache.storm.sql.runtime.serde.tsv.TsvScheme</td>
<td style="text-align: left">org.apache.storm.sql.runtime.serde.tsv.TsvSerializer</td>
<td style="text-align: left">No</td>
</tr>
</tbody></table>
<h4 id="avro">Avro</h4>
<p>Avro requires users to describe the schema of record (both input and output). Schema should be described on <code>TBLPROPERTIES</code>.
Input format needs to be described to <code>input.avro.schema</code>, and output format needs to be described to <code>output.avro.schema</code>.
Schema string should be an escaped JSON so that <code>TBLPROPERTIES</code> is valid JSON.</p>
<p>Example Schema description:</p>
<p><code>&quot;input.avro.schema&quot;: &quot;{\&quot;type\&quot;: \&quot;record\&quot;, \&quot;name\&quot;: \&quot;large_orders\&quot;, \&quot;fields\&quot; : [ {\&quot;name\&quot;: \&quot;ID\&quot;, \&quot;type\&quot;: \&quot;int\&quot;}, {\&quot;name\&quot;: \&quot;TOTAL\&quot;, \&quot;type\&quot;: \&quot;int\&quot;} ]}&quot;</code></p>
<p><code>&quot;output.avro.schema&quot;: &quot;{\&quot;type\&quot;: \&quot;record\&quot;, \&quot;name\&quot;: \&quot;large_orders\&quot;, \&quot;fields\&quot; : [ {\&quot;name\&quot;: \&quot;ID\&quot;, \&quot;type\&quot;: \&quot;int\&quot;}, {\&quot;name\&quot;: \&quot;TOTAL\&quot;, \&quot;type\&quot;: \&quot;int\&quot;} ]}&quot;</code></p>
<h4 id="csv">CSV</h4>
<p>It uses <a href="https://tools.ietf.org/html/rfc4180">Standard RFC4180</a> CSV Parser and doesn&#39;t need any other properties.</p>
<h4 id="tsv">TSV</h4>
<p>By default TSV uses <code>\t</code> as delimiter, but users can set another delimiter by setting <code>input.tsv.delimiter</code> and/or <code>output.tsv.delimiter</code>.
Please note that it supports only one letter for delimiter.</p>
<h3 id="supported-data-sources">Supported Data Sources</h3>
<table><thead>
<tr>
<th style="text-align: left">Data Source</th>
<th style="text-align: left">Artifact Name</th>
<th style="text-align: left">Location prefix</th>
<th style="text-align: left">Support Input data source</th>
<th style="text-align: left">Support Output data source</th>
<th style="text-align: left">Requires properties</th>
</tr>
</thead><tbody>
<tr>
<td style="text-align: left">Socket</td>
<td style="text-align: left"><built-in></td>
<td style="text-align: left"><code>socket://host:port</code></td>
<td style="text-align: left">Yes</td>
<td style="text-align: left">Yes</td>
<td style="text-align: left">No</td>
</tr>
<tr>
<td style="text-align: left">Kafka</td>
<td style="text-align: left">org.apache.storm:storm-sql-kafka</td>
<td style="text-align: left"><code>kafka://topic?bootstrap-servers=host1:port1,host2:port2</code></td>
<td style="text-align: left">Yes</td>
<td style="text-align: left">Yes</td>
<td style="text-align: left">Yes</td>
</tr>
<tr>
<td style="text-align: left">Redis</td>
<td style="text-align: left">org.apache.storm:storm-sql-redis</td>
<td style="text-align: left"><code>redis://:[password]@host:port/[dbIdx]</code></td>
<td style="text-align: left">No</td>
<td style="text-align: left">Yes</td>
<td style="text-align: left">Yes</td>
</tr>
<tr>
<td style="text-align: left">MongoDB</td>
<td style="text-align: left">org.apache.stormg:storm-sql-mongodb</td>
<td style="text-align: left"><code>mongodb://[username:password@]host1[:port1][,host2[:port2],...[,hostN[:portN]]][/[database][?options]]</code></td>
<td style="text-align: left">No</td>
<td style="text-align: left">Yes</td>
<td style="text-align: left">Yes</td>
</tr>
<tr>
<td style="text-align: left">HDFS</td>
<td style="text-align: left">org.apache.storm:storm-sql-hdfs</td>
<td style="text-align: left"><code>hdfs://host:port/path-to-file</code></td>
<td style="text-align: left">No</td>
<td style="text-align: left">Yes</td>
<td style="text-align: left">Yes</td>
</tr>
</tbody></table>
<h4 id="socket">Socket</h4>
<p>Socket data source is a built-in feature so users don&#39;t need to add any artifacts to <code>--artifacts</code> options.</p>
<p>Please note that Socket data source is only for testing: it doesn&#39;t ensure any delivery guarantee.</p>
<p>TIP: <code>netcat</code> is a convenient tool for Socket: users can use netcat to connect Socket data source for either or both input and output purposes.</p>
<h4 id="kafka">Kafka</h4>
<p>Kafka data source requires below properties only when its used for output data source:</p>
<ul>
<li><code>producer</code>: Specify Kafka Producer configuration - Please refer <a href="http://kafka.apache.org/documentation.html#producerconfigs">Kafka producer configs</a> for details.
<ul>
<li>Do not set <code>bootstrap.servers</code>. It is extracted from the URI you provide for the data source (e.g. <code>kafka://topic?bootstrap-servers=localhost:9092,localhost:9093</code> would extract to <code>localhost:9092,localhost:9093</code>).</li>
<li>Do not set <code>value.serializer</code>. It is hardcoded to use <code>ByteBufferSerializer</code>. Instead use the <code>STORED AS INPUTFORMAT ... OUTPUTFORMAT ...</code> syntax to specify the output serializer Storm will use to create the ByteBuffer from input tuples.</li>
</ul></li>
</ul>
<p>Please note that <code>storm-sql-kafka</code> requires users to provide <code>storm-kafka-client</code>, and <code>storm-kafka-client</code> requires users to provide <code>kafka-clients</code>.
You can use below as working reference for <code>--artifacts</code> option, and change dependencies version, and see it works:</p>
<p><code>org.apache.storm:storm-sql-kafka:2.0.0-SNAPSHOT,org.apache.storm:storm-kafka-client:2.0.0-SNAPSHOT,org.apache.kafka:kafka-clients:1.1.0^org.slf4j:slf4j-log4j12</code></p>
<h4 id="redis">Redis</h4>
<p>Redis data source requires below properties to be set:</p>
<ul>
<li><code>data.type</code>: data type to be used for storing - only <code>&quot;STRING&quot;</code> and <code>&quot;HASH&quot;</code> are supported</li>
<li><code>data.additional.key</code>: key if data type needs both key and field (field will be used as field)</li>
<li><code>redis.timeout</code>: timeout in milliseconds (ex. <code>&quot;3000&quot;</code>)</li>
<li><code>use.redis.cluster</code>: <code>&quot;true&quot;</code> if data source is Redis Cluster env., <code>&quot;false&quot;</code> otherwise.</li>
</ul>
<p>Please note that <code>storm-sql-redis</code> requires users to provide <code>storm-redis</code>.
You can use below as working reference for <code>--artifacts</code> option, and change dependencies version if really needed:</p>
<p><code>org.apache.storm:storm-sql-redis:2.0.0-SNAPSHOT,org.apache.storm:storm-redis:2.0.0-SNAPSHOT</code></p>
<h4 id="mongodb">MongoDB</h4>
<p>MongoDB data source requires below properties to be set:</p>
<p><code>{&quot;collection.name&quot;: &quot;storm_sql_mongo&quot;, &quot;ser.field&quot;: &quot;serfield&quot;}</code></p>
<ul>
<li><code>ser.field</code>: field to store - record will be serialized and stored as BSON in this field</li>
<li><code>collection.name</code>: Collection name</li>
</ul>
<p>Please note that <code>storm-sql-mongodb</code> requires users to provide <code>storm-mongodb</code>.
You can use below as working reference for <code>--artifacts</code> option, and change dependencies version if really needed:</p>
<p><code>org.apache.storm:storm-sql-mongodb:2.0.0-SNAPSHOT,org.apache.storm:storm-mongodb:2.0.0-SNAPSHOT</code></p>
<p>Storing record with preserving fields are not supported for now.</p>
<h4 id="hdfs">HDFS</h4>
<p>HDFS data source requires below properties to be set:</p>
<ul>
<li><code>hdfs.file.path</code>: HDFS file path</li>
<li><code>hdfs.file.name</code>: HDFS file name - please refer to <a href="http://github.com/apache/storm/blob/v2.3.0/external/storm-hdfs/src/main/java/org/apache/storm/hdfs/bolt/format/SimpleFileNameFormat.java">SimpleFileNameFormat</a></li>
<li><code>hdfs.rotation.size.kb</code>: HDFS FileSizeRotationPolicy in KB</li>
<li><code>hdfs.rotation.time.seconds</code>: HDFS TimedRotationPolicy in seconds</li>
</ul>
<p>Please note that <code>hdfs.rotation.size.kb</code> and <code>hdfs.rotation.time.seconds</code> only one can be used for hdfs rotation.</p>
<p>And note that <code>storm-sql-hdfs</code> requires users to provide <code>storm-hdfs</code>.
You can use below as working reference for <code>--artifacts</code> option, and change dependencies version if really needed:</p>
<p><code>org.apache.storm:storm-sql-hdfs:2.0.0-SNAPSHOT,org.apache.storm:storm-hdfs:2.0.0-SNAPSHOT</code></p>
<p>Also, hdfs configuration files should be provided.
You can put the <code>core-site.xml</code> and <code>hdfs-site.xml</code> into the <code>conf</code> directory which is in Storm installation directory.</p>
</div>
</div>
</div>
</div>
<footer>
<div class="container-fluid">
<div class="row">
<div class="col-md-3">
<div class="footer-widget">
<h5>Meetups</h5>
<ul class="latest-news">
<li><a href="http://www.meetup.com/Apache-Storm-Apache-Kafka/">Apache Storm & Apache Kafka</a> <span class="small">(Sunnyvale, CA)</span></li>
<li><a href="http://www.meetup.com/Apache-Storm-Kafka-Users/">Apache Storm & Kafka Users</a> <span class="small">(Seattle, WA)</span></li>
<li><a href="http://www.meetup.com/New-York-City-Storm-User-Group/">NYC Storm User Group</a> <span class="small">(New York, NY)</span></li>
<li><a href="http://www.meetup.com/Bay-Area-Stream-Processing">Bay Area Stream Processing</a> <span class="small">(Emeryville, CA)</span></li>
<li><a href="http://www.meetup.com/Boston-Storm-Users/">Boston Realtime Data</a> <span class="small">(Boston, MA)</span></li>
<li><a href="http://www.meetup.com/storm-london">London Storm User Group</a> <span class="small">(London, UK)</span></li>
<!-- <li><a href="http://www.meetup.com/Apache-Storm-Kafka-Users/">Seatle, WA</a> <span class="small">(27 Jun 2015)</span></li> -->
</ul>
</div>
</div>
<div class="col-md-3">
<div class="footer-widget">
<h5>About Apache Storm</h5>
<p>Apache Storm integrates with any queueing system and any database system. Apache Storm's spout abstraction makes it easy to integrate a new queuing system. Likewise, integrating Apache Storm with database systems is easy.</p>
</div>
</div>
<div class="col-md-3">
<div class="footer-widget">
<h5>First Look</h5>
<ul class="footer-list">
<li><a href="/releases/current/Rationale.html">Rationale</a></li>
<li><a href="/releases/current/Tutorial.html">Tutorial</a></li>
<li><a href="/releases/current/Setting-up-development-environment.html">Setting up development environment</a></li>
<li><a href="/releases/current/Creating-a-new-Storm-project.html">Creating a new Apache Storm project</a></li>
</ul>
</div>
</div>
<div class="col-md-3">
<div class="footer-widget">
<h5>Documentation</h5>
<ul class="footer-list">
<li><a href="/releases/current/index.html">Index</a></li>
<li><a href="/releases/current/javadocs/index.html">Javadoc</a></li>
<li><a href="/releases/current/FAQ.html">FAQ</a></li>
</ul>
</div>
</div>
</div>
<hr/>
<div class="row">
<div class="col-md-12">
<p align="center">Copyright © 2019 <a href="http://www.apache.org">Apache Software Foundation</a>. All Rights Reserved.
<br>Apache Storm, Apache, the Apache feather logo, and the Apache Storm project logos are trademarks of The Apache Software Foundation.
<br>All other marks mentioned may be trademarks or registered trademarks of their respective owners.</p>
</div>
</div>
</div>
</footer>
<!--Footer End-->
<!-- Scroll to top -->
<span class="totop"><a href="#"><i class="fa fa-angle-up"></i></a></span>
</body>
</html>