{"record":{"id":"4ce8b2dfd7395437","repo":"apache/seatunnel","slug":"adding-missing-fields-to-select-clause","errorCode":null,"errorMessage":"Adding missing fields to SELECT clause: {}","messagePattern":"Adding missing fields to SELECT clause: (.+?)","errorType":"console","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"seatunnel-connectors-v2/connector-jdbc/src/main/java/org/apache/seatunnel/connectors/seatunnel/jdbc/source/SqlWhereConditionHelper.java","lineNumber":475,"sourceCode":"        // Check missing fields in SELECT clause only (not entire SQL)\n        List<String> missingRawNames = findMissingFields(selectClause, rawNames);\n        if (missingRawNames.isEmpty()) {\n            return sql;\n        }\n\n        // Get original forms for missing fields\n        List<String> missingFieldsWithQuotes = new ArrayList<>();\n        for (String rawName : missingRawNames) {\n            FieldInfo info = fieldInfoMap.get(rawName);\n            if (info != null) {\n                missingFieldsWithQuotes.add(info.getOriginalForm());\n            } else {\n                // Fallback: use raw name if FieldInfo not found (should not happen)\n                missingFieldsWithQuotes.add(rawName);\n            }\n        }\n\n        log.warn(\"Adding missing fields to SELECT clause: {}\", missingFieldsWithQuotes);\n\n        // Try to insert before FROM clause (safer for column index)\n        if (fromIndex != -1) {\n            StringBuilder insertion = new StringBuilder();\n            for (String field : missingFieldsWithQuotes) {\n                insertion.append(\", \").append(field);\n            }\n            // Insert before FROM\n            StringBuilder newSql = new StringBuilder(sql);\n            newSql.insert(fromIndex, insertion.toString() + \" \");\n            return newSql.toString();\n        }\n\n        // Fallback: insert after SELECT (may affect column index)\n        Matcher matcher = SELECT_PATTERN.matcher(sql);\n        if (matcher.find()) {\n            int insertPosition = matcher.end();\n            StringBuilder newSql = new StringBuilder(sql);","sourceCodeStart":457,"sourceCodeEnd":493,"githubUrl":"https://github.com/apache/seatunnel/blob/cf67b549a7a6c35fa0beb12d83c62892427ea919/seatunnel-connectors-v2/connector-jdbc/src/main/java/org/apache/seatunnel/connectors/seatunnel/jdbc/source/SqlWhereConditionHelper.java#L457-L493","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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."],"exampleFix":"// before (custom query)\nSELECT a FROM t WHERE b > 1\n// after\nSELECT a, b FROM t WHERE b > 1","handlingStrategy":"validation","validationCode":"Set<String> whereCols = extractWhereColumns(whereClause);\nSet<String> selectCols = extractSelectColumns(query);\nif (!selectCols.containsAll(whereCols)) {\n    // rewrite query to project all filter columns before handing to SeaTunnel\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["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"],"tags":["jdbc","sql","query-rewriting","where-clause"],"backgroundTag":"sql-query-failed","analyzedSha":"cf67b549a7a6c35fa0beb12d83c62892427ea919","analyzedAt":"2026-09-10T21:44:55.265Z","contentChangedAt":"2026-09-10T21:44:55.265Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}