forked from docs/doc-exports
Reviewed-by: Pruthi, Vineet <vineet.pruthi@t-systems.com> Co-authored-by: Hasko, Vladimir <vladimir.hasko@t-systems.com> Co-committed-by: Hasko, Vladimir <vladimir.hasko@t-systems.com>
125 lines
36 KiB
HTML
125 lines
36 KiB
HTML
<a name="dli_09_0010"></a><a name="dli_09_0010"></a>
|
|
|
|
<h1 class="topictitle1">Reading Data from Kafka and Writing Data to GaussDB(DWS)</h1>
|
|
<div id="body8662426"><div class="notice" id="dli_09_0010__en-us_topic_0000001269182164_note04712015123019"><span class="noticetitle"><img src="public_sys-resources/notice_3.0-en-us.png"> </span><div class="noticebody"><p id="dli_09_0010__en-us_topic_0000001269182164_p19332181517330">This guide provides reference for Flink 1.12 only.</p>
|
|
</div></div>
|
|
<div class="section" id="dli_09_0010__en-us_topic_0000001269182164_section10920163411416"><h4 class="sectiontitle">Description</h4><p id="dli_09_0010__en-us_topic_0000001269182164_p128093392048">This example analyzes real-time vehicle driving data and collects statistics on data results that meet specific conditions. The real-time vehicle driving data is stored in the Kafka source table, and then the analysis result is output to GaussDB(DWS).</p>
|
|
<p id="dli_09_0010__en-us_topic_0000001269182164_p17817311367">For example, enter the following sample data:</p>
|
|
<pre class="screen" id="dli_09_0010__en-us_topic_0000001269182164_screen14982105910615">{"car_id":"3027", "car_owner":"lilei", "car_age":"7", "average_speed":"76", "total_miles":"15000"}
|
|
{"car_id":"3028", "car_owner":"hanmeimei", "car_age":"6", "average_speed":"92", "total_miles":"17000"}
|
|
{"car_id":"3029", "car_owner":"Ann", "car_age":"10", "average_speed":"81", "total_miles":"230000"}</pre>
|
|
<div class="p" id="dli_09_0010__en-us_topic_0000001269182164_p13373161717716">Expected output is vehicles meeting the average_speed <= 90 and total_miles <= 200,000 condition.<pre class="screen" id="dli_09_0010__en-us_topic_0000001269182164_screen82511349972">{"car_id":"3027", "car_owner":"lilei", "car_age":"7", "average_speed":"76", "total_miles":"15000"}</pre>
|
|
</div>
|
|
</div>
|
|
<div class="section" id="dli_09_0010__en-us_topic_0000001269182164_section99670144912"><h4 class="sectiontitle">Prerequisites</h4><ol id="dli_09_0010__en-us_topic_0000001269182164_ol188213811126"><li id="dli_09_0010__en-us_topic_0000001269182164_li168618410461">You have created a DMS for Kafka instance.<div class="caution" id="dli_09_0010__en-us_topic_0000001269182164_note11428103813378"><span class="cautiontitle"><img src="public_sys-resources/caution_3.0-en-us.png"> </span><div class="cautionbody"><p id="dli_09_0010__en-us_topic_0000001269182164_p11427173817376">When you create the instance, do not enable <strong id="dli_09_0010__en-us_topic_0000001269182164_b1513915555283">Kafka SASL_SSL</strong>.</p>
|
|
</div></div>
|
|
</li><li id="dli_09_0010__en-us_topic_0000001269182164_li58321354155514">You have created a GaussDB(DWS) instance.</li></ol>
|
|
</div>
|
|
<div class="section" id="dli_09_0010__en-us_topic_0000001269182164_section12587518310"><h4 class="sectiontitle">Overall Development Process</h4><div class="p" id="dli_09_0010__en-us_topic_0000001269182164_p7741285314">Overall Process<div class="fignone" id="dli_09_0010__en-us_topic_0000001269182164_fig1691441652"><span class="figcap"><b>Figure 1 </b>Job development process</span><br><span><img id="dli_09_0010__en-us_topic_0000001269182164_image691841454" src="en-us_image_0000001318262121.png"></span></div>
|
|
</div>
|
|
<p id="dli_09_0010__en-us_topic_0000001269182164_p16413127863"><a href="#dli_09_0010__en-us_topic_0000001269182164_section792923214216">Step 1: Create a Queue</a></p>
|
|
<p id="dli_09_0010__en-us_topic_0000001269182164_p0567192986"><a href="#dli_09_0010__en-us_topic_0000001269182164_section78516116518">Step 2: Create a Kafka Topic</a></p>
|
|
<p id="dli_09_0010__en-us_topic_0000001269182164_p1259352616818"><a href="#dli_09_0010__en-us_topic_0000001269182164_section1627154113018">Step 3: Create a GaussDB(DWS) Database and Table</a></p>
|
|
<p id="dli_09_0010__en-us_topic_0000001269182164_p11783144819818"><a href="#dli_09_0010__en-us_topic_0000001269182164_section074025752119">Step 4: Create an Enhanced Datasource Connection</a></p>
|
|
<p id="dli_09_0010__en-us_topic_0000001269182164_p102618381914"><a href="#dli_09_0010__en-us_topic_0000001269182164_section12448959174212">Step 5: Run a Job</a></p>
|
|
<p id="dli_09_0010__en-us_topic_0000001269182164_p491452441010"><a href="#dli_09_0010__en-us_topic_0000001269182164_section4387527162418">Step 6: Send Data and Query Results</a></p>
|
|
</div>
|
|
<div class="section" id="dli_09_0010__en-us_topic_0000001269182164_section792923214216"><a name="dli_09_0010__en-us_topic_0000001269182164_section792923214216"></a><a name="en-us_topic_0000001269182164_section792923214216"></a><h4 class="sectiontitle">Step 1: Create a Queue</h4><ol id="dli_09_0010__en-us_topic_0000001269182164_ol193907145108"><li id="dli_09_0010__en-us_topic_0000001269182164_li3390161431020">Log in to the DLI console. In the navigation pane on the left, choose <strong id="dli_09_0010__en-us_topic_0000001269182164_b1357622113512">Resources</strong> > <strong id="dli_09_0010__en-us_topic_0000001269182164_b175777211657">Queue Management</strong>.</li><li id="dli_09_0010__en-us_topic_0000001269182164_li5390171401016">On the displayed page, click <strong id="dli_09_0010__en-us_topic_0000001269182164_b271515251657">Buy Queue</strong> in the upper right corner.</li><li id="dli_09_0010__en-us_topic_0000001269182164_li133901314191011">On the <strong id="dli_09_0010__en-us_topic_0000001269182164_b146746271357">Buy Queue</strong> page, set queue parameters as follows:<ul id="dli_09_0010__en-us_topic_0000001269182164_ul161521581016"><li id="dli_09_0010__en-us_topic_0000001269182164_li5992112615541"><strong id="dli_09_0010__en-us_topic_0000001269182164_b1331554693213">Billing Mode</strong>: . </li><li id="dli_09_0010__en-us_topic_0000001269182164_li17566251558"><strong id="dli_09_0010__en-us_topic_0000001269182164_b470893865">Region</strong> and <strong id="dli_09_0010__en-us_topic_0000001269182164_b470815310612">Project</strong>: Retain the default values.</li><li id="dli_09_0010__en-us_topic_0000001269182164_li9378124110319"><strong id="dli_09_0010__en-us_topic_0000001269182164_b2259558620">Name</strong>: Enter a queue name.<div class="note" id="dli_09_0010__en-us_topic_0000001269182164_note1523218284569"><img src="public_sys-resources/note_3.0-en-us.png"><span class="notetitle"> </span><div class="notebody"><p id="dli_09_0010__en-us_topic_0000001269182164_en-us_topic_0069078607_en-us_topic_0069077926_p61185513">The queue name can contain only digits, letters, and underscores (_), but cannot contain only digits or start with an underscore (_). The name must contain 1 to 128 characters.</p>
|
|
<p id="dli_09_0010__en-us_topic_0000001269182164_p6288122915199"><strong id="dli_09_0010__en-us_topic_0000001269182164_b747571310616">The queue name is case-insensitive. Uppercase letters will be automatically converted to lowercase letters.</strong></p>
|
|
</div></div>
|
|
</li><li id="dli_09_0010__en-us_topic_0000001269182164_li1761814682119"><strong id="dli_09_0010__en-us_topic_0000001269182164_b1219041413620">Type</strong>: Select <strong id="dli_09_0010__en-us_topic_0000001269182164_b1419013143619">For general purpose</strong>. Select the <strong id="dli_09_0010__en-us_topic_0000001269182164_b74106166610">Dedicated Resource Mode</strong>.</li><li id="dli_09_0010__en-us_topic_0000001269182164_li360481635014"><strong id="dli_09_0010__en-us_topic_0000001269182164_b1472355411322">AZ Mode</strong> and <strong id="dli_09_0010__en-us_topic_0000001269182164_b10729155420323">Specifications</strong>: Retain the default values.</li><li id="dli_09_0010__en-us_topic_0000001269182164_li32421882515"><strong id="dli_09_0010__en-us_topic_0000001269182164_b55911351269">Enterprise Project</strong>: Select <strong id="dli_09_0010__en-us_topic_0000001269182164_b165933520615">default</strong>.</li><li id="dli_09_0010__en-us_topic_0000001269182164_li6862026155115"><strong id="dli_09_0010__en-us_topic_0000001269182164_b558113519619">Advanced Settings</strong>: Select <strong id="dli_09_0010__en-us_topic_0000001269182164_b158118351868">Custom</strong>.</li><li id="dli_09_0010__en-us_topic_0000001269182164_li615215819015"><strong id="dli_09_0010__en-us_topic_0000001269182164_b619553813611">CIDR Block</strong>: Specify the queue network segment. For example, <strong id="dli_09_0010__en-us_topic_0000001269182164_b1306123914619">10.0.0.0/16</strong>.<div class="caution" id="dli_09_0010__en-us_topic_0000001269182164_note243428112912"><span class="cautiontitle"><img src="public_sys-resources/caution_3.0-en-us.png"> </span><div class="cautionbody"><p id="dli_09_0010__en-us_topic_0000001269182164_p114344818296">The CIDR block of a queue cannot overlap with the CIDR blocks of DMS Kafka and RDS for MySQL DB instances. Otherwise, datasource connections will fail to be created.</p>
|
|
</div></div>
|
|
</li><li id="dli_09_0010__en-us_topic_0000001269182164_li1066019193813">Set other parameters as required.</li></ul>
|
|
</li><li id="dli_09_0010__en-us_topic_0000001269182164_li83901314181011">Click <strong id="dli_09_0010__en-us_topic_0000001269182164_b13183194612618">Buy</strong>. Confirm the configuration and click <strong id="dli_09_0010__en-us_topic_0000001269182164_b518313462610">Submit</strong>.</li></ol>
|
|
</div>
|
|
<div class="section" id="dli_09_0010__en-us_topic_0000001269182164_section78516116518"><a name="dli_09_0010__en-us_topic_0000001269182164_section78516116518"></a><a name="en-us_topic_0000001269182164_section78516116518"></a><h4 class="sectiontitle">Step 2: Create a Kafka Topic</h4><ol id="dli_09_0010__en-us_topic_0000001269182164_ol68922017114"><li id="dli_09_0010__en-us_topic_0000001269182164_li48921006112">On the Kafka management console, click an instance name on the <strong id="dli_09_0010__en-us_topic_0000001269182164_b14363105713615">DMS for Kafka</strong> page. Basic information of the Kafka instance is displayed.</li><li id="dli_09_0010__en-us_topic_0000001269182164_li6892202113">Choose <strong id="dli_09_0010__en-us_topic_0000001269182164_b185191586617">Topics</strong> in the navigation pane on the left. On the displayed page, click <strong id="dli_09_0010__en-us_topic_0000001269182164_b175201958968">Create Topic</strong>. Configure the following parameters:<ul id="dli_09_0010__en-us_topic_0000001269182164_ul114131915412"><li id="dli_09_0010__en-us_topic_0000001269182164_li105301717185414"><strong id="dli_09_0010__en-us_topic_0000001269182164_b6317142611812">Topic Name</strong>: For this example, enter <strong id="dli_09_0010__en-us_topic_0000001269182164_b15413112411715">testkafkatopic</strong>.</li><li id="dli_09_0010__en-us_topic_0000001269182164_li20948104275411"><strong id="dli_09_0010__en-us_topic_0000001269182164_b773410311983">Partitions</strong>: Set the value to <strong id="dli_09_0010__en-us_topic_0000001269182164_b13734131081">1</strong>.</li><li id="dli_09_0010__en-us_topic_0000001269182164_li15662134885416"><strong id="dli_09_0010__en-us_topic_0000001269182164_b28098346817">Replicas</strong>: Set the value to <strong id="dli_09_0010__en-us_topic_0000001269182164_b2809193417812">1</strong>.</li></ul>
|
|
<p id="dli_09_0010__en-us_topic_0000001269182164_p11749490558">Retain default values for other parameters.</p>
|
|
</li></ol>
|
|
</div>
|
|
<div class="section" id="dli_09_0010__en-us_topic_0000001269182164_section1627154113018"><a name="dli_09_0010__en-us_topic_0000001269182164_section1627154113018"></a><a name="en-us_topic_0000001269182164_section1627154113018"></a><h4 class="sectiontitle">Step 3: Create a GaussDB(DWS) Database and Table</h4><ol id="dli_09_0010__en-us_topic_0000001269182164_ol5444161915482"><li id="dli_09_0010__en-us_topic_0000001269182164_li1644413197483">.</li><li id="dli_09_0010__en-us_topic_0000001269182164_li13452124716514">Connect to the default database <strong id="dli_09_0010__en-us_topic_0000001269182164_b18676849484">gaussdb</strong> of a GaussDB(DWS) cluster.<pre class="screen" id="dli_09_0010__en-us_topic_0000001269182164_screen83931272818">gsql -d gaussdb -h <em id="dli_09_0010__en-us_topic_0000001269182164_i2455205614816">Connection address of the GaussDB(DWS) cluster</em> -U dbadmin -p 8000 -W <em id="dli_09_0010__en-us_topic_0000001269182164_i1445513561485">password</em> -r</pre>
|
|
<ul id="dli_09_0010__en-us_topic_0000001269182164_ul174831718681"><li id="dli_09_0010__en-us_topic_0000001269182164_li15692151710103"><strong id="dli_09_0010__en-us_topic_0000001269182164_b9858438797">gaussdb</strong>: Default database of the GaussDB(DWS) cluster</li><li id="dli_09_0010__en-us_topic_0000001269182164_li124831018983"><strong id="dli_09_0010__en-us_topic_0000001269182164_b4873355996">Connection address of the DWS cluster</strong>: If a public network address is used for connection, set this parameter to the public network IP address or domain name. If a private network address is used for connection, set this parameter to the private network IP address or domain name. If an ELB is used for connection, set this parameter to the ELB address.</li><li id="dli_09_0010__en-us_topic_0000001269182164_li727319471581"><strong id="dli_09_0010__en-us_topic_0000001269182164_b1075133081217">dbadmin</strong>: Default administrator username used during cluster creation</li><li id="dli_09_0010__en-us_topic_0000001269182164_li4715191411119"><strong id="dli_09_0010__en-us_topic_0000001269182164_b7213175111122">password</strong>: Default password of the administrator</li></ul>
|
|
</li><li id="dli_09_0010__en-us_topic_0000001269182164_li1024132193916">Run the following command to create the <strong id="dli_09_0010__en-us_topic_0000001269182164_b10948115419123">testdwsdb</strong> database:<pre class="screen" id="dli_09_0010__en-us_topic_0000001269182164_screen6700124819131">CREATE DATABASE testdwsdb;</pre>
|
|
</li><li id="dli_09_0010__en-us_topic_0000001269182164_li18700124812130">Run the following command to exit the <strong id="dli_09_0010__en-us_topic_0000001269182164_b1388018595122">gaussdb</strong> database and connect to <strong id="dli_09_0010__en-us_topic_0000001269182164_b11881165931217">testdwsdb</strong>:<pre class="screen" id="dli_09_0010__en-us_topic_0000001269182164_screen184211821618">\q
|
|
gsql -d testdwsdb -h <em id="dli_09_0010__en-us_topic_0000001269182164_i197449614131">Connection address of the GaussDB(DWS) cluster</em> -U dbadmin -p 8000 -W <em id="dli_09_0010__en-us_topic_0000001269182164_i1375066191311">password</em> -r</pre>
|
|
</li><li id="dli_09_0010__en-us_topic_0000001269182164_li1996848151611">Run the following commands to create a table:<pre class="screen" id="dli_09_0010__en-us_topic_0000001269182164_screen1610120280179">create schema test;
|
|
set current_schema= test;
|
|
drop table if exists qualified_cars;
|
|
CREATE TABLE qualified_cars
|
|
(
|
|
car_id VARCHAR,
|
|
car_owner VARCHAR,
|
|
car_age INTEGER ,
|
|
average_speed FLOAT8,
|
|
total_miles FLOAT8
|
|
);</pre>
|
|
</li></ol>
|
|
</div>
|
|
<div class="section" id="dli_09_0010__en-us_topic_0000001269182164_section074025752119"><a name="dli_09_0010__en-us_topic_0000001269182164_section074025752119"></a><a name="en-us_topic_0000001269182164_section074025752119"></a><h4 class="sectiontitle">Step 4: Create an Enhanced Datasource Connection</h4><ul id="dli_09_0010__en-us_topic_0000001269182164_ul1231663714228"><li id="dli_09_0010__en-us_topic_0000001269182164_li193161137122213"><strong id="dli_09_0010__en-us_topic_0000001269182164_b17750434161311">Connecting DLI to Kafka</strong><ol id="dli_09_0010__en-us_topic_0000001269182164_ol24611049949"><li id="dli_09_0010__en-us_topic_0000001269182164_li71971337017">On the Kafka management console, click an instance name on the <strong id="dli_09_0010__en-us_topic_0000001269182164_b18700153512134">DMS for Kafka</strong> page. Basic information of the Kafka instance is displayed.</li><li id="dli_09_0010__en-us_topic_0000001269182164_li19197133109">In the <strong id="dli_09_0010__en-us_topic_0000001269182164_b15871639101316">Connection</strong> pane, obtain the <strong id="dli_09_0010__en-us_topic_0000001269182164_b165871739201316">Instance Address (Private Network)</strong>. In the <strong id="dli_09_0010__en-us_topic_0000001269182164_b75871339141313">Network</strong> pane, obtain the VPC and subnet of the instance.</li><li id="dli_09_0010__en-us_topic_0000001269182164_li557658113910">Click the security group name in the <strong id="dli_09_0010__en-us_topic_0000001269182164_b1340604371314">Network</strong> pane. On the displayed page, click the <strong id="dli_09_0010__en-us_topic_0000001269182164_b14406104320136">Inbound Rules</strong> tab and add a rule to allow access from DLI queues. For example, if the CIDR block of the queue is 10.0.0.0/16, set <strong id="dli_09_0010__en-us_topic_0000001269182164_b675611447139">Priority</strong> to <strong id="dli_09_0010__en-us_topic_0000001269182164_b475724461315">1</strong>, <strong id="dli_09_0010__en-us_topic_0000001269182164_b1759184418136">Action</strong> to <strong id="dli_09_0010__en-us_topic_0000001269182164_b97591844171313">Allow</strong>, <strong id="dli_09_0010__en-us_topic_0000001269182164_b16760184491313">Protocol</strong> to <strong id="dli_09_0010__en-us_topic_0000001269182164_b14760104441319">TCP</strong>, <strong id="dli_09_0010__en-us_topic_0000001269182164_b207604445132">Type</strong> to <strong id="dli_09_0010__en-us_topic_0000001269182164_b87601544151317">IPv4</strong>, <strong id="dli_09_0010__en-us_topic_0000001269182164_b8760114414138">Source</strong> to <strong id="dli_09_0010__en-us_topic_0000001269182164_b7760104411134">10.0.0.0/16</strong>, and click <strong id="dli_09_0010__en-us_topic_0000001269182164_b4761244181318">OK</strong>.</li><li id="dli_09_0010__en-us_topic_0000001269182164_li10751165711389">Log in to the DLI management console. In the navigation pane on the left, choose <strong id="dli_09_0010__en-us_topic_0000001269182164_b77723465133">Datasource Connections</strong>. On the displayed page, click <strong id="dli_09_0010__en-us_topic_0000001269182164_b107721946141317">Create</strong> in the <strong id="dli_09_0010__en-us_topic_0000001269182164_b077344641311">Enhanced</strong> tab.</li><li id="dli_09_0010__en-us_topic_0000001269182164_li10469451946">In the displayed dialog box, set the following parameters: For details, see the following section:<ul id="dli_09_0010__en-us_topic_0000001269182164_ul1032935016521"><li id="dli_09_0010__en-us_topic_0000001269182164_li1332914503526"><strong id="dli_09_0010__en-us_topic_0000001269182164_b1576055481310">Connection Name</strong>: Enter a name for the enhanced datasource connection. For this example, enter <strong id="dli_09_0010__en-us_topic_0000001269182164_b1039071115142">dli_kafka</strong>.</li><li id="dli_09_0010__en-us_topic_0000001269182164_li432905017524"><strong id="dli_09_0010__en-us_topic_0000001269182164_b18285204911146">Resource Pool</strong>: Select the name of the queue created in <a href="#dli_09_0010__en-us_topic_0000001269182164_section792923214216">Step 1: Create a Queue</a>.</li><li id="dli_09_0010__en-us_topic_0000001269182164_li1932945012529"><strong id="dli_09_0010__en-us_topic_0000001269182164_b7496185881414">VPC</strong>: Select the VPC of the Kafka instance.</li><li id="dli_09_0010__en-us_topic_0000001269182164_li5329750115213"><strong id="dli_09_0010__en-us_topic_0000001269182164_b164012391519">Subnet</strong>: Select the subnet of Kafka instance.</li><li id="dli_09_0010__en-us_topic_0000001269182164_li16590071163">Set other parameters as you need.</li></ul>
|
|
<p id="dli_09_0010__en-us_topic_0000001269182164_p3174856105519">Click <strong id="dli_09_0010__en-us_topic_0000001269182164_b1723116614155">OK</strong>. Click the name of the created datasource connection to view its status. You can perform subsequent steps only after the connection status changes to <strong id="dli_09_0010__en-us_topic_0000001269182164_b19900147111515">Active</strong>.</p>
|
|
</li><li id="dli_09_0010__en-us_topic_0000001269182164_li18197531400">Choose <strong id="dli_09_0010__en-us_topic_0000001269182164_b14302010171515">Resources</strong> > <strong id="dli_09_0010__en-us_topic_0000001269182164_b64301310151517">Queue Management</strong> from the navigation pane, locate the queue you created in <a href="#dli_09_0010__en-us_topic_0000001269182164_section792923214216">Step 1: Create a Queue</a>. In the <strong id="dli_09_0010__en-us_topic_0000001269182164_b1543115109156">Operation</strong> column, click <strong id="dli_09_0010__en-us_topic_0000001269182164_b204311110111518">More</strong> > <strong id="dli_09_0010__en-us_topic_0000001269182164_b174319107151">Test Address Connectivity</strong>.</li><li id="dli_09_0010__en-us_topic_0000001269182164_li171971831506">In the displayed dialog box, enter <em id="dli_09_0010__en-us_topic_0000001269182164_i13222151281515">Kafka instance address (private network)</em><strong id="dli_09_0010__en-us_topic_0000001269182164_b132227127158">:</strong><em id="dli_09_0010__en-us_topic_0000001269182164_i32236128157">port</em> in the <strong id="dli_09_0010__en-us_topic_0000001269182164_b172231012191515">Address</strong> box and click <strong id="dli_09_0010__en-us_topic_0000001269182164_b16223191201515">Test</strong> to check whether the instance is reachable.</li></ol>
|
|
</li><li id="dli_09_0010__en-us_topic_0000001269182164_li474495213221"><strong id="dli_09_0010__en-us_topic_0000001269182164_b16169191421511">Connecting DLI to GaussDB(DWS)</strong><ol id="dli_09_0010__en-us_topic_0000001269182164_ol17815135442310"><li id="dli_09_0010__en-us_topic_0000001269182164_li14815454112312">On the GaussDB(DWS) management console, choose <strong id="dli_09_0010__en-us_topic_0000001269182164_b930716154159">Clusters</strong>. On the displayed page, click the name of the created GaussDB(DWS) cluster to view basic information.</li><li id="dli_09_0010__en-us_topic_0000001269182164_li19666016361"><a name="dli_09_0010__en-us_topic_0000001269182164_li19666016361"></a><a name="en-us_topic_0000001269182164_li19666016361"></a>In the Basic Information tab, locate the <strong id="dli_09_0010__en-us_topic_0000001269182164_b1545162314158">Database Attributes</strong> pane and obtain the private IP address and port number of the DB instance. In the <strong id="dli_09_0010__en-us_topic_0000001269182164_b10545112312152">Network</strong> pane, obtain VPC, and subnet information.</li><li id="dli_09_0010__en-us_topic_0000001269182164_li4233434123610">Click the security group name. On the displayed page, click the <strong id="dli_09_0010__en-us_topic_0000001269182164_b56571624181514">Inbound Rules</strong> tab and add a rule to allow access from DLI queues. For example, if the CIDR block of the queue is 10.0.0.0/16, set <strong id="dli_09_0010__en-us_topic_0000001269182164_b8826185911150">Priority</strong> to <strong id="dli_09_0010__en-us_topic_0000001269182164_b6826145971513">1</strong>, <strong id="dli_09_0010__en-us_topic_0000001269182164_b128261659151518">Action</strong> to <strong id="dli_09_0010__en-us_topic_0000001269182164_b1682615591156">Allow</strong>, <strong id="dli_09_0010__en-us_topic_0000001269182164_b17826195911156">Protocol</strong> to <strong id="dli_09_0010__en-us_topic_0000001269182164_b3826259171519">TCP</strong>, <strong id="dli_09_0010__en-us_topic_0000001269182164_b1182715921511">Type</strong> to <strong id="dli_09_0010__en-us_topic_0000001269182164_b18271359151513">IPv4</strong>, <strong id="dli_09_0010__en-us_topic_0000001269182164_b1482775941515">Source</strong> to <strong id="dli_09_0010__en-us_topic_0000001269182164_b138271959161519">10.0.0.0/16</strong>, and click <strong id="dli_09_0010__en-us_topic_0000001269182164_b12827195951515">OK</strong>.</li><li id="dli_09_0010__en-us_topic_0000001269182164_li14803182620216">Check whether the Kafka instance and GaussDB(DWS) instance are in the same VPC and subnet.<ol type="a" id="dli_09_0010__en-us_topic_0000001269182164_ol184431423137"><li id="dli_09_0010__en-us_topic_0000001269182164_li957111932">If they are, go to <a href="#dli_09_0010__en-us_topic_0000001269182164_li9816175412318">7</a>. You do not need to create an enhanced datasource connection again.</li><li id="dli_09_0010__en-us_topic_0000001269182164_li1086652519411">If they are not, go to <a href="#dli_09_0010__en-us_topic_0000001269182164_li11976319011">5</a>. Create an enhanced datasource connection to connect DLI to the subnet where the GaussDB(DWS) instance locates.</li></ol>
|
|
</li><li id="dli_09_0010__en-us_topic_0000001269182164_li11976319011"><a name="dli_09_0010__en-us_topic_0000001269182164_li11976319011"></a><a name="en-us_topic_0000001269182164_li11976319011"></a>Log in to the DLI management console. In the navigation pane on the left, choose <strong id="dli_09_0010__en-us_topic_0000001269182164_b15789237161618">Datasource Connections</strong>. On the displayed page, click <strong id="dli_09_0010__en-us_topic_0000001269182164_b5789237141615">Create</strong> in the <strong id="dli_09_0010__en-us_topic_0000001269182164_b13790143791617">Enhanced</strong> tab.</li><li id="dli_09_0010__en-us_topic_0000001269182164_li198151354192319">In the displayed dialog box, set the following parameters: For details, see the following section:<ul id="dli_09_0010__en-us_topic_0000001269182164_ul17815125415233"><li id="dli_09_0010__en-us_topic_0000001269182164_li1181518543233"><strong id="dli_09_0010__en-us_topic_0000001269182164_b1946155216169">Connection Name</strong>: Enter a name for the enhanced datasource connection. For this example, enter <strong id="dli_09_0010__en-us_topic_0000001269182164_b148167545163">dli_dws</strong>.</li><li id="dli_09_0010__en-us_topic_0000001269182164_li681518542232"><strong id="dli_09_0010__en-us_topic_0000001269182164_b4315152014172">Resource Pool</strong>: Select the name of the queue created in <a href="#dli_09_0010__en-us_topic_0000001269182164_section792923214216">Step 1: Create a Queue</a>.</li><li id="dli_09_0010__en-us_topic_0000001269182164_li58162542235"><strong id="dli_09_0010__en-us_topic_0000001269182164_b114754228177">VPC</strong>: Select the VPC of the GaussDB(DWS) instance.</li><li id="dli_09_0010__en-us_topic_0000001269182164_li11816105432317"><strong id="dli_09_0010__en-us_topic_0000001269182164_b14682193051719">Subnet</strong>: Select the subnet of GaussDB(DWS) instance.</li><li id="dli_09_0010__en-us_topic_0000001269182164_li781675472310">Set other parameters as you need.</li></ul>
|
|
<p id="dli_09_0010__en-us_topic_0000001269182164_p1081617549235">Click <strong id="dli_09_0010__en-us_topic_0000001269182164_b12637133918171">OK</strong>. Click the name of the created datasource connection to view its status. You can perform subsequent steps only after the connection status changes to <strong id="dli_09_0010__en-us_topic_0000001269182164_b205631341191712">Active</strong>.</p>
|
|
</li><li id="dli_09_0010__en-us_topic_0000001269182164_li9816175412318"><a name="dli_09_0010__en-us_topic_0000001269182164_li9816175412318"></a><a name="en-us_topic_0000001269182164_li9816175412318"></a>Choose <strong id="dli_09_0010__en-us_topic_0000001269182164_b145311044101714">Resources</strong> > <strong id="dli_09_0010__en-us_topic_0000001269182164_b553194411175">Queue Management</strong> from the navigation pane, locate the queue you created in <a href="#dli_09_0010__en-us_topic_0000001269182164_section792923214216">Step 1: Create a Queue</a>. In the <strong id="dli_09_0010__en-us_topic_0000001269182164_b5531144191712">Operation</strong> column, click <strong id="dli_09_0010__en-us_topic_0000001269182164_b1753184471717">More</strong> > <strong id="dli_09_0010__en-us_topic_0000001269182164_b1553144412172">Test Address Connectivity</strong>.</li><li id="dli_09_0010__en-us_topic_0000001269182164_li7816454162319">In the displayed dialog box, enter <em id="dli_09_0010__en-us_topic_0000001269182164_i1081034616173">floating IP address</em><strong id="dli_09_0010__en-us_topic_0000001269182164_b10810154612177">:</strong><em id="dli_09_0010__en-us_topic_0000001269182164_i4810164641711">database port</em> of the GaussDB(DWS) instance you have obtained in <a href="#dli_09_0010__en-us_topic_0000001269182164_li19666016361">2</a> in the <strong id="dli_09_0010__en-us_topic_0000001269182164_b13810446121710">Address</strong> box and click <strong id="dli_09_0010__en-us_topic_0000001269182164_b181020466173">Test</strong> to check whether the database is reachable.</li></ol>
|
|
</li></ul>
|
|
</div>
|
|
<div class="section" id="dli_09_0010__en-us_topic_0000001269182164_section12448959174212"><a name="dli_09_0010__en-us_topic_0000001269182164_section12448959174212"></a><a name="en-us_topic_0000001269182164_section12448959174212"></a><h4 class="sectiontitle">Step 5: Run a Job</h4><ol id="dli_09_0010__en-us_topic_0000001269182164_ol1313811362437"><li id="dli_09_0010__en-us_topic_0000001269182164_li219661215114">On the DLI management console, choose <strong id="dli_09_0010__en-us_topic_0000001269182164_b18319141021816">Job Management</strong> > <strong id="dli_09_0010__en-us_topic_0000001269182164_b14319201018187">Flink Jobs</strong>. On the <strong id="dli_09_0010__en-us_topic_0000001269182164_b10319410121815">Flink Jobs</strong> page, click <strong id="dli_09_0010__en-us_topic_0000001269182164_b13319171071817">Create Job</strong>.</li><li id="dli_09_0010__en-us_topic_0000001269182164_li18197181225114">In the <strong id="dli_09_0010__en-us_topic_0000001269182164_b74491913201813"> Create Job</strong> dialog box, set <strong id="dli_09_0010__en-us_topic_0000001269182164_b16449151381819">Type</strong> to <strong id="dli_09_0010__en-us_topic_0000001269182164_b5449141315184">Flink OpenSource SQL</strong> and <strong id="dli_09_0010__en-us_topic_0000001269182164_b134495134187">Name</strong> to <strong id="dli_09_0010__en-us_topic_0000001269182164_b1744910135182">FlinkKafkaDWS</strong>. Click <strong id="dli_09_0010__en-us_topic_0000001269182164_b93541037121819">OK</strong>.</li><li id="dli_09_0010__en-us_topic_0000001269182164_li119731295112">On the job editing page, set the following parameters and retain the default values of other parameters.<ul id="dli_09_0010__en-us_topic_0000001269182164_ul1970291612112"><li id="dli_09_0010__en-us_topic_0000001269182164_li6702216152118"><strong id="dli_09_0010__en-us_topic_0000001269182164_b698624103317">Queue</strong>: Select the queue created in <a href="#dli_09_0010__en-us_topic_0000001269182164_section792923214216">Step 1: Create a Queue</a>.</li><li id="dli_09_0010__en-us_topic_0000001269182164_li1629221563615"><strong id="dli_09_0010__en-us_topic_0000001269182164_b947110102198">Flink Version</strong>: Select <strong id="dli_09_0010__en-us_topic_0000001269182164_b14771710151918">1.12</strong>.</li><li id="dli_09_0010__en-us_topic_0000001269182164_li84401118192110"><strong id="dli_09_0010__en-us_topic_0000001269182164_b141801212171912">Save Job Log</strong>: Enable this function.</li><li id="dli_09_0010__en-us_topic_0000001269182164_li12684193718212"><strong id="dli_09_0010__en-us_topic_0000001269182164_b9444149194">OBS Bucket</strong>: Select an OBS bucket for storing job logs and grant access permissions of the OBS bucket as prompted.</li><li id="dli_09_0010__en-us_topic_0000001269182164_li1382275713215"><strong id="dli_09_0010__en-us_topic_0000001269182164_b55220156195">Enable Checkpointing</strong>: Enable this function.</li><li id="dli_09_0010__en-us_topic_0000001269182164_li1479717252318">Enter a SQL statement in the editing pane. The following is an example. Modify the parameters in bold as you need.<div class="note" id="dli_09_0010__en-us_topic_0000001269182164_note44252719209"><img src="public_sys-resources/note_3.0-en-us.png"><span class="notetitle"> </span><div class="notebody"><p id="dli_09_0010__en-us_topic_0000001269182164_p0606182217205">In this example, the syntax version of Flink OpenSource SQL is 1.12. In this example, the data source is Kafka and the result data is written to GaussDB(DWS).</p>
|
|
</div></div>
|
|
<pre class="screen" id="dli_09_0010__en-us_topic_0000001269182164_screen342507162015">create table car_infos(
|
|
car_id STRING,
|
|
car_owner STRING,
|
|
car_age INT,
|
|
average_speed DOUBLE,
|
|
total_miles DOUBLE
|
|
) with (
|
|
"connector" = "kafka",
|
|
"properties.bootstrap.servers" = " <em id="dli_09_0010__en-us_topic_0000001269182164_i18791141118211"><strong id="dli_09_0010__en-us_topic_0000001269182164_b19791511142117">10.128.0.120:9092,10.128.0.89:9092,10.128.0.83:9092</strong></em> ",-- Internal network address and port number of the Kafka instance
|
|
"properties.group.id" = "click",
|
|
"topic" = " <strong id="dli_09_0010__en-us_topic_0000001269182164_b14732149124816">testkafkatopic</strong>",--Created Kafka topic
|
|
"format" = "json",
|
|
"scan.startup.mode" = "latest-offset"
|
|
);
|
|
|
|
create table qualified_cars (
|
|
car_id STRING,
|
|
car_owner STRING,
|
|
car_age INT,
|
|
average_speed DOUBLE,
|
|
total_miles DOUBLE
|
|
)
|
|
WITH (
|
|
'connector' = 'gaussdb',
|
|
'driver' = 'com.gauss200.jdbc.Driver',
|
|
'url'='jdbc:gaussdb://<strong id="dli_09_0010__en-us_topic_0000001269182164_b1583194417443"><em id="dli_09_0010__en-us_topic_0000001269182164_i461911045214">192.168.168.16:8000</em>/testdwsdb</strong> ', ---192.168.168.16:8000 indicates the internal IP address and port of the GaussDB(DWS) instance. testdwsdb indicates the name of the created GaussDB(DWS) database.
|
|
'table-name' = ' <strong id="dli_09_0010__en-us_topic_0000001269182164_b476565124315">test\".\"qualified_cars</strong>', ---test indicates the schema of the created GaussDB(DWS) table, and qualified_cars indicates the GaussDB(DWS) table name.
|
|
'pwd_auth_name'= '<em id="dli_09_0010__en-us_topic_0000001269182164_i1136955711428"><strong id="dli_09_0010__en-us_topic_0000001269182164_b183691857184219">xxxxx</strong></em>', -- Name of the datasource authentication of the password type created on DLI. If datasource authentication is used, you do not need to set the username and password for the job.
|
|
'write.mode' = 'insert'
|
|
);
|
|
|
|
/** Output information about qualified vehicles **/
|
|
INSERT INTO qualified_cars
|
|
SELECT *
|
|
FROM car_infos
|
|
where average_speed <= 90 and total_miles <= 200000;</pre>
|
|
</li></ul>
|
|
</li><li id="dli_09_0010__en-us_topic_0000001269182164_li219761217517">Click <strong id="dli_09_0010__en-us_topic_0000001269182164_b8257114692314">Check Semantic</strong> and ensure that the SQL statement passes the check. Click <strong id="dli_09_0010__en-us_topic_0000001269182164_b7929947152315">Save</strong>. Click <strong id="dli_09_0010__en-us_topic_0000001269182164_b687217488236">Start</strong>, confirm the job parameters, and click <strong id="dli_09_0010__en-us_topic_0000001269182164_b587274862318">Start Now</strong> to execute the job. Wait until the job status changes to <strong id="dli_09_0010__en-us_topic_0000001269182164_b1975844914236">Running</strong>.</li></ol>
|
|
</div>
|
|
<div class="section" id="dli_09_0010__en-us_topic_0000001269182164_section4387527162418"><a name="dli_09_0010__en-us_topic_0000001269182164_section4387527162418"></a><a name="en-us_topic_0000001269182164_section4387527162418"></a><h4 class="sectiontitle">Step 6: Send Data and Query Results</h4><ol id="dli_09_0010__en-us_topic_0000001269182164_ol0558165272410"><li id="dli_09_0010__en-us_topic_0000001269182164_li152645383324">Use the Kafka client to send data to topics created in <a href="#dli_09_0010__en-us_topic_0000001269182164_section78516116518">Step 2: Create a Kafka Topic</a> to simulate real-time data streams.<p id="dli_09_0010__en-us_topic_0000001269182164_p1136153383217">The sample data is as follows:</p>
|
|
<pre class="screen" id="dli_09_0010__en-us_topic_0000001269182164_screen313623313217">{"car_id":"3027", "car_owner":"lilei", "car_age":"7", "average_speed":"76", "total_miles":"15000"}
|
|
{"car_id":"3028", "car_owner":"hanmeimei", "car_age":"6", "average_speed":"92", "total_miles":"17000"}
|
|
{"car_id":"3029", "car_owner":"Ann", "car_age":"10", "average_speed":"81", "total_miles":"230000"}</pre>
|
|
</li><li id="dli_09_0010__en-us_topic_0000001269182164_li06096763419">Connect to the created GaussDB(DWS) cluster.</li><li id="dli_09_0010__en-us_topic_0000001269182164_li1247361815504">Connect to the default database <strong id="dli_09_0010__en-us_topic_0000001269182164_b66085239257">testdwsdb</strong> of a GaussDB(DWS) cluster.<pre class="screen" id="dli_09_0010__en-us_topic_0000001269182164_screen15137185717515">gsql -d testdwsdb -h <em id="dli_09_0010__en-us_topic_0000001269182164_i131894642516">Connection address of the GaussDB(DWS) cluster</em> -U dbadmin -p 8000 -W <em id="dli_09_0010__en-us_topic_0000001269182164_i153251346132513">password</em> -r</pre>
|
|
</li><li id="dli_09_0010__en-us_topic_0000001269182164_li1113716579515">Run the following statement to query GaussDB(DWS) table data:<pre class="screen" id="dli_09_0010__en-us_topic_0000001269182164_screen182059495311">select * from test.qualified_cars;</pre>
|
|
<div class="p" id="dli_09_0010__en-us_topic_0000001269182164_p29701047531">The query result is as follows:<pre class="screen" id="dli_09_0010__en-us_topic_0000001269182164_screen2081319157535">car_id car_owner car_age average_speed total_miles
|
|
3027 lilei 7 76.0 15000.0</pre>
|
|
</div>
|
|
</li></ol>
|
|
</div>
|
|
</div>
|
|
<div>
|
|
<div class="familylinks">
|
|
<div class="parentlink"><strong>Parent topic:</strong> <a href="dli_09_0006.html">Flink OpenSource SQL Jobs</a></div>
|
|
</div>
|
|
</div>
|
|
|