This topic describes how to use the DataWorks data synchronization feature to export data from a MaxCompute table to Object Storage Service (OSS) as a CSV file.
DataWorks provides a visual configuration interface and scheduling capabilities that handle the data transfer between MaxCompute and OSS without requiring custom code. You configure a Batch Synchronization node that reads from MaxCompute using an ODPS Reader and writes to OSS using an OSS Writer, then run the job once to transfer the data.
MaxCompute, DataWorks, and OSS must all be in the same region.
Prerequisites
Before you begin, ensure that you have:
Migrate MaxCompute data to OSS
The migration consists of six steps: create a MaxCompute table, import sample data, create an OSS bucket and destination file, add data sources for both services in DataWorks, then run a Batch Synchronization job.
Step 1: Create a table in MaxCompute
Log on to the DataWorks console and select a region in the upper-left corner.
In the left navigation pane, click Workspace.
On the Workspaces page, find your workspace and in the Actions column, choose Shortcuts > DataStudio.
On the DataStudio page, create a MaxCompute SQL node and run the following statement to create a table named
transs:CREATE TABLE transs (name STRING, id STRING, gender STRING);
Step 2: Import data into the transs table
Download demo_data.csv to your computer.
In the left navigation pane, choose Data Integration > Data Upload and Download.
Click Go to Data Upload and Download.
In the left navigation pane, click the upload icon
and then click Upload Data.Upload
demo_data.csvto the MaxCompute table transs.
Step 3: Create a bucket and destination file in OSS
Log on to the OSS console.
In the left navigation pane, click Buckets, then click Create Bucket.
Create an empty file named
qwee.csvon your computer and upload it to the bucket. The field names inqwee.csvmust match those in thetransstable (name,id,gender). For upload instructions, see Upload objects.
Step 4: Add a MaxCompute data source in DataWorks
Log on to the DataWorks console and select a region.
In the left navigation pane, click Workspace, then click the name of your workspace.
On the Workspace Details page, click Data Sources in the left navigation pane.
On the Data Source tab, click Add Data Source and select MaxCompute.
On the Add MaxCompute Data Source page, complete the Basic Information fields. For configuration details, see Configure a MaxCompute data source.
Step 5: Add an OSS data source in DataWorks
For configuration details, see Configure an OSS data source.
Step 6: Create and run a Batch Synchronization node
Log on to the DataWorks console and select a region.
In the left navigation pane, choose Data Development and O&M > Data Development.
In the Select Workspace section, click Go to Data Studio.
In the left pane, click the
icon and select Create Node > Data Integration > Batch Synchronization.On the node configuration page, set the following parameters:
Parameter Value Data Source > Source The MaxCompute data source you added in step 4 Data Source > Destination The OSS data source you added in step 5 Data Source > Table transsDestination > Text Type CSV Destination > Object Name (Path Included) The OSS object path, for example qwee.csvordata/output/qwee.csvRuntime Resource Your dedicated resource group Keep the default values for all other parameters.
Alternatively, click the
icon to switch to the code editor and paste the following script:{ "order":{ "hops":[ { "from":"Reader", "to":"Writer" } ] }, "setting":{ "errorLimit":{ "record":"0" }, "speed":{ "concurrent":1, "dmu":1, "throttle":false } }, "steps":[ { "category":"reader", "name":"Reader", "parameter":{ "column":[ "name", "id", "gender" ], "datasource":"odps_first", "partition":[], "table":"Transs" }, "stepType":"odps" }, { "category":"writer", "name":"Writer", "parameter":{ "datasource":"Trans", "dateFormat":"yyyy-MM-dd HH:mm:ss", "encoding":"UTF-8", "fieldDelimiter":",", "fileFormat":"csv", "nullFormat":"null", "object":"qwee.csv", "writeMode":"truncate" }, "stepType":"oss" } ], "type":"job", "version":"2.0" }The script uses
writeMode: truncate, which overwritesqwee.csvif the file already exists in the bucket.Click Run.
Verify the migration
After the job completes, confirm the data transferred correctly:
Log on to the OSS console and navigate to your bucket.
Locate
qwee.csvand confirm its file size is greater than 0 bytes.Download the file and verify it contains the expected rows from the
transstable.
To confirm row counts match, run the following statement in MaxCompute before and after the migration, then compare the result against the row count in the downloaded CSV:
SELECT COUNT(*) FROM transs;For download instructions, see Download objects.
What's next
To schedule recurring exports, configure a scheduling dependency on the Batch Synchronization node in DataWorks.
To migrate larger datasets or add transformations, explore the DataWorks Data Integration documentation for advanced Reader and Writer parameter options.