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

84 lines
7.9 KiB
HTML

<a name="dli_08_0358"></a><a name="dli_08_0358"></a>
<h1 class="topictitle1">userDefined Source Table</h1>
<div id="body8662426"><div class="section" id="dli_08_0358__en-us_topic_0000001214861837_en-us_topic_0000001177564695_section112823715587"><h4 class="sectiontitle">Function</h4><p id="dli_08_0358__en-us_topic_0000001214861837_en-us_topic_0000001177564695_p64151541135819">You can call APIs to obtain data from the cloud ecosystem or an open source ecosystem and use the obtained data as input of Flink jobs.</p>
</div>
<div class="section" id="dli_08_0358__en-us_topic_0000001214861837_en-us_topic_0000001177564695_section8327155014598"><h4 class="sectiontitle">Prerequisites</h4><p id="dli_08_0358__en-us_topic_0000001214861837_en-us_topic_0000001177564695_p5125113581119">The customized source class needs to inherit the <strong id="dli_08_0358__en-us_topic_0000001214861837_en-us_topic_0000001177564695_b56189461713">RichParallelSourceFunction</strong> class and specify the data type as Row.</p>
<p id="dli_08_0358__en-us_topic_0000001214861837_en-us_topic_0000001177564695_p207001657135918">For example, run <strong id="dli_08_0358__en-us_topic_0000001214861837_en-us_topic_0000001177564695_b186091648815">public class MySource extends RichParallelSourceFunction&lt;Row&gt;{}</strong> to declare custom class <strong id="dli_08_0358__en-us_topic_0000001214861837_en-us_topic_0000001177564695_b17748108682">MySource</strong>. You need to implement the <strong id="dli_08_0358__en-us_topic_0000001214861837_en-us_topic_0000001177564695_b2091219575302">open</strong>, <strong id="dli_08_0358__en-us_topic_0000001214861837_en-us_topic_0000001177564695_b15409259183018">run</strong>, <strong id="dli_08_0358__en-us_topic_0000001214861837_en-us_topic_0000001177564695_b1860914013314">close</strong>, and <strong id="dli_08_0358__en-us_topic_0000001214861837_en-us_topic_0000001177564695_b1785210215312">cancel</strong> functions. Encapsulate the class into a JAR file and upload the file through the UDF JAR on the SQL editing page.</p>
<div class="p" id="dli_08_0358__en-us_topic_0000001214861837_en-us_topic_0000001177564695_p1743013391011">Content of the dependent pom configuration file is as follows:<pre class="screen" id="dli_08_0358__en-us_topic_0000001214861837_en-us_topic_0000001177564695_screen199261049900">&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>
<div class="section" id="dli_08_0358__en-us_topic_0000001214861837_en-us_topic_0000001177564695_section18628156525"><h4 class="sectiontitle">Syntax</h4><pre class="screen" id="dli_08_0358__en-us_topic_0000001214861837_en-us_topic_0000001177564695_screen167361602153">create table userDefinedSource (
attr_name attr_type
(',' attr_name attr_type)*
)
with (
'connector.type' = 'user-defined',
'connector.class-name' = ''
);</pre>
</div>
<div class="section" id="dli_08_0358__en-us_topic_0000001214861837_en-us_topic_0000001177564695_section1954818219319"><h4 class="sectiontitle">Parameters</h4>
<div class="tablenoborder"><table cellpadding="4" cellspacing="0" summary="" id="dli_08_0358__en-us_topic_0000001214861837_en-us_topic_0000001177564695_table2791332205214" frame="border" border="1" rules="all"><caption><b>Table 1 </b>Parameter description</caption><thead align="left"><tr id="dli_08_0358__en-us_topic_0000001214861837_en-us_topic_0000001177564695_row1279183219529"><th align="left" class="cellrowborder" valign="top" width="33.33333333333333%" id="mcps1.3.4.2.2.4.1.1"><p id="dli_08_0358__en-us_topic_0000001214861837_en-us_topic_0000001177564695_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_0358__en-us_topic_0000001214861837_en-us_topic_0000001177564695_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_0358__en-us_topic_0000001214861837_en-us_topic_0000001177564695_p77919321522">Description</p>
</th>
</tr>
</thead>
<tbody><tr id="dli_08_0358__en-us_topic_0000001214861837_en-us_topic_0000001177564695_row1779113219522"><td class="cellrowborder" valign="top" width="33.33333333333333%" headers="mcps1.3.4.2.2.4.1.1 "><p id="dli_08_0358__en-us_topic_0000001214861837_en-us_topic_0000001177564695_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_0358__en-us_topic_0000001214861837_en-us_topic_0000001177564695_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_0358__en-us_topic_0000001214861837_en-us_topic_0000001177564695_p1279153210522">Source type. The value can only be <strong id="dli_08_0358__en-us_topic_0000001214861837_en-us_topic_0000001177564695_b108168351236">user-defined</strong>, indicating a custom source.</p>
</td>
</tr>
<tr id="dli_08_0358__en-us_topic_0000001214861837_en-us_topic_0000001177564695_row27911932155217"><td class="cellrowborder" valign="top" width="33.33333333333333%" headers="mcps1.3.4.2.2.4.1.1 "><p id="dli_08_0358__en-us_topic_0000001214861837_en-us_topic_0000001177564695_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_0358__en-us_topic_0000001214861837_en-us_topic_0000001177564695_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_0358__en-us_topic_0000001214861837_en-us_topic_0000001177564695_p5792153216525">Fully qualified class name of the source class</p>
</td>
</tr>
<tr id="dli_08_0358__en-us_topic_0000001214861837_en-us_topic_0000001177564695_row3792143217529"><td class="cellrowborder" valign="top" width="33.33333333333333%" headers="mcps1.3.4.2.2.4.1.1 "><p id="dli_08_0358__en-us_topic_0000001214861837_en-us_topic_0000001177564695_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_0358__en-us_topic_0000001214861837_en-us_topic_0000001177564695_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_0358__en-us_topic_0000001214861837_en-us_topic_0000001177564695_p127927323525">Parameter of the constructor of the source class. Only one parameter of the string type is supported.</p>
</td>
</tr>
</tbody>
</table>
</div>
</div>
<div class="section" id="dli_08_0358__en-us_topic_0000001214861837_en-us_topic_0000001177564695_section1643745417537"><h4 class="sectiontitle">Precautions</h4><p id="dli_08_0358__en-us_topic_0000001214861837_en-us_topic_0000001177564695_p88622312543"><strong id="dli_08_0358__en-us_topic_0000001214861837_en-us_topic_0000001177564695_b2985281796">connector.class-name</strong> must be a fully qualified class name.</p>
</div>
<div class="section" id="dli_08_0358__en-us_topic_0000001214861837_en-us_topic_0000001177564695_section8515152835418"><h4 class="sectiontitle">Example</h4><pre class="screen" id="dli_08_0358__en-us_topic_0000001214861837_en-us_topic_0000001177564695_screen11244155517544">create table userDefinedSource (
attr1 int,
attr2 int
)
with (
'connector.type' = 'user-defined',
'connector.class-name' = 'xx.xx.MySource'
);</pre>
</div>
</div>
<div>
<div class="familylinks">
<div class="parentlink"><strong>Parent topic:</strong> <a href="dli_08_0300.html">Creating a Source Table</a></div>
</div>
</div>