Resource is a concept specific to MaxCompute. To accomplish jobs by using user-defined functions (UDFs) or MapReduce, you must upload files as MaxCompute resources. This topic describes common operations on resources, such as adding, viewing, downloading, and deleting resources.
The following table describes common resource operations.
Operation | Description | Performed by | Operation platform |
Operation | Description | Performed by | Operation platform |
Add resources | Adds resources to a MaxCompute project. | Users who have the Write permission on resources. | You can run the commands that are described in this topic on the following platforms: |
View resource information | Views the detailed information of a resource. | Users who have the Read permission on resources. |
View a resource list | Views the information of resources in the project. | Users who have the List permission on objects in a project |
Create an alias for a resource | Creates an alias for a resource. | Users who have the Write permission on resources. |
Download resources | Downloads resources in a MaxCompute project to your on-premises machine. | Users who have the Write permission on resources. |
Delete resources | Deletes existing resources from a MaxCompute project. | Users who have the Delete permission on resources. |
Add resources
Adds resources to a MaxCompute project.
Limits
MaxCompute does not allow you to add external tables as resources.
The maximum size of a resource file is 2048 MB. The size of resources referenced by a single SQL or MapReduce job cannot exceed 2,048 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 type of the resource. For more information about resource types, see Resource.
local_file: required. The path of the file that you want to add. The file name is used as the resource name, which uniquely identifies a resource.
table_name: required. The name of a table in MaxCompute.
spec: required. If the resource that you want to add is a partitioned table, MaxCompute takes only a partition in the table as a resource, instead of taking the whole table as a resource.
alias: optional. The name of the resource. If this parameter is not specified, the file name is used as the resource name. JAR packages or Python script files that are used as resources do not support this parameter.
comment: optional. The comment of the resource.
-f: optional. If a duplicate resource name exists, the existing resource is replaced. If you do not specify this option and a duplicate resource name exists, the resource fails to be added.
Examples
Example 1: Add a file as a resource to a MaxCompute project.
The following result is returned:
OK: Resource 'banking.txt' have been created.
Example 2: Add a partitioned table whose alias is sale.res as a resource 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 file as a 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
Views the information of a specified resource in the project. The information includes the resource name, owner, resource type, resource size, creation time, last modification time, and MD5 value of the resource file.
View a resource list
Views the information of resources in a project. The information includes the resource name, owner, creation time, last modification time, and resource type.
Create an alias for a resource
Creates an alias for a resource. The alias command can be used in MapReduce or UDF code to read different resources based on a specified resource name. During this process, you do not need to modify the code.
Syntax
Parameters
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;
-- Set the alias of the resource res_20121208 to resName and call this resource.
alias resName=res_20121208;
jar -resources resName -libjars work.jar -classpath ./work.jar com.company.MainClass args ...;
-- Set the alias of the resource res_20121209 to resName and call this resource.
alias resName=res_20121209;
jar -resources resName -libjars work.jar -classpath ./work.jar com.company.MainClass args ...;
In this example, the resName
alias references different resource tables in two jobs. You can read different copies of data without the need to modify the code.
Download resources
Downloads resources in a MaxCompute project to your on-premises machine. The resource type must be FILE, JAR, ARCHIVE, or PY. The TABLE type is not supported.
Syntax
get resource <resource_name> <path>;
Parameters
Examples
get resource getaddr.jar D:\;
Delete resources
Deletes existing resources from a MaxCompute project.