Skip to content

Commit

Permalink
[CALCITE-6729] Ensure TypedValue allows sub-types for local represent…
Browse files Browse the repository at this point in the history
…ations
  • Loading branch information
chrisdennis committed Dec 12, 2024
1 parent 2baa36e commit 43ace08
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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

0 comments on commit 43ace08

Please sign in to comment.