You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@seatunnel.apache.org by "dybyte (via GitHub)" <gi...@apache.org> on 2025/09/03 05:52:46 UTC
[PR] [Improve][Core] Add convenience methods for creating nested ArrayType [seatunnel]
dybyte opened a new pull request, #9812:
URL: https://github.com/apache/seatunnel/pull/9812
### Purpose of this pull request
This PR introduces convenience methods in `ArrayType` to simplify the creation of nested arrays.
These methods do not change any existing behavior; they are purely helper functions to reduce boilerplate and potential mistakes when defining nested arrays.
They will also be useful for future features that require nested type support.
### Does this PR introduce _any_ user-facing change?
No
### How was this patch tested?
Add `ArrayTypeTest`
### 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/contribution/new-license.md)
* [ ] If necessary, please update the documentation to describe the new feature. https://github.com/apache/seatunnel/tree/dev/docs
* [ ] 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: commits-unsubscribe@seatunnel.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [Improve][API] Add convenience methods for creating nested ArrayType [seatunnel]
Posted by "Hisoka-X (via GitHub)" <gi...@apache.org>.
Hisoka-X commented on code in PR #9812:
URL: https://github.com/apache/seatunnel/pull/9812#discussion_r2319179810
##########
seatunnel-api/src/main/java/org/apache/seatunnel/api/table/type/ArrayType.java:
##########
@@ -61,6 +66,35 @@ public ArrayType(Class<T> arrayClass, SeaTunnelDataType<E> elementType) {
this.elementType = elementType;
}
+ @SuppressWarnings("unchecked")
+ public static <E> ArrayType<E[], E> of(SeaTunnelDataType<E> elementType) {
+ if (elementType == null) {
+ throw CommonError.illegalArgument("elementType is null", OPERATION);
+ }
+ Class<E[]> arrayClass = (Class<E[]>) toArrayClass(elementType);
+ return new ArrayType<>(arrayClass, elementType);
+ }
+
+ @SuppressWarnings("unchecked")
+ public static <E> ArrayType<?, ?> of(SeaTunnelDataType<E> elementType, int dimensions) {
+ if (dimensions < 1) {
+ throw CommonError.illegalArgument("dimensions must be >= 1", OPERATION);
+ }
+ SeaTunnelDataType<?> current = elementType;
+ for (int i = 0; i < dimensions; i++) {
+ current = of(current);
+ }
+ return (ArrayType<?, ?>) current;
+ }
+
+ public ArrayType<T[], T> addDimension() {
+ return ArrayType.of(this);
+ }
+
+ public int getDimensions() {
+ return dimensionOf(arrayClass);
+ }
Review Comment:
I'm not sure we really need this tool. How about let's add it when we need it?
--
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: commits-unsubscribe@seatunnel.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [Improve][API] Add convenience methods for creating nested ArrayType [seatunnel]
Posted by "dybyte (via GitHub)" <gi...@apache.org>.
dybyte commented on code in PR #9812:
URL: https://github.com/apache/seatunnel/pull/9812#discussion_r2319296462
##########
seatunnel-api/src/main/java/org/apache/seatunnel/api/table/type/ArrayType.java:
##########
@@ -61,6 +66,35 @@ public ArrayType(Class<T> arrayClass, SeaTunnelDataType<E> elementType) {
this.elementType = elementType;
}
+ @SuppressWarnings("unchecked")
+ public static <E> ArrayType<E[], E> of(SeaTunnelDataType<E> elementType) {
+ if (elementType == null) {
+ throw CommonError.illegalArgument("elementType is null", OPERATION);
+ }
+ Class<E[]> arrayClass = (Class<E[]>) toArrayClass(elementType);
+ return new ArrayType<>(arrayClass, elementType);
+ }
+
+ @SuppressWarnings("unchecked")
+ public static <E> ArrayType<?, ?> of(SeaTunnelDataType<E> elementType, int dimensions) {
+ if (dimensions < 1) {
+ throw CommonError.illegalArgument("dimensions must be >= 1", OPERATION);
+ }
+ SeaTunnelDataType<?> current = elementType;
+ for (int i = 0; i < dimensions; i++) {
+ current = of(current);
+ }
+ return (ArrayType<?, ?>) current;
+ }
+
+ public ArrayType<T[], T> addDimension() {
+ return ArrayType.of(this);
+ }
+
+ public int getDimensions() {
+ return dimensionOf(arrayClass);
+ }
Review Comment:
Ok. Closing this PR for now, feel free to reopen it if we need these helpers in the future.
--
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: commits-unsubscribe@seatunnel.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [Improve][API] Add convenience methods for creating nested ArrayType [seatunnel]
Posted by "dybyte (via GitHub)" <gi...@apache.org>.
dybyte closed pull request #9812: [Improve][API] Add convenience methods for creating nested ArrayType
URL: https://github.com/apache/seatunnel/pull/9812
--
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: commits-unsubscribe@seatunnel.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org