corgy-w opened a new pull request, #13266:
URL: https://github.com/apache/seatunnel/pull/13266

   ### What
   
   The SQL config parser no longer discards the rest of the file after a block 
comment that opens and closes on the same line, e.g. `/* header */`.
   
   ### Why
   
   `SqlConfigBuilder.parseAnnoConfigAndSqlLine` treats every line starting with 
`/*` as the start of an annotation block and only leaves that state when it 
meets a line that is exactly `*/`:
   
   ```java
   if (line.trim().startsWith(SQL_ANNOTATION_PREFIX)) {   // "/*"
       anno = true;
       continue;
   }
   if (anno) {
       if (line.trim().equals(SQL_ANNOTATION_SUFFIX)) {   // "*/"
           anno = false;
       }
   }
   ```
   
   A one-line comment never produces that closing line, so `anno` stays true 
until the end of the file and every following statement is skipped. The parser 
then fails with the misleading
   
   ```
   ParserException: The SQL config must contain at least one source table
   ```
   
   even though the file contains a valid `CREATE TABLE ... ;` / `INSERT INTO 
...;` sequence. The multi-line license header used by the existing test 
resource works only because its closing line is exactly ` */`, which is why the 
case was missed.
   
   ### Fix
   
   Only enter the annotation state when the comment does not close on the same 
line:
   
   ```java
   if (line.trim().startsWith(SQL_ANNOTATION_PREFIX)) {
       if (!line.trim()
               .substring(SQL_ANNOTATION_PREFIX.length())
               .contains(SQL_ANNOTATION_SUFFIX)) {
           anno = true;
       }
       continue;
   }
   ```
   
   Checking the remainder of the line (instead of `endsWith`) also covers `/* 
note */ CREATE ...`, where the comment closes before the statement on the same 
line.
   
   ### How verified
   
   New test 
`SqlConfigBuilderTest#testSingleLineBlockCommentDoesNotSwallowTheRestOfTheFile`,
 a config that starts with `/* a one-line header comment */` followed by a 
source, a sink and an `INSERT INTO`:
   
   - before the fix: `ParserException: The SQL config must contain at least one 
source table` (the whole file is skipped);
   - after the fix: `Tests run: 2, Failures: 0, Errors: 0, Skipped: 0` (`mvn -o 
-pl seatunnel-config/seatunnel-config-sql test -Dtest=SqlConfigBuilderTest`). 
The existing multi-line-header test still passes.
   
   ### Compatibility
   
   No option, API or format change. Files that only use `/* ... */` across 
multiple lines, `--` line comments, or no comments are parsed exactly as before.
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to