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 Operation platform
Add resources Adds resources to a MaxCompute project. Users who have the WRITE permission on resources You can execute the statements described in this topic on the following platforms:
View information of resources 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 a resource Downloads resources in a MaxCompute project to your on-premises machine. Users who have the WRITE permission on resources
Delete a resource 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];
  • Parameter
    • file|archive|table|py|jar: required. The type of the resource. For more information about resource types, see Resource.
    • local_file: required. The directory where the local file is saved. 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;
      Returned results:
      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;
      Returned results:
      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];
      Returned results:
      OK: Resource 'python.py' have been created.

View information of resources

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;
    Returned results:
    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 a resource

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 directory in which the resource is saved on your on-premises machine.
  • Example
    get resource getaddr.jar D:\;

Delete a resource

Deletes existing resources from a MaxCompute project.

  • Syntax
    drop resource <resource_name>;
  • Parameter

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

  • Example
    drop resource getaddr.jar;
    Returned results:
    Confirm to "drop resource getaddr.jar" (yes/no)? y
    OK