From 43ace08fae1f8a8ef7c8d640fb93fc0e5884189f Mon Sep 17 00:00:00 2001 From: Chris Dennis Date: Wed, 11 Dec 2024 15:29:24 -0500 Subject: [PATCH] [CALCITE-6729] Ensure TypedValue allows sub-types for local representations --- .../org/apache/calcite/avatica/remote/TypedValue.java | 2 +- .../apache/calcite/avatica/remote/TypedValueTest.java | 10 ++++++++++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/core/src/main/java/org/apache/calcite/avatica/remote/TypedValue.java b/core/src/main/java/org/apache/calcite/avatica/remote/TypedValue.java index 142a06b319..88506fcfab 100644 --- a/core/src/main/java/org/apache/calcite/avatica/remote/TypedValue.java +++ b/core/src/main/java/org/apache/calcite/avatica/remote/TypedValue.java @@ -269,7 +269,7 @@ public Object toLocal() { * representation. */ private static Object serialToLocal(ColumnMetaData.Rep rep, Object value) { assert value != null; - if (value.getClass() == rep.clazz) { + if (rep.clazz.isInstance(value)) { return value; } switch (rep) { diff --git a/core/src/test/java/org/apache/calcite/avatica/remote/TypedValueTest.java b/core/src/test/java/org/apache/calcite/avatica/remote/TypedValueTest.java index 335fa8a1a1..cce081ddef 100644 --- a/core/src/test/java/org/apache/calcite/avatica/remote/TypedValueTest.java +++ b/core/src/test/java/org/apache/calcite/avatica/remote/TypedValueTest.java @@ -44,6 +44,7 @@ import static org.hamcrest.CoreMatchers.instanceOf; import static org.hamcrest.CoreMatchers.is; +import static org.hamcrest.CoreMatchers.sameInstance; import static org.junit.Assert.assertArrayEquals; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNotNull; @@ -266,6 +267,15 @@ private void serializeAndEqualityCheck(TypedValue value) { Object localObjCopy = tv1Copy.toLocal(); assertTrue("The local object is an " + localObjCopy.getClass(), localObjCopy instanceof List); } + + @Test public void testObjects() { + Object o1 = "This is a string"; + TypedValue tv1 = TypedValue.ofJdbc(Rep.OBJECT, o1, Unsafe.localCalendar()); + Object jdbcObj = tv1.toJdbc(Unsafe.localCalendar()); + assertThat(jdbcObj, is(sameInstance(o1))); + Object localObj = tv1.toLocal(); + assertThat(jdbcObj, is(sameInstance(o1))); + } } // End TypedValueTest.java