MaxCompute lets you use external tables to access data stored in Hologres. This method lets you quickly query Hologres data without importing it into MaxCompute. This topic describes how to create a Hologres external table by specifying the Hologres data source, Security Token Service (STS) authentication information or dual-signature mode, the mapped target table, and Java Database Connectivity (JDBC) driver information in the CREATE EXTERNAL TABLE statement.
Background information
Hologres is a real-time interactive analysis data warehouse that is compatible with the PostgreSQL protocol and seamlessly connected to MaxCompute at the storage layer.
You can create a Hologres external table in MaxCompute to query data from a Hologres data source using the PostgreSQL JDBC driver and STS authentication. This method eliminates redundant storage and the need to import or export data, which lets you quickly retrieve query results.
Prerequisites
Before you create a Hologres external table, ensure that the following prerequisites are met:
A Hologres database and a target table have been created.
For more information about how to create a Hologres database, see Create a database.
For more information about how to create a Hologres table, see CREATE TABLE.
Assume the following Hologres instance information:
Hologres database name:
mc_test.Hologres database schema:
public.Hologres database classic network endpoint:
hgprecn-cn-oew210ut****-cn-hangzhou-internal.hologres.aliyuncs.com:80.Hologres table name:
holo. The table contains the following data:
A destination MaxCompute project has been created.
For more information about how to create a MaxCompute project, see Create a MaxCompute project.
The MaxCompute client has been installed.
For more information about how to install the MaxCompute client, see Install and configure the MaxCompute client.
Limits
The following limits apply to Hologres external tables:
MaxCompute does not support UPDATE or DELETE operations on Hologres external tables.
Hologres partitioned tables do not correspond to MaxCompute partitioned tables, and Hologres external tables do not support partitions. However, when you query a MaxCompute external table that maps to a Hologres partitioned parent table in direct read mode, partition pruning can be performed if the query conditions match the partition key columns of the child tables.
When you write a large amount of data to a Hologres external table using parallel multi-process writing, a write process may, in rare cases, rewrite data and cause data duplication.
For Hologres external tables created in MaxCompute, the DECIMAL data type defaults to 18 decimal places and cannot be modified. It can only be created as
decimal(38,18). If you need fewer decimal places, you can set the data type to String when you create the external table in MaxCompute and then use thecastfunction to convert the data type before use.Hologres external tables created in MaxCompute do not support complex data types such as Array, Map, or Struct.
When you create a Hologres external table in MaxCompute, some Hologres data types, such as MONEY, do not have a corresponding data type in MaxCompute and are not supported.
Hologres external tables do not support the cluster property.
Hologres external tables do not support mapping to Hologres Dynamic Tables.
You cannot perform INSERT OVERWRITE operations on Hologres external tables. To overwrite data from MaxCompute to Hologres, you can read the Hologres external table that maps to a MaxCompute table from the Hologres side and use the INSERT OVERWRITE semantics of Hologres. For more information, see INSERT OVERWRITE.
Alternatively, you can perform this operation from the MaxCompute side using the
CALL EXEC_EXTERNAL_QUERYmethod. This method uses a MaxCompute function to execute a Hologres SQL command with INSERT OVERWRITE semantics. For more information, see Submit an execution command to Hologres based on the current user identity.
Precautions
Guidelines for creating Hologres external tables
If the IP address whitelist feature is enabled for Hologres, you must create the Hologres external table in dual-signature mode. If you create the Hologres external table in STS mode, the IP address whitelist blocks MaxCompute from accessing Hologres.
You can map a Hologres external table to either a parent table or a child table. However, parent tables are read-only.
When you write data to a Hologres external table, the Hologres INSERT ON CONFLICT(UPSERT) mechanism is not supported. If the Hologres source table has a primary key, avoid writing data that causes primary key conflicts.
Table and field names are case-insensitive. When you create or query tables and fields, forced case conversion is not supported.
Schema compatibility
If the schema of the Hologres source table is inconsistent with the schema of the external table:
Inconsistent number of columns: If the number of columns in the Hologres source table is less than the number of columns in the external table's Data Definition Language (DDL) statement, the system reports an error such as
column "xxx" does not existwhen reading data. If the number of columns in the Hologres source table is greater than the number of columns in the external table's DDL statement, the system discards the extra columns.Inconsistent column types: MaxCompute does not support using the INT data type to read STRING data from a Hologres source table. MaxCompute supports using the STRING data type to read INT data, but this is not recommended.
Create a Hologres external table
When you create an external table, you must specify a StorageHandler, configure STS authentication information or enable dual-signature mode, and provide the JDBC connection address in the CREATE EXTERNAL TABLE DDL statement to access the Hologres data source.
Syntax
Create a Hologres external table in STS mode. For a code sample, see Example of creating an external table in STS mode.
CREATE EXTERNAL TABLE [IF NOT EXISTS] <table_name>( <col1_name> <data_type>, <col2_name> <data_type>, ...... ) stored BY 'com.aliyun.odps.jdbc.JdbcStorageHandler' WITH serdeproperties ( 'odps.properties.rolearn'='<ram_arn>') location '<jdbc:postgresql://<endpoint>:<port>/<database>?ApplicationName=MaxCompute&[currentSchema=<schema>&][useSSL={true|false}&]table=<holo_table_name>/>' tblproperties ( 'mcfed.mapreduce.jdbc.driver.class'='org.postgresql.Driver', 'odps.federation.jdbc.target.db.type'='holo', 'odps.federation.jdbc.colmapping'='<table_column1>:<source_column1>, <table_column2>:<source_column2>,...' );Create a Hologres external table in dual-signature mode. For a code sample, see Example of creating an external table in dual-signature mode.
With a dual-signature Hologres external table, a RAM user can access tables in both MaxCompute and Hologres for which they have permissions, without requiring manual authorization. This mode also supports the Hologres IP address whitelist feature.
-- Enable the dual-signature switch. SET odps.sql.common.table.planner.ext.hive.bridge=true; -- Create the external table. CREATE EXTERNAL TABLE [IF NOT EXISTS] <table_name>( <col1_name> <data_type>, <col2_name> <data_type>, ...... ) STORED BY '<com.aliyun.odps.jdbc.JdbcStorageHandler>' LOCATION '<jdbc:postgresql://<endpoint>:<port>/<database>?ApplicationName=MaxCompute&[currentSchema=<schema>&][useSSL={true|false}&]table=<holo_table_name>/>' tblproperties ( 'mcfed.mapreduce.jdbc.driver.class'='org.postgresql.Driver', 'odps.federation.jdbc.target.db.type'='holo', ['odps.federation.jdbc.colmapping'='<table_column1>:<source_column1>, <table_column2>:<source_column2>,...'] );
Parameters
Parameter | Required | Description |
odps.sql.common.table.planner.ext.hive.bridge | Yes | A flag to enable dual-signature mode for creating the Hologres external table. Set this to |
No | You do not need to specify this parameter when creating a Hologres external table in STS mode. | |
IF NOT EXISTS | No | If you do not specify the IF NOT EXISTS option and a table with the same name exists, an error is reported. If you specify IF NOT EXISTS, the statement returns success regardless of whether a table with the same name exists, even if the original table structure is inconsistent with the target table structure. The metadata of the existing table with the same name is not changed. |
table_name | Yes | The name of the Hologres external table to be created in MaxCompute. |
col_name | Yes | The name of a column in the Hologres external table. |
data_type | Yes | The data type of a column in the Hologres external table. |
STORED BY | Yes | Specifies the StorageHandler, which defines how to query the Hologres external table. The value is fixed at |
ram_arn | Yes | This parameter is required when creating a Hologres external table in STS mode. It specifies the Alibaba Cloud Resource Name (ARN) of the RAM role, which is used for STS authentication when creating the external table. You can obtain the ARN in the Resource Access Management console by clicking the name of the target RAM role and viewing the Basic Information section. |
No | Do not specify this parameter when creating a Hologres external table in dual-signature mode. | |
LOCATION | Yes | The JDBC connection address of the Hologres instance. It includes:
|
tblproperties | Yes |
|
Create a Hologres external table (STS mode)
Follow these steps to create a Hologres external table in STS mode.
Create a RAM role
Create a RAM role to obtain its Amazon Resource Name (ARN). The ARN is used for STS authentication when you create the external table.
Log on to the Resource Access Management console. You can create a role as shown in the figure.

