Codes
Codes are reusable code artifacts used in pipelines. In D.Hub, Python and SQL scripts can be registered as code resources to be referenced and executed in pipeline steps.
Code Overview
Code resources serve the following roles:
- Reusability: Write code once and reuse it across multiple pipelines.
- Version Control: Code change history is managed by version.
- Classification System: Systematically classify codes through categories and tags.
- Duplication: Duplicate code to create copies in the same or a different collection.
- Collection Integration: Include in collections to manage alongside related datasets and pipelines as a group.
Supported Languages
The programming languages supported by D.Hub code artifacts are as follows:
| Language | Purpose | Description |
|---|---|---|
| Python | Data processing, AI/ML | Leverages data processing libraries such as Pandas, Polars, PyArrow |
| SQL | Data querying, transformation | Analytics database queries and data transformation tasks |
When executing code in a pipeline step, the appropriate execution environment is automatically selected based on the language field. Python code runs on the workflow engine, while SQL code runs on the analytics database.
Code Detail Screen
When you select a code item in the collection tree, detailed information is displayed in the right panel.
Code Editor
A full-featured code editor based on Monaco Editor is provided, supporting both read mode and edit mode.
- Syntax Highlighting: Appropriate syntax highlighting is applied for both Python and SQL.
- Line Numbers: Line numbers are displayed on the left side of the code for easy reference to specific locations.
- Copy: Copy the entire code to the clipboard.
- Formatting: Automatically format code using the Format button in the toolbar.
- In-Editor Search: Search for text within the editor.
AI Code Assistant
The code editor has built-in AI-powered code generation and modification features.
- Inline AI Chat: Open the inline AI prompt with
Cmd+K(macOS) /Ctrl+K(Windows) to generate or modify code using natural language. - Code Selection Menu: After selecting code, an AI menu appears to request AI editing for the selected region.
- Accept/Reject: Review AI-generated code and accept or reject it.
Python Package Management
For Python code, a package input section is displayed at the bottom of the editor. You can specify the Python packages required for code execution.
Metadata
Code resources include the following metadata:
| Field | Description |
|---|---|
| Name | Unique identifier for the code |
| Alias | Display name shown to users |
| Category | Resource classification (default: code) |
| Type | Code type (user-defined) |
| Tags | Tag list for search and classification |
| Comment | Description of the code |
The code name is referenced in the pipeline step's script field. Using intuitive and consistent naming conventions makes it easier to find code when configuring pipelines.
Creating and Editing Code
Creating with Template Wizard
You can create new code through the collection's Create New feature or Template-Based Creation.
- Enter the code name, language, and category.
- Write the script in the code editor.
- Add necessary metadata (tags, description).
- Click the Create button to save.
Editing Code
When registered code is modified, a new version is created. Previous versions are preserved, so you can revert to a previous state if needed.
Duplicating Code
Use the code's Duplicate feature to duplicate code. You can specify the same collection or a different collection as the target to create a copy.
Version Control
Code resources are stored version by version in object storage.
- Version List: View all versions of the code in chronological order.
- Version Comparison: Select two versions to compare changes in Monaco DiffEditor. You can switch between Side-by-side and Unified modes.
- Version Restore: Restore a previous version as the current version.
- Version Download: Download the code file for a specific version.
Modifying code can affect the behavior of pipelines that reference it. Check related pipelines before making changes.
For detailed version management methods, see the Version Control documentation.
Usage in Pipelines
Code artifacts are referenced through the pipeline step's script field. A single code can be reused across multiple pipelines, and the code is automatically loaded and executed when the pipeline runs.
For more details on pipeline configuration, see the Pipelines (Collection) documentation.
Next Steps
- Pipelines (Collection) — Pipeline management in collections
- Version Control — Resource version management system
- Template-Based Creation - Code Wizard — How to use the code creation wizard