Manage MaxCompute metadata resources programmatically with the CatalogAPI SDK for Java and Python.
Product version: v0.2.2
SDK repository:aliyun/aliyun-odps-openapi-sdk
Overview
CatalogAPI SDK is an open SDK for managing the MaxCompute data catalog. It provides programmatic access to metadata resources such as Project, Schema, Table, Connection, Role, Taxonomy, DataPolicy, DataScan, and Model.
Features
Core capabilities:
Table management
Create and update internal and external tables, query and delete internal tables, external tables, views, materialized views, and snapshot tables.
Connection management
Manage Connection configurations for accessing external data sources such as OSS and OTS.
Permission management
Implement fine-grained access control through Role and Policy.
Data security
Implement column-level access control through Taxonomy and Policy Tag, and dynamic data masking through DataPolicy.
Metadata crawling
Automatically discover and crawl metadata from external data sources through DataScan.
Model management
Manage metadata for machine learning models with multi-version support.
Resource search
Search various metadata entities within a namespace.
Resource model
CatalogAPI follows a RESTful design style. The core resource hierarchy is as follows:
Namespace (primary account UID)
├── Connection # External data source connection
├── Role # Custom role
├── Taxonomy # Policy tag classification
│ └── PolicyTag # Policy tag
├── DataPolicy # Data policy (masking rules)
├── DataScan # Metadata crawling task
│ └── ScanJob # Crawling job
Project # MaxCompute project
└── Schema # Namespace (directory)
├── Table # Data table
│ └── Partition # Partition
└── Model # Machine learning modelNamespace ID is the Alibaba Cloud primary account UID.
Quick start
Install the SDK
CatalogAPI SDK is available in Java and Python, hosted on the Alibaba Cloud GitHub repository.
// Add dependency in Maven project
<dependency>
<groupId>com.aliyun.odps</groupId>
<artifactId>catalog-api</artifactId>
<version>0.2.2</version>
</dependency>pip install pyodps-catalogInitialize the client
Initialize the CatalogAPI client using an AccessKey pair.
Do not hard-code AccessKey pairs in your code. Use environment variables or configuration files to manage credentials.
import com.aliyun.odps.catalog.Client;
import com.aliyun.odps.models.Config;
public class CatalogDemo {
public static void main(String[] args) throws Exception {
// Initialize configuration
Config config = new Config();
config.setAccessKeyId(System.getenv("ALIBABACLOUD_ACCESS_KEY_ID"));
config.setAccessKeySecret(System.getenv("ALIBABACLOUD_ACCESS_KEY_SECRET"));
// Set the MaxCompute endpoint. The SDK automatically discovers the CatalogAPI endpoint through the routing API.
// Replace cn-shanghai with your actual region.
config.setOdpsEndpoint("service.cn-shanghai.maxcompute.aliyun.com");
// Create client
Client client = new Client(config);
// Use client to call APIs
}
}import os
from pyodps_catalog.client import Client
from maxcompute_tea_openapi.models import Config
# Initialize configuration
config = Config(
access_key_id=os.environ.get('ALIBABACLOUD_ACCESS_KEY_ID'),
access_key_secret=os.environ.get('ALIBABACLOUD_ACCESS_KEY_SECRET'),
# Method 1 (recommended): Set odps_endpoint. The SDK automatically discovers the CatalogAPI endpoint through the routing API.
odps_endpoint='service.cn-shanghai.maxcompute.aliyun.com'
# Method 2: Directly specify the CatalogAPI endpoint.
# endpoint='catalogapi.cn-shanghai.maxcompute.aliyun.com'
)
# Create client
client = Client(config)
# Use client to call APIsExample: List tables
This example lists all tables in a specified schema:
import com.aliyun.odps.catalog.models.ListTablesResponse;
import com.aliyun.odps.catalog.models.Table;
ListTablesResponse response = client.listTables(
"my_project", // projectId
"default", // schemaName
100, // pageSize
"" // pageToken. Pass empty string for the first call
);
if (response.getTables() != null) {
for (Table table : response.getTables()) {
System.out.println("Table: " + table.getTableName());
}
}
// If more pages exist, use nextPageToken to continue
String nextToken = response.getNextPageToken();response = client.list_tables(
project_id="my_project",
schema_name="default",
page_size=100,
page_token=""
)
if response.tables:
for table in response.tables:
print(f"Table: {table.table_name}")
# If more pages exist, use next_page_token to continue
next_token = response.next_page_tokenAuthentication
Access credentials
CatalogAPI requires an Alibaba Cloud AccessKey pair for authentication. We recommend using a RAM user AccessKey pair and following the least privilege principle.
Permission list
The following table lists the required permissions for each API operation:
Policy and Role
CatalogAPI supports Policy-based access control. A Policy consists of a set of Bindings, where each Binding assigns a Role to a set of Members.
Policy model
{ "etag": "string", "bindings": [ { "role": "string", "members": ["string"] } ] }etag: used for read-modify-write consistency validation
bindings: list of role bindings
role: role name
members: list of members in the format user:{userId}
Set Policy example
import com.aliyun.odps.catalog.models.*; // Construct SetPolicyRequest Policy policy = new Policy(); Binding binding = new Binding(); // The role field requires the full resource path format: namespaces/{namespaceId}/roles/{roleName} binding.setRole("namespaces/{namespaceId}/roles/odps.admin"); binding.setMembers(Arrays.asList("user:123456789")); policy.setBindings(Arrays.asList(binding)); policy.setEtag("fetch_with_get_policy"); SetPolicyRequest request = new SetPolicyRequest(); request.setPolicy(policy); // Set table Policy client.setTablePolicy(table, request);
Data models
Common fields
Field | Type | Description |
name | string | REST resource full name, globally unique within the domain. The SDK uses the resource name to construct REST request URLs. Typically an output-only field. |
Data types
In addition to standard JSON types, the following special data type markers are used:
Data types | Description |
enum | Semantic enumeration type, represented as a string in JSON format |
int64 | 64-bit integer, transmitted as a string |
Table model
Table is one of the core resources in CatalogAPI.
{
"etag": "string",
"name": "string",
"projectId": "string",
"schemaName": "string",
"tableName": "string",
"type": "enum(TableType)",
"description": "string",
"tableSchema": { "object(TableFieldSchema)" },
"clustering": { "object(Clustering)" },
"tableConstraints": { "object(TableConstraints)" },
"partitionDefinition": { "object(PartitionDefinition)" },
"tableFormatDefinition": { "object(TableFormatDefinition)" },
"externalDataConfiguration": { "object(ExternalDataConfiguration)" },
"maxLakeConfiguration": { "object(MaxLakeConfiguration)" },
"externalCatalogTableOptions": { "object(ExternalCatalogTableOptions)" },
"expirationOptions": { "object(ExpirationOptions)" },
"createTime": "string (int64 format)",
"lastModifiedTime": "string (int64 format)",
"labels": { "map<string, string>" }
}TableFieldSchema model
Supported data types (FieldDataType):TINYINT,SMALLINT,INT,BIGINT,BINARY,FLOAT,DOUBLE,DECIMAL,VARCHAR,CHAR,STRING,DATE,DATETIME,TIMESTAMP,TIMESTAMP_NTZ,BOOLEAN,STRUCT,ARRAY,MAP
{
"fieldName": "string",
"sqlTypeDefinition": "string",
"typeCategory": "enum(FieldDataType)",
"mode": "enum(FieldMode)",
"fields": [{ "object(TableFieldSchema)" }],
"description": "string",
"policyTags": { "object(PolicyTags)" },
"maxLength": "string (int64 format)",
"precision": "string (int64 format)",
"scale": "string (int64 format)",
"defaultValueExpression": "string"
}Connection model
Connection is used to configure connection information for accessing external data sources such as OSS and OTS.
{
"name": "string",
"connectionName": "string",
"description": "string",
"creationTime": "string (int64 format)",
"lastModifiedTime": "string (int64 format)",
"connectionType": "enum(ConnectionType)",
"cloudResource": { "object(CloudResourceOptions)" },
"region": "string"
}Role model
Role is used to define custom roles.
{
"name": "string",
"roleName": "string",
"description": "string",
"includedPermissions": ["string"],
"etag": "string",
"deleted": false
}Taxonomy model
Taxonomy is used to manage the classification system of policy tags (Policy Tag).
{
"name": "string",
"taxonomyName": "string",
"description": "string",
"activatedPolicyTypes": ["enum(PolicyType)"],
"policyTagCount": 0,
"createTime": "string (int64 format)",
"lastModifiedTime": "string (int64 format)"
}PolicyTag model
PolicyTag is a policy tag attached to a Taxonomy, used to implement column-level access control.
{
"name": "string",
"policyTagName": "string",
"description": "string",
"parentPolicyTag": "string",
"childPolicyTags": ["string"]
}DataPolicy model
DataPolicy is used to define data masking rules.
{
"name": "string",
"dataPolicyName": "string",
"policyTag": "string",
"dataPolicyType": "enum(DataPolicyType)",
"dataMaskingPolicy": { "object(DataMaskingPolicy)" }
}DataScan model
DataScan is used to configure metadata crawling tasks.
{
"name": "string",
"scanName": "string",
"type": "string",
"creator": "string",
"customerId": "string",
"namespaceId": "string",
"description": "string",
"scanId": "string",
"creationTime": 0,
"lastModifiedTime": 0,
"lastTriggeredTime": 0,
"lastSuccessfulScheduleTime": 0,
"lastTriggeredBy": "string",
"schedulingStatus": "string",
"source": { "object(DataScanSource)" },
"target": { "object(DataScanTarget)" },
"properties": { "object(DataScanProperties)" },
"schedulerMode": "string",
"schedulerInterval": "string",
"scheduledCount": 0
}Model
Model is used to manage metadata for machine learning models.
{
"name": "string",
"modelName": "string",
"versionName": "string",
"defaultVersion": "string",
"createTime": "string",
"updateTime": "string",
"versionCreateTime": "string",
"versionUpdateTime": "string",
"description": "string",
"versionDescription": "string",
"expirationDays": 0,
"versionExpirationDays": 0,
"sourceType": "string",
"modelType": "string",
"labels": { "map<string, string>" },
"transform": { "map<string, string>" },
"path": "string",
"options": { "map<string, string>" },
"extraInfo": { "map<string, string>" },
"versionExtraInfo": { "map<string, string>" },
"trainingInfo": { "map<string, string>" },
"inferenceParameters": { "map<string, string>" },
"featureColumns": { "object(ModelFieldSchema)" },
"tasks": ["string"]
}Schema model
{
"name": "string",
"schemaName": "string",
"description": "string",
"type": "enum(SchemaType)",
"owner": "string",
"externalSchemaConfiguration": { "object(ExternalSchemaConfiguration)" }
}Project model
{
"name": "string",
"projectId": "string",
"owner": "string",
"description": "string",
"createTime": "string (int64 format)",
"lastModifiedTime": "string (int64 format)",
"schemaEnabled": "boolean",
"region": "string"
}Partition model
{
"spec": "string"
}Field | Type | Description |
spec | string | Partition spec. Example format: bu=tt/ds=20250515 |
Search model
{
"name": "string",
"displayName": "string",
"type": "string",
"aspects": { "map<string, string>" },
"createTime": "string",
"lastModifiedTime": "string",
"description": "string"
}API reference
General notes
URL prefix: All API URLs in this document use the following prefix:/api/catalog/v1alpha/.
This prefix is not repeated in individual API descriptions.
Error handling
HTTP status code | Reason | Description |
400 | InvalidArgument | Invalid request input |
403 | AccessDenied | No permission to perform this operation |
404 | NotFound | The object to be operated on does not exist |
409 | AlreadyExists | The object to be created already exists |
429 | RateLimitExceeded | Request rate too high. Rate limiting triggered |
500 | InternalError | Internal server error |
Table API
Create table
Create a new table.
Method signature
Table createTable(Table table)Request parameters
Parameter
Type
Required
Description
table
Table
Yes
Table object, containing the full table definition
Response
Returns the created Table object.
Usage example
// Construct table Table table = new Table(); table.setProjectId("my_project"); table.setSchemaName("default"); table.setTableName("my_table"); table.setDescription("This is an example table"); table.setType("TABLE"); // Set table schema TableFieldSchema field = new TableFieldSchema(); field.setFieldName("id"); field.setTypeCategory("BIGINT"); field.setMode("REQUIRED"); TableFieldSchema nameField = new TableFieldSchema(); nameField.setFieldName("name"); nameField.setTypeCategory("STRING"); nameField.setMode("NULLABLE"); TableFieldSchema schema = new TableFieldSchema(); schema.setFields(Arrays.asList(field, nameField)); table.setTableSchema(schema); // Create table Table createdTable = client.createTable(table); System.out.println("Created table: " + createdTable.getName());
Get table
Get detailed information about a specified table.
Method signature
Table getTable(Table table)Request parameters
Parameter
Type
Required
Description
table
Table
Yes
Table object containing projectId, schemaName, and tableName
Response
Returns a Table object.
Usage example
Table query = new Table(); query.setProjectId("my_project"); query.setSchemaName("default"); query.setTableName("my_table"); Table result = client.getTable(query); System.out.println("Table type: " + result.getType()); System.out.println("Description: " + result.getDescription());
Update table
Update the attributes of a specified table.
Method signature
Table updateTable(Table table)Request parameters
Parameter
Type
Required
Description
table
Table
Yes
Table object containing the updates
Response
Returns the updated Table object.
Usage example
Table table = client.getTable(query); table.setDescription("Updated description"); Table updated = client.updateTable(table);
Delete table
Delete a specified table.
Method signature
HttpResponse deleteTable(Table table)Request parameters
Parameter
Type
Required
Description
table
Table
Yes
Table object containing projectId, schemaName, and tableName
Response
Returns an empty HttpResponse on success.
Usage example
HttpResponse response = client.deleteTable(table); System.out.println("Status code: " + response.getStatusCode());
List tables
List all tables in a specified schema.
Method signature
ListTablesResponse listTables(String projectId, String schemaName, Integer pageSize, String pageToken)Request parameters
Parameter
Type
Required
Description
projectId
string
Yes
Project ID
schemaName
string
Yes
Schema name
pageSize
integer
No
Page size. Defaults to 100, maximum 1000
pageToken
string
No
Page token. Defaults to empty
Response
{ "tables": [Table], "nextPageToken": "string" }Usage example
ListTablesResponse response = client.listTables("my_project", "default", 100, ""); // Iterate through all pages while (response.getTables() != null && !response.getTables().isEmpty()) { for (Table t : response.getTables()) { System.out.println(t.getTableName()); } if (response.getNextPageToken() == null || response.getNextPageToken().isEmpty()) { break; } response = client.listTables("my_project", "default", 100, response.getNextPageToken()); }
Set table Policy
Set the access policy of a table.
Method signature
Policy setTablePolicy(Table table, SetPolicyRequest request)Request parameters
Parameter
Type
Required
Description
table
Table
Yes
Table object
request
SetPolicyRequest
Yes
Policy request
Response
Returns the updated Policy object.
Get table Policy
Get the access policy of a table.
Method signature
Policy getTablePolicy(Table table)Request parameters
Parameter
Type
Required
Description
table
Table
Yes
Table object
Response
Returns the Policy object of the table.
Get table DataToken
Get a temporary access token for a specified table.
Method signature
DataToken getDataToken(Table table, Integer duration)Request parameters
Parameter
Type
Required
Description
table
Table
Yes
Table object
duration
integer
No
Token validity period (seconds)
Response
{ "version": "string", "type": "string", "value": "string", "expiration": "string" }DataToken field description
Field
Type
Description
version
string
Format version. Currently V1
type
string
Type. Currently only STS is supported
value
string
Token content, base64-encoded
expiration
string
Expiration time
Partition API
List partitions
List all partitions of a specified table.
Method signature
ListPartitionsResponse listPartitions( String projectId, String schemaName, String tableName, Integer pageSize, String pageToken, String query, String view )Request parameters
Parameter
Type
Required
Description
projectId
string
Yes
Project ID
schemaName
string
Yes
Schema name
tableName
string
Yes
Table name
pageSize
integer
No
Page size. Defaults to 100, maximum 1000
pageToken
string
No
Page token. Defaults to empty
query
string
No
Partition search condition, for example, partition_name:part
view
string
No
Currently, only BASIC is supported
Response
{ "partitions": [Partition], "nextPageToken": "string" }
Connection API
Create connection
Create a new external data source connection.
Method signature
Connection createConnection(String namespace, Connection connection)Request parameters
Parameter
Type
Required
Description
namespace
string
Yes
Namespace ID (primary account UID)
connection
Connection
Yes
Connection object
Response
Returns the created Connection object.
Usage example
// Construct Connection Connection conn = new Connection(); conn.setConnectionName("my_oss_connection"); conn.setDescription("Connection for accessing OSS"); conn.setConnectionType("CLOUD_RESOURCE"); CloudResourceOptions options = new CloudResourceOptions(); options.setRamRoleArn("acs:ram::123456789:role/MaxComputeOSSRole"); conn.setCloudResource(options); // Create connection Connection created = client.createConnection("123456789", conn);
List connections
List all connections in a specified namespace.
Method signature
ListConnectionsResponse listConnections(String namespace, Integer pageSize, String pageToken)Request parameters
Parameter
Type
Required
Description
namespace
string
Yes
Namespace ID
pageSize
integer
No
Page size. Defaults to 100, maximum 1000
pageToken
string
No
Page token. Defaults to empty
Response
{ "connections": [Connection], "nextPageToken": "string" }
Get connection
Get detailed information about a specified connection.
Method signature
Connection getConnection(String namespace, String connectionName)
Update connection
Update the attributes of a specified connection.
Method signature
Connection updateConnection(String namespace, String connectionName, Connection connection, String updateMask)Request parameters
Parameter
Type
Required
Description
namespace
string
Yes
Namespace ID
connectionName
string
Yes
Connection name
connection
Connection
Yes
Connection object containing the updates
updateMask
string
Yes
Specify the fields to update. Currently, only the description field is supported
Response
Returns the updated Connection object.
Usage example
Connection conn = new Connection(); conn.setConnectionName("my_oss_connection"); conn.setDescription("Updated description"); Connection updated = client.updateConnection("123456789", "my_oss_connection", conn, "description");
Delete connection
Delete a specified connection.
Method signature
HttpResponse deleteConnection(String namespace, String connectionName)
Set connection Policy
Set the access policy of a connection.
Method signature
Policy setConnectionPolicy(String namespace, String connectionName, SetPolicyRequest request)
Get connection Policy
Get the access policy of a connection.
Method signature
Policy getConnectionPolicy(String namespace, String connectionName)
Role API
Create role
Create a custom Role.
Method signature
Role createRole(String namespace, Role role)Request parameters
Parameter
Type
Required
Description
namespace
string
Yes
Namespace ID
role
Role
Yes
Role object
Response
Returns the created Role object.
Usage example
Role role = new Role(); role.setRoleName("my_custom_role"); role.setDescription("Custom role"); role.setIncludedPermissions(Arrays.asList("odps:CreateTable", "odps:ListTable")); Role created = client.createRole("123456789", role);
List roles
List all roles in a specified namespace.
Method signature
ListRolesResponse listRoles( String namespace, Integer pageSize, String pageToken, String view, Boolean showDeleted )Request parameters
Parameter
Type
Required
Description
namespace
string
Yes
Namespace ID
pageSize
integer
No
Page size. Defaults to 100, maximum 1000
pageToken
string
No
Page token. Defaults to empty
view
enum(RoleView)
No
Defaults to BASIC. When set to FULL, all fields are returned
showDeleted
boolean
No
Whether to include deleted roles. Defaults to false
Response
{ "roles": [Role], "nextPageToken": "string" }
Get role
Get detailed information about a specified role.
Method signature
Role getRole(String namespace, String roleName)Request parameters
Parameter
Type
Required
Description
namespace
string
Yes
Namespace ID
roleName
string
Yes
Role name
Update role
Update the attributes of a specified role.
Method signature
Role updateRole(String namespace, String roleName, Role role, String updateMask)Request parameters
Parameter
Type
Required
Description
namespace
string
Yes
Namespace ID
roleName
string
Yes
Role name
role
Role
Yes
Role object containing the updates
updateMask
string
Yes
Specify the fields to update, such as
"description, includedPermissions"
Delete role
Delete a specified custom role.
Method signature
HttpResponse deleteRole(String namespace, String roleName)
After a role is deleted, the following changes take effect immediately:
The role can no longer be bound to a Policy.
Policies already bound to this role remain in a bound state, but have no effect.
The List roles operation does not list deleted roles by default. After a role is deleted, it still counts toward the total limit and remains in a deleted state for seven days. After seven days, the role is permanently deleted, all resource bindings with this role are removed, and it no longer counts toward the total limit.
Set role Policy
Set the access policy of a role.
Method signature
Policy setRolePolicy(String namespace, String roleName, SetPolicyRequest request)
Get role Policy
Get the access policy of a role.
Method signature
Policy getRolePolicy(String namespace, String roleName)
Taxonomy API
Create Taxonomy
Create a new policy tag classification.
Method signature
Taxonomy createTaxonomy(String namespace, Taxonomy taxonomy)Request parameters
Parameter
Type
Required
Description
namespace
string
Yes
Namespace ID
taxonomy
Taxonomy
Yes
Taxonomy object
Response
Returns the created Taxonomy object.
Usage example
Taxonomy taxonomy = new Taxonomy(); taxonomy.setTaxonomyName("sensitive_data"); taxonomy.setDescription("Sensitive data classification"); taxonomy.setActivatedPolicyTypes(Arrays.asList("FINE_GRAINED_ACCESS_CONTROL")); Taxonomy created = client.createTaxonomy("123456789", taxonomy);
List Taxonomy
List all Taxonomies in a specified namespace.
Method signature
ListTaxonomiesResponse listTaxonomies(String namespace, Integer pageSize, String pageToken)
Get Taxonomy
Get detailed information about a specified Taxonomy.
Method signature
Taxonomy getTaxonomy(String namespace, String taxonomyId)
Update Taxonomy
Update the attributes of a specified Taxonomy.
Method signature
Taxonomy updateTaxonomy(String namespace, String taxonomyId, Taxonomy taxonomy, String updateMask)Request parameters
Parameter
Type
Required
Description
namespace
string
Yes
Namespace ID
taxonomyId
string
Yes
Taxonomy ID
taxonomy
Taxonomy
Yes
Taxonomy object containing the updates
updateMask
string
Yes
Specify the fields to update, such as
"description, activatedPolicyTypes"
Delete Taxonomy
Cascade-deletes all policy tags, configured data policies, and column binding relationships under the taxonomy.
Method signature
HttpResponse deleteTaxonomy(String namespace, String taxonomyId)
Set Taxonomy Policy
Set the access policy of a Taxonomy.
Method signature
Policy setTaxonomyPolicy(String namespace, String taxonomyId, SetPolicyRequest request)
Get Taxonomy Policy
Get the access policy of a Taxonomy.
Method signature
Policy getTaxonomyPolicy(String namespace, String taxonomyId)
PolicyTag API
Create PolicyTag
Create a new policy tag under a specified Taxonomy.
Method signature
PolicyTag createPolicyTag(String namespace, String taxonomyId, PolicyTag policyTag)Request parameters
Parameter
Type
Required
Description
namespace
string
Yes
Namespace ID
taxonomyId
string
Yes
Taxonomy ID
policyTag
PolicyTag
Yes
PolicyTag object
Response
Returns the created PolicyTag object.
Usage example
PolicyTag tag = new PolicyTag(); tag.setPolicyTagName("phone_number"); tag.setDescription("Phone number masking tag"); PolicyTag created = client.createPolicyTag("123456789", "taxonomy_id_123", tag);
List PolicyTag
List all PolicyTags under a specified Taxonomy.
Method signature
ListPolicyTagsResponse listPolicyTags( String namespace, String taxonomyId, Integer pageSize, String pageToken )
Get PolicyTag
Get detailed information about a specified PolicyTag.
Method signature
PolicyTag getPolicyTag(String namespace, String taxonomyId, String policyTagId)
Update PolicyTag
Update the attributes of a specified PolicyTag.
Method signature
PolicyTag updatePolicyTag( String namespace, String taxonomyId, String policyTagId, PolicyTag policyTag, String updateMask )Request parameters
Parameter
Type
Required
Description
namespace
string
Yes
Namespace ID
taxonomyId
string
Yes
Taxonomy ID
policyTagId
string
Yes
PolicyTag ID
policyTag
PolicyTag
Yes
PolicyTag object containing the updates
updateMask
string
Yes
Specify the fields to update. Currently, only the description field is supported
Delete PolicyTag
Delete a policy tag and recursively delete: all child nodes of the policy tag, all data policies configured on the policy tag (including child nodes), and column binding relationships of the policy tag on tables (including child nodes).
Method signature
HttpResponse deletePolicyTag(String namespace, String taxonomyId, String policyTagId)
Set PolicyTag Policy
Set the access policy of a PolicyTag.
Method signature
Policy setPolicyTagPolicy(String namespace, String taxonomyId, String policyTagId, SetPolicyRequest request)
Get PolicyTag Policy
Get the access policy of a PolicyTag.
Method signature
Policy getPolicyTagPolicy(String namespace, String taxonomyId, String policyTagId)
DataPolicy API
Create DataPolicy
Create a new data policy (masking rule).
Method signature
DataPolicy createDataPolicy(String namespace, DataPolicy dataPolicy)Request parameters
Parameter
Type
Required
Description
namespace
string
Yes
Namespace ID
dataPolicy
DataPolicy
Yes
DataPolicy object
Response
Returns the created DataPolicy object.
Usage example
// Construct masking rule DataMaskingPolicy maskingPolicy = new DataMaskingPolicy(); maskingPolicy.setPredefinedExpression("STRING_MASKED_BA"); DataPolicy policy = new DataPolicy(); policy.setDataPolicyName("phone_masking"); policy.setPolicyTag("namespaces/123456789/taxonomies/tid_123/policyTags/ptid_456"); policy.setDataPolicyType("DATA_MASKING_POLICY"); policy.setDataMaskingPolicy(maskingPolicy); DataPolicy created = client.createDataPolicy("123456789", policy);
List DataPolicy
List all DataPolicies in a specified namespace.
Method signature
ListDataPoliciesResponse listDataPolicies(String namespace, Integer pageSize, String pageToken)
Get DataPolicy
Get detailed information about a specified DataPolicy.
Method signature
DataPolicy getDataPolicy(String namespace, String dataPolicyName)
Delete DataPolicy
Delete a specified DataPolicy.
Method signature
HttpResponse deleteDataPolicy(String namespace, String dataPolicyName)
Set DataPolicy Policy
Set the access policy of a DataPolicy.
Method signature
Policy setDataPolicyPolicy(String namespace, String dataPolicyName, SetPolicyRequest request)
Get DataPolicy Policy
Get the access policy of a DataPolicy.
Method signature
Policy getDataPolicyPolicy(String namespace, String dataPolicyName)
DataScan API
Create DataScan
Create a new metadata crawling task.
Method signature
DataScan createDataScan(String namespace, DataScan dataScan)Request parameters
Parameter
Type
Required
Description
namespace
string
Yes
Namespace ID
dataScan
DataScan
Yes
DataScan object
Response
Returns the created DataScan object.
Usage example
// Construct crawling task DataScanSource source = new DataScanSource(); source.setLocation("oss://my-bucket/my-path/"); source.setConnection("my_oss_connection"); DataScanTarget target = new DataScanTarget(); target.setProject("my_project"); target.setSchema("default"); target.setNamePrefix("auto_"); DataScanProperties properties = new DataScanProperties(); properties.setFormatFilter("AUTO"); properties.setScanMode("SAMPLE"); properties.setAutoCommit(true); DataScan dataScan = new DataScan(); dataScan.setScanName("my_oss_scan"); dataScan.setType("TABLE_DISCOVERY"); dataScan.setDescription("Crawl OSS metadata"); dataScan.setSource(source); dataScan.setTarget(target); dataScan.setProperties(properties); dataScan.setSchedulerMode("MANUAL"); DataScan created = client.createDataScan("123456789", dataScan);
List DataScan
List all DataScans in a specified namespace.
Method signature
ListDataScansResponse listDataScans(String namespace, Integer pageSize, String pageToken)
Get DataScan
Get detailed information about a specified DataScan.
Method signature
DataScan getDataScan(String namespace, String dataScanName)
Update DataScan
Update the attributes of a specified DataScan.
Method signature
DataScan updateDataScan(String namespace, DataScan dataScan, String updateMask)
Delete DataScan
Delete a specified DataScan.
Method signature
HttpResponse deleteDataScan(String namespace, String dataScanName)
Trigger DataScan
Manually trigger a DataScan crawling task.
Method signature
HttpResponse triggerDataScan(String namespace, String dataScanName)Usage example
HttpResponse response = client.triggerDataScan("123456789", "my_oss_scan"); System.out.println("Triggered: " + response.getStatusCode());
List DataScan jobs
List the crawling job history of a specified DataScan.
Method signature
ListDataScanJobsResponse listDataScanJobs( String namespace, String dataScanName, Integer pageSize, String pageToken )Response
{ "scanJobs": [ScanJob], "nextPageToken": "string" }ScanJob model
Field
Type
Description
jobId
string
Job ID
namespaceId
string
Namespace to which the job belongs
dataScanId
string
System-generated dataScan ID
dataScanName
string
Name of the parent crawling task
triggeredBy
string
Person who triggered this crawling job. scheduler for scheduled triggers
startTime
int64
Crawling job start time, UTC timestamp
endTime
int64
Crawling job end time, UTC timestamp
status
string
Crawling job status: Created/Running/Terminated/Failed
statusDetail
string
Crawling job status details, such as error messages
ddl
string
DDL information returned by the crawling job that needs to be committed
stats
string
Stats information returned by the crawling job in JSON format
Model API
Create model
Create a new machine learning model.
Method signature
Model createModel(String projectId, String schemaName, Model model)Request parameters
Parameter
Type
Required
Description
projectId
string
Yes
Project ID
schemaName
string
Yes
Schema name
model
Model
Yes
Model object
Response
Returns the created Model object.
Usage example
Model model = new Model(); model.setModelName("my_llm_model"); model.setVersionName("v1"); model.setDefaultVersion("v1"); model.setDescription("My large language model"); model.setSourceType("IMPORT"); model.setModelType("LLM"); model.setPath("oss://my-bucket/models/my_llm/"); model.setTasks(Arrays.asList("text-generation", "chat")); Model created = client.createModel("my_project", "default", model);
List models
List all models in a specified schema.
Method signature
ListModelsResponse listModels( String projectId, String schemaName, Integer pageSize, String pageToken )
Get model
Get detailed information about a specified model.
Method signature
Model getModel(String projectId, String schemaName, String modelName, String versionName)Request parameters
Parameter
Type
Required
Description
projectId
string
Yes
Project ID
schemaName
string
Yes
Schema name
modelName
string
Yes
Model name
versionName
string
No
Version name. If not specified, the model metadata (without version) is queried
Update model
Update the attributes of a specified model.
Method signature
Model updateModel( String projectId, String schemaName, String modelName, Model model, String updateMask, String versionName )
Delete model
Delete a specified model (including all versions).
Method signature
HttpResponse deleteModel(String projectId, String schemaName, String modelName)
Create model version
Create a new version for a specified model.
Method signature
Model createModelVersion(String projectId, String schemaName, String modelName, Model model)Usage example
Model version = new Model(); version.setModelName("my_llm_model"); version.setVersionName("v2"); version.setVersionDescription("Updated model version"); version.setPath("oss://my-bucket/models/my_llm_v2/"); version.setTasks(Arrays.asList("text-generation", "chat")); Model createdVersion = client.createModelVersion("my_project", "default", "my_llm_model", version);
Delete model version
Delete a specified model version.
Method signature
HttpResponse deleteModelVersion( String projectId, String schemaName, String modelName, String versionName )
List model versions
List all versions of a specified model.
Method signature
ListModelVersionsResponse listModelVersions( String projectId, String schemaName, String modelName, Integer pageSize, String pageToken )
Set model Policy
Set the access policy of a model.
Method signature
Policy setModelPolicy(String projectId, String schemaName, String modelName, SetPolicyRequest request)
Get model Policy
Get the access policy of a model.
Method signature
Policy getModelPolicy(String projectId, String schemaName, String modelName)
Project API
Get Project
Get detailed information about a specified Project.
Method signature
Project getProject(String projectId)Usage example
Project project = client.getProject("my_project"); System.out.println("Project owner: " + project.getOwner()); System.out.println("Schema enabled: " + project.getSchemaEnabled()); System.out.println("Region: " + project.getRegion());
Schema API
Create Schema
Create a new Schema in a specified Project.
Method signature
Schema createSchema(String projectId, Schema schema)Request parameters
Parameter
Type
Required
Description
projectId
string
Yes
Project ID
schema
Schema
Yes
Schema object
Response
Returns the created Schema object.
Usage example
Schema schema = new Schema(); schema.setSchemaName("my_schema"); schema.setDescription("My custom schema"); Schema created = client.createSchema("my_project", schema);
List Schema
List all Schemas in a specified Project.
Method signature
ListSchemasResponse listSchemas(String projectId, Integer pageSize, String pageToken)
Get Schema
Get detailed information about a specified Schema.
Method signature
Schema getSchema(String projectId, String schemaName)
Update Schema
Update the attributes of a specified Schema.
Method signature
Schema updateSchema(String projectId, String schemaName, String updateMask, Schema schema)Request parameters
Parameter
Type
Required
Description
projectId
string
Yes
Project ID
schemaName
string
Yes
Schema name
updateMask
string
Yes
Specify the fields to update. Currently, only the description and owner fields are supported, and only one field can be updated at a time
schema
Schema
Yes
Schema object containing the updates
Delete Schema
Delete a specified Schema.
Method signature
HttpResponse deleteSchema(String projectId, String schemaName)
Set Schema Policy
Set the access policy of a Schema.
Method signature
Policy setSchemaPolicy(String projectId, String schemaName, SetPolicyRequest request)
Get Schema Policy
Get the access policy of a Schema.
Method signature
Policy getSchemaPolicy(String projectId, String schemaName)
Search API
Search entities
Search various entities within a specified namespace.
Method signature
SearchResponse search( String namespaceId, String query, Integer pageSize, String pageToken, String orderBy )Request parameters
Parameter
Type
Required
Description
namespaceId
string
Yes
Primary account ID. Search is performed within the scope of this primary account
query
string
Yes
Search query string composed of one or more query conditions separated by commas
pageSize
integer
No
Number of results per page. Must be > 0, maximum 100
pageToken
string
No
Page token
orderBy
string
No
Result sort order
Query syntax
List of query conditions:
Query condition
Description
name:foo
Match foo as a substring against the entity name
description:bar
Match bar as a substring against the entity description
type=TABLE
Required. Match entities of a specific type. Currently supports TABLE, RESOURCE, SCHEMA
project=proj
Search entities under a single specified project only. The caller must have SearchProject permission for the project
project=(proj1|proj2|proj3)
Search entities across multiple projects (up to 512). The caller must have SearchProject permission for all specified projects
region=region_id
Search entities under projects in a specified region
project=proj and project=(proj1|proj2|proj3) cannot be used together
region=region_id cannot be used together with the project query condition
Sort order (orderBy)
Valid values
Description
default
Internal storage order (default)
create_time asc
Creation time ascending
create_time desc
Creation time descending
last_modified_time asc
Last modification time ascending
last_modified_time desc
Last modification time descending
Response
{ "entries": [SearchResultEntry], "nextPageToken": "string" }Usage example
// Search all tables in a specified project SearchResponse response = client.search( "123456789", // namespaceId "type=TABLE,project=my_project", // query 50, // pageSize "", // pageToken "last_modified_time desc" // orderBy ); if (response.getEntries() != null) { for (SearchResultEntry entry : response.getEntries()) { System.out.println("Name: " + entry.getDisplayName()); System.out.println("Type: " + entry.getType()); System.out.println("Path: " + entry.getName()); } }
Usage limits
Rate limits
Rate limits are enforced at the primary account level. Each method has its own rate limit, which varies by request category.
Limit | Value |
Get and GetPolicy methods | 1500 requests / 15 seconds |
List, Create, Update, Delete, and SetPolicy methods | 150 requests / 15 seconds |
GetProject, ListTables, ListPartitions view=StorageDetail/FULL | 15 requests / 15 seconds |
Capacity limits
Limit | Value |
Number of custom roles per primary account | 300 |
Number of permissions per Role | 3000 |
Number of principals per Allow Policy | 1500 |
Total size of a single custom Role (including description, roleName, etc.) | 64KB |
Policy Tag limits
Limit | Value |
Number of Policy Tags bound to a single column in a single table | 1 |
Number of Taxonomies per account | 40 |
Number of Policy Tags per Taxonomy | 100 |
Depth of a Policy Tag Tree | 5 |
Number of Data Policies per Tag | 8 |
Pagination limits
Parameter | Default value | Maximum value |
pageSize | 100 | 1000 (100 for some APIs) |
Naming conventions
Connection naming conventions
Field | Convention |
connectionName | Unique within the namespace. Case-sensitive. Valid characters: [a-z][A-Z][0-9]_. Length range: [3, 32] bytes |
Role naming conventions
Field | Convention |
roleName | Unique within the namespace. Case-sensitive. Valid characters: [a-z][A-Z][0-9]_. Length range: [3, 255] bytes |
Taxonomy naming conventions
Field | Convention |
taxonomyName | Unique within the namespace. Case-sensitive. Valid characters: [a-z][A-Z][0-9]_. Length range: [3, 255] bytes |
PolicyTag naming conventions
Field | Convention |
policyTagName | Unique within the parent Taxonomy. Case-sensitive. Valid characters: [a-z][A-Z][0-9]_. Length range: [3, 255] bytes |
DataPolicy naming conventions
Field | Convention |
dataPolicyName | Unique at the account level |
Model naming conventions
Field | Convention |
modelName | Unique within the parent schema. Case-insensitive. Valid characters: [a-z][A-Z][0-9]_. Length range: [3, 255] bytes |
versionName | Unique within the same model. Case-insensitive. Valid characters: [a-z][A-Z][0-9]_. Length range: [3, 255] bytes |
FAQ
What is a Namespace ID?
Namespace ID is the Alibaba Cloud primary account UID. When calling namespace-level APIs such as Connection, Role, Taxonomy, DataPolicy, and DataScan, the primary account UID must be passed as the namespace parameter.
What is the three-tier model?
MaxCompute supports two metadata organization methods:
Two-tier model: Project → Table (traditional method)
Three-tier model: Project → Schema → Table (new method)
Through Project.schemaEnabled field to determine whether the three-tier model is enabled for a Project. If the three-tier model is enabled, the schemaName parameter must be specified when calling Table APIs.
How to implement column-level access control using Policy Tag?
Complete workflow for column-level access control:
Create a Taxonomy with activatedPolicyTypes set to FINE_GRAINED_ACCESS_CONTROL.
Create PolicyTags under the Taxonomy (supports a tree-like hierarchical structure).
Bind a PolicyTag to a specified column in the table column schema.
Create a DataPolicy for the PolicyTag (define masking rules, optional).
Use Policy to control which users can access columns bound with PolicyTag.
How to check DataScan crawling results?
After a DataScan crawling task runs, a ScanJob is generated. Job history can be viewed through the listDataScanJobs API. Each ScanJob contains:
status: job status (Created/Running/Terminated/Failed)
ddl: DDL information returned by crawling that needs to be committed
stats: statistics information returned by crawling (JSON format)
Are policy tags restored when restoring deleted tables with the RESTORE command?
No. Policy tags that were applied to the table before deletion are not restored with the table. After restoration, policy tags must be reapplied to the table columns.
How to handle pagination?
Most List APIs return a nextPageToken field. If this field is not empty, more pages are available. Pass the nextPageToken as the pageToken parameter in the next request to retrieve the next page of data.
Appendix
SDK version history
Version | Release date | Description |
v0.2.2 | — | Current version |
Glossary
Term | Description |
Namespace | Namespace, corresponding to the Alibaba Cloud primary account UID |
Project | MaxCompute project |
Schema | Namespace (directory) for the three-tier model |
Table | Data table |
Connection | External data source connection |
Role | Custom role |
Taxonomy | Policy tag classification system |
PolicyTag | Policy tag for implementing column-level access control |
DataPolicy | Data policy for defining data masking rules |
DataScan | Metadata crawling task |
Model | Machine learning model metadata |
Policy | Access policy, consisting of a set of Bindings |
Binding | Bind a role to a set of members |