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

  1. Include all WHERE-clause columns in your SELECT list to avoid the automatic modification: SELECT a, b FROM t WHERE b > 1.
  2. Review the warning to confirm the auto-added columns match your schema expectations.
  3. Verify the raw column name is valid (quoting/case) if the injected query later errors.
  4. 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

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


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)