forked from docs/doc-exports
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>
150 lines
12 KiB
HTML
150 lines
12 KiB
HTML
<a name="dli_08_15102"></a><a name="dli_08_15102"></a>
|
|
|
|
<h1 class="topictitle1">string_split</h1>
|
|
<div id="body0000001262655754"><p id="dli_08_15102__p8060118">The <strong id="dli_08_15102__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_15102__section119977579256"><h4 class="sectiontitle">Description</h4><pre class="screen" id="dli_08_15102__screen1265101518263">string_split(target, separator)</pre>
|
|
|
|
<div class="tablenoborder"><table cellpadding="4" cellspacing="0" summary="" id="dli_08_15102__table343016642713" frame="border" border="1" rules="all"><caption><b>Table 1 </b>string_split parameters</caption><thead align="left"><tr id="dli_08_15102__row843114615273"><th align="left" class="cellrowborder" valign="top" width="33.33333333333333%" id="mcps1.3.2.3.2.4.1.1"><p id="dli_08_15102__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_15102__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_15102__p143111662712">Description</p>
|
|
</th>
|
|
</tr>
|
|
</thead>
|
|
<tbody><tr id="dli_08_15102__row6431767278"><td class="cellrowborder" valign="top" width="33.33333333333333%" headers="mcps1.3.2.3.2.4.1.1 "><p id="dli_08_15102__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_15102__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_15102__p194311463278">Target string to be processed</p>
|
|
<div class="note" id="dli_08_15102__note11538021162815"><span class="notetitle"> NOTE: </span><div class="notebody"><ul id="dli_08_15102__ul1534973892810"><li id="dli_08_15102__li143492038102812">If <strong id="dli_08_15102__b10236897134572">target </strong>is <strong id="dli_08_15102__b16943849034572">NULL</strong>, an empty line is returned.</li><li id="dli_08_15102__li384713910285">If <strong id="dli_08_15102__b20901485484572">target</strong> contains two or more consecutive separators, an empty substring is returned.</li><li id="dli_08_15102__li1546714518283">If <strong id="dli_08_15102__b19769034324572">target</strong> does not contain a specified separator, the original string passed to <strong id="dli_08_15102__b12056830834572">target</strong> is returned.</li></ul>
|
|
</div></div>
|
|
</td>
|
|
</tr>
|
|
<tr id="dli_08_15102__row943118619270"><td class="cellrowborder" valign="top" width="33.33333333333333%" headers="mcps1.3.2.3.2.4.1.1 "><p id="dli_08_15102__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_15102__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_15102__p14431166182710">Separator. Currently, only single-character separators are supported.</p>
|
|
</td>
|
|
</tr>
|
|
</tbody>
|
|
</table>
|
|
</div>
|
|
</div>
|
|
<div class="section" id="dli_08_15102__section1492821012311"><h4 class="sectiontitle">Example</h4><ol id="dli_08_15102__ol7875193418214"><li id="dli_08_15102__li138145563218">Create a Flink OpenSource SQL job by referring to <a href="dli_08_15058.html">Kafka</a> and <a href="dli_08_15060.html">Print</a>, enter the following job running script, and submit the job.<div class="p" id="dli_08_15102__p143639573219">When you create a job, set <strong id="dli_08_15102__b0200124142710">Flink Version</strong> to <strong id="dli_08_15102__b14201202413271">1.15</strong> in the <strong id="dli_08_15102__b020262417273">Running Parameters</strong> tab. Select <strong id="dli_08_15102__b12021124192718">Save Job Log</strong>, and specify the OBS bucket for saving job logs. <strong id="dli_08_15102__b16167185013463">Change the values of the parameters in bold as needed in the following script.</strong><pre class="screen" id="dli_08_15102__screen1468682935015">CREATE TABLE kafkaSource (
|
|
target STRING,
|
|
separator VARCHAR
|
|
) WITH (
|
|
'connector' = 'kafka',
|
|
'topic' = '<em id="dli_08_15102__i92511645115213"><strong id="dli_08_15102__b142512045135215">Kafka</strong></em><em id="dli_08_15102__i11251045105212"><strong id="dli_08_15102__b152513453529">Topic</strong></em>',
|
|
'properties.bootstrap.servers' = '<em id="dli_08_15102__i19502125313520"><strong id="dli_08_15102__b450205314529">KafkaAddress1:KafkaPort,KafkaAddress2:KafkaPort</strong></em>',
|
|
'properties.group.id' = '<em id="dli_08_15102__i81871458175216"><strong id="dli_08_15102__b31882585524">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_15102__li1087510342213">Connect to the Kafka cluster and send the following test data to the Kafka topic:<pre class="screen" id="dli_08_15102__screen7222143315544">{"target":"test-flink","separator":"-"}
|
|
{"target":"flink","separator":"-"}
|
|
{"target":"one-two-ww-three","separator":"-"}</pre>
|
|
<p id="dli_08_15102__p1275313257277">The data is as follows:</p>
|
|
|
|
<div class="tablenoborder"><table cellpadding="4" cellspacing="0" summary="" id="dli_08_15102__table564073111353" frame="border" border="1" rules="all"><caption><b>Table 2 </b>Test table data</caption><thead align="left"><tr id="dli_08_15102__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_15102__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_15102__p18640143113356">separator (VARCHAR)</p>
|
|
</th>
|
|
</tr>
|
|
</thead>
|
|
<tbody><tr id="dli_08_15102__row166401431183513"><td class="cellrowborder" valign="top" width="50%" headers="mcps1.3.3.2.2.3.2.3.1.1 "><p id="dli_08_15102__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_15102__p15640931143513">-</p>
|
|
</td>
|
|
</tr>
|
|
<tr id="dli_08_15102__row3640123103514"><td class="cellrowborder" valign="top" width="50%" headers="mcps1.3.3.2.2.3.2.3.1.1 "><p id="dli_08_15102__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_15102__p164012318356">-</p>
|
|
</td>
|
|
</tr>
|
|
<tr id="dli_08_15102__row35201593611"><td class="cellrowborder" valign="top" width="50%" headers="mcps1.3.3.2.2.3.2.3.1.1 "><p id="dli_08_15102__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_15102__p1452215143617">-</p>
|
|
</td>
|
|
</tr>
|
|
</tbody>
|
|
</table>
|
|
</div>
|
|
</li><li id="dli_08_15102__li5875534023">View output.<ul id="dli_08_15102__ul133191514102210"><li id="dli_08_15102__li11970649381">Method 1:<ol type="a" id="dli_08_15102__ol4711275385"><li id="dli_08_15102__li5612141010388">Log in to the DLI console. In the navigation pane, choose <strong id="dli_08_15102__b12525068392">Job Management</strong> > <strong id="dli_08_15102__b1253112613396">Flink Jobs</strong>.</li><li id="dli_08_15102__li117110711383">Locate the row that contains the target Flink job, and choose <strong id="dli_08_15102__b8891122611394">More</strong> > <strong id="dli_08_15102__b176998313392">FlinkUI</strong> in the <strong id="dli_08_15102__b1269013318396">Operation</strong> column.</li><li id="dli_08_15102__li07833554385">On the Flink UI, choose <strong id="dli_08_15102__b55731924164317">Task Managers</strong>, click the task name, and select <strong id="dli_08_15102__b1533215289439">Stdout</strong> to view job logs.</li></ol>
|
|
</li><li id="dli_08_15102__li341910155285">Method 2: If you select <strong id="dli_08_15102__b177373261494">Save Job Log</strong> on the <strong id="dli_08_15102__b1473762613918">Running Parameters</strong> tab before submitting the job, perform the following operations:<ol type="a" id="dli_08_15102__ol864115198285"><li id="dli_08_15102__li10901621122819">Log in to the DLI console. In the navigation pane, choose <strong id="dli_08_15102__b187990674015">Job Management</strong> > <strong id="dli_08_15102__b12806463408">Flink Jobs</strong>.</li><li id="dli_08_15102__li1912163912282">Click the name of the corresponding Flink job, choose <strong id="dli_08_15102__b12759946124318">Run Log</strong>, click <strong id="dli_08_15102__b10636145194311">OBS Bucket</strong>, and locate the folder of the log you want to view according to the date.</li><li id="dli_08_15102__li0641191914285">Go to the folder of the date, find the folder whose name contains <strong id="dli_08_15102__b498820184517">taskmanager</strong>, download the <strong id="dli_08_15102__b157762415458">taskmanager.out</strong> file, and view result logs.</li></ol>
|
|
</li></ul>
|
|
<div class="p" id="dli_08_15102__p987011431648">The query result is as follows:<pre class="screen" id="dli_08_15102__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_15102__p16316133920410">The output data is as follows:</p>
|
|
|
|
<div class="tablenoborder"><table cellpadding="4" cellspacing="0" summary="" id="dli_08_15102__table33162391646" frame="border" border="1" rules="all"><caption><b>Table 3 </b>Result table data</caption><thead align="left"><tr id="dli_08_15102__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_15102__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_15102__p163161639449">item (STRING)</p>
|
|
</th>
|
|
</tr>
|
|
</thead>
|
|
<tbody><tr id="dli_08_15102__row1131612393412"><td class="cellrowborder" valign="top" width="50%" headers="mcps1.3.3.2.3.4.2.3.1.1 "><p id="dli_08_15102__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_15102__p1031673910413">test</p>
|
|
</td>
|
|
</tr>
|
|
<tr id="dli_08_15102__row1631614391411"><td class="cellrowborder" valign="top" width="50%" headers="mcps1.3.3.2.3.4.2.3.1.1 "><p id="dli_08_15102__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_15102__p331611392417">flink</p>
|
|
</td>
|
|
</tr>
|
|
<tr id="dli_08_15102__row2316173917418"><td class="cellrowborder" valign="top" width="50%" headers="mcps1.3.3.2.3.4.2.3.1.1 "><p id="dli_08_15102__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_15102__p123162391246">flink</p>
|
|
</td>
|
|
</tr>
|
|
<tr id="dli_08_15102__row1131611391042"><td class="cellrowborder" valign="top" width="50%" headers="mcps1.3.3.2.3.4.2.3.1.1 "><p id="dli_08_15102__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_15102__p113161539646">one</p>
|
|
</td>
|
|
</tr>
|
|
<tr id="dli_08_15102__row1631611398416"><td class="cellrowborder" valign="top" width="50%" headers="mcps1.3.3.2.3.4.2.3.1.1 "><p id="dli_08_15102__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_15102__p1831612391547">two</p>
|
|
</td>
|
|
</tr>
|
|
<tr id="dli_08_15102__row63166391413"><td class="cellrowborder" valign="top" width="50%" headers="mcps1.3.3.2.3.4.2.3.1.1 "><p id="dli_08_15102__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_15102__p133163394410">ww</p>
|
|
</td>
|
|
</tr>
|
|
<tr id="dli_08_15102__row0316103911411"><td class="cellrowborder" valign="top" width="50%" headers="mcps1.3.3.2.3.4.2.3.1.1 "><p id="dli_08_15102__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_15102__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_15101.html">Table-Valued Functions</a></div>
|
|
</div>
|
|
</div>
|
|
|