doc-exports/docs/dli/api-ref/dli_02_0308.html
Su, Xiaomeng 483e5cc6cc dli_api_20240430
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-05-15 12:04:03 +00:00

82 lines
7.7 KiB
HTML

<a name="dli_02_0308"></a><a name="dli_02_0308"></a>
<h1 class="topictitle1">Creating and Submitting a SQL Job</h1>
<div id="body1602473883610"><div class="section" id="dli_02_0308__section851316282599"><h4 class="sectiontitle">Scenario Description</h4><p id="dli_02_0308__p18834648103219">This section describes how to create and query SQL jobs using APIs.</p>
</div>
<div class="section" id="dli_02_0308__section155144213214"><h4 class="sectiontitle">Constraints</h4><ul id="dli_02_0308__ul759612191669"><li id="dli_02_0308__li45963199610">It takes 6 to 10 minutes to start a job using a new queue for the first time.</li></ul>
</div>
<div class="section" id="dli_02_0308__section13856162971"><h4 class="sectiontitle">Involved APIs</h4><ul id="dli_02_0308__ul1862251633812"><li id="dli_02_0308__li462221673818"><a href="dli_02_0194.html">Creating a Queue</a>: Create a queue.</li><li id="dli_02_0308__li46223161388"><a href="dli_02_0028.html">Creating a Database (Discarded)</a>: Create a database.</li><li id="dli_02_0308__li1137901761318"><a href="dli_02_0034.html">Creating a Table (Discarded)</a>: Create a table.</li><li id="dli_02_0308__li1484215716133"><a href="dli_02_0019.html">Importing Data (Discarded)</a>: Import the data to be queried.</li><li id="dli_02_0308__li5692722014"><a href="dli_02_0022.html">Querying Job Details</a>: Check whether the imported data is correct.</li><li id="dli_02_0308__li9641746152414"><a href="dli_02_0102.html">Submitting a SQL Job (Recommended)</a>: Submit a query job.</li></ul>
</div>
<div class="section" id="dli_02_0308__section2742155213719"><h4 class="sectiontitle">Procedure</h4><ol id="dli_02_0308__ol454620011213"><li id="dli_02_0308__li135461061218">Create a SQL queue. For details, see <a href="dli_02_0307.html">Creating a Queue</a>.</li><li id="dli_02_0308__li117291344122510">Create a database.<ul id="dli_02_0308__ul2729144122513"><li id="dli_02_0308__li57278446258">API<p id="dli_02_0308__p7727134452510"><a name="dli_02_0308__li57278446258"></a><a name="li57278446258"></a>URI format: POST /v1.0/{project_id}/databases</p>
<ul id="dli_02_0308__ul14727644162512"><li id="dli_02_0308__li9727134442515">Obtain the value of {project_id} from <a href="dli_02_0183.html">Obtaining a Project ID</a>.</li><li id="dli_02_0308__li1372710448250">For details about the request parameters, see <a href="dli_02_0028.html">Creating a Database (Discarded)</a>.</li></ul>
</li><li id="dli_02_0308__li5728744172513">Request example<ul id="dli_02_0308__ul772864412254"><li id="dli_02_0308__li17728194415253">Description: Creates a database named <strong id="dli_02_0308__b1186613510343">db1</strong> in the project whose ID is <strong id="dli_02_0308__b1657121011346">48cc2c48765f481480c7db940d6409d1</strong>.</li><li id="dli_02_0308__li137287448256">Example URL: POST https://{<em id="dli_02_0308__i1832141133414">endpoint</em>}/v1.0/48cc2c48765f481480c7db940d6409d1/databases</li><li id="dli_02_0308__li14728144414252">Body:<pre class="screen" id="dli_02_0308__screen672864492517">{
"database_name": "db1",
"description": "this is for test"
}</pre>
</li></ul>
</li><li id="dli_02_0308__li19729134452514">Example response<pre class="screen" id="dli_02_0308__screen15729114442511">{
"is_success": true,
"message": ""
}</pre>
</li></ul>
</li><li id="dli_02_0308__li970315312304">Create a table.<ul id="dli_02_0308__ul470310318306"><li id="dli_02_0308__li117031316309">API<p id="dli_02_0308__p0703173113019"><a name="dli_02_0308__li117031316309"></a><a name="li117031316309"></a>URI format: POST /v1.0/{<em id="dli_02_0308__i1524324717349">project_id</em>}/databases/{<em id="dli_02_0308__i4414550163411">database_name</em>}/tables</p>
<ul id="dli_02_0308__ul187037363019"><li id="dli_02_0308__li370323113013">Obtain the value of {<em id="dli_02_0308__i176915541344">project_id</em>} from <a href="dli_02_0183.html">Obtaining a Project ID</a>.</li><li id="dli_02_0308__li1670316318304">For details about the request parameters, see <a href="dli_02_0034.html">Creating a Table (Discarded)</a>.</li></ul>
</li><li id="dli_02_0308__li157031431301">Request example<ul id="dli_02_0308__ul1270319353013"><li id="dli_02_0308__li1070313113020">Description: In the project whose ID is <strong id="dli_02_0308__b1197151233517">48cc2c48765f481480c7db940d6409d1</strong>, create a table named <strong id="dli_02_0308__b6907171411355">tb1</strong> in the <strong id="dli_02_0308__b520331820359">db1</strong> database.</li><li id="dli_02_0308__li870443193015">Example URL: POST https://{<em id="dli_02_0308__i323772812357">endpoint</em>}/v1.0/48cc2c48765f481480c7db940d6409d1/databases/db1/tables</li><li id="dli_02_0308__li270410303012">Body:<pre class="screen" id="dli_02_0308__screen77042314309">{
"table_name": "tb1",
"data_location": "OBS",
"description": "",
"data_type": "csv",
"data_path": "obs://obs/path1/test.csv",
"columns": [
{
"column_name": "column1",
"type": "string",
"description": "",
"is_partition_column": true
},
{
"column_name": "column2",
"type": "string",
"description": "",
"is_partition_column": false
}
],
"with_column_header": true,
"delimiter": ",",
"quote_char": "\"",
"escape_char": "\\",
"date_format": "yyyy-MM-dd",
"timestamp_format": "yyyy-MM-dd HH:mm:ss"
}</pre>
</li></ul>
</li><li id="dli_02_0308__li17047343019">Example response<pre class="screen" id="dli_02_0308__screen137049318303">{
"is_success": true,
"message": ""
}</pre>
</li></ul>
</li><li id="dli_02_0308__li566476163912">(Optional) If the table to be created does not contain data, use the <a href="dli_02_0019.html">Importing Data (Discarded)</a> API to import data to the table.</li><li id="dli_02_0308__li1880513257207">(Optional) After data is imported, you can use the <a href="dli_02_0022.html">Querying Job Details</a> API to check whether the imported data is correct.</li><li id="dli_02_0308__li125211016104016">Submit a query job.<ul id="dli_02_0308__ul26571210114414"><li id="dli_02_0308__li146576102444">API<p id="dli_02_0308__p10657111019442"><a name="dli_02_0308__li146576102444"></a><a name="li146576102444"></a>URI format: POST /v1.0/{<em id="dli_02_0308__i938127193718">project_id</em>}/jobs/submit-job</p>
<ul id="dli_02_0308__ul56581107449"><li id="dli_02_0308__li17658191013442">Obtain the value of {<em id="dli_02_0308__i179494150370">project_id</em>} from <a href="dli_02_0183.html">Obtaining a Project ID</a>.</li><li id="dli_02_0308__li3658201018442">For details about the request parameters, see <a href="dli_02_0028.html">Creating a Database (Discarded)</a>.</li></ul>
</li><li id="dli_02_0308__li10658410164410">Request example<ul id="dli_02_0308__ul14658161015442"><li id="dli_02_0308__li865851014449">Description: Submit a SQL job in the project whose ID is <strong id="dli_02_0308__b043517347377">48cc2c48765f481480c7db940d6409d1</strong> and query data in the <strong id="dli_02_0308__b08831837143712">tb1</strong> table in the database <strong id="dli_02_0308__b144266407379">db1</strong>.</li><li id="dli_02_0308__li6658171074411">Example URL: POST https://{<em id="dli_02_0308__i16945104683715">endpoint</em>}/v1.0/48cc2c48765f481480c7db940d6409d1/jobs/submit-job</li><li id="dli_02_0308__li165811084419">Body:<pre class="screen" id="dli_02_0308__screen3658131064420">{
"currentdb": "db1",
"sql": "select * from tb1 limit 10",
"queue_name": "queue1"
}</pre>
</li></ul>
</li><li id="dli_02_0308__li2065912101446">Example response<pre class="screen" id="dli_02_0308__screen765961024418">{
"is_success": true,
"message": "",
"job_id":""95fcc908-9f1b-446c-8643-5653891d9fd9",
"job_type": "QUERY",
"job_mode": "async"
}</pre>
</li></ul>
</li></ol>
</div>
</div>
<div>
<div class="familylinks">
<div class="parentlink"><strong>Parent topic:</strong> <a href="dli_02_0306.html">Getting Started</a></div>
</div>
</div>