SEPURI-SAI-KRISHNA opened a new issue, #12496:
URL: https://github.com/apache/seatunnel/issues/12496

   ### Search before asking
   
   - [X] I had searched in the 
[issues](https://github.com/apache/seatunnel/issues?q=is%3Aissue+label%3A%22bug%22)
 and found no similar issues.
   
   ### What happened
   
   The `Sql` transform resolves function names, `CAST` target types, datetime 
field names, `VECTOR_REDUCE` methods and the `engine` option value by 
uppercasing the user's text with `String.toUpperCase()`, which uses the JVM 
default locale.
   
   On a worker whose default locale is Turkish (`tr`) or Azeri (`az`), 
lowercase `i` uppercases to `İ` rather than `I`. A keyword spelled in lower or 
mixed case therefore stops matching the constant it is compared against, and a 
valid query fails with an "Unsupported ..." error.
   
   An all uppercase spelling is unaffected. I checked all 156 distinct keywords 
these switches compare against, extracted from the source, against every locale 
the JDK exposes: no locale alters an already uppercase keyword, and the only 
locales that alter the lowercase form are `tr` and `az` variants (8 of them on 
JDK 11, 10 on JDK 17 and 21). 64 of the 156 keywords are affected, being the 
ones that contain an `i`.
   
   I verified this on `dev` at c3f06f9a8 with the production code untouched, 
changing nothing but the default locale. The same query passes under `en` and 
fails under `tr-TR`.
   
   This is the same defect class as #11949, which covered the `LOWER()` and 
`UPPER()` SQL functions (they convert user *data*) and was fixed in #11951. The 
sites below are the lookups that resolve SQL *keywords*. They are different 
code and were not covered by that fix. `NumericFunction` in the same package 
was already moved to `Locale.ROOT` in #11937; these seven files are the 
remainder.
   
   ### SeaTunnel Version
   
   dev (reproduced at c3f06f9a8)
   
   ### SeaTunnel Config
   
   ```conf
   transform {
     Sql {
       plugin_input = "fake"
       plugin_output = "out"
       query = "select sign(age) as s, cast(age as int) as c from fake"
     }
   }
   ```
   
   ### Running Command
   
   Any Zeta job running the config above on a worker whose default locale is 
Turkish, for example started with `-Duser.language=tr -Duser.country=TR`. The 
same query with `SIGN` and `INT` spelled in uppercase succeeds on the same 
worker.
   
   ### Error Exception
   
   ```log
   org.apache.seatunnel.transform.exception.TransformException:
     ErrorCode:[COMMON-05], ErrorDescription:[Unsupported operation] - 
Unsupported function: sign
   
   org.apache.seatunnel.transform.exception.TransformException:
     ErrorCode:[COMMON-05], ErrorDescription:[Unsupported operation] - 
Unsupported CAST FROM INT AS type: int
   ```
   
   With `engine = "internal"` on the same worker:
   
   ```log
   java.lang.IllegalArgumentException: No enum constant
     org.apache.seatunnel.transform.sql.SQLEngineFactory.EngineType.İNTERNAL
   ```
   
   ### Zeta or Flink or Spark Version
   
   Zeta
   
   ### Java or Scala Version
   
   Reproduced on JDK 17. The affected locale set is the same on JDK 11 and 21.
   
   ### Screenshots
   
   _No response_
   
   ### Are you willing to submit PR?
   
   - [X] Yes I am willing to submit a PR!
   
   ### Affected sites
   
   All under 
`seatunnel-transforms-v2/src/main/java/org/apache/seatunnel/transform/sql/`, 
verified present on dev at c3f06f9a8. This is every remaining default-locale 
case conversion in that subtree.
   
   | file | site |
   | --- | --- |
   | `SQLTransform` | `engine` option value, so `engine = "internal"` is 
rejected |
   | `ZetaSQLFunction` | function dispatch, time-key expression, `CAST` 
argument |
   | `ZetaSQLType` | function return type, time-key expression type |
   | `DateTimeFunction` | `DATEADD`, `DATEDIFF`, `DATE_TRUNC` and `EXTRACT` 
fields |
   | `VectorFunction` | `VECTOR_REDUCE` method |
   | `CastFunction` | `CAST` target type |
   | `SystemFunction` | `TRUE`/`FALSE` compare, behaviour neutral, listed for 
completeness |
   
   Affected keywords include `SIN`, `SINH`, `ASIN`, `SIGN`, `SUBSTRING`, 
`INSTR`, `INSERT`, `POSITION`, `SPLIT`, `RIGHT`, `BIT_LENGTH`, `CEIL`, 
`CEILING`, `TRIM`, `LTRIM`, `RTRIM`, `RADIANS`, `PI`, `IFNULL`, `NULLIF`, 
`MULTI_IF`, `UUID`, `TIMESTAMPADD`, `DATEDIFF`, `FROM_UNIXTIME`, 
`PARSEDATETIME`, `FORMATDATETIME` and `REGEXP_LIKE` in the dispatch; `INT`, 
`INTEGER`, `BIGINT`, `SMALLINT`, `TINYINT`, `STRING`, `BINARY`, `DECIMAL`, 
`TIME`, `TIMESTAMP`, `TIMESTAMP_TZ` and `DATETIME` in `CAST`; `MINUTE`, 
`MILLISECOND`, `MICROSECONDS`, `ISODOW`, `ISOYEAR` and `MILLENNIUM` as datetime 
fields; `CURRENT_TIME` and `CURRENT_TIMESTAMP`; `RANDOM_PROJECTION` and 
`SPARSE_RANDOM_PROJECTION`; and `INTERNAL` for `engine`.
   
   `seatunnel-transforms-v2` has 11 further default-locale conversions outside 
`transform/sql/`, in the `validator`, `Calcite` and `nlpmodel` plugins. Those 
are separate plugins and are not covered here.
   
   ### Code of Conduct
   
   - [X] I agree to follow this project's [Code of 
Conduct](https://www.apache.org/foundation/policies/conduct)
   


-- 
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