Select the trusted entity type for the RAM role as needed. You can choose either an Alibaba Cloud account or an identity provider.
Alibaba Cloud account:
A RAM user that belongs to an Alibaba Cloud account can assume a RAM role to access cloud resources. For more information, see Create a RAM role for a trusted Alibaba Cloud account.
Identity provider:
By setting up Single Sign-On (SSO), you can log on to the Alibaba Cloud Management Console from your corporate account system. This meets your enterprise's unified user logon authentication requirements. For more information, see Create a RAM role for a trusted identity provider.
Modify the trust policy.
On the Roles page, click the name of the RAM role that you created.
Click the Trust Policy tab.
On the Trust Policy tab, click Edit Trust Policy.
Modify the trust policy configuration.
The required modification to the trust policy depends on the selected trusted entity type.
Trusted entity is an Alibaba Cloud account:
{ "Statement": [ { "Action": "sts:AssumeRole", "Effect": "Allow", "Principal": { "RAM": [ "acs:ram::<UID>:root" ] } }, { "Action": "sts:AssumeRole", "Effect": "Allow", "Principal": { "Service": [ "<UID>@odps.aliyuncs.com" ] } } ], "Version": "1" }Trusted entity is an identity provider:
{ "Statement": [ { "Action": "sts:AssumeRole", "Condition": { "StringEquals": { "saml:recipient": "https://signin.aliyun.com/saml-role/sso" } }, "Effect": "Allow", "Principal": { "Federated": [ "acs:ram::<UID>:saml-provider/IDP" ] } }, { "Action": "sts:AssumeRole", "Effect": "Allow", "Principal": { "Service": [ "<UID>@odps.aliyuncs.com" ] } } ], "Version": "1" }Note<UID> specifies the Alibaba Cloud account ID. You can obtain the ID from the User Information page.
Click OK.
Configuring RAM role permissions in Hologres
The RAM role requires developer permissions for the Hologres instance to use Hologres within its authorized scope. By default, a RAM role does not have permissions to view or manage instances in the Hologres console. The Alibaba Cloud account must grant the required RAM permissions before the RAM role can perform subsequent operations. You can add the RAM role to the Hologres instance and grant permissions in one of the following ways:
Grant permissions in the Hologres console.
Log on to the Hologres console.
In the navigation pane on the left, click Instance List, and then click the name of the Hologres instance to which you want to grant permissions.
On the instance details page, click Account Management.
Follow the steps in the figure to add a RAM role to the Hologres instance. On the User Management page, click Add User.

