All Products
Search
Document Center

:CREATE TABLE statement for creating a table in a MaxCompute data source

Last Updated:Feb 29, 2024

Table creation statement

In this example, the name of the data table to be created is test_maxcompute_table, and the name of the corresponding done table is test_maxcompute_table_done.

#1. Create a data table.
CREATE TABLE IF NOT EXISTS test_maxcompute_table
(
  pk_id Bigint ,
  cate_id Bigint ,
  vector_array string 
)
PARTITIONED by 
(
  ds STRING
);

#2. Create a partition in the data table.
alter table test_maxcompute_table  add if not exists partition (ds="20230423");

#3. Create a done table.
create table test_maxcompute_table_done (attribute string) partitioned by (ds string);

#4. Create a partition in the done table.
alter table test_maxcompute_table_done  add if not exists partition (ds="20230423");


#5. Insert data into the data table.
insert into test_maxcompute_table partition (ds='20230423') select 1,'12345','xxx,xxx,xxx,xx....';

#6. Insert data into the done table.
insert into table ecom_table_done partition (ds="20230423") select '{"swift_start_timestamp":1682179200}';
Note

Fields contained in your MaxCompute table can be of the following data types: STRING, BOOLEAN, DOUBLE, BIGINT, and DATETIME.

Authorization statement

The account that you use to log on to the OpenSearch console must be granted the following permissions on the MaxCompute table that you want to configure: the DESCRIBE, SELECT, and DOWNLOAD permissions on the table and the LABEL permission on the fields of the table.

-- Add an account that is used to manage Havenask instances.
add user ****@aliyun.com;

-- Grant the required permissions to the account.
GRANT describe,select,download ON TABLE table_xxx TO USER ****@aliyun.com
GRANT describe,select,download ON TABLE table_xxx_done TO USER ****@aliyun.com

-- If you enable field permission verification for your MaxCompute table, the system prevents you from accessing highly privileged fields when you pull data, and indexes cannot be created for the table. In this case, you must grant your account the permissions to access fields. 
-- Grant permissions on the entire project.
SET LABEL 3 to USER ****@aliyun.com

-- Grant permissions on a single table.
GRANT LABEL 3 ON TABLE table_xxx(col1, col2) TO ****@aliyun.com

Parameters for adding a MaxCompute data source

image

Parameter

Required

Description

Data Source Type

Yes

The type of the data source. Select MaxCompute.

Data Source Name

Yes

The name of the data source. The name must be up to 30 characters in length and can contain digits, letters, and underscores (_).

Project

Yes

The name of the MaxCompute project that you want to access. You can view the project name on the DataStudio page of the corresponding workspace.

image

Note

If the workspace is in standard mode, suffix the project name with _dev. For example, if the project name is zy_ts_test, set this parameter to zy_ts_test_dev.

image

AccessKey ID

Yes

The AccessKey ID and AccessKey secret of the current Alibaba Cloud account or RAM user. You can view the AccessKey ID and AccessKey secret in the Account Management console.

image

AccessKey Secret

Yes

Table

Yes

The name of the data table that you want to access.

Partition Key

Yes

The name of the partition key of the data table. For example, if the name of a partition is ds=20230423, the name of the partition key is ds.