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.
If you want to use a mapping table that is created for a search index to query data, the search index is created.
Usage notes
Tablestore SDK for Java V5.13.0 or later supports the SQL query feature. Before you use the SQL query feature, make sure that Tablestore SDK for Java V5.13.0 or later is obtained. For more information about the version history of Tablestore SDK for Java, see Version history of Tablestore SDK for Java.
Parameters
Parameter | Description |
query | The SQL statement. Configure the parameter based on the required feature. |
Examples
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 to execute the create table test_table (pk varchar(1024), long_value bigint(20), double_value double, string_value mediumtext, bool_value bool, primary key(pk))
statement to create a mapping table for a table named test_table:
private static void createTable(SyncClient client) {
// Create an SQL request.
SQLQueryRequest request = new SQLQueryRequest("create table test_table (pk varchar(1024), long_value bigint(20), double_value double, string_value mediumtext, bool_value bool, primary key(pk))");
client.sqlQuery(request);
}
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 deleted 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 mapping tables.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 the index information about tables.If you want to list the names of mapping tables in the current database, you can execute the
SHOW TABLES
statement. For more information, see List mapping table names.