diff --git a/modules/calcite/src/main/java/org/apache/ignite/internal/processors/query/calcite/schema/CacheTableDescriptorImpl.java b/modules/calcite/src/main/java/org/apache/ignite/internal/processors/query/calcite/schema/CacheTableDescriptorImpl.java index f4557df7dfb66..1f9cfd858df6e 100644 --- a/modules/calcite/src/main/java/org/apache/ignite/internal/processors/query/calcite/schema/CacheTableDescriptorImpl.java +++ b/modules/calcite/src/main/java/org/apache/ignite/internal/processors/query/calcite/schema/CacheTableDescriptorImpl.java @@ -644,8 +644,8 @@ private boolean isOwner(UUID nodeId, GridDhtPartitionTopology top, int parts) { /** */ private static Object unwrap(Object val, GridCacheContext cctx, boolean keepBinary) { - // Fast path: simple values have nothing to unwrap. - if (val == null || QueryUtils.isSqlType(val.getClass())) + // Fast path: simple values have nothing to unwrap. Numbers and strings skip the lookup among SQL types. + if (val == null || val instanceof Number || val instanceof String || QueryUtils.isSqlType(val.getClass())) return val; return cctx.unwrapBinaryIfNeeded(val, keepBinary, null); diff --git a/modules/calcite/src/main/java/org/apache/ignite/internal/processors/query/calcite/util/TypeUtils.java b/modules/calcite/src/main/java/org/apache/ignite/internal/processors/query/calcite/util/TypeUtils.java index 5383556de7b98..8a734cc88932c 100644 --- a/modules/calcite/src/main/java/org/apache/ignite/internal/processors/query/calcite/util/TypeUtils.java +++ b/modules/calcite/src/main/java/org/apache/ignite/internal/processors/query/calcite/util/TypeUtils.java @@ -458,9 +458,16 @@ public static boolean hasScale(RelDataType type) { /** */ public static @Nullable Object toInternal(DataContext ctx, @Nullable Object val, Type storageType) { - if (val == null) - return null; - else if (storageType == java.sql.Date.class) + // Fast path: numbers and strings of the storage type are kept as is. The method is small to be inlined. + if (val == null || storageType == val.getClass() && (val instanceof Number || val instanceof String)) + return val; + + return toInternal0(ctx, val, storageType); + } + + /** */ + private static Object toInternal0(DataContext ctx, Object val, Type storageType) { + if (storageType == java.sql.Date.class) return (int)(toLong(ctx, val) / DateTimeUtils.MILLIS_PER_DAY); else if (storageType == LocalDate.class) return (int)(toLong(ctx, val) / DateTimeUtils.MILLIS_PER_DAY);