DataWorks Copilot

更新时间:
复制 MD 格式

Use DataWorks Copilot to efficiently generate, optimize, explain, and test SQL and Python code through natural language interaction. You can access its capabilities in the code editor or DataWorks Copilot Ask mode. This topic describes the core capabilities and use cases of DataWorks Copilot.

Overview

Powered by a large language model (LLM), DataWorks Copilot offers intelligent SQL and Python programming support for data developers. It supports two interaction methods: the code editor, which provides real-time code completion and right-click shortcuts, and DataWorks Copilot Ask mode for a conversational Q&A experience. Core capabilities include code generation, code refactoring, code debugging, code optimization, code explanation, comment generation, code testing, Code Q&A, intelligent Notebook cell generation, and cross-engine quick table search. You can enhance the model's accuracy by adding context, such as tables, nodes, data collections, Rules, or local files. You can also switch between different large language models. This feature works out of the box and requires no coding expertise, significantly improving the efficiency of data modeling, data development, and debugging. This enables accessible, high-quality, and efficient data development.

Access

Code editor

Use case 1: Intelligent code completion

How to use: While coding in a node, DataWorks Copilot intelligently predicts and suggests subsequent code snippets based on the context, such as existing code and referenced table structures. Suggestions appear automatically. Press the Tab key to accept a suggestion.

Use case 2: Right-click menu shortcuts

How to use: In the code editor, select the desired code, right-click, and choose Copilot from the shortcut menu.

image

DataWorks Copilot Ask mode

Ask mode, the default for DataWorks Copilot, solves specific coding problems in a Q&A format. Use it to perform code generation, code refactoring, code debugging, comment generation, code explanation, code optimization, code testing, Code Q&A, intelligent Notebook cell generation, and quick table search. You can also select code in the editor to provide context for your requests.

Quick start

This section describes how to quickly get started with DataWorks Copilot Ask mode.

Step 1: Open DataWorks Copilot Ask mode

  • Log in to the DataWorks console. In the left-side navigation pane, choose Data Development and O&M > DataStudio. Select the desired workspace and click to enter Data Studio.

  • Click the image icon in the upper-right corner of the Data Studio page to open DataWorks Copilot Ask mode.

Step 2: Add context (Optional)

Add context to help DataWorks Copilot better understand your request. You can enter @ in the dialog box or click the @ icon in the lower-right corner to open the context menu and select a context type.

The following context types are supported:

  • Table: Reference metadata from one or more tables.

  • Node/Code file: Reference the code within a specific node.

  • Data collection: Reference a data collection from Data Map.

  • Rules: Temporarily apply one or more rules to the current conversation.

  • Local file: Upload a local document as background information.

Step 3: Switch models (Optional)

By default, DataWorks Copilot uses the default model. You can click the image icon at the bottom of the dialog box and select another supported large language model from the menu.

Step 4: Ask questions

Enter your request in the dialog box. Engage in a multi-turn conversation by asking follow-up questions or providing more details. This helps refine your request until DataWorks Copilot fully understands your intent and generates the desired output.

Features

DataWorks Copilot Ask mode supports generating SQL and Python code through natural language and provides features like code refactoring, code optimization, code explanation, code debugging, and test case generation. The following table details the core features:

Capability

Description

Example

Code generation

Generates code from natural language instructions.

"Write an SQL query to find the top three products with the highest sales in each city from the sales table."

Code refactoring

Refactors code based on your requirements.

"Rewrite this SQL statement that uses JOIN to use window functions."

Code debugging

Finds and fixes errors in selected code.

"This SQL statement returns an error: invalid identifier. Can you help me find what's wrong?"

Comment generation

Generates comments for the specified code.

"Add Chinese comments to this complex SQL logic, explaining the purpose of each CTE."

Code explanation

Explains the logic and function of selected code.

"Explain what PARTITION BY and ROW_NUMBER() mean in this code."

Code optimization

Optimizes the specified code.

"This query is very slow. Please optimize it and identify any performance bottlenecks."

Code testing

Generates a test plan for selected code.

"Design some test cases for this SQL code that calculates user retention. What edge cases should be considered?"

Code Q&A

