ptupitsyn commented on code in PR #2595:
URL: https://github.com/apache/ignite-3/pull/2595#discussion_r1331723170


##########
modules/marshaller-common/src/main/java/org/apache/ignite/internal/marshaller/Marshaller.java:
##########
@@ -64,16 +65,35 @@ public static <T> Marshaller createMarshaller(
      * @param mapper Mapper.
      * @return Marshaller.
      */
-    private static <T> SimpleMarshaller simpleMarshaller(MarshallerColumn[] 
cols, OneColumnMapper<T> mapper) {
-        final BinaryMode mode = MarshallerUtil.mode(mapper.targetType());
+    private static SimpleMarshaller simpleMarshaller(MarshallerColumn[] cols, 
OneColumnMapper<?> mapper) {
+        int colIdx = -1;
 
-        final MarshallerColumn col = cols[0];
+        if (mapper.mappedColumn() == null) {
+            if (cols.length != 1) {
+                throw new IllegalArgumentException(
+                        "Failed to map object to a single column, because 
schema contains more columns and no mapped columns were provided"
+                );
+            }
 
-        assert cols.length == 1;
-        assert mode == col.type() : "Target type is not compatible.";
-        assert !mapper.targetType().isPrimitive() : "Non-nullable types are 
not allowed.";
+            colIdx = 0;
+        } else {
+            for (int i = 0; i < cols.length; i++) {
+                if (cols[i].name().equals(mapper.mappedColumn())) {
+                    colIdx = i;
+                }
+            }
+
+            if (colIdx < 0) {
+                throw new IllegalArgumentException("Failed to map object to a 
single column:" + mapper.mappedColumn());

Review Comment:
   ```suggestion
                   throw new IllegalArgumentException("Failed to map object to 
a single column: mappedColumn '" + mapper.mappedColumn() + "' is not present in 
the schema.");
   ```



##########
modules/marshaller-common/src/main/java/org/apache/ignite/internal/marshaller/Marshaller.java:
##########
@@ -85,29 +105,36 @@ private static <T> SimpleMarshaller 
simpleMarshaller(MarshallerColumn[] cols, On
      * @param allowUnmappedFields Whether specified class can contain fields 
that are not mapped to columns.
      * @return Pojo marshaller.
      */
-    private static <T> PojoMarshaller pojoMarshaller(
+    private static PojoMarshaller pojoMarshaller(
             MarshallerColumn[] cols,
-            PojoMapper<T> mapper,
+            PojoMapper<?> mapper,
             boolean requireAllFields,
             boolean allowUnmappedFields) {
+        assert !mapper.targetType().isPrimitive() : "Non-nullable types are 
not allowed.";
+
         FieldAccessor[] fieldAccessors = new FieldAccessor[cols.length];
         int usedFields = 0;
 
         // Build handlers.
         for (int i = 0; i < cols.length; i++) {
-            final MarshallerColumn col = cols[i];
+            MarshallerColumn col = cols[i];
 
-            String fieldName = mapper.fieldForColumn(col.name());
+            String columnName = col.name();
 
-            if (requireAllFields && fieldName == null) {
-                throw new IllegalArgumentException("No field found for column 
" + col.name());
-            }
+            String fieldName = mapper.fieldForColumn(columnName);
 
-            fieldAccessors[i] = (fieldName == null) ? 
FieldAccessor.noopAccessor(col) :
-                    FieldAccessor.create(mapper.targetType(), fieldName, col, 
i);
+            if (fieldName == null) {
+                if (requireAllFields) {
+                    throw new IllegalArgumentException("No field found for 
column " + columnName);

Review Comment:
   ```suggestion
                       throw new IllegalArgumentException("No field found for 
column '" + columnName + "'");
   ```



##########
modules/marshaller-common/src/main/java/org/apache/ignite/internal/marshaller/Marshaller.java:
##########
@@ -64,16 +65,35 @@ public static <T> Marshaller createMarshaller(
      * @param mapper Mapper.
      * @return Marshaller.
      */
-    private static <T> SimpleMarshaller simpleMarshaller(MarshallerColumn[] 
cols, OneColumnMapper<T> mapper) {
-        final BinaryMode mode = MarshallerUtil.mode(mapper.targetType());
+    private static SimpleMarshaller simpleMarshaller(MarshallerColumn[] cols, 
OneColumnMapper<?> mapper) {
+        int colIdx = -1;
 
-        final MarshallerColumn col = cols[0];
+        if (mapper.mappedColumn() == null) {
+            if (cols.length != 1) {
+                throw new IllegalArgumentException(
+                        "Failed to map object to a single column, because 
schema contains more columns and no mapped columns were provided"
+                );
+            }
 
-        assert cols.length == 1;
-        assert mode == col.type() : "Target type is not compatible.";
-        assert !mapper.targetType().isPrimitive() : "Non-nullable types are 
not allowed.";
+            colIdx = 0;
+        } else {
+            for (int i = 0; i < cols.length; i++) {
+                if (cols[i].name().equals(mapper.mappedColumn())) {
+                    colIdx = i;
+                }
+            }
+
+            if (colIdx < 0) {
+                throw new IllegalArgumentException("Failed to map object to a 
single column:" + mapper.mappedColumn());
+            }
+        }
+
+        assert !mapper.targetType().isPrimitive() : "Non-nullable types are 
not allowed";

Review Comment:
   Should we change it to `IllegalArgumentException`? This can happen because 
of the user code, right?



##########
modules/marshaller-common/src/main/java/org/apache/ignite/internal/marshaller/Marshaller.java:
##########
@@ -64,16 +65,35 @@ public static <T> Marshaller createMarshaller(
      * @param mapper Mapper.
      * @return Marshaller.
      */
-    private static <T> SimpleMarshaller simpleMarshaller(MarshallerColumn[] 
cols, OneColumnMapper<T> mapper) {
-        final BinaryMode mode = MarshallerUtil.mode(mapper.targetType());
+    private static SimpleMarshaller simpleMarshaller(MarshallerColumn[] cols, 
OneColumnMapper<?> mapper) {
+        int colIdx = -1;
 
-        final MarshallerColumn col = cols[0];
+        if (mapper.mappedColumn() == null) {
+            if (cols.length != 1) {
+                throw new IllegalArgumentException(
+                        "Failed to map object to a single column, because 
schema contains more columns and no mapped columns were provided"

Review Comment:
   ```suggestion
                           "Failed to map object to a single column: schema 
contains " + cols.length + "columns, mappedColumn is null"
   ```



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