apache/dolphinscheduler · error · TaskException
SQL column name conflict: duplicate column name '" + label +
Error message
SQL column name conflict: duplicate column name '" + label + "'. Please use aliases to ensure unique column names.
What it means
When processing a SELECT result set, SqlTask builds a JSON object per row keyed by column label. If two or more columns share the same label, keys would overwrite each other, so the task fails fast with this error asking for unique column aliases.
Source
Thrown at dolphinscheduler-task-plugin/dolphinscheduler-task-sql/src/main/java/org/apache/dolphinscheduler/plugin/task/sql/SqlTask.java:267
* result process
*
* @param resultSet resultSet
* @throws Exception Exception
*/
private String resultProcess(ResultSet resultSet) throws Exception {
ArrayNode resultJSONArray = JSONUtils.createArrayNode();
if (resultSet != null) {
ResultSetMetaData md = resultSet.getMetaData();
int num = md.getColumnCount();
String[] columnLabels = new String[num];
// Check for duplicates in column definitions (across all columns)
Set<String> uniqueLabels = new HashSet<>(num);
for (int i = 1; i <= num; i++) {
String label = md.getColumnLabel(i);
columnLabels[i - 1] = label;
if (!uniqueLabels.add(label)) {
throw new TaskException("SQL column name conflict: duplicate column name '" + label
+ "'. Please use aliases to ensure unique column names.");
}
}
while (resultSet.next()) {
ObjectNode mapOfColValues = JSONUtils.createObjectNode();
for (int i = 1; i <= num; i++) {
mapOfColValues.set(columnLabels[i - 1], JSONUtils.toJsonNode(resultSet.getObject(i)));
}
resultJSONArray.add(mapOfColValues);
}
int displayRows = sqlParameters.getDisplayRows() > 0 ? sqlParameters.getDisplayRows()
: TaskConstants.DEFAULT_DISPLAY_ROWS;
displayRows = Math.min(displayRows, resultJSONArray.size());
log.info("display sql result {} rows as follows:", displayRows);
for (int i = 0; i < displayRows; i++) {
String row = JSONUtils.toJsonString(resultJSONArray.get(i));View on GitHub (pinned to 02eac45a1b)
Solutions
- Add unique aliases to the duplicated columns: `SELECT a.id AS a_id, b.id AS b_id ...`
- Restrict the select list to only needed columns instead of `SELECT *`
- Rename columns in the underlying view/table if duplicates come from a shared view
Example fix
// before String sql = "SELECT a.id, b.id FROM t_a a JOIN t_b b ON a.k = b.k"; // after String sql = "SELECT a.id AS a_id, b.id AS b_id FROM t_a a JOIN t_b b ON a.k = b.k";
Defensive patterns
Strategy: validation
Validate before calling
String validateUniqueLabels(String sql) {
// run 'SELECT ... LIMIT 0' via the same connection and check md.getColumnLabel(i) uniqueness
// or statically: ensure every selected column in a JOIN has an alias
return sql.matches("(?i).*select\s+\*.*from.*join.*") ? "expand SELECT * and alias duplicates" : null;
} Try / catch
try {
sqlTask.execute();
} catch (TaskException e) {
if (e.getMessage().contains("SQL column name conflict")) {
// fix SQL: add aliases, then retry
}
} Prevention
- Always alias every column in JOIN queries
- Avoid SELECT * in production SQL task definitions
- Test queries with a LIMIT 1 preview before scheduling
When it happens
Trigger: Executing a SQL query whose result set contains duplicate column labels, e.g. `SELECT a.id, b.id FROM a JOIN b` or `SELECT *` from a join of tables with same-named columns, without aliases.
Common situations: Join queries selecting unaliased id/name columns from multiple tables; `SELECT *` over joined tables; stored procedures or views emitting duplicate labels; UNION queries with identical column names.
Understand the failure class
Background: Schema validation failed / invalid input schema: payload rejected because its shape doesn't match the expected schema — this error's family across 28 libraries.
Related errors
- GET_DATASOURCE_TABLES_ERROR
- Execute sql task failed
- Cancel sql task failed
- SQL task prepareStatementAndBind error
- Query t_ds_process_instance error
AI-assisted analysis of apache/dolphinscheduler@02eac45a1b (2026-09-06).
Data as JSON: /api/errors/337a0d7b6acf2118.
Report an issue: GitHub.