doc-exports/docs/dli/sqlreference/dli_08_0274.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

90 lines
6.8 KiB
HTML

<a name="dli_08_0274"></a><a name="dli_08_0274"></a>
<h1 class="topictitle1">Custom Sink Stream</h1>
<div id="body1587982674379"><p id="dli_08_0274__p5831736182311">Compile code to write the data processed by DLI to a specified cloud ecosystem or open-source ecosystem.</p>
<div class="section" id="dli_08_0274__section820185715231"><h4 class="sectiontitle">Syntax</h4><pre class="screen" id="dli_08_0274__screen1423618261511">CREATE SINK STREAM stream_id (attr_name attr_type (',' attr_name attr_type)* )
WITH (
type = "user_defined",
type_class_name = "",
type_class_parameter = ""
);</pre>
</div>
<div class="section" id="dli_08_0274__section5117155995116"><h4 class="sectiontitle">Keywords</h4>
<div class="tablenoborder"><table cellpadding="4" cellspacing="0" summary="" id="dli_08_0274__table2972926145319" frame="border" border="1" rules="all"><caption><b>Table 1 </b>Keywords</caption><thead align="left"><tr id="dli_08_0274__row29913265537"><th align="left" class="cellrowborder" valign="top" width="15.840000000000002%" id="mcps1.3.3.2.2.4.1.1"><p id="dli_08_0274__p17998132611534">Parameter</p>
</th>
<th align="left" class="cellrowborder" valign="top" width="10.25%" id="mcps1.3.3.2.2.4.1.2"><p id="dli_08_0274__p12310279537">Mandatory</p>
</th>
<th align="left" class="cellrowborder" valign="top" width="73.91%" id="mcps1.3.3.2.2.4.1.3"><p id="dli_08_0274__p10982717536">Description</p>
</th>
</tr>
</thead>
<tbody><tr id="dli_08_0274__row816152795316"><td class="cellrowborder" valign="top" width="15.840000000000002%" headers="mcps1.3.3.2.2.4.1.1 "><p id="dli_08_0274__p202362713532">type</p>
</td>
<td class="cellrowborder" valign="top" width="10.25%" headers="mcps1.3.3.2.2.4.1.2 "><p id="dli_08_0274__p6281227165310">Yes</p>
</td>
<td class="cellrowborder" valign="top" width="73.91%" headers="mcps1.3.3.2.2.4.1.3 "><p id="dli_08_0274__p143216277530">Data source type. The value <strong id="dli_08_0274__b9174112715116">user_defined</strong> indicates that the data source is a user-defined data source.</p>
</td>
</tr>
<tr id="dli_08_0274__row0343279539"><td class="cellrowborder" valign="top" width="15.840000000000002%" headers="mcps1.3.3.2.2.4.1.1 "><p id="dli_08_0274__p13427275537">type_class_name</p>
</td>
<td class="cellrowborder" valign="top" width="10.25%" headers="mcps1.3.3.2.2.4.1.2 "><p id="dli_08_0274__p34712277532">Yes</p>
</td>
<td class="cellrowborder" valign="top" width="73.91%" headers="mcps1.3.3.2.2.4.1.3 "><p id="dli_08_0274__p20521827195312">Name of the sink class for obtaining source data. The value must contain the complete package path.</p>
</td>
</tr>
<tr id="dli_08_0274__row955727195316"><td class="cellrowborder" valign="top" width="15.840000000000002%" headers="mcps1.3.3.2.2.4.1.1 "><p id="dli_08_0274__p156112719538">type_class_parameter</p>
</td>
<td class="cellrowborder" valign="top" width="10.25%" headers="mcps1.3.3.2.2.4.1.2 "><p id="dli_08_0274__p1654277535">Yes</p>
</td>
<td class="cellrowborder" valign="top" width="73.91%" headers="mcps1.3.3.2.2.4.1.3 "><p id="dli_08_0274__p10706276532">Input parameter of the user-defined sink class. Only one parameter of the string type is supported.</p>
</td>
</tr>
</tbody>
</table>
</div>
</div>
<div class="section" id="dli_08_0274__section191711427205614"><h4 class="sectiontitle">Precautions</h4><p id="dli_08_0274__p24564018112">The user-defined sink class needs to inherit the <strong id="dli_08_0274__b15969457114">RichSinkFunction</strong> class and specify the data type as Row. For example, define MySink class: <strong id="dli_08_0274__b860119451814">public class MySink extends RichSinkFunction&lt;Row&gt;{}</strong>. It aims to implement the <strong id="dli_08_0274__b460194518116">open</strong>, <strong id="dli_08_0274__b136011445117">invoke</strong>, and <strong id="dli_08_0274__b14602245711">close</strong> functions.</p>
<p id="dli_08_0274__p1166105441219">Dependency pom:</p>
<pre class="screen" id="dli_08_0274__screen1071745801119">&lt;dependency&gt;
&lt;groupId&gt;org.apache.flink&lt;/groupId&gt;
&lt;artifactId&gt;flink-streaming-java_2.11&lt;/artifactId&gt;
&lt;version&gt;${flink.version}&lt;/version&gt;
&lt;scope&gt;provided&lt;/scope&gt;
&lt;/dependency&gt;
&lt;dependency&gt;
&lt;groupId&gt;org.apache.flink&lt;/groupId&gt;
&lt;artifactId&gt;flink-core&lt;/artifactId&gt;
&lt;version&gt;${flink.version}&lt;/version&gt;
&lt;scope&gt;provided&lt;/scope&gt;
&lt;/dependency&gt;</pre>
</div>
<div class="section" id="dli_08_0274__section7600402288"><h4 class="sectiontitle">Example</h4><p id="dli_08_0274__p19311143182815">Writing data encoded in CSV format to a DIS stream is used as an example.</p>
</div>
<div class="codecoloring" codetype="Sql" id="dli_08_0274__screen194421611162913"><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></pre></div></td><td class="code"><div><pre><span></span><span class="k">CREATE</span><span class="w"> </span><span class="n">SINK</span><span class="w"> </span><span class="n">STREAM</span><span class="w"> </span><span class="n">user_out_data</span><span class="w"> </span><span class="p">(</span>
<span class="w"> </span><span class="k">count</span><span class="w"> </span><span class="nb">INT</span>
<span class="p">)</span>
<span class="w"> </span><span class="k">WITH</span><span class="w"> </span><span class="p">(</span><span class="w"> </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;user_defined&quot;</span><span class="p">,</span><span class="w"> </span>
<span class="w"> </span><span class="n">type_class_name</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="ss">&quot;mySourceSink.MySink&quot;</span><span class="p">,</span><span class="w"> </span>
<span class="w"> </span><span class="n">type_class_parameter</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="ss">&quot;&quot;</span>
<span class="w"> </span><span class="p">);</span>
</pre></div></td></tr></table></div>
</div>
<div class="note" id="dli_08_0274__note156291340143015"><img src="public_sys-resources/note_3.0-en-us.png"><span class="notetitle"> </span><div class="notebody"><p id="dli_08_0274__p863974010300">To customize the implementation of the sink class, you need to pack the class in a JAR package and upload the UDF function on the SQL editing page.</p>
</div></div>
</div>
<div>
<div class="familylinks">
<div class="parentlink"><strong>Parent topic:</strong> <a href="dli_08_0272.html">Custom Stream Ecosystem</a></div>
</div>
</div>