MaxCompute data sources
This topic describes how to configure a MaxCompute data source.
Prerequisites
-
You are familiar with MaxCompute (formerly ODPS). If you are not familiar with MaxCompute, click here for reference.
-
Table permissions: When you configure a MaxCompute table, the account that you use to log on to OpenSearch must have the required permissions on the table (describe, select, download, and field-level label permissions).
The following statements grant the permissions:
-- Add the account
add user ****@aliyun.com;
-- Grant the required table 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 field-level permission checks are enabled in MaxCompute, high-permission fields cannot be accessed when data is pulled, and the table index cannot be built. In this case, grant field-level access permissions to the account.
-- 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
-
The MaxCompute table field types supported by OpenSearch Retrieval Engine Edition are STRING, BOOLEAN, DOUBLE, BIGINT, and DATETIME.
For detailed descriptions of table creation statements and parameter configurations, see Create table statements for MaxCompute data sources
Configure a MaxCompute data source
1. Log on to the OpenSearch console. In the upper-left corner, switch to OpenSearch Retrieval Engine Edition. On the Instance Management page, find the instance in the list and click Manage in the Actions column.
-
On the Configuration Center > Data Source Configuration page, click Add Data Source. When you add the data source, select MaxCompute and specify information such as the data source name, Project, accesskeyId, accesskeySecret, Table, partition key, and automatic index rebuilding.
3. After the configuration is complete, click Verify. After the verification is passed, the OK button becomes available.
4. After you add a data source, you must configure the index schema to add index tables for the data source. For more information, see Add an index table.
5. After the index tables are configured, you must update the configuration and rebuild indexes before the online cluster can use them. For more information, see Update configurations.
Note:
-
Data source name: the name of the data source that you create. The naming convention is InstanceName_CustomName.
-
Project, accesskeyId, accesskeySecret, Table, and partition key: the parameters required to access the MaxCompute data source.
-
Automatic index rebuilding: specifies whether to enable automatic index rebuilding tasks. If this feature is enabled, when a change to the current data source is detected, indexes are automatically rebuilt for the index tables that reference the data source.
-
If you enable automatic index rebuilding, you must create a done table. For information about how to create the table, see Automatic reindexing below.
Automatic index rebuilding
Purpose of the done table: If you enable automatic index rebuilding when you configure a data source, the OpenSearch Retrieval Engine Edition instance automatically rebuilds indexes based on changes to your done table.
Example: Assume that your MaxCompute data table is mytable and its partition is ds=20220113. After the data source is configured and indexes are rebuilt for the first time, a new partition is produced every day (the data in the new partition is the full data of the table). The OpenSearch Retrieval Engine Edition instance needs to detect the new partition and then automatically rebuild indexes to pull the data in the new partition. In this case, you can use automatic index rebuilding + a done table to implement this feature.
Procedure:
1. When you add a data source, enable automatic index rebuilding.
2. Configure a done table in MaxCompute. Assume that the data table is named mytable and the partition key is named ds. Then, the done table is named mytable_done and its partition key is named ds. The two tables are displayed in MaxCompute as follows:
odps:sql:xxx> show tables;
InstanceId: xxx
SQL: .
ALIYUN$****@aliyun.com:mytable #Table of the full data source
ALIYUN$****@aliyun.com:mytable_done #Done table that controls automatic full builds
Statement for creating the done table:
create table mytable_done (attribute string) partitioned by (ds string);
3. After the data in the ds=20220114 partition of the mytable data table is produced, configure the done table to trigger index rebuilding on the OpenSearch Retrieval Engine Edition instance.
-- Add a partition
alter table mytable_done add if not exists partition (ds="20220114");
-- Insert the automatic full build signal data
insert into table mytable_done partition (ds="20220114") select '{"swift_start_timestamp":1642003200}';
The final content of the done table is shown below:
odps:sql:xxx> select * from mytable_done where ds=20220114 limit 1;
InstanceId: xxx
SQL: .
+-----------+----+
| attribute | ds |
+-----------+----+
| {"swift_start_timestamp":1642003200} | 20220114 |
+-----------+----+
After the automatic full build signal data is inserted into the done table, the OpenSearch Retrieval Engine Edition instance detects the signal in the done table and automatically triggers index rebuilding.
-
The done table must have at least one partition key, and the partition key name must be the same as that of the data table. If the partition key of the data table is ds, the partition key of the done table must also be ds.
-
The done table has only one field of the string type, and the field name must be "attribute".
-
The partitions added to the done table must exist in the data table. If the data table has the partitions ds="20220114", ds="20220115", and ds="20220116", the partitions newly added to the done table must also be within the range of the data table partitions.
-
When data is inserted into the done table, the value of the attribute field is a JSON string, such as
{"swift_start_timestamp":1642003200}. The timestamp indicates the start offset from which real-time incremental data is consumed.
Edit a MaxCompute data source
-
On the Data Source Configuration page, find the data source and click Modify in the Actions column on the right.
-
On the Edit Data Source page, modify information such as Project, accesskeyId, accesskeySecret, Table, and partition key.
After you modify the information, click Verify. After the verification is passed, click OK to save the changes.
-
After the data source is modified, you must update the configuration and rebuild indexes before the online cluster can use it. For more information, see Update configurations.
We recommend that you set partitions at the hour level, such as yyyyMMddHH (for example, 2022011314). This makes it easier to produce multiple full data sets per day in the future.
Delete a MaxCompute data source
-
Select Data Source Configuration and click Delete.
-
After you click Delete, the system checks whether the current data source is referenced by an index table.
-
If the data source is not referenced by an index table, click OK to delete the data source. After the change, you must push the configuration and rebuild indexes for the change to take effect.
-
If the data source is referenced by an index table, an error is reported when you directly delete the data source.
The system displays the message "The current data source is referenced by an index table. Delete the index table or remove the association before you delete the data source."
You must first delete the index tables that reference the data source (Delete an index table) before you can delete the data source.
Usage notes
-
You cannot modify the data source name when you edit a data source.
-
MaxCompute external tables are not supported. You must create internal tables.
-
The table configured for a MaxCompute data source must be a partitioned table.
-
The tables that you produce in MaxCompute are used as the full data input, and API data sources are used to push real-time data.