sharpca opened a new pull request, #13170:
URL: https://github.com/apache/seatunnel/pull/13170

   ### Purpose of this pull request
   
   Yes, I am contributing this fix to Apache SeaTunnel.
   
   This pull request fixes #13169.
   
   Several `seatunnel-api` code paths match an identifier or a type name with 
`String#toUpperCase()` / `String#toLowerCase()` **without** `Locale.ROOT`, so 
the result depends on the JVM default locale of the worker.
   
   In a Turkish or Azerbaijani locale an upper-case `I` lower-cases to the 
dotless `ı` and a lower-case `i` upper-cases to the dotted `İ`, so a name that 
contains an `i` or an `I` no longer matches the constant it was compared 
against.
   
   | Class | Call site | Effect under `tr-TR` |
   | --- | --- | --- |
   | `org.apache.seatunnel.api.common.PluginIdentifier` | `hashCode()` 
lower-cases the engine type, the plugin type and the plugin name | `equals()` 
compares with `StringUtils.equalsIgnoreCase`, which is locale independent, so 
two equal identifiers got different hash codes and a `HashMap` lookup could 
miss |
   | `org.apache.seatunnel.api.metalake.MetalakeConfigUtils` | 
`MetaLakeType.valueOf(metalakeType.toUpperCase())` | the configured type 
`gravitino` became `GRAVİTİNO`, which is not a `MetaLakeType` constant |
   | `org.apache.seatunnel.api.metalake.MetaLakeFactory` | the client and the 
mapper registries are keyed by the lower-cased type name and are looked up with 
the lower-cased enum constant name | the registry key was `gravitino` while the 
lookup key was `gravıtıno`, so the lookup failed with `Unknown MetalakeClient 
type: gravıtıno` |
   | 
`org.apache.seatunnel.api.metalake.gravitino.GravitinoTableSchemaConvertor` | 
the Gravitino type names are lower-cased before they are matched | a type name 
that contains an upper-case `I`, for example `INTEGER`, was lower-cased to 
`ınteger` and no longer matched, so the column type was not converted |
   
   All of these conversions now use `Locale.ROOT`.
   
   The metalake path is not dead code: `MetalakeConfigUtils.getMetalakeConfig` 
is called by the Flink and Spark starters and by the Zeta job config parser, so 
a job that enables the metalake failed to start on such a worker.
   
   This is disjoint from the other locale pull requests: #13074 covers 
`SeaTunnelDataTypeConvertorUtil` and `VectorIndex`, #13063 covers `JdbcDialect` 
and `CatalogUtils`, and #12269 covers the plugin discovery.
   
   ### Does this PR introduce _any_ user-facing change?
   
   Yes, in one way:
   
   - Only for JVMs whose default locale is Turkish or Azerbaijani. A job that 
enables the metalake now starts instead of failing with `No enum constant 
org.apache.seatunnel.common.constants.MetaLakeType.GRAVİTİNO`, and the metalake 
column types are now converted.
   
   Nothing else changes for the default locale or for the configuration. The 
change is documented in `docs/en/introduction/concepts/incompatible-changes.md` 
and `docs/zh/introduction/concepts/incompatible-changes.md`.
   
   ### How was this patch tested?
   
   Three unit tests were added:
   
   - `PluginIdentifierTest#testHashCodeIsIndependentOfDefaultLocale` builds two 
identifiers that are equal ignoring case and asserts that their hash codes are 
equal under a Turkish default locale.
   - `MetalakeLocaleTest` resolves the metalake type, and the metalake client 
and mapper registries, under a Turkish default locale.
   - 
`GravitinoTableSchemaConvertorTest#testConvertTypeIsIndependentOfDefaultLocale` 
converts a column of type `INTEGER` under a Turkish default locale.
   
   Each test switches the default locale to `tr-TR` and restores it in a 
`finally` block, so the locale cannot leak into the other tests that share the 
JVM.
   
   ```shell
   ./mvnw -pl seatunnel-api -am install \
     
-Dtest='PluginIdentifierTest,MetalakeLocaleTest,GravitinoTableSchemaConvertorTest'
 test
   ```
   
   Result: 59 tests, 0 failures. `spotless:check` passes.
   
   The new tests were also run against the unpatched sources to confirm that 
they fail there:
   
   - `PluginIdentifierTest`: the two identifiers are equal but their hash codes 
differ (`expected: <-1353815929> but was: <1534074303>`).
   - `MetalakeLocaleTest`: the metalake type lookup fails with 
`IllegalArgumentException: No enum constant 
org.apache.seatunnel.common.constants.MetaLakeType.GRAVİTİNO`, and the mapper 
registry lookup fails with `IllegalArgumentException: Unknown MetalakeClient 
type: gravıtıno`.
   - `GravitinoTableSchemaConvertorTest`: the `INTEGER` column is not converted.
   
   ### Check list
   
   * [ ] If any new Jar binary package adding in your PR, please add License 
Notice according
     [New License 
Guide](https://github.com/apache/seatunnel/blob/dev/docs/en/developer/new-license.md)
   * [x] If necessary, please update the documentation to describe the new 
feature. https://github.com/apache/seatunnel/tree/dev/docs
   * [x] If necessary, please update `incompatible-changes.md` to describe the 
incompatibility caused by this PR.
   * [ ] If you are contributing the connector code, please check that the 
following files are updated:
     1. Update 
[plugin-mapping.properties](https://github.com/apache/seatunnel/blob/dev/plugin-mapping.properties)
 and add new connector information in it
     2. Update the pom file of 
[seatunnel-dist](https://github.com/apache/seatunnel/blob/dev/seatunnel-dist/pom.xml)
     3. Add ci label in 
[label-scope-conf](https://github.com/apache/seatunnel/blob/dev/.github/workflows/labeler/label-scope-conf.yml)
     4. Add e2e testcase in 
[seatunnel-e2e](https://github.com/apache/seatunnel/tree/dev/seatunnel-e2e/seatunnel-connector-v2-e2e/)
     5. Update connector 
[plugin_config](https://github.com/apache/seatunnel/blob/dev/config/plugin_config)
   


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