You can execute the CREATE TABLE statement to create a mapping table for an existing table or a search index. When you create a mapping table, specify the names and types of fields in the table, the primary key information about the table, and the execution engine for data queries based on your business requirements.
For more information about the CREATE TABLE statement, see Create a mapping table for a table and Create mapping tables for search indexes.
Prerequisites
An OTSClient instance is initialized. For more information, see Initialize an OTSClient instance.
A data table is created. For more information, see Create data tables.
If you want to use a mapping table that is created for a search index to query data, make sure that a search index is created. For more information, see Create a search index.
Parameters
Parameter | Description |
query | The SQL statement. Configure this parameter based on the required feature. |
Example
This topic describes how to create a mapping table for a table. If you want to create a mapping table for a search index, replace the SQL statement in the sample code with the SQL statement that is used to create a mapping table for a search index.
The following sample code provides an example on how execute the create table test_table (pk varchar(1024), long_value bigint, double_value double, string_value mediumtext, bool_value bool, primary key(pk))
statement to create a mapping table for a table named test_table:
const params = {
query: "create table test_table (pk varchar(1024), long_value bigint, double_value double, string_value mediumtext, bool_value bool, primary key(pk))",
}
client.sqlQuery(params, function (err, data) {
if (err) {
console.log('sqlQuery error:', err.toString());
} else {
console.log('sqlQuery success:', data);
}
});
FAQ
References
If you want to accelerate data queries and computing by executing SQL statements, you can create a secondary index or a search index. For more information, see Index selection policy and Computing pushdown.
You can execute the SELECT statement to query and analyze data in the table for which you created a mapping table. For more information, see Query data.
If an attribute column is added to or removed from a data table, you can execute the
ALTER TABLE
statement to modify the mapping table that is created for the data table. For more information, see Update attribute columns of a mapping table.If you want to query the description of a table, you can execute the
DESCRIBE
statement. For more information, see Query information about tables.If you no longer require a mapping table that is created for a table or a search index, you can execute the
DROP MAPPING TABLE
statement to delete the mapping table. For more information, see Delete mapping tables.If you want to view the index information about a table, you can execute the
SHOW INDEX
statement. For more information, see Query index information about tables.If you want to query the names of mapping tables in the current database, you can execute the
SHOW TABLES
statement. For more information, see List the names of tables.