Answers questions about code syntax, functions, and more.

"What is the difference between the explode function and lateral view in MaxCompute?"

Intelligent Notebook cell generation

Generates a Notebook code cell from a natural language prompt.

"Create a cell, use pandas to read the /data/users.csv file, and display the first 5 rows."

Quick table search

Finds tables across compute engines and data sources by using keywords.

"Find all tables related to 'user' or 'customer'."

Code generation

Description: Generates code based on your instructions in natural language.

Instructions: You can use one of the following methods:

  • In the code editor, right-click a blank area and choose Copilot > SQL Statement Generation to open the DataWorks Copilot interface. Then, enter a natural language request to generate the required code.

  • In the code editor, click the image icon in the upper-right corner of the top navigation bar in Data Studio, to open DataWorks Copilot Chat (Ask mode). In the chat input box, enter /, select Code generation, and then enter a natural language request to have the large model return the required code.

Code refactoring

Description: Refactors specified code through natural language interaction.

Instructions: You can use one of the following methods:

  • In the code editor, select the target code, right-click a blank area, and choose Copilot > SQL Statement Rewrite to open the DataWorks Copilot interface and enter your refactoring requirements.

  • In the code editor, select the target code, enter / in the DataWorks Copilot Chat (Ask mode) input box, select Code rewriting, enter the refactoring requirements, click Send, and wait for DataWorks Copilot to return the result.

Code debugging

Description: DataWorks Copilot supports finding and fixing errors in specified code snippets.

Instructions: You can use one of the following methods:

  • In the code editor, select the target code, right-click a blank area, and choose Copilot > SQL Statement Rectification to open the DataWorks Copilot interface.

  • In the code editor, select the target code, enter / in the DataWorks Copilot Chat (Ask mode) input box, select Code Error correction, click Send, and wait for DataWorks Copilot to return the result.

Comment generation

Description: DataWorks Copilot supports generating comments for specified SQL content to improve its readability.

Instructions: You can use one of the following methods:

  • In the code editor, select the target code, right-click a blank area, and choose Copilot > Generate Comments to open the DataWorks Copilot interface.

  • In the code editor, select the target code, enter / in the Data Agent Chat (Ask mode) input box, select Generate Comments, and click Send. Then, wait for Data Agent to return the result.

Code explanation

Description: DataWorks Copilot supports explaining specified SQL content to improve its readability.

Instructions: In the code editor, select the target code, enter / in the DataWorks Copilot Chat (Ask mode) input box, select Code interpretation, click Send, and wait for DataWorks Copilot to return the result.

Code optimization

Description: DataWorks Copilot supports optimizing selected SQL code to help simplify code logic, improve code execution efficiency, and reduce database load.

Instructions: In the code editor, select the target code, enter / in the Data Agent Chat (Ask mode) input box, select Code Optimization, click Send, and wait for Data Agent to return the results.

Code testing

Description: DataWorks Copilot supports providing a test plan for selected SQL code. This plan helps you create test cases to verify that your code works as expected.

Instructions: In the code editor, select the target code, enter / in the DataWorks Copilot Chat (Ask mode) input box, select Code Testing, click Send, and wait for DataWorks Copilot to return the results.

Code Q&A

Description: DataWorks Copilot provides explanations and usage examples for questions about SQL syntax or MaxCompute functions, which helps deepen your understanding of SQL syntax and functions.

Instructions: In DataWorks Copilot Ask mode, enter your request in the dialog box and click Send. Wait for DataWorks Copilot to return the result.

Intelligent Notebook cell generation

Description: Enter a keyword-based prompt to generate a Notebook cell.

Instructions: In the chat input box of DataWorks Copilot Chat (Ask mode), enter / and select Generate Notebook Cell. Then, enter keywords in the editing window and click Send. DataWorks Copilot then generates the corresponding Notebook node.

Quick table search

Description: Searches for tables across all compute engines and data sources based on keywords.

Instructions: In DataWorks Copilot Chat (Ask mode), enter / in the chat input box and select Quick Find Table. Then, enter keywords in the editing window and click Send. DataWorks Copilot returns tables from the bound compute engines and data sources that match the keywords.