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 add, view, download, and delete resources.

The following table describes common statements that are used for resource operations.
Operation Description Role Platform
Add resources Adds resources to a MaxCompute project. Users who have the WRITE permission on resources. You can execute the statements 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 current 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 500 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 overwritten when you perform this operation. If you do not specify this option and a duplicate resource name exists, the operation fails.
  • Examples
    • Example 1: Add a file as a resource to a MaxCompute project.
      add file banking.txt;
      The following result is returned:
      OK: Resource 'banking.txt' have been created.
    • Example 2: Add a partitioned table named 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 current project. The information includes 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.

  • Example
    -- View information of resource 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

View a resource list

Views the information of resources in the current project. The information includes the resource name, owner, creation time, last modification time, and resource type.

  • Syntax
    list resources;
  • Example
    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

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
    alias <alias>=<real>;
  • Parameters
    • alias: the alias of the resource.
    • real: the name of the resource.
  • Example
    -- 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
    • resource_name: required. The name of the resource that you want to download.
    • path: required. The path where the resource is saved on your on-premises machine.
  • Example
    get resource getaddr.jar D:\;

Delete resources

Deletes existing resources from a MaxCompute project.

  • Syntax
    drop resource <resource_name>;
  • Parameters

    resource_name: the name of the resource that you want to delete.

  • Example
    drop resource getaddr.jar;
    The following result is returned:
    Confirm to "drop resource getaddr.jar" (yes/no)? y
    OK