Skip to content

[Improvement][task-sql] Support executing SQL from resource center file #18019

@macdoor

Description

@macdoor

Search before asking

  • I had searched in the issues and found no similar feature requirement.

Description

Purpose

Using Resource Center SQL files makes it much easier to manage SQL scripts:

  • SQL scripts can be version-controlled and reviewed independently (e.g. via Git)
  • Multiple workflows can share the same SQL file, avoiding duplication
  • Updating SQL logic only requires updating the file, without editing every SQL task node

Extend the SQL task type to support:

  1. Executing SQL from a Resource Center file (in addition to inline script)
  2. Applying parameter placeholders (${...}, $[...]) consistently for both inline SQL and file-based SQL

This is similar to what other task types already support (e.g. HiveCli, Shell, Spark, Python, Flink/FlinkSqlGateway).

Background

In current dev:

  • SqlParameters only has a single sql field
  • The SQL task UI only supports inline SQL text
  • Users who keep large SQL scripts in the Resource Center cannot reference them directly from the SQL task
  • Parameter placeholder replacement is partially handled when binding parameters, but there is no way to:
    • load SQL content from a file first
    • then apply placeholders on that content

For large / shared SQL scripts, putting them into the Resource Center and referencing them from tasks is a common pattern. Tasks like HiveCli, Shell, Spark, Python already support this mode.

Proposal

Backend

  1. Extend SqlParameters (dolphinscheduler-task-api):

    • Add fields:
      • sqlSource: "SCRIPT" (default) or "FILE"
      • sqlResource: resource path in Resource Center
    • Keep existing sql for inline SQL (backward compatible).
    • Update:
      • checkParameters() to accept either sql OR sqlResource
      • getResourceFilesList() to return a ResourceInfo when sqlResource is set, so Worker downloads the file
  2. Extend SqlTask (dolphinscheduler-task-sql):

    • Before splitting SQL, ensure SQL content:

      private void ensureSqlContent() {
      if (StringUtils.isNotEmpty(sqlParameters.getSql())) {
      return;
      }
      if (StringUtils.isEmpty(sqlParameters.getSqlResource())) {
      return;
      }
      // Use TaskExecutionContext.getResourceContext()
      // to resolve local path and read SQL text into sqlParameters.sql
      }

Are you willing to submit a PR?

  • Yes I am willing to submit a PR!

Code of Conduct

Metadata

Metadata

Assignees

Labels

StaleUIui and front end relatedbackendimprovementmake more easy to user or prompt friendly

Type

No type
No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions