Skip to content

Commit eccf644

Browse files
chrisdennismihaibudiu
authored andcommitted
[CALCITE-6729] Ensure TypedValue allows sub-types for local representations
1 parent 2baa36e commit eccf644

File tree

2 files changed

+11
-1
lines changed

2 files changed

+11
-1
lines changed

core/src/main/java/org/apache/calcite/avatica/remote/TypedValue.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -269,7 +269,7 @@ public Object toLocal() {
269269
* representation. */
270270
private static Object serialToLocal(ColumnMetaData.Rep rep, Object value) {
271271
assert value != null;
272-
if (value.getClass() == rep.clazz) {
272+
if (rep.clazz.isInstance(value)) {
273273
return value;
274274
}
275275
switch (rep) {

core/src/test/java/org/apache/calcite/avatica/remote/TypedValueTest.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@
4444

4545
import static org.hamcrest.CoreMatchers.instanceOf;
4646
import static org.hamcrest.CoreMatchers.is;
47+
import static org.hamcrest.CoreMatchers.sameInstance;
4748
import static org.junit.Assert.assertArrayEquals;
4849
import static org.junit.Assert.assertEquals;
4950
import static org.junit.Assert.assertNotNull;
@@ -266,6 +267,15 @@ private void serializeAndEqualityCheck(TypedValue value) {
266267
Object localObjCopy = tv1Copy.toLocal();
267268
assertTrue("The local object is an " + localObjCopy.getClass(), localObjCopy instanceof List);
268269
}
270+
271+
@Test public void testObjects() {
272+
Object o1 = "This is a string";
273+
TypedValue tv1 = TypedValue.ofJdbc(Rep.OBJECT, o1, Unsafe.localCalendar());
274+
Object jdbcObj = tv1.toJdbc(Unsafe.localCalendar());
275+
assertThat(jdbcObj, is(sameInstance(o1)));
276+
Object localObj = tv1.toLocal();
277+
assertThat(jdbcObj, is(sameInstance(o1)));
278+
}
269279
}
270280

271281
// End TypedValueTest.java

0 commit comments

Comments
 (0)