This is an automated email from the ASF dual-hosted git repository.
ptupitsyn pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/ignite-3.git
The following commit(s) were added to refs/heads/main by this push:
new 344d25dd69 IGNITE-23285 Fix Mapper.nativelySupported (#4645)
344d25dd69 is described below
commit 344d25dd698f3946ded1ebcffec97da8b45e55e3
Author: Pavel Tupitsyn <[email protected]>
AuthorDate: Tue Oct 29 17:53:27 2024 +0200
IGNITE-23285 Fix Mapper.nativelySupported (#4645)
* Remove `BitSet` (not supported)
* List actual numeric types instead of using `Number` interface (which
includes a lot of unsupported types like `AtomicLong`)
---
.../org/apache/ignite/table/mapper/Mapper.java | 36 +++++++++++++---------
.../apache/ignite/table/mapper/MapperBuilder.java | 2 +-
.../internal/schema/marshaller/MapperTest.java | 9 +++---
3 files changed, 28 insertions(+), 19 deletions(-)
diff --git
a/modules/api/src/main/java/org/apache/ignite/table/mapper/Mapper.java
b/modules/api/src/main/java/org/apache/ignite/table/mapper/Mapper.java
index 64800ef068..94c53e40c9 100644
--- a/modules/api/src/main/java/org/apache/ignite/table/mapper/Mapper.java
+++ b/modules/api/src/main/java/org/apache/ignite/table/mapper/Mapper.java
@@ -17,11 +17,11 @@
package org.apache.ignite.table.mapper;
+import java.math.BigDecimal;
import java.time.Instant;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.LocalTime;
-import java.util.BitSet;
import java.util.Objects;
import java.util.UUID;
@@ -153,19 +153,27 @@ public interface Mapper<T> {
* @return {@code True} if the given type is supported natively and can be
mapped to a single column.
*/
static boolean nativelySupported(Class<?> type) {
- return !Objects.requireNonNull(type).isPrimitive()
- && (String.class == type
- || Boolean.class == type
- || UUID.class == type
- || BitSet.class == type
- || byte[].class == type
- || LocalDate.class == type
- || LocalTime.class == type
- || LocalDateTime.class == type
- || Instant.class == type
- || Void.class == type
- || Number.class
- .isAssignableFrom(type)); //
Byte, Short, Integer, Long, Float, Double, BigInteger, BigDecimal
+ //noinspection SimplifiableIfStatement
+ if (Objects.requireNonNull(type).isPrimitive()) {
+ return false;
+ }
+
+ return String.class == type
+ || Boolean.class == type
+ || UUID.class == type
+ || byte[].class == type
+ || LocalDate.class == type
+ || LocalTime.class == type
+ || LocalDateTime.class == type
+ || Instant.class == type
+ || Void.class == type
+ || BigDecimal.class == type
+ || Byte.class == type
+ || Short.class == type
+ || Integer.class == type
+ || Long.class == type
+ || Float.class == type
+ || Double.class == type;
}
/**
diff --git
a/modules/api/src/main/java/org/apache/ignite/table/mapper/MapperBuilder.java
b/modules/api/src/main/java/org/apache/ignite/table/mapper/MapperBuilder.java
index ba6c03779f..7bdf97dbad 100644
---
a/modules/api/src/main/java/org/apache/ignite/table/mapper/MapperBuilder.java
+++
b/modules/api/src/main/java/org/apache/ignite/table/mapper/MapperBuilder.java
@@ -96,7 +96,7 @@ public final class MapperBuilder<T> {
* @return {@code type} if it is a valid POJO.
* @throws IllegalArgumentException If {@code type} cannot be used as POJO
for mapping and/or is of invalid kind.
*/
- public <O> Class<O> ensureValidPojo(Class<O> type) {
+ private static <O> Class<O> ensureValidPojo(Class<O> type) {
if (Mapper.nativelySupported(type)) {
throw new IllegalArgumentException("Unsupported class. Can't map
fields of natively supported type: " + type.getName());
} else if (type.isAnonymousClass() || type.isLocalClass() ||
type.isSynthetic()
diff --git
a/modules/schema/src/test/java/org/apache/ignite/internal/schema/marshaller/MapperTest.java
b/modules/schema/src/test/java/org/apache/ignite/internal/schema/marshaller/MapperTest.java
index dd30b7c577..bf8eb0e813 100644
---
a/modules/schema/src/test/java/org/apache/ignite/internal/schema/marshaller/MapperTest.java
+++
b/modules/schema/src/test/java/org/apache/ignite/internal/schema/marshaller/MapperTest.java
@@ -23,12 +23,12 @@ import static org.junit.jupiter.api.Assertions.assertNull;
import static org.junit.jupiter.api.Assertions.assertThrows;
import java.math.BigDecimal;
-import java.math.BigInteger;
+import java.time.Instant;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.LocalTime;
import java.util.ArrayList;
-import java.util.BitSet;
+import java.util.UUID;
import java.util.function.Function;
import org.apache.ignite.internal.schema.testobjects.TestOuterObject;
import
org.apache.ignite.internal.schema.testobjects.TestOuterObject.NestedObject;
@@ -95,14 +95,15 @@ public class MapperTest {
Long.class,
Float.class,
Double.class,
- BigInteger.class,
BigDecimal.class,
- BitSet.class,
byte[].class,
String.class,
LocalDate.class,
LocalTime.class,
LocalDateTime.class,
+ Instant.class,
+ UUID.class,
+ Boolean.class
}) {
assertNull(((OneColumnMapper<?>) Mapper.of(c)).mappedColumn());