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>
99 lines
9.7 KiB
HTML
99 lines
9.7 KiB
HTML
<a name="dli_08_0347"></a><a name="dli_08_0347"></a>
|
|
|
|
<h1 class="topictitle1">User-defined Result Table</h1>
|
|
<div id="body8662426"><div class="section" id="dli_08_0347__en-us_topic_0000001163132424_en-us_topic_0000001177560413_section18893144724516"><h4 class="sectiontitle">Function</h4><p id="dli_08_0347__en-us_topic_0000001163132424_en-us_topic_0000001177560413_p188831151194614">Write your Java code to insert the processed data into a specified database supported by your cloud service.</p>
|
|
</div>
|
|
<div class="section" id="dli_08_0347__en-us_topic_0000001163132424_en-us_topic_0000001177560413_section20477184319477"><a name="dli_08_0347__en-us_topic_0000001163132424_en-us_topic_0000001177560413_section20477184319477"></a><a name="en-us_topic_0000001163132424_en-us_topic_0000001177560413_section20477184319477"></a><h4 class="sectiontitle">Prerequisites</h4><p id="dli_08_0347__en-us_topic_0000001163132424_en-us_topic_0000001177560413_p2014764514455"><strong id="dli_08_0347__en-us_topic_0000001163132424_en-us_topic_0000001177560413_b511014181163">Implement the custom sink class :</strong></p>
|
|
<p id="dli_08_0347__en-us_topic_0000001163132424_en-us_topic_0000001177560413_p84021931182316">The custom sink class is inherited from Flink open-source class <strong id="dli_08_0347__en-us_topic_0000001163132424_en-us_topic_0000001177560413_b14344171943519">RichSinkFunction</strong>. The data type is <strong id="dli_08_0347__en-us_topic_0000001163132424_en-us_topic_0000001177560413_b12371112117350">Tuple2<Boolean, Row</strong>>.</p>
|
|
<div class="p" id="dli_08_0347__en-us_topic_0000001163132424_en-us_topic_0000001177560413_p18716479472">For example, define the <strong id="dli_08_0347__en-us_topic_0000001163132424_en-us_topic_0000001177560413_b17562153113520">MySink</strong> class by <strong id="dli_08_0347__en-us_topic_0000001163132424_en-us_topic_0000001177560413_b6619101210368">public class MySink extends RichSinkFunction< Tuple2<Boolean, Row>>{}</strong>, and implement the <strong id="dli_08_0347__en-us_topic_0000001163132424_en-us_topic_0000001177560413_b5878115418372">open</strong>, <strong id="dli_08_0347__en-us_topic_0000001163132424_en-us_topic_0000001177560413_b16307195612379">invoke</strong>, and <strong id="dli_08_0347__en-us_topic_0000001163132424_en-us_topic_0000001177560413_b1647855819375">close</strong> functions. A code example is as follows:<pre class="screen" id="dli_08_0347__en-us_topic_0000001163132424_en-us_topic_0000001177560413_screen10384584273">public class MySink extends RichSinkFunction<Tuple2<Boolean, Row>> {
|
|
// Initialize the object.
|
|
@Override
|
|
public void open(Configuration parameters) throws Exception {}
|
|
|
|
@Override
|
|
// Implement the data processing logic.
|
|
/* The <strong id="dli_08_0347__en-us_topic_0000001163132424_en-us_topic_0000001177560413_b9404164024014">in</strong> parameter contains two values. The first value is of the Boolean type. The value <strong id="dli_08_0347__en-us_topic_0000001163132424_en-us_topic_0000001177560413_b1084225818404">true</strong> indicates the insert or update operation, and the value <strong id="dli_08_0347__en-us_topic_0000001163132424_en-us_topic_0000001177560413_b1870272214114">false</strong> indicates the delete operation. If the interconnected sink does not support the delete operation, the deletion will not be executed. The second value indicates the data to be operated.*/
|
|
public void invoke(Tuple2<Boolean, Row> in, Context context) throws Exception {}
|
|
|
|
@Override
|
|
public void close() throws Exception {}
|
|
}</pre>
|
|
</div>
|
|
<p id="dli_08_0347__en-us_topic_0000001163132424_en-us_topic_0000001177560413_p9389193111212">Content of the dependent pom configuration file is as follows:</p>
|
|
<pre class="screen" id="dli_08_0347__en-us_topic_0000001163132424_en-us_topic_0000001177560413_screen199261049900"><dependency>
|
|
<groupId>org.apache.flink</groupId>
|
|
<artifactId>flink-streaming-java_2.11</artifactId>
|
|
<version>${flink.version}</version>
|
|
<scope>provided</scope>
|
|
</dependency>
|
|
|
|
<dependency>
|
|
<groupId>org.apache.flink</groupId>
|
|
<artifactId>flink-core</artifactId>
|
|
<version>${flink.version}</version>
|
|
<scope>provided</scope>
|
|
</dependency></pre>
|
|
<p id="dli_08_0347__en-us_topic_0000001163132424_en-us_topic_0000001177560413_p7901199104719">Pack the implemented class and compile it in a JAR file, and upload it using the UDF Jar parameter on the editing page of your Flink OpenSource SQL job. </p>
|
|
</div>
|
|
<div class="section" id="dli_08_0347__en-us_topic_0000001163132424_en-us_topic_0000001177560413_section14958171413479"><h4 class="sectiontitle">Syntax</h4><pre class="screen" id="dli_08_0347__en-us_topic_0000001163132424_en-us_topic_0000001177560413_screen167361602153">create table userDefinedSink (
|
|
attr_name attr_type
|
|
(',' attr_name attr_type)*
|
|
)
|
|
with (
|
|
'connector.type' = 'user-defined',
|
|
'connector.class-name' = ''
|
|
);</pre>
|
|
</div>
|
|
<div class="section" id="dli_08_0347__en-us_topic_0000001163132424_en-us_topic_0000001177560413_section1741317224521"><h4 class="sectiontitle">Parameters</h4>
|
|
<div class="tablenoborder"><table cellpadding="4" cellspacing="0" summary="" id="dli_08_0347__en-us_topic_0000001163132424_en-us_topic_0000001177560413_table2791332205214" frame="border" border="1" rules="all"><caption><b>Table 1 </b>Parameter description</caption><thead align="left"><tr id="dli_08_0347__en-us_topic_0000001163132424_en-us_topic_0000001177560413_row1279183219529"><th align="left" class="cellrowborder" valign="top" width="33.33333333333333%" id="mcps1.3.4.2.2.4.1.1"><p id="dli_08_0347__en-us_topic_0000001163132424_en-us_topic_0000001177560413_p1479163215212">Parameter</p>
|
|
</th>
|
|
<th align="left" class="cellrowborder" valign="top" width="14.211421142114212%" id="mcps1.3.4.2.2.4.1.2"><p id="dli_08_0347__en-us_topic_0000001163132424_en-us_topic_0000001177560413_p4791183295213">Mandatory</p>
|
|
</th>
|
|
<th align="left" class="cellrowborder" valign="top" width="52.45524552455245%" id="mcps1.3.4.2.2.4.1.3"><p id="dli_08_0347__en-us_topic_0000001163132424_en-us_topic_0000001177560413_p77919321522">Description</p>
|
|
</th>
|
|
</tr>
|
|
</thead>
|
|
<tbody><tr id="dli_08_0347__en-us_topic_0000001163132424_en-us_topic_0000001177560413_row1779113219522"><td class="cellrowborder" valign="top" width="33.33333333333333%" headers="mcps1.3.4.2.2.4.1.1 "><p id="dli_08_0347__en-us_topic_0000001163132424_en-us_topic_0000001177560413_p18574195918524">connector.type</p>
|
|
</td>
|
|
<td class="cellrowborder" valign="top" width="14.211421142114212%" headers="mcps1.3.4.2.2.4.1.2 "><p id="dli_08_0347__en-us_topic_0000001163132424_en-us_topic_0000001177560413_p10791183205214">Yes</p>
|
|
</td>
|
|
<td class="cellrowborder" valign="top" width="52.45524552455245%" headers="mcps1.3.4.2.2.4.1.3 "><p id="dli_08_0347__en-us_topic_0000001163132424_en-us_topic_0000001177560413_p1279153210522">Connector type. The value can only be a user-defined sink.</p>
|
|
</td>
|
|
</tr>
|
|
<tr id="dli_08_0347__en-us_topic_0000001163132424_en-us_topic_0000001177560413_row27911932155217"><td class="cellrowborder" valign="top" width="33.33333333333333%" headers="mcps1.3.4.2.2.4.1.1 "><p id="dli_08_0347__en-us_topic_0000001163132424_en-us_topic_0000001177560413_p2079115329523">connector.class-name</p>
|
|
</td>
|
|
<td class="cellrowborder" valign="top" width="14.211421142114212%" headers="mcps1.3.4.2.2.4.1.2 "><p id="dli_08_0347__en-us_topic_0000001163132424_en-us_topic_0000001177560413_p179114323526">Yes</p>
|
|
</td>
|
|
<td class="cellrowborder" valign="top" width="52.45524552455245%" headers="mcps1.3.4.2.2.4.1.3 "><p id="dli_08_0347__en-us_topic_0000001163132424_en-us_topic_0000001177560413_p5792153216525">Fully qualified class name of the sink class. For details about the implementation of the sink class, see <a href="#dli_08_0347__en-us_topic_0000001163132424_en-us_topic_0000001177560413_section20477184319477">Prerequisites</a>.</p>
|
|
</td>
|
|
</tr>
|
|
<tr id="dli_08_0347__en-us_topic_0000001163132424_en-us_topic_0000001177560413_row3792143217529"><td class="cellrowborder" valign="top" width="33.33333333333333%" headers="mcps1.3.4.2.2.4.1.1 "><p id="dli_08_0347__en-us_topic_0000001163132424_en-us_topic_0000001177560413_p179215324527">connector.class-parameter</p>
|
|
</td>
|
|
<td class="cellrowborder" valign="top" width="14.211421142114212%" headers="mcps1.3.4.2.2.4.1.2 "><p id="dli_08_0347__en-us_topic_0000001163132424_en-us_topic_0000001177560413_p4792732135213">No</p>
|
|
</td>
|
|
<td class="cellrowborder" valign="top" width="52.45524552455245%" headers="mcps1.3.4.2.2.4.1.3 "><p id="dli_08_0347__en-us_topic_0000001163132424_en-us_topic_0000001177560413_p127927323525">Parameter of the constructor of the sink class. Only one parameter of the string type is supported.</p>
|
|
</td>
|
|
</tr>
|
|
</tbody>
|
|
</table>
|
|
</div>
|
|
</div>
|
|
<div class="section" id="dli_08_0347__en-us_topic_0000001163132424_en-us_topic_0000001177560413_section1643745417537"><h4 class="sectiontitle">Precautions</h4><p id="dli_08_0347__en-us_topic_0000001163132424_en-us_topic_0000001177560413_p88622312543"><strong id="dli_08_0347__en-us_topic_0000001163132424_en-us_topic_0000001177560413_b514314361213">connector.class-name</strong> must be a fully qualified class name.</p>
|
|
</div>
|
|
<div class="section" id="dli_08_0347__en-us_topic_0000001163132424_en-us_topic_0000001177560413_section8515152835418"><h4 class="sectiontitle">Example</h4><pre class="screen" id="dli_08_0347__en-us_topic_0000001163132424_en-us_topic_0000001177560413_screen11244155517544">create table userDefinedSink (
|
|
attr1 int,
|
|
attr2 int
|
|
)
|
|
with (
|
|
'connector.type' = 'user-defined',
|
|
'connector.class-name' = 'xx.xx.MySink'
|
|
);</pre>
|
|
</div>
|
|
</div>
|
|
<div>
|
|
<div class="familylinks">
|
|
<div class="parentlink"><strong>Parent topic:</strong> <a href="dli_08_0307.html">Creating a Result Table</a></div>
|
|
</div>
|
|
</div>
|
|
|