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>
306 lines
32 KiB
HTML
306 lines
32 KiB
HTML
<a name="dli_08_15030"></a><a name="dli_08_15030"></a>
|
|
|
|
<h1 class="topictitle1">ClickHouse</h1>
|
|
<div id="body0000001784633049"><div class="section" id="dli_08_15030__dli_08_0256_en-us_topic_0132788972_section108631122164917"><h4 class="sectiontitle">Function</h4><p id="dli_08_15030__p76091541019">DLI has the capability to export data from Flink jobs to the ClickHouse database. However, it only supports exporting data to result tables.</p>
|
|
<p id="dli_08_15030__p661816320442">ClickHouse is a column-based database oriented to online analysis and processing. It supports SQL query and provides good query performance. The aggregation analysis and query performance based on large and wide tables is excellent, which is one order of magnitude faster than other analytical databases. </p>
|
|
|
|
<div class="tablenoborder"><table cellpadding="4" cellspacing="0" summary="" id="dli_08_15030__table3954102713514" frame="border" border="1" rules="all"><caption><b>Table 1 </b>Supported types</caption><thead align="left"><tr id="dli_08_15030__row139551727153515"><th align="left" class="cellrowborder" valign="top" width="33.87%" id="mcps1.3.1.4.2.3.1.1"><p id="dli_08_15030__p169550272355">Type</p>
|
|
</th>
|
|
<th align="left" class="cellrowborder" valign="top" width="66.13%" id="mcps1.3.1.4.2.3.1.2"><p id="dli_08_15030__p9955172713520">Description</p>
|
|
</th>
|
|
</tr>
|
|
</thead>
|
|
<tbody><tr id="dli_08_15030__row595518271358"><td class="cellrowborder" valign="top" width="33.87%" headers="mcps1.3.1.4.2.3.1.1 "><p id="dli_08_15030__p4955182716353">Supported Table Types</p>
|
|
</td>
|
|
<td class="cellrowborder" valign="top" width="66.13%" headers="mcps1.3.1.4.2.3.1.2 "><p id="dli_08_15030__p1595518273356">Result table</p>
|
|
</td>
|
|
</tr>
|
|
</tbody>
|
|
</table>
|
|
</div>
|
|
</div>
|
|
<div class="section" id="dli_08_15030__dli_08_0256_en-us_topic_0132788972_section2579142713429"><h4 class="sectiontitle">Prerequisites</h4><ul id="dli_08_15030__ul16362030161817"><li id="dli_08_15030__li7362123012186">Your jobs are running on a dedicated queue of DLI.</li><li id="dli_08_15030__li7801231131817">You have established an enhanced datasource connection to ClickHouse and set the port in the security group rule of the ClickHouse cluster as needed.</li></ul>
|
|
</div>
|
|
<div class="section" id="dli_08_15030__dli_08_0256_section9685114274916"><h4 class="sectiontitle">Caveats</h4><ul id="dli_08_15030__ul13298309230"><li id="dli_08_15030__li13608118132418">When you create a Flink OpenSource SQL job, set <strong id="dli_08_15030__dli_08_15029_b163001353185217">Flink Version</strong> to <strong id="dli_08_15030__dli_08_15029_b1430115539523">1.15</strong> in the <strong id="dli_08_15030__dli_08_15029_b1030175315523">Running Parameters</strong> tab. Select <strong id="dli_08_15030__dli_08_15029_b430135325212">Save Job Log</strong>, and specify the OBS bucket for saving job logs.</li><li id="dli_08_15030__li980192610493">Storing authentication credentials such as usernames and passwords in code or plaintext poses significant security risks. It is recommended using DEW to manage credentials instead. Storing encrypted credentials in configuration files or environment variables and decrypting them when needed ensures security. For details, see .</li><li id="dli_08_15030__li8627172413266">When you create a ClickHouse cluster for MRS, set the cluster version to MRS 3.1.0 or later.</li><li id="dli_08_15030__li11291830192316">The ClickHouse result table does not support table data deletion.</li><li id="dli_08_15030__li18722511382">Flink supports the following data types: string, tinyint, smallint, int, bigint, float, double, date, timestamp, decimal, and array.<p id="dli_08_15030__p5810135218381"><a name="dli_08_15030__li18722511382"></a><a name="li18722511382"></a>The array supports only the int, bigint, string, float, and double data types.</p>
|
|
</li></ul>
|
|
</div>
|
|
<div class="section" id="dli_08_15030__dli_08_0256_en-us_topic_0132788972_section3126105364419"><h4 class="sectiontitle">Syntax</h4><div class="codecoloring" codetype="Sql" id="dli_08_15030__dli_08_0256_screen1461215294716"><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>
|
|
<span class="normal">9</span></pre></div></td><td class="code"><div><pre><span></span><span class="k">create</span><span class="w"> </span><span class="k">table</span><span class="w"> </span><span class="n">clickhouseSink</span><span class="w"> </span><span class="p">(</span>
|
|
<span class="w"> </span><span class="n">attr_name</span><span class="w"> </span><span class="n">attr_type</span><span class="w"> </span>
|
|
<span class="w"> </span><span class="p">(</span><span class="s1">','</span><span class="w"> </span><span class="n">attr_name</span><span class="w"> </span><span class="n">attr_type</span><span class="p">)</span><span class="o">*</span><span class="w"> </span>
|
|
<span class="p">)</span>
|
|
<span class="k">with</span><span class="w"> </span><span class="p">(</span>
|
|
<span class="w"> </span><span class="s1">'type'</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="s1">'clickhouse'</span><span class="p">,</span>
|
|
<span class="w"> </span><span class="s1">'url'</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="s1">''</span><span class="p">,</span>
|
|
<span class="w"> </span><span class="s1">'table-name'</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="s1">''</span>
|
|
<span class="p">);</span>
|
|
</pre></div></td></tr></table></div>
|
|
</div>
|
|
</div>
|
|
<div class="section" id="dli_08_15030__dli_08_0256_section4299113491"><h4 class="sectiontitle">Parameter Description</h4>
|
|
<div class="tablenoborder"><table cellpadding="4" cellspacing="0" summary="" id="dli_08_15030__table11617424154613" frame="border" border="1" rules="all"><caption><b>Table 2 </b>Parameters</caption><thead align="left"><tr id="dli_08_15030__row146177242466"><th align="left" class="cellrowborder" valign="top" width="18.37%" id="mcps1.3.5.2.2.6.1.1"><p id="dli_08_15030__p1361712418461">Parameter</p>
|
|
</th>
|
|
<th align="left" class="cellrowborder" valign="top" width="9.719999999999999%" id="mcps1.3.5.2.2.6.1.2"><p id="dli_08_15030__p176171424114615">Mandatory</p>
|
|
</th>
|
|
<th align="left" class="cellrowborder" valign="top" width="13.22%" id="mcps1.3.5.2.2.6.1.3"><p id="dli_08_15030__p1567884219416">Default Value</p>
|
|
</th>
|
|
<th align="left" class="cellrowborder" valign="top" width="11.37%" id="mcps1.3.5.2.2.6.1.4"><p id="dli_08_15030__p419114510416">Data Type</p>
|
|
</th>
|
|
<th align="left" class="cellrowborder" valign="top" width="47.32%" id="mcps1.3.5.2.2.6.1.5"><p id="dli_08_15030__p261712247467">Description</p>
|
|
</th>
|
|
</tr>
|
|
</thead>
|
|
<tbody><tr id="dli_08_15030__row136171242461"><td class="cellrowborder" valign="top" width="18.37%" headers="mcps1.3.5.2.2.6.1.1 "><p id="dli_08_15030__p992213916285">connector</p>
|
|
</td>
|
|
<td class="cellrowborder" valign="top" width="9.719999999999999%" headers="mcps1.3.5.2.2.6.1.2 "><p id="dli_08_15030__p169221598288">Yes</p>
|
|
</td>
|
|
<td class="cellrowborder" valign="top" width="13.22%" headers="mcps1.3.5.2.2.6.1.3 "><p id="dli_08_15030__p967894211418">None</p>
|
|
</td>
|
|
<td class="cellrowborder" valign="top" width="11.37%" headers="mcps1.3.5.2.2.6.1.4 "><p id="dli_08_15030__p121910451416">String</p>
|
|
</td>
|
|
<td class="cellrowborder" valign="top" width="47.32%" headers="mcps1.3.5.2.2.6.1.5 "><p id="dli_08_15030__p1492219917287">Result table type. Set this parameter to <strong id="dli_08_15030__b6667318514343">clickhouse</strong>.</p>
|
|
</td>
|
|
</tr>
|
|
<tr id="dli_08_15030__row1961742414462"><td class="cellrowborder" valign="top" width="18.37%" headers="mcps1.3.5.2.2.6.1.1 "><p id="dli_08_15030__p189227911283">url</p>
|
|
</td>
|
|
<td class="cellrowborder" valign="top" width="9.719999999999999%" headers="mcps1.3.5.2.2.6.1.2 "><p id="dli_08_15030__p119227912817">Yes</p>
|
|
</td>
|
|
<td class="cellrowborder" valign="top" width="13.22%" headers="mcps1.3.5.2.2.6.1.3 "><p id="dli_08_15030__p1367811423413">None</p>
|
|
</td>
|
|
<td class="cellrowborder" valign="top" width="11.37%" headers="mcps1.3.5.2.2.6.1.4 "><p id="dli_08_15030__p1819174554113">String</p>
|
|
</td>
|
|
<td class="cellrowborder" valign="top" width="47.32%" headers="mcps1.3.5.2.2.6.1.5 "><p id="dli_08_15030__p271993713110">ClickHouse URL</p>
|
|
<p id="dli_08_15030__p393765714189">It is in the format of <strong id="dli_08_15030__b4243816153818">jdbc:clickhouse://</strong><em id="dli_08_15030__i195704214387">ClickHouseBalancer instance service IP address 1</em><strong id="dli_08_15030__b23221030183812">:</strong><em id="dli_08_15030__i273713365388">ClickHouseBalancer port</em><strong id="dli_08_15030__b182872392389">,</strong><em id="dli_08_15030__i1575374316389">ClickHouseBalancer instance service IP address 2</em><strong id="dli_08_15030__b14376155083817">:</strong><em id="dli_08_15030__i425321193911">ClickHouseBalancer port</em><strong id="dli_08_15030__b745644123915">/</strong><em id="dli_08_15030__i20544894397">Database name</em>.</p>
|
|
<ul id="dli_08_15030__ul15210101291220"><li id="dli_08_15030__li10428100111319">IP address of a ClickHouseBalancer instance:<p id="dli_08_15030__p5718212134"><a name="dli_08_15030__li10428100111319"></a><a name="li10428100111319"></a>Log in to the MRS console and choose <strong id="dli_08_15030__b17819907494343">Clusters</strong> > <strong id="dli_08_15030__b13901120954343">Active Clusters</strong> in the navigation pane. Click a cluster name, and choose <strong id="dli_08_15030__b17731642734343">Components</strong> > <strong id="dli_08_15030__b5762992004343">ClickHouse</strong> > <strong id="dli_08_15030__b18805115474343">Instances</strong> to obtain the business IP address of the ClickHouseBalancer instance.</p>
|
|
</li><li id="dli_08_15030__li34551059111218">ClickHouseBalancer port number:<p id="dli_08_15030__p5859134117289"><a name="dli_08_15030__li34551059111218"></a><a name="li34551059111218"></a>Log in to the MRS console and choose <strong id="dli_08_15030__b12806471294343">Clusters</strong> > <strong id="dli_08_15030__b7447921494343">Active Clusters</strong> in the navigation pane. Click a cluster name, and choose <strong id="dli_08_15030__b6659153884343">Components</strong> > <strong id="dli_08_15030__b11031639334343">ClickHouse</strong> > <strong id="dli_08_15030__b6301629874343">Service Configuration</strong>. On the <strong id="dli_08_15030__b7445536714343">Service Configuration</strong> page, select <strong id="dli_08_15030__b504525684343">ClickHouseBalancer</strong> from the <strong id="dli_08_15030__b11591685754343">All Roles</strong> drop-down list. If the MRS cluster does not have Kerberos authentication enabled, search for <strong id="dli_08_15030__b349531794014">lb_http_port</strong> and set it (defaults to <strong id="dli_08_15030__b13578154114401">21425</strong>). If Kerberos authentication is enabled, search for <strong id="dli_08_15030__b2565510417">lb_https_port</strong> and set it (defaults to <strong id="dli_08_15030__b1587712223418">21426</strong>).</p>
|
|
</li><li id="dli_08_15030__li11558457172813">The database name is the name of the database created for the ClickHouse cluster. If the database name does not exist, there is no need to specify it.</li><li id="dli_08_15030__li18234125952814">You can configure multiple IP addresses for ClickHouseBalancer instances to avoid single points of failure (SPOFs) of the instances.</li><li id="dli_08_15030__li36971737326">If the MRS cluster has Kerberos authentication enabled, you also need to add the <strong id="dli_08_15030__b1137920735115">ssl</strong> and <strong id="dli_08_15030__b27661910105119">sslmode</strong> request parameters to the URL, setting <strong id="dli_08_15030__b185721326155119">ssl</strong> to <strong id="dli_08_15030__b16795152815515">true</strong> and <strong id="dli_08_15030__b4447731185116">sslmode</strong> to <strong id="dli_08_15030__b623683325114">none</strong>. Refer to <a href="#dli_08_15030__li1997152814379">Example 2</a> for an example.</li></ul>
|
|
</td>
|
|
</tr>
|
|
<tr id="dli_08_15030__row1761802415461"><td class="cellrowborder" valign="top" width="18.37%" headers="mcps1.3.5.2.2.6.1.1 "><p id="dli_08_15030__p1092209122818">table-name</p>
|
|
</td>
|
|
<td class="cellrowborder" valign="top" width="9.719999999999999%" headers="mcps1.3.5.2.2.6.1.2 "><p id="dli_08_15030__p149225917285">Yes</p>
|
|
</td>
|
|
<td class="cellrowborder" valign="top" width="13.22%" headers="mcps1.3.5.2.2.6.1.3 "><p id="dli_08_15030__p15107510366">None</p>
|
|
</td>
|
|
<td class="cellrowborder" valign="top" width="11.37%" headers="mcps1.3.5.2.2.6.1.4 "><p id="dli_08_15030__p619945134117">String</p>
|
|
</td>
|
|
<td class="cellrowborder" valign="top" width="47.32%" headers="mcps1.3.5.2.2.6.1.5 "><p id="dli_08_15030__p169222932814">ClickHouse table name.</p>
|
|
</td>
|
|
</tr>
|
|
<tr id="dli_08_15030__row1261892474618"><td class="cellrowborder" valign="top" width="18.37%" headers="mcps1.3.5.2.2.6.1.1 "><p id="dli_08_15030__p16922169172812">driver</p>
|
|
</td>
|
|
<td class="cellrowborder" valign="top" width="9.719999999999999%" headers="mcps1.3.5.2.2.6.1.2 "><p id="dli_08_15030__p1992213917286">No</p>
|
|
</td>
|
|
<td class="cellrowborder" valign="top" width="13.22%" headers="mcps1.3.5.2.2.6.1.3 "><p id="dli_08_15030__p1567814244119">ru.yandex.clickhouse.ClickHouseDriver</p>
|
|
</td>
|
|
<td class="cellrowborder" valign="top" width="11.37%" headers="mcps1.3.5.2.2.6.1.4 "><p id="dli_08_15030__p11191245174112">String</p>
|
|
</td>
|
|
<td class="cellrowborder" valign="top" width="47.32%" headers="mcps1.3.5.2.2.6.1.5 "><p id="dli_08_15030__p196305763311">Driver required for connecting to the database. If you do not set this parameter, the automatically extracted driver will be used, which defaults to <strong id="dli_08_15030__b361217175815">ru.yandex.clickhouse.ClickHouseDriver</strong>.</p>
|
|
</td>
|
|
</tr>
|
|
<tr id="dli_08_15030__row15618102474612"><td class="cellrowborder" valign="top" width="18.37%" headers="mcps1.3.5.2.2.6.1.1 "><p id="dli_08_15030__p179229932813">username</p>
|
|
</td>
|
|
<td class="cellrowborder" valign="top" width="9.719999999999999%" headers="mcps1.3.5.2.2.6.1.2 "><p id="dli_08_15030__p1922209182815">No</p>
|
|
</td>
|
|
<td class="cellrowborder" valign="top" width="13.22%" headers="mcps1.3.5.2.2.6.1.3 "><p id="dli_08_15030__p13678154274110">None</p>
|
|
</td>
|
|
<td class="cellrowborder" valign="top" width="11.37%" headers="mcps1.3.5.2.2.6.1.4 "><p id="dli_08_15030__p819104517414">String</p>
|
|
</td>
|
|
<td class="cellrowborder" valign="top" width="47.32%" headers="mcps1.3.5.2.2.6.1.5 "><p id="dli_08_15030__p1192217952818">Username for accessing the ClickHouse database. This parameter is mandatory when Kerberos authentication is enabled for the MRS cluster.</p>
|
|
</td>
|
|
</tr>
|
|
<tr id="dli_08_15030__row1561842464619"><td class="cellrowborder" valign="top" width="18.37%" headers="mcps1.3.5.2.2.6.1.1 "><p id="dli_08_15030__p392219919280">password</p>
|
|
</td>
|
|
<td class="cellrowborder" valign="top" width="9.719999999999999%" headers="mcps1.3.5.2.2.6.1.2 "><p id="dli_08_15030__p139222912811">No</p>
|
|
</td>
|
|
<td class="cellrowborder" valign="top" width="13.22%" headers="mcps1.3.5.2.2.6.1.3 "><p id="dli_08_15030__p196026823612">None</p>
|
|
</td>
|
|
<td class="cellrowborder" valign="top" width="11.37%" headers="mcps1.3.5.2.2.6.1.4 "><p id="dli_08_15030__p1919445114116">String</p>
|
|
</td>
|
|
<td class="cellrowborder" valign="top" width="47.32%" headers="mcps1.3.5.2.2.6.1.5 "><p id="dli_08_15030__p692213915286">Password for accessing the ClickHouse database. This parameter is mandatory when Kerberos authentication is enabled for the MRS cluster.</p>
|
|
</td>
|
|
</tr>
|
|
<tr id="dli_08_15030__row16618102434612"><td class="cellrowborder" valign="top" width="18.37%" headers="mcps1.3.5.2.2.6.1.1 "><p id="dli_08_15030__p209223952815">sink.buffer-flush.max-rows</p>
|
|
</td>
|
|
<td class="cellrowborder" valign="top" width="9.719999999999999%" headers="mcps1.3.5.2.2.6.1.2 "><p id="dli_08_15030__p69221095281">No</p>
|
|
</td>
|
|
<td class="cellrowborder" valign="top" width="13.22%" headers="mcps1.3.5.2.2.6.1.3 "><p id="dli_08_15030__p3678134210417">100</p>
|
|
</td>
|
|
<td class="cellrowborder" valign="top" width="11.37%" headers="mcps1.3.5.2.2.6.1.4 "><p id="dli_08_15030__p019144519418">Integer</p>
|
|
</td>
|
|
<td class="cellrowborder" valign="top" width="47.32%" headers="mcps1.3.5.2.2.6.1.5 "><p id="dli_08_15030__p0922090288">Maximum number of rows to be updated when data is written. The default value is <strong id="dli_08_15030__b20074373094343">100</strong>.</p>
|
|
</td>
|
|
</tr>
|
|
<tr id="dli_08_15030__row126181924134616"><td class="cellrowborder" valign="top" width="18.37%" headers="mcps1.3.5.2.2.6.1.1 "><p id="dli_08_15030__p189221590287">sink.buffer-flush.interval</p>
|
|
</td>
|
|
<td class="cellrowborder" valign="top" width="9.719999999999999%" headers="mcps1.3.5.2.2.6.1.2 "><p id="dli_08_15030__p3922499281">No</p>
|
|
</td>
|
|
<td class="cellrowborder" valign="top" width="13.22%" headers="mcps1.3.5.2.2.6.1.3 "><p id="dli_08_15030__p8678174213413">1s</p>
|
|
</td>
|
|
<td class="cellrowborder" valign="top" width="11.37%" headers="mcps1.3.5.2.2.6.1.4 "><p id="dli_08_15030__p61915456415">Duration</p>
|
|
</td>
|
|
<td class="cellrowborder" valign="top" width="47.32%" headers="mcps1.3.5.2.2.6.1.5 "><p id="dli_08_15030__p0922129152814">Interval for data update. The unit can be ms, milli, millisecond/s, sec, second/min, or minute. The default value is <strong id="dli_08_15030__b10880251911">1s</strong>. Value <strong id="dli_08_15030__b20901127154343">0</strong> indicates that data is not updated.</p>
|
|
</td>
|
|
</tr>
|
|
<tr id="dli_08_15030__row967410521254"><td class="cellrowborder" valign="top" width="18.37%" headers="mcps1.3.5.2.2.6.1.1 "><p id="dli_08_15030__p19922199142815">sink.max-retries</p>
|
|
</td>
|
|
<td class="cellrowborder" valign="top" width="9.719999999999999%" headers="mcps1.3.5.2.2.6.1.2 "><p id="dli_08_15030__p49221913284">No</p>
|
|
</td>
|
|
<td class="cellrowborder" valign="top" width="13.22%" headers="mcps1.3.5.2.2.6.1.3 "><p id="dli_08_15030__p367854244110">3</p>
|
|
</td>
|
|
<td class="cellrowborder" valign="top" width="11.37%" headers="mcps1.3.5.2.2.6.1.4 "><p id="dli_08_15030__p1119345174113">Integer</p>
|
|
</td>
|
|
<td class="cellrowborder" valign="top" width="47.32%" headers="mcps1.3.5.2.2.6.1.5 "><p id="dli_08_15030__p692210910280">Maximum number of retries for writing data to the result table. The default value is <strong id="dli_08_15030__b10909335314343">3</strong>.</p>
|
|
</td>
|
|
</tr>
|
|
</tbody>
|
|
</table>
|
|
</div>
|
|
</div>
|
|
<div class="section" id="dli_08_15030__dli_08_0256_en-us_topic_0132788972_section19670175612466"><h4 class="sectiontitle">Example</h4><ul id="dli_08_15030__ul199301314141314"><li id="dli_08_15030__li16663721143017"><strong id="dli_08_15030__b20664202173016">Example 1: Read data from Kafka and insert the data into ClickHouse. (The ClickHouse version is 21.3.4.25 of MRS, and Kerberos authentication is not enabled for the MRS cluster):</strong><ol id="dli_08_15030__ol17650162114303"><li id="dli_08_15030__li104821538123118">Create an enhanced datasource connection in the VPC and subnet where ClickHouse and Kafka clusters locate, and bind the connection to the required Flink elastic resource pool.</li><li id="dli_08_15030__li1065013217308">Set ClickHouse and Kafka cluster security groups and add inbound rules to allow access from the Flink queue. Test the connectivity using the ClickHouse address. If the connection passes the test, it is bound to the queue.</li><li id="dli_08_15030__li10386615133912">Use the ClickHouse client to connect to the ClickHouse server and run the following command to query other environment parameters such as the cluster identifier:<pre class="screen" id="dli_08_15030__screen11935133574913">select cluster,shard_num,replica_num,host_name from system.clusters;</pre>
|
|
<div class="p" id="dli_08_15030__p187501439204919">The following information is displayed:<pre class="screen" id="dli_08_15030__screen6935435194910">┌─cluster────┬────┬─shard_num─┐
|
|
│ default_cluster │ 1 │ 1 │
|
|
│ default_cluster │ 1 │ 2 │
|
|
└──────── ┴────┴────── ┘</pre>
|
|
</div>
|
|
<p id="dli_08_15030__p175781245123119">Run the following command to create database <strong id="dli_08_15030__b10311187574343">flink</strong> on a node of the ClickHouse cluster based on the obtained cluster ID, for example, <strong id="dli_08_15030__b14240595974343">default_cluster</strong>:</p>
|
|
<pre class="screen" id="dli_08_15030__screen10793142053420">CREATE DATABASE flink ON CLUSTER default_cluster;</pre>
|
|
</li><li id="dli_08_15030__li1225510139344">Run the following command to create the ReplicatedMergeTree table named <strong id="dli_08_15030__b18507548074343">order</strong> on the node of cluster <strong id="dli_08_15030__b16549057514343">default_cluster</strong> and on database <strong id="dli_08_15030__b20961188374343">flink</strong>:<pre class="screen" id="dli_08_15030__screen7656131311356">CREATE TABLE flink.order ON CLUSTER default_cluster(order_id String,order_channel String,order_time String,pay_amount Float64,real_pay Float64,pay_time String,user_id String,user_name String,area_id String) ENGINE = ReplicatedMergeTree('/clickhouse/tables/{shard}/flink/order', '{replica}')ORDER BY order_id;</pre>
|
|
</li><li id="dli_08_15030__li053432873518">Create a Flink OpenSource SQL job. Enter the following job script and submit the job. The job script uses the DMS Kafka data source and the ClickHouse result table.<p id="dli_08_15030__p175820416369"><a name="dli_08_15030__li053432873518"></a><a name="li053432873518"></a>Change the values of the parameters in bold as needed in the following script.</p>
|
|
<pre class="screen" id="dli_08_15030__screen14841516183610">create table orders (
|
|
order_id string,
|
|
order_channel string,
|
|
order_time string,
|
|
pay_amount double,
|
|
real_pay double,
|
|
pay_time string,
|
|
user_id string,
|
|
user_name string,
|
|
area_id string
|
|
) WITH (
|
|
'connector' = 'kafka',
|
|
'topic' = '<em id="dli_08_15030__i4543155265320"><strong id="dli_08_15030__b1754316528535">Kafka</strong></em><em id="dli_08_15030__i15341759195319"><strong id="dli_08_15030__b5227105913538">Topic</strong></em>',
|
|
'properties.bootstrap.servers' = '<em id="dli_08_15030__i9319103215313"><strong id="dli_08_15030__b0322115133213">KafkaAddress1:KafkaPort,KafkaAddress2:KafkaPort</strong></em>',
|
|
'properties.group.id' = '<em id="dli_08_15030__i14535174011311"><strong id="dli_08_15030__b1466610178329">GroupId</strong></em>',
|
|
'scan.startup.mode' = 'latest-offset',
|
|
'format' = 'json'
|
|
);
|
|
|
|
create table clickhouseSink(
|
|
order_id string,
|
|
order_channel string,
|
|
order_time string,
|
|
pay_amount double,
|
|
real_pay double,
|
|
pay_time string,
|
|
user_id string,
|
|
user_name string,
|
|
area_id string
|
|
) with (
|
|
'connector' = 'clickhouse',
|
|
'url' = 'jdbc:clickhouse://<em id="dli_08_15030__i39221556189"><strong id="dli_08_15030__b129223561588">ClickhouseAddress1:ClickhousePort,ClickhouseAddress2:ClickhousePort</strong></em>/flink',
|
|
'username' = '<strong id="dli_08_15030__b166792419914">username</strong>',
|
|
'password' = '<strong id="dli_08_15030__b52419331095">password</strong>',
|
|
'table-name' = 'order',
|
|
'sink.buffer-flush.max-rows' = '10',
|
|
'sink.buffer-flush.interval' = '3s'
|
|
);
|
|
|
|
insert into clickhouseSink select * from orders;</pre>
|
|
</li><li id="dli_08_15030__li1280414396368">Connect to the Kafka cluster and insert the following test data into DMS Kafka:<pre class="screen" id="dli_08_15030__screen108135812366">{"order_id":"202103241000000001", "order_channel":"webShop", "order_time":"2021-03-24 10:00:00", "pay_amount":"100.00", "real_pay":"100.00", "pay_time":"2021-03-24 10:02:03", "user_id":"0001", "user_name":"Alice", "area_id":"330106"}
|
|
|
|
{"order_id":"202103241606060001", "order_channel":"appShop", "order_time":"2021-03-24 16:06:06", "pay_amount":"200.00", "real_pay":"180.00", "pay_time":"2021-03-24 16:10:06", "user_id":"0001", "user_name":"Alice", "area_id":"330106"}
|
|
|
|
{"order_id":"202103251202020001", "order_channel":"miniAppShop", "order_time":"2021-03-25 12:02:02", "pay_amount":"60.00", "real_pay":"60.00", "pay_time":"2021-03-25 12:03:00", "user_id":"0002", "user_name":"Bob", "area_id":"330110"}</pre>
|
|
</li><li id="dli_08_15030__li9543134513613">Use the ClickHouse client to connect to the ClickHouse and run the following command to query the data written to table <strong id="dli_08_15030__b15571771454343">order</strong> in database <strong id="dli_08_15030__b21167117914343">flink</strong>:<pre class="screen" id="dli_08_15030__screen13928659378">select * from flink.order;</pre>
|
|
<p id="dli_08_15030__p7928254374">The query result is as follows:</p>
|
|
<pre class="screen" id="dli_08_15030__screen129283517371">202103241000000001 webShop 2021-03-24 10:00:00 100 100 2021-03-24 10:02:03 0001 Alice 330106
|
|
|
|
202103241606060001 appShop 2021-03-24 16:06:06 200 180 2021-03-24 16:10:06 0001 Alice 330106
|
|
|
|
202103251202020001 miniAppShop 2021-03-25 12:02:02 60 60 2021-03-25 12:03:00 0002 Bob 330110 </pre>
|
|
</li></ol>
|
|
</li><li id="dli_08_15030__li1997152814379"><a name="dli_08_15030__li1997152814379"></a><a name="li1997152814379"></a><strong id="dli_08_15030__b1245617572063">Example 2: Read data from Kafka and insert the data into ClickHouse. The procedure is as follows (The ClickHouse version is 21.3.4.25 of MRS, and Kerberos authentication is enabled for the MRS cluster):</strong><ol id="dli_08_15030__ol6885163611417"><li id="dli_08_15030__li1888513361418">Create an enhanced datasource connection in the VPC and subnet where ClickHouse and Kafka clusters locate, and bind the connection to the required Flink elastic resource pool.</li><li id="dli_08_15030__li0885836194118">Set ClickHouse and Kafka cluster security groups and add inbound rules to allow access from the Flink queue. Test the connectivity using the ClickHouse address. If the connection passes the test, it is bound to the queue.</li><li id="dli_08_15030__li148851936194110">Use the ClickHouse client to connect to the ClickHouse server and run the following command to query other environment parameters such as the cluster identifier:<pre class="screen" id="dli_08_15030__screen1088543613415">select cluster,shard_num,replica_num,host_name from system.clusters;</pre>
|
|
<div class="p" id="dli_08_15030__p988543664114">The following information is displayed:<pre class="screen" id="dli_08_15030__screen18852036174114">┌─cluster────┬────┬─shard_num─┐
|
|
│ default_cluster │ 1 │ 1 │
|
|
│ default_cluster │ 1 │ 2 │
|
|
└──────── ┴────┴────── ┘</pre>
|
|
</div>
|
|
<p id="dli_08_15030__p98851836194119">Run the following command to create database <strong id="dli_08_15030__b9682055734343">flink</strong> on a node of the ClickHouse cluster based on the obtained cluster ID, for example, <strong id="dli_08_15030__b9090902584343">default_cluster</strong>:</p>
|
|
<pre class="screen" id="dli_08_15030__screen15885436204118">CREATE DATABASE flink ON CLUSTER default_cluster;</pre>
|
|
</li><li id="dli_08_15030__li128855366411">Run the following command to create the ReplicatedMergeTree table named <strong id="dli_08_15030__b1175150014343">order</strong> on the node of cluster <strong id="dli_08_15030__b950139764343">default_cluster</strong> and on database <strong id="dli_08_15030__b16178247334343">flink</strong>:<pre class="screen" id="dli_08_15030__screen1388543634115">CREATE TABLE flink.order ON CLUSTER default_cluster(order_id String,order_channel String,order_time String,pay_amount Float64,real_pay Float64,pay_time String,user_id String,user_name String,area_id String) ENGINE = ReplicatedMergeTree('/clickhouse/tables/{shard}/flink/order', '{replica}')ORDER BY order_id;</pre>
|
|
</li><li id="dli_08_15030__li14885133614118">Create a Flink OpenSource SQL job. Enter the following job script and submit the job. The job script uses the Kafka data source and the ClickHouse result table.<p id="dli_08_15030__p1488553674114"><a name="dli_08_15030__li14885133614118"></a><a name="li14885133614118"></a>Change the values of the parameters in bold as needed in the following script.</p>
|
|
<pre class="screen" id="dli_08_15030__screen118864362413">create table orders (
|
|
order_id string,
|
|
order_channel string,
|
|
order_time string,
|
|
pay_amount double,
|
|
real_pay double,
|
|
pay_time string,
|
|
user_id string,
|
|
user_name string,
|
|
area_id string
|
|
) WITH (
|
|
'connector' = 'kafka',
|
|
'topic' = '<em id="dli_08_15030__i1886163644119"><strong id="dli_08_15030__b188861036164110">Kafka</strong></em><em id="dli_08_15030__i188653617411"><strong id="dli_08_15030__b148861636184112">Topic</strong></em>',
|
|
'properties.bootstrap.servers' = '<em id="dli_08_15030__i1588653612413"><strong id="dli_08_15030__b6886173684115">KafkaAddress1:KafkaPort,KafkaAddress2:KafkaPort</strong></em>',
|
|
'properties.group.id' = '<em id="dli_08_15030__i148863360414"><strong id="dli_08_15030__b1988613619415">GroupId</strong></em>',
|
|
'scan.startup.mode' = 'latest-offset',
|
|
'format' = 'json'
|
|
);
|
|
|
|
create table clickhouseSink(
|
|
order_id string,
|
|
order_channel string,
|
|
order_time string,
|
|
pay_amount double,
|
|
real_pay double,
|
|
pay_time string,
|
|
user_id string,
|
|
user_name string,
|
|
area_id string
|
|
) with (
|
|
'connector' = 'clickhouse',
|
|
'url' = 'jdbc:clickhouse://<em id="dli_08_15030__i288613604119"><strong id="dli_08_15030__b888663644116">ClickhouseAddress1:ClickhousePort,ClickhouseAddress2:ClickhousePort</strong></em>/flink?ssl=true&sslmode=none',
|
|
'table-name' = 'order',
|
|
'username' = '<strong id="dli_08_15030__b13691111375910">username</strong>',
|
|
'password' = '<strong id="dli_08_15030__b9849536195919">password</strong>', --<em id="dli_08_15030__i135100591997">Key in the DEW secret</em>
|
|
'sink.buffer-flush.max-rows' = '10',
|
|
'sink.buffer-flush.interval' = '3s',
|
|
'dew.endpoint'='<strong id="dli_08_15030__b203212217117">kms.xx.xx.com</strong>', --<em id="dli_08_15030__i483613018115">Endpoint information for the DEW service being used</em>
|
|
'dew.csms.secretName'='<strong id="dli_08_15030__b8760182618117">xx</strong>', --<em id="dli_08_15030__i1589171691215">Name of the DEW shared secret</em>
|
|
'dew.csms.decrypt.fields'='<strong id="dli_08_15030__b1553674291211">password</strong>', --The <strong id="dli_08_15030__b07101645151315">password</strong> field value must be decrypted and replaced using DEW secret management.
|
|
'dew.csms.version'='<strong id="dli_08_15030__b115221931710">v1</strong>'
|
|
);
|
|
|
|
insert into clickhouseSink select * from orders;</pre>
|
|
</li><li id="dli_08_15030__li68861936124116">Connect to the Kafka cluster and insert the following test data into Kafka:<pre class="screen" id="dli_08_15030__screen288611364415">{"order_id":"202103241000000001", "order_channel":"webShop", "order_time":"2021-03-24 10:00:00", "pay_amount":"100.00", "real_pay":"100.00", "pay_time":"2021-03-24 10:02:03", "user_id":"0001", "user_name":"Alice", "area_id":"330106"}
|
|
|
|
{"order_id":"202103241606060001", "order_channel":"appShop", "order_time":"2021-03-24 16:06:06", "pay_amount":"200.00", "real_pay":"180.00", "pay_time":"2021-03-24 16:10:06", "user_id":"0001", "user_name":"Alice", "area_id":"330106"}
|
|
|
|
{"order_id":"202103251202020001", "order_channel":"miniAppShop", "order_time":"2021-03-25 12:02:02", "pay_amount":"60.00", "real_pay":"60.00", "pay_time":"2021-03-25 12:03:00", "user_id":"0002", "user_name":"Bob", "area_id":"330110"}</pre>
|
|
</li><li id="dli_08_15030__li12886133612414">Use the ClickHouse client to connect to the ClickHouse and run the following command to query the data written to table <strong id="dli_08_15030__b17349230494343">order</strong> in database <strong id="dli_08_15030__b20269392754343">flink</strong>:<pre class="screen" id="dli_08_15030__screen13886193684120">select * from flink.order;</pre>
|
|
<p id="dli_08_15030__p3886153664116">The query result is as follows:</p>
|
|
<pre class="screen" id="dli_08_15030__screen38863362413">202103241000000001 webShop 2021-03-24 10:00:00 100 100 2021-03-24 10:02:03 0001 Alice 330106
|
|
|
|
202103241606060001 appShop 2021-03-24 16:06:06 200 180 2021-03-24 16:10:06 0001 Alice 330106
|
|
|
|
202103251202020001 miniAppShop 2021-03-25 12:02:02 60 60 2021-03-25 12:03:00 0002 Bob 330110 </pre>
|
|
</li></ol>
|
|
</li></ul>
|
|
</div>
|
|
</div>
|
|
<div>
|
|
<div class="familylinks">
|
|
<div class="parentlink"><strong>Parent topic:</strong> <a href="dli_08_15027.html">Connectors</a></div>
|
|
</div>
|
|
</div>
|
|
|