Skip to content

Commit c733f0d

Browse files
Madhavanclaude
andcommitted
fix(connector): type assertGenericMap keys as Object for shaded/non-shaded Avro
Follow-up to the testSchema Avro tolerance fix. After normalizing non-shaded Avro arrays to shaded, testSchema failed one layer deeper at assertGenericMap: ClassCastException: org.apache.avro.util.Utf8 cannot be cast to org.apache.pulsar.shade.org.apache.avro.util.Utf8 A map column (e.g. map<text,double>) comes back from Pulsar as a plain java.util.Map whose keys are non-shaded Avro Utf8. The parameter type Map<Utf8,Object> (shaded Utf8) made the compiler insert a checkcast to the shaded Utf8 on getKey(), which threw even though keys are compared via toString(). Type the parameter as Map<Object,Object> (as assertMapsEqual already does) so no checkcast is inserted. Top-level maps (ymap, ymapoftuple) are the only ones needing this -- maps nested inside arrays (e.g. zmap inside ysetofudt) are already converted to shaded by the binary round-trip in normalizeToShadedAvro. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
1 parent e2e67b0 commit c733f0d

1 file changed

Lines changed: 5 additions & 1 deletion

File tree

connector/src/test/java/com/datastax/oss/pulsar/source/PulsarCassandraSourceTests.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -760,7 +760,11 @@ public void testSchema(String ksName) throws InterruptedException, IOException {
760760
}
761761
}
762762

763-
void assertGenericMap(String field, Map<Utf8, Object> gm) {
763+
// Keys are typed as Object (not the shaded Utf8): a map column value comes back from Pulsar as a
764+
// plain java.util.Map whose keys may be non-shaded Avro Utf8, and a Map<Utf8,Object> parameter
765+
// would make the compiler insert a checkcast to the shaded Utf8 on getKey() that throws. Keys are
766+
// compared via toString() to tolerate either Avro flavor.
767+
void assertGenericMap(String field, Map<Object, Object> gm) {
764768
switch (field) {
765769
case "map":
766770
log.debug("field={} gm={}", field, gm);

0 commit comments

Comments
 (0)