ptupitsyn commented on code in PR #4778: URL: https://github.com/apache/ignite-3/pull/4778#discussion_r1862006748
########## modules/compute/src/main/java/org/apache/ignite/internal/compute/ComputeUtils.java: ########## @@ -362,10 +378,15 @@ private static Throwable mapToComputeException(Throwable origin) { @Nullable Object input, @Nullable Class<?> pojoType ) { + Loggers.forClass(ComputeUtils.class).info("unmarshalOrNotIfNull {} {}", input, marshaller); Review Comment: Looks like temporary code - remove? ########## modules/compute/src/main/java/org/apache/ignite/internal/compute/ComputeUtils.java: ########## @@ -394,6 +415,46 @@ private static Throwable mapToComputeException(Throwable origin) { ); } + /** + * Unmarshals the input from the {@link ComputeJobDataHolder} using provided marshaller if input was marshalled on the client. If the + * input was marshalled as a {@link Tuple} or POJO, then, if provided pojo type is not {@code null} and not a {@link Tuple}, unmarshals + * the input as a pojo using the provided pojo type, otherwise unmarshals it as a {@link Tuple}. + * + * @param marshaller Optional marshaller to unmarshal the input. + * @param argumentHolder Argument holder. + * @param pojoType Pojo type to use when unmarshalling as a pojo. + * @param <T> Result type. + * @return Unmarshalled object. + */ + private static <T> @Nullable T unmarshalFromDataHolder( + @Nullable Marshaller<T, byte[]> marshaller, + ComputeJobDataHolder argumentHolder, + @Nullable Class<?> pojoType + ) { + Loggers.forClass(ComputeUtils.class).info("unmarshalFromDataHolder {}", argumentHolder.type()); + ComputeJobDataType type = argumentHolder.type(); + switch (type) { + case TUPLE: // Fallthrough TODO https://issues.apache.org/jira/browse/IGNITE-23320 + case POJO: Review Comment: ```suggestion case POJO: ``` ########## modules/compute/src/main/java/org/apache/ignite/internal/compute/ComputeUtils.java: ########## @@ -394,6 +415,46 @@ private static Throwable mapToComputeException(Throwable origin) { ); } + /** + * Unmarshals the input from the {@link ComputeJobDataHolder} using provided marshaller if input was marshalled on the client. If the + * input was marshalled as a {@link Tuple} or POJO, then, if provided pojo type is not {@code null} and not a {@link Tuple}, unmarshals + * the input as a pojo using the provided pojo type, otherwise unmarshals it as a {@link Tuple}. + * + * @param marshaller Optional marshaller to unmarshal the input. + * @param argumentHolder Argument holder. + * @param pojoType Pojo type to use when unmarshalling as a pojo. + * @param <T> Result type. + * @return Unmarshalled object. + */ + private static <T> @Nullable T unmarshalFromDataHolder( + @Nullable Marshaller<T, byte[]> marshaller, + ComputeJobDataHolder argumentHolder, + @Nullable Class<?> pojoType + ) { + Loggers.forClass(ComputeUtils.class).info("unmarshalFromDataHolder {}", argumentHolder.type()); + ComputeJobDataType type = argumentHolder.type(); + switch (type) { + case TUPLE: // Fallthrough TODO https://issues.apache.org/jira/browse/IGNITE-23320 + case POJO: + Tuple tuple = TupleWithSchemaMarshalling.unmarshal(argumentHolder.data()); + if (pojoType != null && pojoType != Tuple.class) { + return (T) unmarshalPojo(pojoType, tuple); + } + return (T) tuple; + case MARSHALLED_CUSTOM: Review Comment: ```suggestion case MARSHALLED_CUSTOM: ``` ########## modules/compute/src/main/java/org/apache/ignite/internal/compute/ComputeUtils.java: ########## @@ -394,6 +415,46 @@ private static Throwable mapToComputeException(Throwable origin) { ); } + /** + * Unmarshals the input from the {@link ComputeJobDataHolder} using provided marshaller if input was marshalled on the client. If the + * input was marshalled as a {@link Tuple} or POJO, then, if provided pojo type is not {@code null} and not a {@link Tuple}, unmarshals + * the input as a pojo using the provided pojo type, otherwise unmarshals it as a {@link Tuple}. + * + * @param marshaller Optional marshaller to unmarshal the input. + * @param argumentHolder Argument holder. + * @param pojoType Pojo type to use when unmarshalling as a pojo. + * @param <T> Result type. + * @return Unmarshalled object. + */ + private static <T> @Nullable T unmarshalFromDataHolder( + @Nullable Marshaller<T, byte[]> marshaller, + ComputeJobDataHolder argumentHolder, + @Nullable Class<?> pojoType + ) { + Loggers.forClass(ComputeUtils.class).info("unmarshalFromDataHolder {}", argumentHolder.type()); + ComputeJobDataType type = argumentHolder.type(); + switch (type) { + case TUPLE: // Fallthrough TODO https://issues.apache.org/jira/browse/IGNITE-23320 + case POJO: + Tuple tuple = TupleWithSchemaMarshalling.unmarshal(argumentHolder.data()); + if (pojoType != null && pojoType != Tuple.class) { + return (T) unmarshalPojo(pojoType, tuple); + } + return (T) tuple; + case MARSHALLED_CUSTOM: + if (marshaller == null) { + throw new ComputeException(MARSHALLING_TYPE_MISMATCH_ERR, "Marshaller should be defined on the client"); + } + try { + return marshaller.unmarshal(argumentHolder.data()); + } catch (Exception ex) { + throw new ComputeException(MARSHALLING_TYPE_MISMATCH_ERR, "Exception in user-defined marshaller", ex); + } + default: Review Comment: ```suggestion default: ``` -- 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: notifications-unsubscr...@ignite.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org