PrestoDB is an open source, distributed SQL query engine for big data that uses a massively parallel processing (MPP) architecture. It supports various data sources, such as MySQL, Elasticsearch, and Tablestore. After you connect PrestoDB to Tablestore, you can use PrestoDB to query, analyze, write, and import data in Tablestore.
Background information
PrestoDB is an open source, distributed SQL query engine for big data that uses an MPP architecture. It supports various data sources, such as MySQL, Elasticsearch, and Tablestore. PrestoDB can be used as a query tool, a data extract, transform, and load (ETL) tool, a load testing tool, and a unified query engine to meet data processing needs in different scenarios.
-
As a query tool, PrestoDB supports SQL queries for daily development and troubleshooting.
-
As a data ETL tool, PrestoDB supports data replication across tables or instances and data copying from disparate data sources.
-
As a load testing tool, PrestoDB supports batch data scanning or writing.
-
As a unified query engine within a data mid-end, PrestoDB supports connections to multiple disparate data sources.
To use Tablestore with PrestoDB, you must first establish a connection. After the connection is established, you can use PrestoDB to query, analyze, write, and import data in Tablestore.
Prerequisites
-
You have a server that runs Linux or macOS with the following software installed. This topic uses a Linux server as an example.
NoteIf you do not have a Linux server, you can use an Elastic Compute Service (ECS) instance. For more information, see Create an instance using the wizard.
-
Java 8 (64-bit) and a Python 3 development environment are installed.
-
PrestoDB is installed.
-
Download the prestodb-tablestore-connector file that corresponds to your PrestoDB version. Upload and decompress the file in the
plugindirectory of your PrestoDB installation folder.The following table describes the compatibility between prestodb-tablestore-connector plugin versions and PrestoDB versions.
Plugin version
PrestoDB version
Description
0.280
First release. This plugin is compatible with PrestoDB 0.280 and later.
-
-
You have the required Tablestore information, such as the access account, instance details, and table information.
-
You have created an AccessKey for a Resource Access Management (RAM) user that has permissions to operate Tablestore. For more information, see Obtain an AccessKey pair.
NoteIf the RAM user does not have the required permissions to operate Tablestore, you must grant the permissions before you proceed. For more information, see Grant permissions to a RAM user using a RAM policy.
Notes
-
This feature applies only to wide table models.
-
The default write mode for PrestoDB is UpdateRow. The PutRow write mode is not supported. If you want to write data to Tablestore using PrestoDB, make sure that the Allow Update parameter for the Tablestore data table is set to Yes. Otherwise, the data write operation will fail.
Important-
You cannot write data to a table using PrestoDB if the table uses a search index time to live (TTL). This is because you must set the Allow Update parameter to No when a search index TTL is used (the value is not -1).
-
To use the PutRow write mode, join DingTalk group 36165029092 (
Tablestore Technical Support-3) to contact us.
You can view the Allow Update setting on the Basic Details tab of the data table in the console or by calling the DescribeTable operation.

-
Field type mapping
Tablestore and PrestoDB use different data types. The following table describes the mapping between the field types.
|
Tablestore field type |
PrestoDB field type |
|
string |
varchar |
|
integer |
bigint |
|
double |
double |
|
boolean |
boolean |
|
binary |
varbinary |
Procedure
To use Tablestore with PrestoDB, you need to connect PrestoDB to Tablestore, run the PrestoDB SQL command-line interface (CLI), create a schema and a mapping table, and then use SQL to operate on data.
Step 1: Connect PrestoDB to Tablestore
After you install PrestoDB, you must configure the PrestoDB catalog and schema to connect to Tablestore. The catalog configuration file is located at etc/catalog/tablestore.properties.
Configuration details
Step 2: Run the Presto SQL CLI
After the connection is established, you can start the Presto Server and run SQL statements.
-
Obtain the client executable file.
-
Download the PrestoDB client.
This topic uses presto-cli-0.280-executable.jar as an example.
-
Save the PrestoDB client to the
bindirectory of the PrestoDB installation folder. -
In the
bindirectory of the PrestoDB installation folder, run the following command to obtain the client executable file.# Rename the PrestoDB client file to presto. Replace presto-cli-0.280-executable.jar with the name of your client version. mv presto-cli-0.280-executable.jar presto # Grant the user permissions to operate the presto file. chmod +x prestoThe following figure shows the directory where the client executable file is located.

