blob: 90af0eb721d2932761fb76799cef69812fb5580d [file] [log] [blame]
<!DOCTYPE html><html><head><meta charset="utf-8"><title>Untitled Document.md</title><style></style></head><body id="preview">
<p>&lt;!–<br>
Licensed to the Apache Software Foundation (ASF) under one<br>
or more contributor license agreements. See the NOTICE file<br>
distributed with this work for additional information<br>
regarding copyright ownership. The ASF licenses this file<br>
to you under the Apache License, Version 2.0 (the<br>
“License”); you may not use this file except in compliance<br>
with the License. You may obtain a copy of the License at</p>
<pre><code> http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing,
software distributed under the License is distributed on an
&quot;AS IS&quot; BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
KIND, either express or implied. See the License for the
specific language governing permissions and limitations
under the License.
</code></pre>
<p>–&gt;</p>
<h1><a id="DDL_Operations_on_CarbonData_19"></a>DDL Operations on CarbonData</h1>
<p>This tutorial will guide you through the data definition language support provided by CarbonData.</p>
<h2><a id="Overview_22"></a>Overview</h2>
<p>The following DDL operations are supported in CarbonData :</p>
<ul>
<li><a href="#create-table">CREATE TABLE</a></li>
<li><a href="#show-table">SHOW TABLE</a></li>
<li><a href="#drop-table">DROP TABLE</a></li>
<li><a href="#compaction">COMPACTION</a></li>
</ul>
<h2><a id="CREATE_TABLE_30"></a>CREATE TABLE</h2>
<p>This command can be used to create carbon table by specifying the list of fields along with the table properties.</p>
<pre><code>CREATE TABLE [IF NOT EXISTS] [db_name.]table_name
[(col_name data_type , ...)]
STORED BY 'carbondata'
[TBLPROPERTIES (property_name=property_value, ...)]
// All Carbon's additional table options will go into properties
</code></pre>
<h3><a id="Parameter_Description_40"></a>Parameter Description</h3>
<table class="table table-striped table-bordered">
<thead>
<tr>
<th>Parameter</th>
<th>Description</th>
<th>Optional</th>
</tr>
</thead>
<tbody>
<tr>
<td>db_name</td>
<td>Name of the Database. Database name should consist of Alphanumeric characters and underscore(_) special character.</td>
<td>Yes</td>
</tr>
<tr>
<td>field_list</td>
<td>Comma separated List of fields with data type. The field names should consist of Alphanumeric characters and underscore(_) special character.</td>
<td>No</td>
</tr>
<tr>
<td>table_name</td>
<td>The name of the table in Database. Table Name should consist of Alphanumeric characters and underscore(_) special character.</td>
<td>No</td>
</tr>
<tr>
<td>STORED BY</td>
<td>“org.apache.carbondata.format”, identifies and creates carbon table.</td>
<td>No</td>
</tr>
<tr>
<td>TBLPROPERTIES</td>
<td>List of carbon table properties.</td>
<td></td>
</tr>
</tbody>
</table>
<h3><a id="Usage_Guideline_50"></a>Usage Guideline</h3>
<p>Following are the table properties usage.</p>
<ul>
<li>
<p><strong>Dictionary Encoding Configuration</strong></p>
<p>By Default dictionary encoding will be enabled for all String columns, and disabled for non-String columns. User can include and exclude columns for dictionary encoding.</p>
<pre><code class="language-ruby"><span class="hljs-constant">TBLPROPERTIES</span> (<span class="hljs-string">"DICTIONARY_EXCLUDE"</span>=<span class="hljs-string">"column1, column2"</span>)
<span class="hljs-constant">TBLPROPERTIES</span> (<span class="hljs-string">"DICTIONARY_INCLUDE"</span>=<span class="hljs-string">"column1, column2"</span>)
</code></pre>
<p>Here, DICTIONARY_EXCLUDE will exclude dictionary creation. This is applicable for high-cardinality columns and is an optional parameter. DICTIONARY_INCLUDE will generate dictionary for the columns specified in the list.</p>
</li>
<li>
<p><strong>Row/Column Format Configuration</strong></p>
<p>Column groups with more than one column are stored in row format, instead of columnar format. By default, each column is a separate column group.</p>
<pre><code class="language-ruby"><span class="hljs-constant">TBLPROPERTIES</span> (<span class="hljs-string">"COLUMN_GROUPS"</span>=<span class="hljs-string">"(column1,column3),(Column4,Column5,Column6)"</span>)
</code></pre>
</li>
<li>
<p><strong>Table Block Size Configuration</strong></p>
<p>The block size of table files can be defined using the property TABLE_BLOCKSIZE. It accepts only integer values. The default value is set to 1024MB and supports a range of 1MB to 2048MB.<br>
If the user does’nt specify this value in the DDL command , default value is used.</p>
<pre><code>TBLPROPERTIES (&quot;TABLE_BLOCKSIZE&quot;=&quot;512 MB&quot;)
</code></pre>
<p>Here 512 MB means the block size of this table is 512 MB, user also can set it as 512M or 512.</p>
</li>
<li>
<p><strong>Inverted Index Configuration</strong></p>
<p>Inverted index is very useful to improve compression ratio and query speed, especially for those low-cardinality columns who are in reward position.<br>
By default inverted index is enabled. The user can disable the inverted index creation for some columns.</p>
<pre><code>TBLPROPERTIES (&quot;NO_INVERTED_INDEX&quot;=&quot;column1,column3&quot;)
</code></pre>
<p>No inverted index shall be generated for the columns specified in NO_INVERTED_INDEX. This property is applicable on columns with high-cardinality and is an optional parameter.</p>
<p><em>Note :</em></p>
<ul>
<li>
<p>By default all columns other than numeric datatype are treated as dimensions and all columns of numeric datatype are treated as measures.</p>
</li>
<li>
<p>All dimensions except complex datatype columns are part of multi dimensional key(MDK). This behavior can be overridden by using TBLPROPERTIES, If the user wants to keep any column (except columns of complex datatype) in multi dimensional key then he can keep the columns either in DICTIONARY_EXCLUDE or DICTIONARY_INCLUDE.</p>
</li>
</ul>
</li>
</ul>
<h3><a id="Example_96"></a>Example:</h3>
<pre><code>CREATE TABLE IF NOT EXISTS productSchema.productSalesTable (
productNumber Int,
productName String,
storeCity String,
storeProvince String,
productCategory String,
productBatch String,
saleQuantity Int,
revenue Int)
STORED BY 'carbondata'
TBLPROPERTIES ('COLUMN_GROUPS'='(productName,productCategory)',
'DICTIONARY_EXCLUDE'='productName',
'DICTIONARY_INCLUDE'='productNumber',
'NO_INVERTED_INDEX'='productBatch')
</code></pre>
<h2><a id="SHOW_TABLE_114"></a>SHOW TABLE</h2>
<p>This command can be used to list all the tables in current database or all the tables of a specific database.</p>
<pre><code>SHOW TABLES [IN db_Name];
</code></pre>
<h3><a id="Parameter_Description_121"></a>Parameter Description</h3>
<table class="table table-striped table-bordered">
<thead>
<tr>
<th>Parameter</th>
<th>Description</th>
<th>Optional</th>
</tr>
</thead>
<tbody>
<tr>
<td>IN db_Name</td>
<td>Name of the database. Required only if tables of this specific database are to be listed.</td>
<td>Yes</td>
</tr>
</tbody>
</table>
<h3><a id="Example_126"></a>Example:</h3>
<pre><code>SHOW TABLES IN ProductSchema;
</code></pre>
<h2><a id="DROP_TABLE_132"></a>DROP TABLE</h2>
<p>This command can be used to delete the existing table.</p>
<pre><code>DROP TABLE [IF EXISTS] [db_name.]table_name;
</code></pre>
<h3><a id="Parameter_Description_140"></a>Parameter Description</h3>
<table class="table table-striped table-bordered">
<thead>
<tr>
<th>Parameter</th>
<th>Description</th>
<th>Optional</th>
</tr>
</thead>
<tbody>
<tr>
<td>db_Name</td>
<td>Name of the database. If not specified, current database will be selected.</td>
<td>YES</td>
</tr>
<tr>
<td>table_name</td>
<td>Name of the table to be deleted.</td>
<td>NO</td>
</tr>
</tbody>
</table>
<h3><a id="Example_146"></a>Example:</h3>
<pre><code>DROP TABLE IF EXISTS productSchema.productSalesTable;
</code></pre>
<h2><a id="COMPACTION_152"></a>COMPACTION</h2>
<p>This command will merge the specified number of segments into one segment. This will enhance the query performance of the table.</p>
<pre><code>ALTER TABLE [db_name.]table_name COMPACT 'MINOR/MAJOR';
</code></pre>
<p>To get details about Compaction refer to <a href="">Data Management</a></p>
<h3><a id="Parameter_Description_162"></a>Parameter Description</h3>
<table class="table table-striped table-bordered">
<thead>
<tr>
<th>Parameter</th>
<th>Description</th>
<th>Optional</th>
</tr>
</thead>
<tbody>
<tr>
<td>db_name</td>
<td>Database name, if it is not specified then it uses current database.</td>
<td>YES</td>
</tr>
<tr>
<td>table_name</td>
<td>The name of the table in provided database.</td>
<td>NO</td>
</tr>
</tbody>
</table>
<h3><a id="Syntax_169"></a>Syntax</h3>
<ul>
<li><strong>Minor Compaction</strong></li>
</ul>
<pre><code>ALTER TABLE carbontable COMPACT MINOR;
</code></pre>
<ul>
<li><strong>Major Compaction</strong></li>
</ul>
<pre><code>ALTER TABLE carbontable COMPACT MAJOR;
</code></pre>
</body></html>