Tunnel operations

更新时间:
复制 MD 格式

MaxCompute allows you to use Tunnel commands to upload and download data.

For more information about Tunnel operations, see Tunnel commands. The following table lists the common commands.

Type

Description

Role

Entry point

Upload data

Uploads data from a local file to a MaxCompute table in append mode.

Users who have the Alter permission on the table.

MaxCompute client

Download data

Downloads data from a MaxCompute table or the execution result of a specified instance to a local file.

Users who have the Select permission on the table.

Upload data

You can upload data from a local file to a MaxCompute table in append mode. Data uploads are free of charge.

  • Limitations

    • You can upload a file or a level-1 directory. Each upload operation can target only one table or a single partition within a table.

    • If you upload data to a partitioned table, you must specify a partition. For tables with multiple partition levels, you must specify a lowest-level partition.

  • Syntax

    Tunnel upload <path> [<project_name>.]<table_name>[/<pt_spc>];
  • Parameters

    • path: Required. The path and filename of the source data file. By default, the data file is in TXT format. The path and filename can contain only English letters, digits, and underscores (_). Chinese characters and spaces are not supported. If a path contains Chinese characters on a system with a non-UTF-8 locale, such as LANG=C, the MaxCompute client (odpscmd) reports a "File not found" error. To resolve this issue, use a path with only English characters or set your system locale to a UTF-8 encoding, such as export LANG=en_US.UTF-8.

      You can specify the file path in two ways: If the file is in the bin directory of the MaxCompute client, set the path parameter to filename.extension. If the file is in another directory, such as D:\test, set the path parameter to the absolute path, for example, D:\test\filename.extension. The Tunnel command-line tool has no file size limit and supports uploading large files. To optimize large file uploads, you can use the -bs parameter to adjust the size of each data block. The default is 100 MiB.

      Note

      On macOS, the path value must be an absolute path. For example, if your file is in the bin directory of the MaxCompute client, set the path parameter to an absolute path, such as /Users/username/MaxCompute/bin/filename.extension.

    • project_name: Optional. The name of the project that contains the destination table. This parameter is required if you access a table in a different project.

    • table_name: Required. The name of the destination table.

    • pt_spc: Optional. The destination partition. You must specify a lowest-level partition. The value must be in the format partition_col1=col1_value1, partition_col2=col2_value1....

  • Examples

    • Example 1: Upload data from the log.txt file to the test_table table in the current project. The log.txt file is stored in the bin directory of the MaxCompute client.

      Tunnel upload log.txt test_table;
    • Example 2: Upload data from the log.txt file to the p1="b1",p2="b2" partition of the test_table table. The table is a two-level partitioned table in the test_project project. The log.txt file is stored in the test folder on drive D.

      Tunnel upload D:\test\log.txt test_project.test_table/p1="b1",p2="b2";

Download data

Downloads data from a MaxCompute table or the execution result of a specified instance to a local file. You are charged for downloading data over the Internet based on the amount of data downloaded. The fee is calculated as follows: Download fee = Data downloaded (GB) × Price (CNY 0.8/GB).

  • Limitations

    • Each download can export data from only one table or one partition to a single file.

    • If you download data from a partitioned table, you must specify a partition. For tables with multiple partition levels, you must specify a lowest-level partition.

  • Syntax

    Tunnel download [<project_name>.]<table_name>[/<pt_spc>] <path>;
  • Parameters

    • project_name: Optional. The name of the project that contains the source table. This parameter is required if you access a table in a different project.

    • table_name: Required. The name of the source table.

    • pt_spc: Optional. The source partition. You must specify a lowest-level partition. The value must be in the format partition_col1=col1_value1, partition_col2=col2_value1....

    • path: Required. The destination path and filename for the downloaded data file. By default, the downloaded data file is in TXT format.

      There are two options for the save path of the data file. You can download the file directly to the bin directory of the MaxCompute client. In this case, set the path parameter to filename.extension. Alternatively, you can download the file to a different path, such as the test folder on drive D. In this case, set the path parameter to D:\test\filename.extension.

  • Examples

    • Example 1: Download the data from the test_project.test_table table (a two-level partitioned table) to the test_table.txt file. The test_table.txt file is located in the bin directory of the MaxCompute client. The command is as follows.

      Tunnel download test_project.test_table/p1="b1",p2="b2" test_table.txt;
    • Example 2: Download data from the test_project.test_table table, a two-level partitioned table, to the test_table.txt file in the test folder on the D drive. The command is as follows.

      Tunnel download test_project.test_table/p1="b1",p2="b2" D:\test\test_table.txt;