-
-
In the
bindirectory of the PrestoDB installation folder, run the command to start the Presto Server.ImportantWhen you start the Presto Server, you must start the coordinator and at least one worker.
# You can start the server in the foreground or background. The foreground mode is more convenient for viewing operational logs. # Method 1: Run in the background ./launcher start # Method 2: Run in the foreground ./launcher run -
In the
bindirectory of the PrestoDB installation folder, run the following command to start the SQL CLI.Note-
By default, PrestoDB runs on port 8080. To change the port, modify the
http-server.http.portsetting in theetc/config.propertiesfile. -
After you modify configuration settings, you must restart the server for the changes to take effect.
-
In the command,
./prestois the relative path of the client executable file in thebindirectory of the PrestoDB installation folder.
./presto --server localhost:8080 --catalog tablestore --schema defaultThe following table describes the configuration items.
Configuration item
Example
Required
Description
--server
localhost:8080
Yes
The URI of the Presto Server. Replace the value as needed. This setting must be the same as the
discovery.uriparameter in theetc/config.propertiesfile in the PrestoDB installation directory.--catalog
tablestore
Yes
The name of the catalog configuration file. Set this to `tablestore`, which is the same as the name of the created catalog configuration file.
--schema
default
Yes
The schema configuration. Keep the default value.
-
Step 3: Create a schema and a mapping table
When you use the dynamic schema configuration mode with a meta table, you must manually create a schema to configure the connected Tablestore instance and perform user authentication. Then, you must create a mapping table for the Tablestore table to query and analyze data.
If you use the local static file schema configuration mode, you do not need to perform this step.
-
Run the following command to create a schema.
The following example shows how to create a Schema named testdb to access the Tablestore instance myinstance.
CREATE SCHEMA tablestore.testdb WITH ( endpoint = 'https://myinstance.cn-hangzhou.ots.aliyuncs.com', instance_name = 'myinstance', access_id = '************************', access_key = '********************************' );For a description of the parameters, see the following table.
Parameter
Example
Required
Description
endpoint
https://myinstance.cn-hangzhou.ots.aliyuncs.com
Yes
The endpoint of the Tablestore instance. For more information, see Endpoints.
instance_name
myinstance
Yes
The name of the Tablestore instance. For more information, see Instances.
access_id
************************
Yes
The AccessKey ID of the Alibaba Cloud account or RAM user.
access_key
********************************
Yes
The AccessKey secret of the Alibaba Cloud account or RAM user.
-
Run the
use <SCHEMA_NAME>;command to use the schema that you created.Replace
<SCHEMA_NAME>with the name of the schema you created. You can run theshow schemas;command to obtain a list of schemas. -
Run the following command to create a mapping table for the Tablestore data table.
ImportantNote the following points when you create a mapping table:
-
Make sure the field types in the mapping table match the field types in the Tablestore data table. For more information, see Field type mapping.
-
The mapping table name must match the table name in Tablestore.
-
In the CREATE TABLE SQL statement, the table_name property maps the Presto table to the actual table in Tablestore. You can create multiple mapping tables with different names for the same Tablestore data table.
-
The mapping table must include all primary key columns of the data table, but it can include only some of the attribute columns.
-
The names and order of the primary key columns in the mapping table must be the same as those in the Tablestore data table. You can map each attribute column in the mapping table to a column in the Tablestore table by specifying the origin_name parameter.
Assume that the data table is named main_table and includes two primary key columns, gid and uid, and three attribute columns, col1, col2, and col3.
The following SQL example creates a mapping table with the same name for the Tablestore data table main_table.
CREATE TABLE if not exists main_table ( gid bigint, uid bigint, c1 boolean with (origin_name = 'col1'), c2 bigint with (origin_name = 'col2'), c3 varchar with (origin_name = 'col3') ) WITH ( table_name = 'main_table' ); -
Step 4: Use SQL to operate on data
Before you use SQL to operate on Tablestore data, make sure that you have run the use <SCHEMA_NAME>; command to use the required schema.
You can use SQL statements to query schema configurations and table metadata, and to read and write data in Tablestore tables. For more SQL examples, see Common SQL examples.
-
Query schema configurations.
-
Obtain a list of schemas
show schemas; -
Obtain a list of tables in a specified schema
show tables;
-
-
View the metadata of a specified table
Replace
<TABLE_NAME>with the actual table name.describe <TABLE_NAME>; -
Data operations.
Read and write Tablestore data.
-
Write data
-
Insert a row of data
The following example inserts a row of data into main_table.
insert into main_table values(10001,10001,true,100,'hangzhou'); -
Import data in batches
ImportantBefore you import data in batches, make sure that the destination table is created and its table schema is the same as that of the source data table.
The following example imports data from the gid, uid, c1, c2, and c3 columns of main_table into sampletable, where gid is greater than 0 and uid is less than 10000.
insert into sampletable select gid, uid, c1, c2, c3 from main_table where gid > 0 and uid < 100000;
-
-
Read data
The following example queries for rows in sampletable where the gid column value is greater than 0, the uid column value is less than 10, and c1 is true.
select * from sampletable where gid > 0 and uid < 10 and c1 = true;
-
Billing
Tablestore supports two billing modes: VCU mode (formerly provisioned mode) and CU mode (formerly pay-as-you-go mode). For billing information, refer to the billing mode of your instance. For more information, see Billing overview.
-
VCU mode (formerly provisioned mode): Billable items include compute capacity, data storage, and outbound internet traffic. Data storage includes high-performance storage, storage-optimized storage, and search index storage.
Accessing Tablestore with a compute engine consumes computing resources. The data storage that is used by the table that stores metadata depends on the storage type that was specified when the instance was created.
-
CU mode (formerly pay-as-you-go mode): Billable items include read throughput, write throughput, data storage, and outbound internet traffic.
When you use a compute engine to access Tablestore, Tablestore meters and bills your usage based on the read and write throughput for specific read and write requests. The data storage that is used by the table that stores metadata depends on the storage type that was specified when the instance was created.
References
-
You can use other compute engines, such as MaxCompute, Spark, Function Compute, and Flink, to query and analyze data in Tablestore tables. For more information, see Compute and analysis overview. You can also use the SQL query and search index aggregation features of Tablestore to query and analyze data in tables. For more information, see SQL query and Search index.
-
You can also use other tools, such as DataWorks data integration and DataX, to migrate data from other data sources to Tablestore. For more information, see Migration tools.
-
If you want to visualize data in charts or other formats, you can use DataV or Grafana. For more information, see Data visualization.
-
By combining compute engines and Tablestore, you can implement solutions such as Use Tablestore and Spark for stream and batch processing to implement integrated storage and computing and Use Tablestore and Flink for big data analytics.
