doc-exports/docs/dli/sqlreference/dli_08_0438.html
Su, Xiaomeng 04d4597cf3 dli_sqlreference_0511_version
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>
2023-11-02 14:34:08 +00:00

155 lines
16 KiB
HTML

<a name="dli_08_0438"></a><a name="dli_08_0438"></a>
<h1 class="topictitle1">string_split</h1>
<div id="body8662426"><p id="dli_08_0438__en-us_topic_0000001262655754_p8060118">The <strong id="dli_08_0438__en-us_topic_0000001262655754_b2822751854572">string_split</strong> function splits a target string into substrings based on the specified separator and returns a substring list.</p>
<div class="section" id="dli_08_0438__en-us_topic_0000001262655754_section119977579256"><h4 class="sectiontitle">Description</h4><pre class="screen" id="dli_08_0438__en-us_topic_0000001262655754_screen1265101518263">string_split(target, separator)</pre>
<div class="tablenoborder"><table cellpadding="4" cellspacing="0" summary="" id="dli_08_0438__en-us_topic_0000001262655754_table343016642713" frame="border" border="1" rules="all"><caption><b>Table 1 </b>string_split parameters</caption><thead align="left"><tr id="dli_08_0438__en-us_topic_0000001262655754_row843114615273"><th align="left" class="cellrowborder" valign="top" width="33.33333333333333%" id="mcps1.3.2.3.2.4.1.1"><p id="dli_08_0438__en-us_topic_0000001262655754_p1643176142717">Parameter</p>
</th>
<th align="left" class="cellrowborder" valign="top" width="33.33333333333333%" id="mcps1.3.2.3.2.4.1.2"><p id="dli_08_0438__en-us_topic_0000001262655754_p164312682715">Data Types</p>
</th>
<th align="left" class="cellrowborder" valign="top" width="33.33333333333333%" id="mcps1.3.2.3.2.4.1.3"><p id="dli_08_0438__en-us_topic_0000001262655754_p143111662712">Description</p>
</th>
</tr>
</thead>
<tbody><tr id="dli_08_0438__en-us_topic_0000001262655754_row6431767278"><td class="cellrowborder" valign="top" width="33.33333333333333%" headers="mcps1.3.2.3.2.4.1.1 "><p id="dli_08_0438__en-us_topic_0000001262655754_p154315611276">target</p>
</td>
<td class="cellrowborder" valign="top" width="33.33333333333333%" headers="mcps1.3.2.3.2.4.1.2 "><p id="dli_08_0438__en-us_topic_0000001262655754_p17431166102716">STRING</p>
</td>
<td class="cellrowborder" valign="top" width="33.33333333333333%" headers="mcps1.3.2.3.2.4.1.3 "><p id="dli_08_0438__en-us_topic_0000001262655754_p194311463278">Target string to be processed</p>
<div class="note" id="dli_08_0438__en-us_topic_0000001262655754_note11538021162815"><span class="notetitle"> NOTE: </span><div class="notebody"><ul id="dli_08_0438__en-us_topic_0000001262655754_ul1534973892810"><li id="dli_08_0438__en-us_topic_0000001262655754_li143492038102812">If <strong id="dli_08_0438__en-us_topic_0000001262655754_b10236897134572">target </strong>is <strong id="dli_08_0438__en-us_topic_0000001262655754_b16943849034572">NULL</strong>, an empty line is returned.</li><li id="dli_08_0438__en-us_topic_0000001262655754_li384713910285">If <strong id="dli_08_0438__en-us_topic_0000001262655754_b20901485484572">target</strong> contains two or more consecutive separators, an empty substring is returned.</li><li id="dli_08_0438__en-us_topic_0000001262655754_li1546714518283">If <strong id="dli_08_0438__en-us_topic_0000001262655754_b19769034324572">target</strong> does not contain a specified separator, the original string passed to <strong id="dli_08_0438__en-us_topic_0000001262655754_b12056830834572">target</strong> is returned.</li></ul>
</div></div>
</td>
</tr>
<tr id="dli_08_0438__en-us_topic_0000001262655754_row943118619270"><td class="cellrowborder" valign="top" width="33.33333333333333%" headers="mcps1.3.2.3.2.4.1.1 "><p id="dli_08_0438__en-us_topic_0000001262655754_p13431156192714">separator</p>
</td>
<td class="cellrowborder" valign="top" width="33.33333333333333%" headers="mcps1.3.2.3.2.4.1.2 "><p id="dli_08_0438__en-us_topic_0000001262655754_p84318620278">VARCHAR</p>
</td>
<td class="cellrowborder" valign="top" width="33.33333333333333%" headers="mcps1.3.2.3.2.4.1.3 "><p id="dli_08_0438__en-us_topic_0000001262655754_p14431166182710">Separator. Currently, only single-character separators are supported.</p>
</td>
</tr>
</tbody>
</table>
</div>
</div>
<div class="section" id="dli_08_0438__en-us_topic_0000001262655754_section1492821012311"><h4 class="sectiontitle">Example</h4><ol id="dli_08_0438__en-us_topic_0000001262655754_ol7875193418214"><li id="dli_08_0438__en-us_topic_0000001262655754_li138145563218">Create a Flink OpenSource SQL job by referring to <a href="dli_08_0386.html#dli_08_0386">Kafka Source Table</a> and <a href="dli_08_0399.html#dli_08_0399">Print Result Table</a>, enter the following job running script, and submit the job.<div class="p" id="dli_08_0438__en-us_topic_0000001262655754_p143639573219">When you create a job, set <strong id="dli_08_0438__en-us_topic_0000001262655754_b20621210134220">Flink Version</strong> to <strong id="dli_08_0438__en-us_topic_0000001262655754_b1562811014428">1.12</strong> in the <strong id="dli_08_0438__en-us_topic_0000001262655754_b1862801019429">Running Parameters</strong> tab. Select <strong id="dli_08_0438__en-us_topic_0000001262655754_b1362812102426">Save Job Log</strong>, and specify the OBS bucket for saving job logs. <strong id="dli_08_0438__en-us_topic_0000001262655754_b16167185013463">Change the values of the parameters in bold as needed in the following script.</strong><pre class="screen" id="dli_08_0438__en-us_topic_0000001262655754_screen1468682935015">CREATE TABLE kafkaSource (
target STRING,
separator VARCHAR
) WITH (
'connector' = 'kafka',
'topic' = '<em id="dli_08_0438__en-us_topic_0000001262655754_i4543155265320"><strong id="dli_08_0438__en-us_topic_0000001262655754_b1754316528535">Kafka</strong></em><em id="dli_08_0438__en-us_topic_0000001262655754_i15341759195319"><strong id="dli_08_0438__en-us_topic_0000001262655754_b5227105913538">Topic</strong></em>',
'properties.bootstrap.servers' = '<em id="dli_08_0438__en-us_topic_0000001262655754_i9319103215313"><strong id="dli_08_0438__en-us_topic_0000001262655754_b0322115133213">KafkaAddress1:KafkaPort,KafkaAddress2:KafkaPort</strong></em>',
'properties.group.id' = '<em id="dli_08_0438__en-us_topic_0000001262655754_i14535174011311"><strong id="dli_08_0438__en-us_topic_0000001262655754_b1466610178329">GroupId</strong></em>',
'scan.startup.mode' = 'latest-offset',
"format" = "json"
);
CREATE TABLE printSink (
target STRING,
item STRING
) WITH (
'connector' = 'print'
);
insert into printSink
select target,
item from
kafkaSource,
lateral table(string_split(target, separator)) as T(item);</pre>
</div>
</li><li id="dli_08_0438__en-us_topic_0000001262655754_li1087510342213">Connect to the Kafka cluster and send the following test data to the Kafka topic:<pre class="screen" id="dli_08_0438__en-us_topic_0000001262655754_screen7222143315544">{"target":"test-flink","separator":"-"}
{"target":"flink","separator":"-"}
{"target":"one-two-ww-three","separator":"-"}</pre>
<p id="dli_08_0438__en-us_topic_0000001262655754_p1275313257277">The data is as follows:</p>
<div class="tablenoborder"><table cellpadding="4" cellspacing="0" summary="" id="dli_08_0438__en-us_topic_0000001262655754_table564073111353" frame="border" border="1" rules="all"><caption><b>Table 2 </b>Test table data</caption><thead align="left"><tr id="dli_08_0438__en-us_topic_0000001262655754_row2064033115350"><th align="left" class="cellrowborder" valign="top" width="50%" id="mcps1.3.3.2.2.3.2.3.1.1"><p id="dli_08_0438__en-us_topic_0000001262655754_p6640831153514">target (STRING)</p>
</th>
<th align="left" class="cellrowborder" valign="top" width="50%" id="mcps1.3.3.2.2.3.2.3.1.2"><p id="dli_08_0438__en-us_topic_0000001262655754_p18640143113356">separator (VARCHAR)</p>
</th>
</tr>
</thead>
<tbody><tr id="dli_08_0438__en-us_topic_0000001262655754_row166401431183513"><td class="cellrowborder" valign="top" width="50%" headers="mcps1.3.3.2.2.3.2.3.1.1 "><p id="dli_08_0438__en-us_topic_0000001262655754_p176401231203510">test-flink</p>
</td>
<td class="cellrowborder" valign="top" width="50%" headers="mcps1.3.3.2.2.3.2.3.1.2 "><p id="dli_08_0438__en-us_topic_0000001262655754_p15640931143513">-</p>
</td>
</tr>
<tr id="dli_08_0438__en-us_topic_0000001262655754_row3640123103514"><td class="cellrowborder" valign="top" width="50%" headers="mcps1.3.3.2.2.3.2.3.1.1 "><p id="dli_08_0438__en-us_topic_0000001262655754_p0640431113512">flink</p>
</td>
<td class="cellrowborder" valign="top" width="50%" headers="mcps1.3.3.2.2.3.2.3.1.2 "><p id="dli_08_0438__en-us_topic_0000001262655754_p164012318356">-</p>
</td>
</tr>
<tr id="dli_08_0438__en-us_topic_0000001262655754_row35201593611"><td class="cellrowborder" valign="top" width="50%" headers="mcps1.3.3.2.2.3.2.3.1.1 "><p id="dli_08_0438__en-us_topic_0000001262655754_p105211514362">one-two-ww-three</p>
</td>
<td class="cellrowborder" valign="top" width="50%" headers="mcps1.3.3.2.2.3.2.3.1.2 "><p id="dli_08_0438__en-us_topic_0000001262655754_p1452215143617">-</p>
</td>
</tr>
</tbody>
</table>
</div>
</li><li id="dli_08_0438__en-us_topic_0000001262655754_li5875534023">View output.<ul id="dli_08_0438__en-us_topic_0000001262655754_ul133191514102210"><li id="dli_08_0438__en-us_topic_0000001262655754_li11970649381">Method 1:<ol type="a" id="dli_08_0438__en-us_topic_0000001262655754_ol4711275385"><li id="dli_08_0438__en-us_topic_0000001262655754_li5612141010388">Log in to the DLI console. In the navigation pane, choose <strong id="dli_08_0438__en-us_topic_0000001262655754_b12525068392">Job Management</strong> &gt; <strong id="dli_08_0438__en-us_topic_0000001262655754_b1253112613396">Flink Jobs</strong>.</li><li id="dli_08_0438__en-us_topic_0000001262655754_li117110711383">Locate the row that contains the target Flink job, and choose <strong id="dli_08_0438__en-us_topic_0000001262655754_b8891122611394">More</strong> &gt; <strong id="dli_08_0438__en-us_topic_0000001262655754_b176998313392">FlinkUI</strong> in the <strong id="dli_08_0438__en-us_topic_0000001262655754_b1269013318396">Operation</strong> column.</li><li id="dli_08_0438__en-us_topic_0000001262655754_li07833554385">On the Flink UI, choose <strong id="dli_08_0438__en-us_topic_0000001262655754_b55731924164317">Task Managers</strong>, click the task name, and select <strong id="dli_08_0438__en-us_topic_0000001262655754_b1533215289439">Stdout</strong> to view job logs.</li></ol>
</li><li id="dli_08_0438__en-us_topic_0000001262655754_li341910155285">Method 2: If you select <strong id="dli_08_0438__en-us_topic_0000001262655754_b17547150133911">Save Job Log</strong> on the <strong id="dli_08_0438__en-us_topic_0000001262655754_b1774513525390">Running Parameters</strong> tab before submitting the job, perform the following operations:<ol type="a" id="dli_08_0438__en-us_topic_0000001262655754_ol864115198285"><li id="dli_08_0438__en-us_topic_0000001262655754_li10901621122819">Log in to the DLI console. In the navigation pane, choose <strong id="dli_08_0438__en-us_topic_0000001262655754_b187990674015">Job Management</strong> &gt; <strong id="dli_08_0438__en-us_topic_0000001262655754_b12806463408">Flink Jobs</strong>.</li><li id="dli_08_0438__en-us_topic_0000001262655754_li1912163912282">Click the name of the corresponding Flink job, choose <strong id="dli_08_0438__en-us_topic_0000001262655754_b12759946124318">Run Log</strong>, click <strong id="dli_08_0438__en-us_topic_0000001262655754_b10636145194311">OBS Bucket</strong>, and locate the folder of the log you want to view according to the date.</li><li id="dli_08_0438__en-us_topic_0000001262655754_li0641191914285">Go to the folder of the date, find the folder whose name contains <strong id="dli_08_0438__en-us_topic_0000001262655754_b498820184517">taskmanager</strong>, download the <strong id="dli_08_0438__en-us_topic_0000001262655754_b157762415458">taskmanager.out</strong> file, and view result logs.</li></ol>
</li></ul>
<div class="p" id="dli_08_0438__en-us_topic_0000001262655754_p987011431648">The query result is as follows:<pre class="screen" id="dli_08_0438__en-us_topic_0000001262655754_screen14315539346">+I(test-flink,test)
+I(test-flink,flink)
+I(flink,flink)
+I(one-two-ww-three,one)
+I(one-two-ww-three,two)
+I(one-two-ww-three,ww)
+I(one-two-ww-three,three)</pre>
</div>
<p id="dli_08_0438__en-us_topic_0000001262655754_p16316133920410">The output data is as follows:</p>
<div class="tablenoborder"><table cellpadding="4" cellspacing="0" summary="" id="dli_08_0438__en-us_topic_0000001262655754_table33162391646" frame="border" border="1" rules="all"><caption><b>Table 3 </b>Result table data</caption><thead align="left"><tr id="dli_08_0438__en-us_topic_0000001262655754_row1831619390419"><th align="left" class="cellrowborder" valign="top" width="50%" id="mcps1.3.3.2.3.4.2.3.1.1"><p id="dli_08_0438__en-us_topic_0000001262655754_p6316183911418">target (STRING)</p>
</th>
<th align="left" class="cellrowborder" valign="top" width="50%" id="mcps1.3.3.2.3.4.2.3.1.2"><p id="dli_08_0438__en-us_topic_0000001262655754_p163161639449">item (STRING)</p>
</th>
</tr>
</thead>
<tbody><tr id="dli_08_0438__en-us_topic_0000001262655754_row1131612393412"><td class="cellrowborder" valign="top" width="50%" headers="mcps1.3.3.2.3.4.2.3.1.1 "><p id="dli_08_0438__en-us_topic_0000001262655754_p13161539744">test-flink</p>
</td>
<td class="cellrowborder" valign="top" width="50%" headers="mcps1.3.3.2.3.4.2.3.1.2 "><p id="dli_08_0438__en-us_topic_0000001262655754_p1031673910413">test</p>
</td>
</tr>
<tr id="dli_08_0438__en-us_topic_0000001262655754_row1631614391411"><td class="cellrowborder" valign="top" width="50%" headers="mcps1.3.3.2.3.4.2.3.1.1 "><p id="dli_08_0438__en-us_topic_0000001262655754_p5316739846">test-flink</p>
</td>
<td class="cellrowborder" valign="top" width="50%" headers="mcps1.3.3.2.3.4.2.3.1.2 "><p id="dli_08_0438__en-us_topic_0000001262655754_p331611392417">flink</p>
</td>
</tr>
<tr id="dli_08_0438__en-us_topic_0000001262655754_row2316173917418"><td class="cellrowborder" valign="top" width="50%" headers="mcps1.3.3.2.3.4.2.3.1.1 "><p id="dli_08_0438__en-us_topic_0000001262655754_p831617391146">flink</p>
</td>
<td class="cellrowborder" valign="top" width="50%" headers="mcps1.3.3.2.3.4.2.3.1.2 "><p id="dli_08_0438__en-us_topic_0000001262655754_p123162391246">flink</p>
</td>
</tr>
<tr id="dli_08_0438__en-us_topic_0000001262655754_row1131611391042"><td class="cellrowborder" valign="top" width="50%" headers="mcps1.3.3.2.3.4.2.3.1.1 "><p id="dli_08_0438__en-us_topic_0000001262655754_p15316193910417">one-two-ww-three</p>
</td>
<td class="cellrowborder" valign="top" width="50%" headers="mcps1.3.3.2.3.4.2.3.1.2 "><p id="dli_08_0438__en-us_topic_0000001262655754_p113161539646">one</p>
</td>
</tr>
<tr id="dli_08_0438__en-us_topic_0000001262655754_row1631611398416"><td class="cellrowborder" valign="top" width="50%" headers="mcps1.3.3.2.3.4.2.3.1.1 "><p id="dli_08_0438__en-us_topic_0000001262655754_p143165391145">one-two-ww-three</p>
</td>
<td class="cellrowborder" valign="top" width="50%" headers="mcps1.3.3.2.3.4.2.3.1.2 "><p id="dli_08_0438__en-us_topic_0000001262655754_p1831612391547">two</p>
</td>
</tr>
<tr id="dli_08_0438__en-us_topic_0000001262655754_row63166391413"><td class="cellrowborder" valign="top" width="50%" headers="mcps1.3.3.2.3.4.2.3.1.1 "><p id="dli_08_0438__en-us_topic_0000001262655754_p1431615391546">one-two-ww-three</p>
</td>
<td class="cellrowborder" valign="top" width="50%" headers="mcps1.3.3.2.3.4.2.3.1.2 "><p id="dli_08_0438__en-us_topic_0000001262655754_p133163394410">ww</p>
</td>
</tr>
<tr id="dli_08_0438__en-us_topic_0000001262655754_row0316103911411"><td class="cellrowborder" valign="top" width="50%" headers="mcps1.3.3.2.3.4.2.3.1.1 "><p id="dli_08_0438__en-us_topic_0000001262655754_p831673913410">one-two-ww-three</p>
</td>
<td class="cellrowborder" valign="top" width="50%" headers="mcps1.3.3.2.3.4.2.3.1.2 "><p id="dli_08_0438__en-us_topic_0000001262655754_p13316339445">three</p>
</td>
</tr>
</tbody>
</table>
</div>
</li></ol>
</div>
</div>
<div>
<div class="familylinks">
<div class="parentlink"><strong>Parent topic:</strong> <a href="dli_08_0437.html">Table-Valued Functions</a></div>
</div>
</div>