Manage resources
A resource is a MaxCompute-specific concept. To use user-defined functions (UDFs) or MapReduce in MaxCompute, resources must first be created as dependencies. This topic describes common resource operations such as adding, viewing, listing, downloading, and deleting resources.
The following table lists common resource operations.
Operation | Description | Required permission | Tool platform |
Add resources to a MaxCompute project. | Users with the write permission on resources. | ||
Create an alias for a resource. | Users with the write permission on resources. | ||
Download resources from a MaxCompute project to a local path. | Users with the read permission on resources. | ||
View detailed information about a resource. | Users with the read permission on resources. | ||
List all resources in the current project. | Users with the list permission for project objects. | ||
Delete an existing resource from a MaxCompute project. | Users with the delete permission on resources. |
Add resources
Add resources to a MaxCompute project.
Limitations
MaxCompute does not support adding external tables as resources.
The size of each resource file cannot exceed 2048 MB. The total size of resources referenced by a single SQL or MapReduce job cannot exceed 2048 MB.
Syntax
add file <local_file> [as <alias>] [comment '<comment>'][-f]; add archive <local_file> [as <alias>] [comment '<comment>'][-f]; add table <table_name> [partition (<spec>)] [as <alias>] [comment '<comment>'][-f]; add py|jar <localfile> [comment '<comment>'][-f];Parameters
file|archive|table|py|jar: Required. The resource type. For more information, see Resource.
local_file: Required. The local file path. The file name is used as the resource name, which uniquely identifies the resource.
table_name: Required. The name of the table in MaxCompute.
spec: Required. If the resource to add is a partitioned table, MaxCompute supports only a single partition as the resource, not the entire partitioned table.
alias: Optional. Specifies the resource name. If this parameter is omitted, the file name is used as the resource name. JAR and Python resources do not support this parameter.
comment: Optional. Adds a comment to the resource.
-f: Optional. If a resource with the same name exists, this option overwrites the existing resource. If this option is not specified, the operation fails when a resource with the same name exists.
Examples
Example 1: Add a FILE resource to MaxCompute.
add file banking.txt;The following result is returned.
OK: Resource 'banking.txt' have been created.Example 2: Add a partitioned table resource with the alias sale.res to MaxCompute.
add table sale_detail partition (ds='20150602') as sale.res comment 'sale detail on 20150602' -f;The following result is returned.
OK: Resource 'sale.res' have been updated.Example 3: Add a Python resource to MaxCompute.
add py python.py [comment '<comment>'][-f];The following result is returned.
OK: Resource 'python.py' have been created.
View resource information
View information about a specified resource in the current project, including the resource name, owner, resource type, resource size, creation time, last modification time, and MD5 value of the resource file.
Syntax
desc resource <resource_name>;Parameters
resource_name: Required. The name of an existing resource.
Return fields
Name: The name of the resource.
Owner: The account of the resource owner.
Type: The resource type.
Comment: The resource comment.
CreatedTime: The resource creation time.
LastModifiedTime: The most recent update time of the resource.
LastUpdator: The account that performed the most recent update.
Size: The size of the resource file in MB.
Md5sum: The MD5 value of the resource file.
NoteResource names in MaxCompute are case-insensitive. resource_A and resource_a refer to the same resource.
Examples
--View information about topn_new.jar. desc resource topn_new.jar;The following result is returned.
Name topn_new.jar Owner ALIYUN$****@test.aliyunid.com Type JAR Comment cloudopenapi CreatedTime 2020-12-29 13:55:11 LastModifiedTime 2020-12-29 13:55:11 LastUpdator Size 11438795 Md5sum 8bcf6aabf****56c0
List resources
List all resources in the current project, including the resource name, owner, creation time, most recent update time, and resource type.
Syntax
list resources;Examples
list resources;The following result is returned.
Resource Name Owner Creation Time Last Modified Time Type Last Updator Resource Size Source comment getaddr.jar ALIYUN$**** 2020-06-18 15:47:28 2020-06-18 15:47:28 jar 1353716 cloudopenapi ip.dat ALIYUN$**** 2020-06-18 15:49:46 2020-06-18 15:49:46 file 8525962 cloudopenapi 2 resources
Create an alias for a resource
Create an alias for a resource. The alias command allows MapReduce or user-defined function (UDF) code to read different resources (data) through a fixed resource name without modifying the code.
Syntax
alias <alias>=<real>;Parameters
alias: The alias of the resource.
real: The original name of the resource.
Examples
--Add resources res_20121208 and res_20121209. add table sale_detail partition (ds='20121208') as res_20121208; add table sale_detail partition (ds='20121209') as res_20121209; --Name resource res_20121208 as resName and reference it. alias resName=res_20121208; jar -resources resName -libjars work.jar -classpath ./work.jar com.company.MainClass args ...; --Name resource res_20121209 as resName and reference it. alias resName=res_20121209; jar -resources resName -libjars work.jar -classpath ./work.jar com.company.MainClass args ...;
In the preceding example, the resource alias resName references different resource tables in the two jobs. Different data can be read without modifying the code.
Download resources
Download a resource from a MaxCompute project to a local path. The resource type must be FILE, JAR, ARCHIVE, or PY. Table resources are not supported.
Syntax
get resource <resource_name> <path>;Parameters
resource_name: Required. The name of the resource to download.
path: Required. The local path to save the resource to.
Examples
get resource getaddr.jar D:\;
Delete resources
Delete an existing resource from a MaxCompute project.
Syntax
drop resource <resource_name>;Parameters
resource_name: The name of the resource to delete.
Examples
drop resource getaddr.jar;The following result is returned.
Confirm to "drop resource getaddr.jar" (yes/no)? y OK