Creates an alias for a resource.
Use ALIAS in MapReduce or User-Defined Function (UDF) code to switch between different resource versions without modifying the code. Assign the same alias to different resources across jobs, and the code reads whichever resource the alias points to at runtime.
Syntax
alias <alias>=<real>;Parameters
| Parameter | Description |
|---|---|
alias | The alias to create for a resource. |
real | The original name of the resource. |
When to use ALIAS
Use ALIAS when your MapReduce or UDF code references a fixed resource name but the underlying resource changes between runs — for example, daily data partitions loaded as separate table resources. Instead of updating the code each time, reassign the alias before each job.
Example
The following example shows how to switch a single alias between two date-partitioned table resources across two jobs, keeping the JAR code unchanged.
-- 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;
-- Create the alias resName for the resource res_20121208 and call this resource.
alias resName=res_20121208;
jar -resources resName -libjars work.jar -classpath ./work.jar com.company.MainClass args ...;
-- Create the alias resName for the resource res_20121209 and call this resource.
alias resName=res_20121209;
jar -resources resName -libjars work.jar -classpath ./work.jar com.company.MainClass args ...;The resName alias points to a different resource table in each job. The JAR code reads resName without any modification between runs.
Related statements
To use ALIAS, first add a resource with one of the following statements. Choose the resource type based on what your code needs:
ADD TABLE: Adds a table as a resource. Use this when your code reads structured data from MaxCompute tables.
ADD JAR: Adds a JAR file as a resource. Required when your UDF or MapReduce code depends on a JAR library.
ADD FILE: Adds a file as a resource. Use this for scripts or flat files your code reads at runtime.
ADD ARCHIVE: Adds an archive file as a resource.
ADD PY: Adds a Python script as a resource.
To manage existing resources:
DESC RESOURCE: Views resource information.
LIST RESOURCES: Views the resource list.
GET RESOURCE: Downloads a resource.
DROP RESOURCE: Deletes a resource.