Follow the steps shown in the figure. On the DB Authorization tab, grant the RAM role developer permissions for the instance.
NoteIf the database permission policy is set to Expert mode, you must change the role type to SuperUser on the User Management page. After this change, no further database authorization is required.

Grant permissions using SQL statements.
You can grant permissions using SQL statements. For more information about the authorization SQL, see Hologres permission model.
By default, a RAM user who assumes a RAM role does not have the required permissions to access the Hologres console. The Alibaba Cloud account must grant the AliyunRAMReadOnlyAccess permission to the RAM user on the Resource Access Management page. Without this permission, the RAM user cannot perform operations in the Hologres console. For more information, see Grant permissions to a RAM user.


Example
After you complete the preceding steps, you can log on to the MaxCompute client and create a Hologres external table based on the prepared data. For more information, see Create a Hologres external table.
Getting Started: Use the MaxCompute client to experience data analytics. Then, switch to your destination project.
For more information about the command that you can use to enter the destination project, see Project operations.
Execute the following command to create a Hologres external table.
The following is a sample SQL command:
CREATE EXTERNAL TABLE IF NOT EXISTS my_table_holo_jdbc ( id bigint, name string ) stored BY 'com.aliyun.odps.jdbc.JdbcStorageHandler' WITH serdeproperties ( 'odps.properties.rolearn'='acs:ram::139699392458****:role/aliyunodpsholorole') location 'jdbc:postgresql://hgprecn-cn-oew210ut****-cn-hangzhou-internal.hologres.aliyuncs.com:80/mc_test?ApplicationName=MaxCompute¤tSchema=public&useSSL=false&table=holo/' tblproperties ( 'mcfed.mapreduce.jdbc.driver.class'='org.postgresql.Driver', 'odps.federation.jdbc.target.db.type'='holo', 'odps.federation.jdbc.colmapping'='id:id,name:name' );Execute the following command to query data from the Hologres source table based on the newly created Hologres external table.
The SQL code is as follows:
-- Add the following properties to access the Hologres external table. SET odps.sql.split.hive.bridge=true; SET odps.sql.hive.compatible=true; SET odps.table.api.enable.holo.table=true; -- Enable the JDBC direct read mode. -- Query data from the Hologres external table. SELECT * FROM my_table_holo_jdbc limit 10;The following result is returned:
+------------+------------+ | id | name | +------------+------------+ | 1 | kate | | 2 | mary | | 3 | bob | | 4 | tom | | 5 | lulu | | 6 | mark | | 7 | haward | | 8 | lilei | | 9 | hanmeimei | | 10 | lily | +------------+------------+Optional: Perform data exchange and association analysis with Hologres based on the Hologres external table.
For example, you can use a Hologres external table to write data processed by MaxCompute into Hologres for accelerated analysis and online services. The following is a sample command.
-- Add the following properties to access the Hologres external table. SET odps.sql.split.hive.bridge=true; SET odps.sql.hive.compatible=true; SET odps.table.api.enable.holo.table=true; -- Enable the JDBC direct read mode. -- Insert data into the Hologres external table. INSERT INTO my_table_holo_jdbc VALUES (12,'alice'); -- Query data from the Hologres external table. SELECT * FROM my_table_holo_jdbc;The following result is returned.
+------------+------------+ | id | name | +------------+------------+ | 12 | alice | | 1 | kate | | 2 | mary | | 3 | bob | | 4 | tom | | 5 | lulu | | 6 | mark | | 7 | haward | | 8 | lilei | | 9 | hanmeimei | | 10 | lily | | 11 | lucy | +------------+------------+Frequently updated dimension tables are stored in Hologres to meet real-time dynamic update requirements. MaxCompute accesses the dimension tables through external tables to perform association analysis with fact tables in MaxCompute. The following is a sample command.
-- Add the following properties to access the Hologres external table. SET odps.sql.split.hive.bridge=true; SET odps.sql.hive.compatible=true; -- Create a MaxCompute internal table. CREATE TABLE holo_test AS SELECT * FROM my_table_holo_jdbc; -- Perform association analysis between the MaxCompute internal table and the Hologres external table. SELECT * FROM my_table_holo_jdbc t1 INNER JOIN holo_test t2 ON t1.id=t2.id;The following result is returned.
+------------+------------+------------+------------+ | id | name | id2 | name2 | +------------+------------+------------+------------+ | 1 | kate | 1 | kate | | 2 | mary | 2 | mary | | 3 | bob | 3 | bob | | 4 | tom | 4 | tom | | 5 | lulu | 5 | lulu | | 6 | mark | 6 | mark | | 7 | harward | 7 | harward | | 8 | lilei | 8 | lilei | | 9 | hanmeimei | 9 | hanmeimei | | 10 | lily | 10 | lily | | 11 | lucy | 11 | lucy | | 12 | alice | 12 | alice | +------------+------------+------------+------------+
Create a Hologres external table (dual-signature mode)
Dual-signature is an authentication and authorization protocol that is jointly developed by MaxCompute and Hologres. On the MaxCompute side, the logon information is signed, and the authentication data is passed to the Hologres side. Hologres then performs same-name authentication and authorization based on the protocol established with MaxCompute. Therefore, you only need to use the same account in both MaxCompute and Hologres to directly access external tables without additional authentication configuration.
An account with the same name as the MaxCompute account must exist in Hologres. This account must have read and write permissions on the corresponding table in Hologres.
Only Hologres V1.3 and later supports the creation of Hologres external tables in dual-signature mode in MaxCompute. Currently, dual-signature mode supports only reading data from Hologres external tables, not writing data to them.
Example
You can directly log on to the MaxCompute client and create a Hologres external table in dual-signature mode. For more information, see Create a Hologres external table.
The following is a sample SQL command:
-- Create the external table.
CREATE EXTERNAL TABLE IF NOT EXISTS holo_mc_external_dbl
(
id int,
name string,
ds string
)
STORED BY 'com.aliyun.odps.jdbc.JdbcStorageHandler'
location 'jdbc:postgresql://hgprecn-cn-zvp2o6aq****-cn-beijing-internal.hologres.aliyuncs.com:80/mc_test?ApplicationName=MaxCompute¤tSchema=public&preferQueryMode=simple&useSSL=false&table=mf_holo_mc_up/'
TBLPROPERTIES (
'mcfed.mapreduce.jdbc.driver.class'='org.postgresql.Driver',
'odps.federation.jdbc.target.db.type'='holo',
'odps.federation.jdbc.colmapping'='id:id,name:name,ds:ds'
);
-- Query the external table (must be executed together with the command to enable the dual-signature switch).
SET odps.sql.common.table.planner.ext.hive.bridge=true;
SELECT * FROM holo_mc_external_dbl;Enable the direct read feature for Hologres external tables
Background
MaxCompute reads Hologres external tables in JDBC mode. The current version supports direct reads from the Hologres storage layer by MaxCompute. This feature offers the following advantages:
Significantly reduces table read latency and improves data query speed.
Significantly reduces the number of connections to the Hologres frontend (FE). Most queries require only one connection.
Limits
The following limits apply when the Hologres direct read mode is enabled. If these limits are not met, the system falls back to JDBC mode.
This feature is supported only on Hologres V1.3.34 or later.
Earlier versions of Hologres do not support the direct read feature.
Due to network connectivity limitations, MaxCompute can access only Hologres instances that are in the same region.
Cross-region access is not supported. An attempt to access a Hologres instance in a different region results in the following error:
FAILED: ODPS-0010000:System internal error - fuxi job failed, caused by: Pangu request failed with error code 3.The direct read feature does not support Hologres cold storage tables.
The direct read feature does not support Hologres row-oriented tables.
If Hologres is configured with a master-slave architecture, you must configure the connection URL of the primary instance. The URL of the secondary instance is not supported.
The direct read feature validates the data types of columns between MaxCompute and Hologres. If a data type mismatch occurs, the feature automatically falls back to JDBC mode. The following data type restrictions apply when you create a Hologres external table in MaxCompute:
The following data types are not supported by either JDBC mode or the MaxCompute direct read mode:
Complex data types such as Array, Map, or Struct are not supported.
Data types such as JSON or MONEY are not supported.
The following data type is supported by JDBC mode but not by the MaxCompute direct read mode:
BINARY type.
The following data type is supported by the MaxCompute direct read mode but not by JDBC mode:
JSONB data type
When you use the Timestamp type in the MaxCompute direct read mode to map to the Timestamp With Time Zone type in Hologres, minor time discrepancies may occur. The specific differences are as follows:
If the time in a Timestamp With Time Zone column in Hologres is before
1900-12-31 15:54:15, the time retrieved in MaxCompute is 5 minutes and 44 seconds ahead.If the time in a Timestamp With Time Zone column in Hologres is between
1900-12-31 15:54:16and1969-12-31 23:59:58, the time retrieved in MaxCompute is 1 second ahead.If a Timestamp With Time Zone value in Hologres is after
1969-12-31 23:59:59, the value returned by a query in MaxCompute is identical.NoteWhen you use the Timestamp type in the MaxCompute direct read mode to map to the Timestamp With Time Zone type in Hologres, time zone offsets occur in addition to minor time discrepancies. For example:
If the MaxCompute time zone is UTC+8 and the time in a Timestamp With Time Zone column in Hologres is
2000-01-01 00:00:00, the time retrieved in MaxCompute is2000-01-01 08:00:00.If the MaxCompute time zone is UTC+8 and the time in a Timestamp With Time Zone column in Hologres is
1969-01-01 00:00:00, the time retrieved in MaxCompute is1969-01-01 08:00:01.
Other data type mappings are as follows:
Hologres data type
MaxCompute data type
Description
TEXT
STRING
VARCHAR
Not applicable
SMALLINT
SMALLINT
Not applicable
INT
INT4
INTEGER
INT
Not applicable
INT8
BIGINT
BIGINT
Not applicable
FLOAT4
REAL
FLOAT
Not applicable
FLOAT
FLOAT8
DOUBLE
Not applicable
BOOL
BOOLEAN
BOOLEAN
Not applicable
TIMESTAMP
TIMESTAMP_NTZ
Storage precision is in microseconds. Time zone discrepancies may exist.
TIMESTAMP WITH TIME ZONE
TIMESTAMP
MaxCompute and Hologres have already performed precision conversion at the underlying layer. MaxCompute output does not include the time zone format.
NUMERIC
DECIMAL
If precision is not specified for MaxCompute's DECIMAL, it defaults to
(38,18). When creating a table with theIMPORT FOREIGN SCHEMAstatement, the system automatically converts the precision.CHAR(n)
CHAR(n)
MaxCompute's
CHAR(n)is a fixed-length character type, wherenis the length. The maximum value is 255. If the length is insufficient, it is padded with spaces.VARCHAR(n)
VARCHAR(n)
MaxCompute's
VARCHAR(n)is a variable-length character type, wherenis the length. The value range is 1 to 65535.DATE
DATE
Not applicable
JSON
STRING
Supported in JDBC mode.
JSONB
JSON
Supported in direct read mode.
For Foreign Server mode, the MaxCompute project must have the three-layer model enabled.
Enable the feature
Add the following parameter before the SQL query when you query a Hologres external table in MaxCompute.
SET odps.table.api.enable.holo.table=true;Verify direct read
You can check the logs in Logview to determine whether the query used the direct read mode. For more information about how to use Logview, see Use Logview 2.0 to view job running information.
In Logview, on the Summary tab, find the external holo tables field to view its properties in the following format:
<project_name>.<table_name>:<access_mode>[<(fallback_reason)>]Parameter descriptions:
Parameter | Description |
project_name | The project name. |
table_name | The table name. |
access_mode | The access mode of the external table. The values are as follows:
|
fallback_reason | If the access_mode is
|
Hologres data import and export
FAQ
How do I resolve the ODPS-0130071 error when directly reading Hologres data through MaxCompute?
Symptom
When you directly read Hologres data, the following error is reported:
ODPS-0130071 Failed to split to equal size...max count: 7777. For example:ODPS-0130071:[0,0] Semantic analysis exception - physical plan generation failed: storage/table/src/input_splits_builder.cpp(195): StorageException: Failed to split to equal size, total size: 2143570729934, min size: 268435456, max size: 272629760, max count: 7777, split size: 275629513, split count: 7777Cause
When MaxCompute directly reads data from Hologres, the default Mapper splitting strategy (input data volume/split.size of 256 MB) causes the number of Mapper instances that are generated by the task to exceed the maximum limit of 7,777.
NoteThis limit is imposed to prevent users from submitting tasks that generate many Mapper instances, which could affect the stability of Hologres files or network connections.
Solution
You can resolve the error by setting the following parameters.
SET odps.external.holo.mapper.instances=10000; -- Increase the concurrency limit, up to a maximum of 10000. SET odps.sql.mapper.split.size=512; -- Adjust the task concurrency, up to a maximum of 512M
Why is an SQL job based on a Hologres external table running slowly, and how can I fix it?
Slow data search on a MaxCompute external table using an SDK.
Symptom
Searching for data in a MaxCompute external table using an SDK is slow.
Solution
External tables support only full table scans, which causes the slow query performance. We recommend that you use a MaxCompute internal table instead.
How do I resolve the error that occurs when a keyword is used as a column name in Hologres?
Symptom
When you use a keyword as a column name in Hologres, the following error is reported if you do not add a special configuration:
ODPS-0123131:User defined function exception - SQLException in nextKeyValueCaused by: org.postgresql.util.PSQLException: ERROR: syntax error at or near ","Solution
Add the
odps.federation.jdbc.colmappingparameter to map the fields of the Hologres source table to the fields of the Hologres external table.For example, if the Hologres source table contains the keyword field
"offset", you must add the parameter'odps.federation.jdbc.colmapping'='offset:"offset"'when you create the Hologres external table.
References
For more information about common issues with Hologres external tables, see Common issues with external tables.



