doc-exports/docs/dli/sqlreference/en-us_topic_0000001621542965.html
Su, Xiaomeng 76a5b1ee83 dli_sqlreference_20240227
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-03-27 22:02:33 +00:00

86 lines
12 KiB
HTML

<a name="EN-US_TOPIC_0000001621542965"></a><a name="EN-US_TOPIC_0000001621542965"></a>
<h1 class="topictitle1">Disabling or Restoring the Lifecycle of a Table</h1>
<div id="body0000001621542965"><div class="section" id="EN-US_TOPIC_0000001621542965__section517215384286"><h4 class="sectiontitle">Function</h4><p id="EN-US_TOPIC_0000001621542965__p4338194819285">This section describes how to disable or restore the lifecycle of a specified table or partition.</p>
<div class="p" id="EN-US_TOPIC_0000001621542965__p48841536204218">You can disable or restore the lifecycle of a table in either of the following scenarios:<ol id="EN-US_TOPIC_0000001621542965__ol14810128191319"><li id="EN-US_TOPIC_0000001621542965__li981016816135">If the lifecycle function has been enabled for a table or partitioned table, the system allows you to disable or restore the lifecycle of the table by changing the value of <strong id="EN-US_TOPIC_0000001621542965__b15161203375715">dli.table.lifecycle.status</strong>.</li><li id="EN-US_TOPIC_0000001621542965__li381117814137">If the lifecycle function is not enabled for a table or partitioned table, the system will add the <strong id="EN-US_TOPIC_0000001621542965__b191874415597">dli.table.lifecycle.status</strong> property to allow you to disable or restore the lifecycle function of the table.</li></ol>
</div>
</div>
<div class="section" id="EN-US_TOPIC_0000001621542965__section1138516665510"><h4 class="sectiontitle">Constraints and Limitations</h4><ul id="EN-US_TOPIC_0000001621542965__ul162161589267"><li id="EN-US_TOPIC_0000001621542965__li18263433152214">The table lifecycle function currently only supports creating tables and versioning tables using Hive and Datasource syntax.</li><li id="EN-US_TOPIC_0000001621542965__li753534652018">The unit of the lifecycle is in days. The value should be a positive integer.</li><li id="EN-US_TOPIC_0000001621542965__li15403171564215">The lifecycle can be set only at the table level. The lifecycle specified for a partitioned table applies to all partitions of the table.</li></ul>
</div>
<div class="section" id="EN-US_TOPIC_0000001621542965__section16438319290"><h4 class="sectiontitle">Syntax</h4><ul id="EN-US_TOPIC_0000001621542965__ul73081311172413"><li id="EN-US_TOPIC_0000001621542965__li1730815115242">This syntax can be used to disable or restore the lifecycle of a table at the table level.<div class="codecoloring" codetype="Sql" id="EN-US_TOPIC_0000001621542965__screen1029465619239"><div class="highlight"><table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre><span class="normal">1</span></pre></div></td><td class="code"><div><pre><span></span><span class="k">ALTER</span><span class="w"> </span><span class="k">TABLE</span><span class="w"> </span><span class="k">table_name</span><span class="w"> </span><span class="k">SET</span><span class="w"> </span><span class="n">TBLPROPERTIES</span><span class="p">(</span><span class="ss">&quot;dli.table.lifecycle.status&quot;</span><span class="o">=</span><span class="err">{</span><span class="n">enable</span><span class="o">|</span><span class="n">disable</span><span class="err">}</span><span class="p">);</span>
</pre></div></td></tr></table></div>
</div>
</li></ul>
<ul id="EN-US_TOPIC_0000001621542965__ul0223614152417"><li id="EN-US_TOPIC_0000001621542965__li1022314144243">This syntax can be used to disable or restore the lifecycle of a specified table at the table or partition table level.<div class="codecoloring" codetype="Sql" id="EN-US_TOPIC_0000001621542965__screen23861851142210"><div class="highlight"><table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre><span class="normal">1</span></pre></div></td><td class="code"><div><pre><span></span><span class="k">ALTER</span><span class="w"> </span><span class="k">TABLE</span><span class="w"> </span><span class="k">table_name</span><span class="w"> </span><span class="p">[</span><span class="n">pt_spec</span><span class="p">]</span><span class="w"> </span><span class="n">LIFECYCLE</span><span class="w"> </span><span class="err">{</span><span class="n">enable</span><span class="o">|</span><span class="n">disable</span><span class="err">}</span><span class="p">;</span>
</pre></div></td></tr></table></div>
</div>
</li></ul>
</div>
<div class="section" id="EN-US_TOPIC_0000001621542965__section16615161512916"><h4 class="sectiontitle">Keywords</h4><p id="EN-US_TOPIC_0000001621542965__p1891694419596"><strong id="EN-US_TOPIC_0000001621542965__b75677352792843">TBLPROPERTIES</strong>: Table properties, which can be used to extend the lifecycle of a table.</p>
</div>
<div class="section" id="EN-US_TOPIC_0000001621542965__section10377152018324"><h4 class="sectiontitle">Parameters</h4>
<div class="tablenoborder"><table cellpadding="4" cellspacing="0" summary="" id="EN-US_TOPIC_0000001621542965__table1463235703117" frame="border" border="1" rules="all"><caption><b>Table 1 </b>Parameters</caption><thead align="left"><tr id="EN-US_TOPIC_0000001621542965__row5632175723110"><th align="left" class="cellrowborder" valign="top" width="22.832283228322833%" id="mcps1.3.5.2.2.4.1.1"><p id="EN-US_TOPIC_0000001621542965__p13474112014326">Parameter</p>
</th>
<th align="left" class="cellrowborder" valign="top" width="16.77167716771677%" id="mcps1.3.5.2.2.4.1.2"><p id="EN-US_TOPIC_0000001621542965__p11632157123114">Mandatory</p>
</th>
<th align="left" class="cellrowborder" valign="top" width="60.396039603960396%" id="mcps1.3.5.2.2.4.1.3"><p id="EN-US_TOPIC_0000001621542965__p1963235719312">Description</p>
</th>
</tr>
</thead>
<tbody><tr id="EN-US_TOPIC_0000001621542965__row146323576319"><td class="cellrowborder" valign="top" width="22.832283228322833%" headers="mcps1.3.5.2.2.4.1.1 "><p id="EN-US_TOPIC_0000001621542965__p3632757133110">table_name</p>
</td>
<td class="cellrowborder" valign="top" width="16.77167716771677%" headers="mcps1.3.5.2.2.4.1.2 "><p id="EN-US_TOPIC_0000001621542965__p86321957183111">Yes</p>
</td>
<td class="cellrowborder" valign="top" width="60.396039603960396%" headers="mcps1.3.5.2.2.4.1.3 "><p id="EN-US_TOPIC_0000001621542965__p11633557133115">Name of the table whose lifecycle is to be disabled or restored</p>
</td>
</tr>
<tr id="EN-US_TOPIC_0000001621542965__row16331657113114"><td class="cellrowborder" valign="top" width="22.832283228322833%" headers="mcps1.3.5.2.2.4.1.1 "><p id="EN-US_TOPIC_0000001621542965__p186331257163117">pt_spec</p>
</td>
<td class="cellrowborder" valign="top" width="16.77167716771677%" headers="mcps1.3.5.2.2.4.1.2 "><p id="EN-US_TOPIC_0000001621542965__p5633145723115">No</p>
</td>
<td class="cellrowborder" valign="top" width="60.396039603960396%" headers="mcps1.3.5.2.2.4.1.3 "><p id="EN-US_TOPIC_0000001621542965__p1563345773119">Partition information of the table whose lifecycle is to be disabled or restored. The format is <strong id="EN-US_TOPIC_0000001621542965__b568214466310">partition_col1=col1_value1, partition_col2=col2_value1...</strong>. For a table with multi-level partitions, all partition values must be specified.</p>
</td>
</tr>
<tr id="EN-US_TOPIC_0000001621542965__row1263325723113"><td class="cellrowborder" valign="top" width="22.832283228322833%" headers="mcps1.3.5.2.2.4.1.1 "><p id="EN-US_TOPIC_0000001621542965__p1163355717319">enable</p>
</td>
<td class="cellrowborder" valign="top" width="16.77167716771677%" headers="mcps1.3.5.2.2.4.1.2 "><p id="EN-US_TOPIC_0000001621542965__p1642574123610">No</p>
</td>
<td class="cellrowborder" valign="top" width="60.396039603960396%" headers="mcps1.3.5.2.2.4.1.3 "><div class="p" id="EN-US_TOPIC_0000001621542965__p13503111143512">Restores the lifecycle function of a table or a specified partition.<ul id="EN-US_TOPIC_0000001621542965__ul36811252133411"><li id="EN-US_TOPIC_0000001621542965__li768112526342">The table and its partitions participate in lifecycle reclamation again. By default, the lifecycle configuration of the current table and its partitions is used.</li><li id="EN-US_TOPIC_0000001621542965__li14681105233411">Before enabling the table lifecycle function, it is recommended to modify the lifecycle configuration of the table and its partitions. This will help prevent any accidental data reclamation caused by the previous configuration once the table lifecycle function is enabled.</li></ul>
</div>
</td>
</tr>
<tr id="EN-US_TOPIC_0000001621542965__row89571133317"><td class="cellrowborder" valign="top" width="22.832283228322833%" headers="mcps1.3.5.2.2.4.1.1 "><p id="EN-US_TOPIC_0000001621542965__p18961411153312">disable</p>
</td>
<td class="cellrowborder" valign="top" width="16.77167716771677%" headers="mcps1.3.5.2.2.4.1.2 "><p id="EN-US_TOPIC_0000001621542965__p39614113336">No</p>
</td>
<td class="cellrowborder" valign="top" width="60.396039603960396%" headers="mcps1.3.5.2.2.4.1.3 "><p id="EN-US_TOPIC_0000001621542965__p878017192353">Disables the lifecycle function of a table or a specified partition.</p>
<ul id="EN-US_TOPIC_0000001621542965__ul1578018192357"><li id="EN-US_TOPIC_0000001621542965__li47809199355">Prevents a table and all its partitions from being reclaimed by the lifecycle. It takes priority over restoring the lifecycle of a table and its partitions. That is, when the lifecycle function of a table or a specified partition is disabled, the partition information of the table whose lifecycle is to be disabled or restored is invalid.</li><li id="EN-US_TOPIC_0000001621542965__li11780111911351">After the lifecycle function of a table is disabled, the lifecycle configuration of the table and the enable and disable flags of its partitions are retained.</li><li id="EN-US_TOPIC_0000001621542965__li19780619153514">After the lifecycle function of a table is disabled, the lifecycle configuration of the table and partitioned table can still be modified.</li></ul>
</td>
</tr>
</tbody>
</table>
</div>
</div>
<div class="section" id="EN-US_TOPIC_0000001621542965__section149182853215"><h4 class="sectiontitle">Example</h4><ul id="EN-US_TOPIC_0000001621542965__ul596932815403"><li id="EN-US_TOPIC_0000001621542965__li49691728134019">Example 1: Disable the lifecycle function of the <strong id="EN-US_TOPIC_0000001621542965__b15627632178">test_lifecycle</strong> table.<div class="codecoloring" codetype="Sql" id="EN-US_TOPIC_0000001621542965__screen2651314183910"><div class="highlight"><table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre><span class="normal">1</span></pre></div></td><td class="code"><div><pre><span></span><span class="k">alter</span><span class="w"> </span><span class="k">table</span><span class="w"> </span><span class="n">test_lifecycle</span><span class="w"> </span><span class="k">SET</span><span class="w"> </span><span class="n">TBLPROPERTIES</span><span class="p">(</span><span class="ss">&quot;dli.table.lifecycle.status&quot;</span><span class="o">=</span><span class="s1">'disable'</span><span class="p">);</span>
</pre></div></td></tr></table></div>
</div>
</li></ul>
<ul id="EN-US_TOPIC_0000001621542965__ul1838133404011"><li id="EN-US_TOPIC_0000001621542965__li3381634144019">Example 2: Disable the lifecycle function for the partition whose time is <strong id="EN-US_TOPIC_0000001621542965__b201139204178">20230520</strong> in the <strong id="EN-US_TOPIC_0000001621542965__b63211034121710">test_lifecycle</strong> table.<div class="codecoloring" codetype="Sql" id="EN-US_TOPIC_0000001621542965__screen14919496405"><div class="highlight"><table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre><span class="normal">1</span></pre></div></td><td class="code"><div><pre><span></span><span class="k">alter</span><span class="w"> </span><span class="k">table</span><span class="w"> </span><span class="n">test_lifecycle</span><span class="w"> </span><span class="n">partition</span><span class="w"> </span><span class="p">(</span><span class="n">dt</span><span class="o">=</span><span class="s1">'20230520'</span><span class="p">)</span><span class="w"> </span><span class="n">LIFECYCLE</span><span class="w"> </span><span class="s1">'disable'</span><span class="p">;</span>
</pre></div></td></tr></table></div>
</div>
<div class="note" id="EN-US_TOPIC_0000001621542965__note1520142145816"><img src="public_sys-resources/note_3.0-en-us.png"><span class="notetitle"> </span><div class="notebody"><ul id="EN-US_TOPIC_0000001621542965__ul14251734145813"><li id="EN-US_TOPIC_0000001621542965__li425434135814">After the lifecycle function of a partitioned table is disabled, the lifecycle function of all partitions within the table will also be disabled.</li></ul>
</div></div>
</li></ul>
</div>
</div>
<div>
<div class="familylinks">
<div class="parentlink"><strong>Parent topic:</strong> <a href="en-us_topic_0000001571023676.html">Table Lifecycle Management</a></div>
</div>
</div>