apache/seatunnel · warning
Adding missing fields to SELECT clause
Error message
Adding missing fields to SELECT clause: {} What it means
SqlWhereConditionHelper.ensureFieldsInSelect detects columns referenced in a WHERE condition that are missing from the SELECT clause of the user's query. It warns about the fields it will add, then injects them into the SELECT list (inserting before FROM) so the wrapped query can filter on them.
Solutions
- Include all WHERE-clause columns in your SELECT list to avoid the automatic modification: SELECT a, b FROM t WHERE b > 1.
- Review the warning to confirm the auto-added columns match your schema expectations.
- Verify the raw column name is valid (quoting/case) if the injected query later errors.
- Use a fully-qualified query matching the catalog table schema so FieldInfo resolution succeeds without fallback.
Example fix
// before (custom query) SELECT a FROM t WHERE b > 1 // after SELECT a, b FROM t WHERE b > 1
Defensive patterns
Strategy: validation
Validate before calling
Set<String> whereCols = extractWhereColumns(whereClause);
Set<String> selectCols = extractSelectColumns(query);
if (!selectCols.containsAll(whereCols)) {
// rewrite query to project all filter columns before handing to SeaTunnel
} Prevention
- Always include WHERE columns in the SELECT list of custom queries
- Use consistent column quoting/case with the schema
- Review query-rewrite warnings after job startup
When it happens
Trigger: applyWhereConditionWithWrap processes a custom query whose WHERE clause references a column absent from the SELECT list, and the field could not be resolved from FieldInfo metadata, so the raw name is treated as a missing field and added.
Common situations: Users write custom SQL like SELECT a FROM t WHERE b > 1 with a filter column not selected; SeaTunnel must add b to the projection to apply pushdown filtering.
Understand the failure class
Background: "query failed", "%w: SQL error" — wrapped database query errors in Go libraries explained — this error's family across 3 libraries.
Related errors
- Column not found in table
- COMMON_SQL_OPERATION_FAILED
- CONNECT_DATABASE_FAILED
- 查询数据库是否存在失败:
- Error reading MySQL variables
AI-assisted analysis of apache/seatunnel@cf67b549a7 (2026-09-10).
Data as JSON: /api/errors/4ce8b2dfd7395437.
Report an issue: GitHub.
Appendix: source
Thrown at seatunnel-connectors-v2/connector-jdbc/src/main/java/org/apache/seatunnel/connectors/seatunnel/jdbc/source/SqlWhereConditionHelper.java:475
// Check missing fields in SELECT clause only (not entire SQL)
List<String> missingRawNames = findMissingFields(selectClause, rawNames);
if (missingRawNames.isEmpty()) {
return sql;
}
// Get original forms for missing fields
List<String> missingFieldsWithQuotes = new ArrayList<>();
for (String rawName : missingRawNames) {
FieldInfo info = fieldInfoMap.get(rawName);
if (info != null) {
missingFieldsWithQuotes.add(info.getOriginalForm());
} else {
// Fallback: use raw name if FieldInfo not found (should not happen)
missingFieldsWithQuotes.add(rawName);
}
}
log.warn("Adding missing fields to SELECT clause: {}", missingFieldsWithQuotes);
// Try to insert before FROM clause (safer for column index)
if (fromIndex != -1) {
StringBuilder insertion = new StringBuilder();
for (String field : missingFieldsWithQuotes) {
insertion.append(", ").append(field);
}
// Insert before FROM
StringBuilder newSql = new StringBuilder(sql);
newSql.insert(fromIndex, insertion.toString() + " ");
return newSql.toString();
}
// Fallback: insert after SELECT (may affect column index)
Matcher matcher = SELECT_PATTERN.matcher(sql);
if (matcher.find()) {
int insertPosition = matcher.end();
StringBuilder newSql = new StringBuilder(sql);View on GitHub (pinned to cf67b549a7)