doc-exports/docs/dli/sqlreference/dli_08_0207.html
Su, Xiaomeng 76a5b1ee83 dli_sqlreference_20240227
Reviewed-by: Pruthi, Vineet <vineet.pruthi@t-systems.com>
Co-authored-by: Su, Xiaomeng <suxiaomeng1@huawei.com>
Co-committed-by: Su, Xiaomeng <suxiaomeng1@huawei.com>
2024-03-27 22:02:33 +00:00

369 lines
29 KiB
HTML
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<a name="dli_08_0207"></a><a name="dli_08_0207"></a>
<h1 class="topictitle1">Data Type</h1>
<div id="body1574406512492"><div class="section" id="dli_08_0207__section1481418106399"><h4 class="sectiontitle">Overview</h4><p id="dli_08_0207__a4443f26bb7a2419da67dd938f8f32f25">Data type is a basic attribute of data and used to distinguish different types of data. Different data types occupy different storage space and support different operations. Data is stored in data tables in the database. Each column of a data table defines the data type. During storage, data must be stored according to data types.</p>
<p id="dli_08_0207__en-us_topic_0060559803_p94805209123">Similar to the open source community, Flink SQL of the big data platform supports both native data types and complex data types.</p>
</div>
<div class="section" id="dli_08_0207__section202052026103914"><h4 class="sectiontitle">Primitive Data Types</h4><p id="dli_08_0207__en-us_topic_0060559804_p197364409183"><a href="#dli_08_0207__t48a8d4da90014446bdf59256969b49c0">Table 1</a> lists native data types supported by Flink SQL.</p>
<div class="tablenoborder"><a name="dli_08_0207__t48a8d4da90014446bdf59256969b49c0"></a><a name="t48a8d4da90014446bdf59256969b49c0"></a><table cellpadding="4" cellspacing="0" summary="" id="dli_08_0207__t48a8d4da90014446bdf59256969b49c0" frame="border" border="1" rules="all"><caption><b>Table 1 </b>Primitive data types</caption><thead align="left"><tr id="dli_08_0207__rc48902c77b65429cbd1bfa9eedc4b593"><th align="left" class="cellrowborder" valign="top" width="21%" id="mcps1.3.2.3.2.5.1.1"><p id="dli_08_0207__a0424def8a05b4f6caeb8d26667341f83"><strong id="dli_08_0207__en-us_topic_0060559804_b167371407186">Data Type</strong></p>
</th>
<th align="left" class="cellrowborder" valign="top" width="31%" id="mcps1.3.2.3.2.5.1.2"><p id="dli_08_0207__a049c7cccf75e4b179265124e06b4d738"><strong id="dli_08_0207__a9775b7bdbaea4a889aace99366dda9c8">Description</strong></p>
</th>
<th align="left" class="cellrowborder" valign="top" width="15%" id="mcps1.3.2.3.2.5.1.3"><p id="dli_08_0207__a18141ff14790413c9a87fc293371d0f7"><strong id="dli_08_0207__a96f391b9c65845a5a722aa85bc602d4a">Storage Space</strong></p>
</th>
<th align="left" class="cellrowborder" valign="top" width="33%" id="mcps1.3.2.3.2.5.1.4"><p id="dli_08_0207__ae38675ffe1314010895d502573a503b8"><strong id="dli_08_0207__en-us_topic_0060559804_b873794011813">Value Range</strong></p>
</th>
</tr>
</thead>
<tbody><tr id="dli_08_0207__r4e37c1b7d5a449778619ba21350b4a16"><td class="cellrowborder" valign="top" width="21%" headers="mcps1.3.2.3.2.5.1.1 "><p id="dli_08_0207__a83a8ce2bbca7419da30bcc28b85cfde6">VARCHAR</p>
</td>
<td class="cellrowborder" valign="top" width="31%" headers="mcps1.3.2.3.2.5.1.2 "><p id="dli_08_0207__ad8fcda6def1e4dfebc939329a2a47a53">Character with a variable length</p>
</td>
<td class="cellrowborder" valign="top" width="15%" headers="mcps1.3.2.3.2.5.1.3 "><p id="dli_08_0207__en-us_topic_0060559804_p872316190298">-</p>
</td>
<td class="cellrowborder" valign="top" width="33%" headers="mcps1.3.2.3.2.5.1.4 "><p id="dli_08_0207__a6da3f213a6af4c43af7c2e737c236a97">-</p>
</td>
</tr>
<tr id="dli_08_0207__r5f1156a36c21439e95d0b9f94155bdac"><td class="cellrowborder" valign="top" width="21%" headers="mcps1.3.2.3.2.5.1.1 "><p id="dli_08_0207__ade0990fc16434a039d468973130958e4">BOOLEAN</p>
</td>
<td class="cellrowborder" valign="top" width="31%" headers="mcps1.3.2.3.2.5.1.2 "><p id="dli_08_0207__abbd631e6268d472da1dbb326dda974c9">Boolean</p>
</td>
<td class="cellrowborder" valign="top" width="15%" headers="mcps1.3.2.3.2.5.1.3 "><p id="dli_08_0207__en-us_topic_0060559804_p845083911301">-</p>
</td>
<td class="cellrowborder" valign="top" width="33%" headers="mcps1.3.2.3.2.5.1.4 "><p id="dli_08_0207__ab9bba2e206554fdeb35def3fbc437fb7">TRUE/FALSE</p>
</td>
</tr>
<tr id="dli_08_0207__r11eead0107ed4b76b077b8250aaa68f4"><td class="cellrowborder" valign="top" width="21%" headers="mcps1.3.2.3.2.5.1.1 "><p id="dli_08_0207__en-us_topic_0060559804_p674074015187">TINYINT</p>
</td>
<td class="cellrowborder" valign="top" width="31%" headers="mcps1.3.2.3.2.5.1.2 "><p id="dli_08_0207__a84979ab640bf4b09829a145707bf025f">Signed integer</p>
</td>
<td class="cellrowborder" valign="top" width="15%" headers="mcps1.3.2.3.2.5.1.3 "><p id="dli_08_0207__en-us_topic_0060559804_p163620413118">1 byte</p>
</td>
<td class="cellrowborder" valign="top" width="33%" headers="mcps1.3.2.3.2.5.1.4 "><p id="dli_08_0207__a915a6060d1ea405aa25dd909b2a6d3b1">-128-127</p>
</td>
</tr>
<tr id="dli_08_0207__r588584e8eb914064a15053229ab306f7"><td class="cellrowborder" valign="top" width="21%" headers="mcps1.3.2.3.2.5.1.1 "><p id="dli_08_0207__a62e9321657004f76b96ede5047ec64ef">SMALLINT</p>
</td>
<td class="cellrowborder" valign="top" width="31%" headers="mcps1.3.2.3.2.5.1.2 "><p id="dli_08_0207__en-us_topic_0060559804_p343541512319">Signed integer</p>
</td>
<td class="cellrowborder" valign="top" width="15%" headers="mcps1.3.2.3.2.5.1.3 "><p id="dli_08_0207__en-us_topic_0060559804_p543551511311">2 bytes</p>
</td>
<td class="cellrowborder" valign="top" width="33%" headers="mcps1.3.2.3.2.5.1.4 "><p id="dli_08_0207__en-us_topic_0060559804_p184367153313">-32768-32767</p>
</td>
</tr>
<tr id="dli_08_0207__r64aefd8c87004b7b95f6e1ca7beaa808"><td class="cellrowborder" valign="top" width="21%" headers="mcps1.3.2.3.2.5.1.1 "><p id="dli_08_0207__en-us_topic_0060559804_p974011407188">INT</p>
</td>
<td class="cellrowborder" valign="top" width="31%" headers="mcps1.3.2.3.2.5.1.2 "><p id="dli_08_0207__en-us_topic_0060559804_p617212258315">Signed integer</p>
</td>
<td class="cellrowborder" valign="top" width="15%" headers="mcps1.3.2.3.2.5.1.3 "><p id="dli_08_0207__af637ee9228c0472e86cf7ccc6a958835">4 bytes</p>
</td>
<td class="cellrowborder" valign="top" width="33%" headers="mcps1.3.2.3.2.5.1.4 "><p id="dli_08_0207__a6fe0b9801dfa475bb2964597ed39c34a">2147483648 to 2147483647</p>
</td>
</tr>
<tr id="dli_08_0207__ra68b253dc2854bde98c76df57231e9e1"><td class="cellrowborder" valign="top" width="21%" headers="mcps1.3.2.3.2.5.1.1 "><p id="dli_08_0207__en-us_topic_0060559804_p87407404183">INTEGER</p>
</td>
<td class="cellrowborder" valign="top" width="31%" headers="mcps1.3.2.3.2.5.1.2 "><p id="dli_08_0207__ab0eade4f7c564622a9e7318055e860ae">Signed integer</p>
</td>
<td class="cellrowborder" valign="top" width="15%" headers="mcps1.3.2.3.2.5.1.3 "><p id="dli_08_0207__en-us_topic_0060559804_p74028459146">4 bytes</p>
</td>
<td class="cellrowborder" valign="top" width="33%" headers="mcps1.3.2.3.2.5.1.4 "><p id="dli_08_0207__a1f321d55da8e425994e59f097988a604">2147483648 to 2147483647</p>
</td>
</tr>
<tr id="dli_08_0207__rd65601780d614322bf9c40f5356e80b6"><td class="cellrowborder" valign="top" width="21%" headers="mcps1.3.2.3.2.5.1.1 "><p id="dli_08_0207__ae3d93ee201e94c7ba3af37ebc4b485b5">BIGINT</p>
</td>
<td class="cellrowborder" valign="top" width="31%" headers="mcps1.3.2.3.2.5.1.2 "><p id="dli_08_0207__a8a837c28549e42b29ef6327b913d4abb">Signed integer</p>
</td>
<td class="cellrowborder" valign="top" width="15%" headers="mcps1.3.2.3.2.5.1.3 "><p id="dli_08_0207__ab5b08fba65ca43d2ac84837e1fca5fae">8 bytes</p>
</td>
<td class="cellrowborder" valign="top" width="33%" headers="mcps1.3.2.3.2.5.1.4 "><p id="dli_08_0207__en-us_topic_0060559804_p1211911323">9223372036854775808 to 9223372036854775807</p>
</td>
</tr>
<tr id="dli_08_0207__ra41aedec8d2f459eb03f6b41553e52c9"><td class="cellrowborder" valign="top" width="21%" headers="mcps1.3.2.3.2.5.1.1 "><p id="dli_08_0207__a1281701bd50d4c6e8df5a21840b0c8fe">REAL</p>
</td>
<td class="cellrowborder" valign="top" width="31%" headers="mcps1.3.2.3.2.5.1.2 "><p id="dli_08_0207__a8159f81c0a764df09b4e5b454976636d">Single-precision floating point</p>
</td>
<td class="cellrowborder" valign="top" width="15%" headers="mcps1.3.2.3.2.5.1.3 "><p id="dli_08_0207__en-us_topic_0060559804_p739713453148">4 bytes</p>
</td>
<td class="cellrowborder" valign="top" width="33%" headers="mcps1.3.2.3.2.5.1.4 "><p id="dli_08_0207__a3fa48cb265214bb8bddaa0add97c60d2">-</p>
</td>
</tr>
<tr id="dli_08_0207__r053751bd45474a2280e142eb6ec120db"><td class="cellrowborder" valign="top" width="21%" headers="mcps1.3.2.3.2.5.1.1 "><p id="dli_08_0207__ac297e6b17f574bb29554db17ce1ee853">FLOAT</p>
</td>
<td class="cellrowborder" valign="top" width="31%" headers="mcps1.3.2.3.2.5.1.2 "><p id="dli_08_0207__ada9c0a0763f341f9b5159ec8a11cef1c">Single-precision floating point</p>
</td>
<td class="cellrowborder" valign="top" width="15%" headers="mcps1.3.2.3.2.5.1.3 "><p id="dli_08_0207__a9ac9404cce8b4f719d47cb3c8d7f6843">4 bytes</p>
</td>
<td class="cellrowborder" valign="top" width="33%" headers="mcps1.3.2.3.2.5.1.4 "><p id="dli_08_0207__a25131f9ffbc844e484ffa040f9b55757">-</p>
</td>
</tr>
<tr id="dli_08_0207__reb41da22a2d246c08c3159d74fd11b67"><td class="cellrowborder" valign="top" width="21%" headers="mcps1.3.2.3.2.5.1.1 "><p id="dli_08_0207__a17a6d1e0432d428d96369e2708ec43f4">DOUBLE</p>
</td>
<td class="cellrowborder" valign="top" width="31%" headers="mcps1.3.2.3.2.5.1.2 "><p id="dli_08_0207__en-us_topic_0060559804_p174982472337">Double-precision floating-point</p>
</td>
<td class="cellrowborder" valign="top" width="15%" headers="mcps1.3.2.3.2.5.1.3 "><p id="dli_08_0207__en-us_topic_0060559804_p14988471335">8 bytes</p>
</td>
<td class="cellrowborder" valign="top" width="33%" headers="mcps1.3.2.3.2.5.1.4 "><p id="dli_08_0207__a7d24f1f9f2ac4bfdacc3c5e8e8e21e52">-</p>
</td>
</tr>
<tr id="dli_08_0207__rf7f3c314ddc741baba5af1f8a9dd37b9"><td class="cellrowborder" valign="top" width="21%" headers="mcps1.3.2.3.2.5.1.1 "><p id="dli_08_0207__aeb1e8eb1ded34ae8b751c26624283ab8">DECIMAL</p>
</td>
<td class="cellrowborder" valign="top" width="31%" headers="mcps1.3.2.3.2.5.1.2 "><p id="dli_08_0207__en-us_topic_0060559804_p174421689348">Data type of valid fixed places and decimal places</p>
</td>
<td class="cellrowborder" valign="top" width="15%" headers="mcps1.3.2.3.2.5.1.3 "><p id="dli_08_0207__en-us_topic_0060559804_p104420843412">-</p>
</td>
<td class="cellrowborder" valign="top" width="33%" headers="mcps1.3.2.3.2.5.1.4 "><p id="dli_08_0207__a66b3411772934ad99c5b97b94015d454">-</p>
</td>
</tr>
<tr id="dli_08_0207__rd8018f68d25948f29f6280885f8dc49d"><td class="cellrowborder" valign="top" width="21%" headers="mcps1.3.2.3.2.5.1.1 "><p id="dli_08_0207__ac96fe07ae6a248db9cdd16bd5c03184c">DATE</p>
</td>
<td class="cellrowborder" valign="top" width="31%" headers="mcps1.3.2.3.2.5.1.2 "><p id="dli_08_0207__a43db0dc02c8b4dd8808fc6b9b23df2e0">Date type in the format of yyyy-MM-dd, for example, 2014-05-29</p>
</td>
<td class="cellrowborder" valign="top" width="15%" headers="mcps1.3.2.3.2.5.1.3 "><p id="dli_08_0207__en-us_topic_0060559804_p513782411341">-</p>
</td>
<td class="cellrowborder" valign="top" width="33%" headers="mcps1.3.2.3.2.5.1.4 "><p id="dli_08_0207__a28e0890f6a074d5c8dd8cc1564a2dbef"><strong id="dli_08_0207__en-us_topic_0093946969_b842352706141039">DATE</strong> does not contain time information. Its value ranges from 0000-01-01 to 9999-12-31.</p>
</td>
</tr>
<tr id="dli_08_0207__r770da34f7000413b867d87ffb9ea08a7"><td class="cellrowborder" valign="top" width="21%" headers="mcps1.3.2.3.2.5.1.1 "><p id="dli_08_0207__en-us_topic_0060559804_p374334016187">TIME</p>
</td>
<td class="cellrowborder" valign="top" width="31%" headers="mcps1.3.2.3.2.5.1.2 "><p id="dli_08_0207__ad448c911954c4b9a9e53aeff90890eec">Time type in the format of HH:MM:SS</p>
<p id="dli_08_0207__a3db24efcecc2469897960df808c4e322">For example, 20:17:40</p>
</td>
<td class="cellrowborder" valign="top" width="15%" headers="mcps1.3.2.3.2.5.1.3 "><p id="dli_08_0207__ae949e3b6fe024580b4f8f8dd7531f303">-</p>
</td>
<td class="cellrowborder" valign="top" width="33%" headers="mcps1.3.2.3.2.5.1.4 "><p id="dli_08_0207__a8e901dc86e2a403daa61a3f5c418263f">-</p>
</td>
</tr>
<tr id="dli_08_0207__rfb92ce6971734462b2f73d633b8b0eaa"><td class="cellrowborder" valign="top" width="21%" headers="mcps1.3.2.3.2.5.1.1 "><p id="dli_08_0207__en-us_topic_0060559804_p166813236219">TIMESTAMP(3)</p>
</td>
<td class="cellrowborder" valign="top" width="31%" headers="mcps1.3.2.3.2.5.1.2 "><p id="dli_08_0207__ac99a7127484f4ade8a423a2d10a0f2ad">Timestamp of date and time</p>
<p id="dli_08_0207__a8697e61ce7684f63adefd07234c5c5e3">For example, 1969-07-20 20:17:40</p>
</td>
<td class="cellrowborder" valign="top" width="15%" headers="mcps1.3.2.3.2.5.1.3 "><p id="dli_08_0207__a6f33d493aed14efbb90d98935eed16f7">-</p>
</td>
<td class="cellrowborder" valign="top" width="33%" headers="mcps1.3.2.3.2.5.1.4 "><p id="dli_08_0207__en-us_topic_0060559804_p06812313214">-</p>
</td>
</tr>
<tr id="dli_08_0207__r02690bac4f7b4f95bedf5b7d780c1506"><td class="cellrowborder" valign="top" width="21%" headers="mcps1.3.2.3.2.5.1.1 "><p id="dli_08_0207__a16f3150770cc404682527273c5da8aed">INTERVAL timeUnit [TO timeUnit]</p>
</td>
<td class="cellrowborder" valign="top" width="31%" headers="mcps1.3.2.3.2.5.1.2 "><p id="dli_08_0207__a027476979d304fafbccfd902df1763ee">Time interval</p>
<p id="dli_08_0207__ae4ebfe968415471b8689d01959c3f299">For example, INTERVAL '1:5' YEAR TO MONTH, INTERVAL '45' DAY</p>
</td>
<td class="cellrowborder" valign="top" width="15%" headers="mcps1.3.2.3.2.5.1.3 "><p id="dli_08_0207__en-us_topic_0060559804_p868323132116">-</p>
</td>
<td class="cellrowborder" valign="top" width="33%" headers="mcps1.3.2.3.2.5.1.4 "><p id="dli_08_0207__en-us_topic_0060559804_p136812312210">-</p>
</td>
</tr>
</tbody>
</table>
</div>
</div>
<div class="section" id="dli_08_0207__section396114618407"><h4 class="sectiontitle">Complex Data Types</h4><p id="dli_08_0207__a69bd856b3943444c856f716f4c2fb00c">Flink SQL supports complex data types and complex type nesting. <a href="#dli_08_0207__t1f67ad6ffe1b4d7c8a38b2a156833dad">Table 2</a> describes complex data types.</p>
<div class="tablenoborder"><a name="dli_08_0207__t1f67ad6ffe1b4d7c8a38b2a156833dad"></a><a name="t1f67ad6ffe1b4d7c8a38b2a156833dad"></a><table cellpadding="4" cellspacing="0" summary="" id="dli_08_0207__t1f67ad6ffe1b4d7c8a38b2a156833dad" frame="border" border="1" rules="all"><caption><b>Table 2 </b>Complex data types</caption><thead align="left"><tr id="dli_08_0207__raa6d6e0cd32f4742a1141b08458ecb50"><th align="left" class="cellrowborder" valign="top" width="14.78%" id="mcps1.3.3.3.2.6.1.1"><p id="dli_08_0207__en-us_topic_0060562661_p49961191248"><strong id="dli_08_0207__abf95a795df78427ab4fbad339c6c16ec">Data Type</strong></p>
</th>
<th align="left" class="cellrowborder" valign="top" width="24.610000000000003%" id="mcps1.3.3.3.2.6.1.2"><p id="dli_08_0207__en-us_topic_0060562661_p099621916243"><strong id="dli_08_0207__en-us_topic_0060562661_b199963195244">Description</strong></p>
</th>
<th align="left" class="cellrowborder" valign="top" width="16.04%" id="mcps1.3.3.3.2.6.1.3"><p id="dli_08_0207__p72709529493"><strong id="dli_08_0207__b8312037113917">Declaration Method</strong></p>
</th>
<th align="left" class="cellrowborder" valign="top" width="22.84%" id="mcps1.3.3.3.2.6.1.4"><p id="dli_08_0207__p1853804619497"><strong id="dli_08_0207__b1195854020396">Reference Method</strong></p>
</th>
<th align="left" class="cellrowborder" valign="top" width="21.73%" id="mcps1.3.3.3.2.6.1.5"><p id="dli_08_0207__p5757628164917"><strong id="dli_08_0207__b42637478395">Construction Method</strong></p>
</th>
</tr>
</thead>
<tbody><tr id="dli_08_0207__r8f37321679154cb392644318d3514834"><td class="cellrowborder" valign="top" width="14.78%" headers="mcps1.3.3.3.2.6.1.1 "><p id="dli_08_0207__a9029c892e7354832a1a2b5db9dd96adc">ARRAY</p>
</td>
<td class="cellrowborder" valign="top" width="24.610000000000003%" headers="mcps1.3.3.3.2.6.1.2 "><p id="dli_08_0207__en-us_topic_0060562661_p209973199242">Indicates a group of ordered fields that are of the same data type.</p>
</td>
<td class="cellrowborder" valign="top" width="16.04%" headers="mcps1.3.3.3.2.6.1.3 "><p id="dli_08_0207__p1227095284918">ARRAY[TYPE]</p>
</td>
<td class="cellrowborder" valign="top" width="22.84%" headers="mcps1.3.3.3.2.6.1.4 "><p id="dli_08_0207__p165383468498">Variable name <strong id="dli_08_0207__b0338154904011">[subscript]</strong>. The subscript starts from 1, for example, <strong id="dli_08_0207__b010884544019">v1[1]</strong>.</p>
</td>
<td class="cellrowborder" valign="top" width="21.73%" headers="mcps1.3.3.3.2.6.1.5 "><p id="dli_08_0207__p167583282499">Array[value1, value2, ...] as v1</p>
</td>
</tr>
<tr id="dli_08_0207__row106117139571"><td class="cellrowborder" valign="top" width="14.78%" headers="mcps1.3.3.3.2.6.1.1 "><p id="dli_08_0207__en-us_topic_0093946794_a6e1fcccbccd343cc9a29e3b7bf3b5578">MAP</p>
</td>
<td class="cellrowborder" valign="top" width="24.610000000000003%" headers="mcps1.3.3.3.2.6.1.2 "><p id="dli_08_0207__en-us_topic_0093946794_a7b85f5d1f72c4517a5ba8db213735d3f">Indicates a group of unordered key/value pairs. The key must be native data type, but the value can be either native data type or complex data type. The type of the same MAP key, as well as the MAP value, must be the same.</p>
</td>
<td class="cellrowborder" valign="top" width="16.04%" headers="mcps1.3.3.3.2.6.1.3 "><p id="dli_08_0207__p9270205244911"><strong id="dli_08_0207__b164781738164012">MAP [TYPE, TYPE]</strong></p>
</td>
<td class="cellrowborder" valign="top" width="22.84%" headers="mcps1.3.3.3.2.6.1.4 "><p id="dli_08_0207__p185387468490">Variable name <strong id="dli_08_0207__b18277193519407">[key]</strong>, for example, <strong id="dli_08_0207__b16103326144017">v1[key]</strong></p>
</td>
<td class="cellrowborder" valign="top" width="21.73%" headers="mcps1.3.3.3.2.6.1.5 "><p id="dli_08_0207__p375892816491">Map[key, value, key2, value2, key3, value3.......] as v1</p>
</td>
</tr>
<tr id="dli_08_0207__row9193161835715"><td class="cellrowborder" valign="top" width="14.78%" headers="mcps1.3.3.3.2.6.1.1 "><p id="dli_08_0207__en-us_topic_0093946794_a65eb49b96203461a9a0e9f58a44e19bb">ROW</p>
</td>
<td class="cellrowborder" valign="top" width="24.610000000000003%" headers="mcps1.3.3.3.2.6.1.2 "><p id="dli_08_0207__en-us_topic_0093946794_a90fcb70c4b6141808319d6db6a176593">Indicates a group of named fields. The data types of the fields can be different.</p>
</td>
<td class="cellrowborder" valign="top" width="16.04%" headers="mcps1.3.3.3.2.6.1.3 "><p id="dli_08_0207__p7270175294911">ROW&lt;a1 TYPE1, a2 TYPE2&gt;</p>
</td>
<td class="cellrowborder" valign="top" width="22.84%" headers="mcps1.3.3.3.2.6.1.4 "><p id="dli_08_0207__p353914612499">Variable name. Field name, for example, <strong id="dli_08_0207__b1892155316404">v1.a1</strong>.</p>
</td>
<td class="cellrowborder" valign="top" width="21.73%" headers="mcps1.3.3.3.2.6.1.5 "><p id="dli_08_0207__p1758728134911">Row('1',2) as v1</p>
</td>
</tr>
</tbody>
</table>
</div>
<div class="p" id="dli_08_0207__p069115834216">Here is a sample code:<div class="codecoloring" codetype="Sql" id="dli_08_0207__en-us_topic_0111501791_screen26644102712"><div class="highlight"><table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre><span class="normal"> 1</span>
<span class="normal"> 2</span>
<span class="normal"> 3</span>
<span class="normal"> 4</span>
<span class="normal"> 5</span>
<span class="normal"> 6</span>
<span class="normal"> 7</span>
<span class="normal"> 8</span>
<span class="normal"> 9</span>
<span class="normal">10</span>
<span class="normal">11</span>
<span class="normal">12</span>
<span class="normal">13</span>
<span class="normal">14</span>
<span class="normal">15</span>
<span class="normal">16</span>
<span class="normal">17</span>
<span class="normal">18</span>
<span class="normal">19</span>
<span class="normal">20</span>
<span class="normal">21</span>
<span class="normal">22</span>
<span class="normal">23</span>
<span class="normal">24</span>
<span class="normal">25</span>
<span class="normal">26</span></pre></div></td><td class="code"><div><pre><span></span><span class="k">CREATE</span><span class="w"> </span><span class="k">SOURCE</span><span class="w"> </span><span class="n">STREAM</span><span class="w"> </span><span class="n">car_infos</span><span class="w"> </span><span class="p">(</span>
<span class="w"> </span><span class="n">car_id</span><span class="w"> </span><span class="n">STRING</span><span class="p">,</span>
<span class="w"> </span><span class="n">address</span><span class="w"> </span><span class="k">ROW</span><span class="o">&lt;</span><span class="n">city</span><span class="w"> </span><span class="n">STRING</span><span class="p">,</span><span class="w"> </span><span class="n">province</span><span class="w"> </span><span class="n">STRING</span><span class="p">,</span><span class="w"> </span><span class="n">country</span><span class="w"> </span><span class="n">STRING</span><span class="o">&gt;</span><span class="p">,</span>
<span class="w"> </span><span class="n">average_speed</span><span class="w"> </span><span class="k">MAP</span><span class="p">[</span><span class="n">STRING</span><span class="p">,</span><span class="w"> </span><span class="n">LONG</span><span class="p">],</span>
<span class="w"> </span><span class="n">speeds</span><span class="w"> </span><span class="nb">ARRAY</span><span class="p">[</span><span class="n">LONG</span><span class="p">]</span>
<span class="p">)</span><span class="w"> </span>
<span class="w"> </span><span class="k">WITH</span><span class="w"> </span><span class="p">(</span>
<span class="w"> </span><span class="k">type</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="ss">&quot;dis&quot;</span><span class="p">,</span>
<span class="w"> </span><span class="n">region</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="ss">&quot;xxx&quot;</span><span class="p">,</span>
<span class="w"> </span><span class="n">channel</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="ss">&quot;dliinput&quot;</span><span class="p">,</span>
<span class="w"> </span><span class="n">encode</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="ss">&quot;json&quot;</span>
<span class="p">);</span>
<span class="k">CREATE</span><span class="w"> </span><span class="n">temp</span><span class="w"> </span><span class="n">STREAM</span><span class="w"> </span><span class="n">car_speed_infos</span><span class="w"> </span><span class="p">(</span>
<span class="w"> </span><span class="n">car_id</span><span class="w"> </span><span class="n">STRING</span><span class="p">,</span>
<span class="w"> </span><span class="n">province</span><span class="w"> </span><span class="n">STRING</span><span class="p">,</span>
<span class="w"> </span><span class="n">average_speed</span><span class="w"> </span><span class="n">LONG</span><span class="p">,</span>
<span class="w"> </span><span class="n">start_speed</span><span class="w"> </span><span class="n">LONG</span>
<span class="p">);</span>
<span class="k">INSERT</span><span class="w"> </span><span class="k">INTO</span><span class="w"> </span><span class="n">car_speed_infos</span><span class="w"> </span><span class="k">SELECT</span>
<span class="w"> </span><span class="n">car_id</span><span class="p">,</span>
<span class="w"> </span><span class="n">address</span><span class="p">.</span><span class="n">province</span><span class="p">,</span>
<span class="w"> </span><span class="n">average_speed</span><span class="p">[</span><span class="n">address</span><span class="p">.</span><span class="n">city</span><span class="p">],</span>
<span class="w"> </span><span class="n">speeds</span><span class="p">[</span><span class="mi">1</span><span class="p">]</span>
<span class="k">FROM</span><span class="w"> </span><span class="n">car_infos</span><span class="p">;</span>
</pre></div></td></tr></table></div>
</div>
</div>
</div>
<div class="section" id="dli_08_0207__section208431452134220"><h4 class="sectiontitle">Complex Type Nesting</h4><ul id="dli_08_0207__ul1480094816435"><li id="dli_08_0207__li0801848164311"><a name="dli_08_0207__li0801848164311"></a><a name="li0801848164311"></a>JSON format enhancement<p id="dli_08_0207__p768383419449"><a name="dli_08_0207__li0801848164311"></a><a name="li0801848164311"></a>The following uses Source as an example. The method of using Sink is the same.</p>
<ul id="dli_08_0207__ul13603165794611"><li id="dli_08_0207__li268985516467"><strong id="dli_08_0207__b176345012414">json_schema</strong> can be configured.<div class="p" id="dli_08_0207__p86961910474">After <strong id="dli_08_0207__b816685411411">json_schema</strong> is configured, fields in DDL can be automatically generated from <strong id="dli_08_0207__b9787182712442">json_schema</strong> without declaration. Here is a sample code:<pre class="screen" id="dli_08_0207__screen61815538475">CREATE SOURCE STREAM data_with_schema WITH (
type = "dis",
region = "xxx",
channel = "dis-in",
encode = "json",
json_schema = '{"definitions":{"address":{"type":"object","properties":{"street_address":{"type":"string"},"city":{"type":"string"},"state":{"type":"string"}},"required":["street_address","city","state"]}},"type":"object","properties":{"billing_address":{"$ref":"#/definitions/address"},"shipping_address":{"$ref":"#/definitions/address"},"optional_address":{"oneOf":[{"type":"null"},{"$ref":"#/definitions/address"}]}}}'
);
CREATE SINK STREAM buy_infos (
billing_address_city STRING,
shipping_address_state string
) WITH (
type = "obs",
encode = "csv",
region = "xxx" ,
field_delimiter = ",",
row_delimiter = "\n",
obs_dir = "bucket/car_infos",
file_prefix = "over",
rolling_size = "100m"
);
insert into buy_infos select billing_address.city, shipping_address.state from data_with_schema;</pre>
</div>
<p id="dli_08_0207__p20647102354914">Example data</p>
<pre class="screen" id="dli_08_0207__screen16786849184916">{
"billing_address":
{
"street_address":"xxx",
"city":"xxx",
"state":"xxx"
},
"shipping_address":
{
"street_address":"xxx",
"city":"xxx",
"state":"xxx"
}
}</pre>
</li><li id="dli_08_0207__li3303543195316">The <strong id="dli_08_0207__b9959141911576">json_schema</strong> and <strong id="dli_08_0207__b209641519145719">json_config</strong> parameters can be left empty. For details about how to use <strong id="dli_08_0207__b2671172214573">json_config</strong>, see the example in <a href="dli_08_0239.html">Open-Source Kafka Source Stream</a>.<p id="dli_08_0207__p048555892414">In this case, the attribute name in the DDL is used as the JSON key for parsing by default.</p>
<p id="dli_08_0207__p39571857125320">The following is example data. It contains nested JSON fields, such as <strong id="dli_08_0207__b190875918145">billing_address</strong> and <strong id="dli_08_0207__b1891418592148">shipping_address</strong>, and non-nested fields <strong id="dli_08_0207__b3914195915142">id</strong> and <strong id="dli_08_0207__b791465971413">type2</strong>.</p>
<pre class="screen" id="dli_08_0207__screen1886965413167">{
"id":"1",
"type2":"online",
"billing_address":
{
"street_address":"xxx",
"city":"xxx",
"state":"xxx"
},
"shipping_address":
{
"street_address":"xxx",
"city":"xxx",
"state":"xxx"
}
}</pre>
<div class="p" id="dli_08_0207__p1580118318255">The table creation and usage examples are as follows:<pre class="screen" id="dli_08_0207__screen197201420105518">CREATE SOURCE STREAM car_info_data (
id STRING,
type2 STRING,
billing_address Row&lt;street_address string, city string, state string&gt;,
shipping_address Row&lt;street_address string, city string, state string&gt;,
optional_address Row&lt;street_address string, city string, state string&gt;
) WITH (
type = "dis",
region = "xxx",
channel = "dis-in",
encode = "json"
);
CREATE SINK STREAM buy_infos (
id STRING,
type2 STRING,
billing_address_city STRING,
shipping_address_state string
) WITH (
type = "obs",
encode = "csv",
region = "xxx",
field_delimiter = ",",
row_delimiter = "\n",
obs_dir = "bucket/car_infos",
file_prefix = "over",
rolling_size = "100m"
);
insert into buy_infos select id, type2, billing_address.city, shipping_address.state from car_info_data; </pre>
</div>
</li></ul>
</li><li id="dli_08_0207__li34661830195812">Complex data types supported by sink serialization<ul id="dli_08_0207__ul163191591201"><li id="dli_08_0207__li31247613012">Currently, only the CSV and JSON formats support complex data types.</li><li id="dli_08_0207__li1812536304">For details about the JSON format, see <a href="#dli_08_0207__li0801848164311">Json format enhancement</a>.</li><li id="dli_08_0207__li1512696302">There is no standard format for CSV files. Therefore, only sink parsing is supported.</li><li id="dli_08_0207__li2012711613013">Output format: It is recommended that the output format be the same as that of the native Flink.<p id="dli_08_0207__p1438971610212"><a name="dli_08_0207__li2012711613013"></a><a name="li2012711613013"></a>Map: {key1=Value1, key2=Value2}</p>
<p id="dli_08_0207__p1584311191524">Row: Attributes are separated by commas (,), for example, <strong id="dli_08_0207__b4724625124714">Row(1,'2') =&gt; 1,'2'</strong>.</p>
</li></ul>
</li></ul>
</div>
</div>
<div>
<div class="familylinks">
<div class="parentlink"><strong>Parent topic:</strong> <a href="dli_08_0233.html">Flink SQL Syntax</a></div>
</div>
</div>