Repository navigation
[FLINK-41780][table] Map element access fails with ClassCastException for a MapData that is neither BinaryMapData nor GenericMapData - #30233
Conversation
…n` for a `MapData` that is neither `BinaryMapData` nor `GenericMapData`
rionmonster
left a comment
There was a problem hiding this comment.
Fix overall seems sound/reasonable (I pulled things down and was able to confirm it went red/green as it relates to the fix). I've added a optional proposed test to exercise another path that reproduces the exact same exception.
I'm good with approving, let me know what you think.
| .build()) | ||
| .runSql( | ||
| "INSERT INTO sink_t SELECT " | ||
| + "MAP_FROM_ENTRIES(ARRAY[ROW('a', CAST(x AS STRING))])['a'] FROM t") |
There was a problem hiding this comment.
As far as I can tell, this should fix the function-returned map case (since the previous deep-copy version fails as expected). I pulled some threads and I think it could be useful to exercise a case where we receive a map as an input column. Claude seemed to think we could add this to ParquetFileSystemITCase which passes (and fails with the exact ColumnarMapData cannot be cast to GenericMapData, exception before this fix):
@TestTemplate
void testMapElementAccess() throws Exception {
String path = TempDirUtils.newFolder(super.fileTempFolder()).toURI().getPath();
super.tableEnv()
.executeSql(
String.format(
"create table map_t ("
+ "id int,"
+ "m map<string, string>"
+ ") with ("
+ "'connector' = 'filesystem',"
+ "'path' = '%s',"
+ "'format' = 'parquet'"
+ ")",
path));
super.tableEnv()
.executeSql("insert into map_t values (1, map['a', 'x']), (2, map['b', 'y'])")
.await();
// the map reaches the Calc as ColumnarMapData; the second row covers a missing key
check(
"select id, m['a'] from map_t",
Arrays.asList(Row.of(1, "x"), Row.of(2, null)));
}
Thoughts on that? If that's overkill, then would it be worth including this same program in the batch suite of tests in CalcBatchSemanticTests
There was a problem hiding this comment.
I don't think it would change anything
the reason is that we don't cover anything else in codegen with this test
What is the purpose of the change
The PR fixes behavior for the case of
MapDatathat is neitherBinaryMapDatanorGenericMapDataBrief change log
codegen
Verifying this change
failing test added
Does this pull request potentially affect one of the following parts:
@Public(Evolving): ( no)Documentation
Was generative AI tooling used to co-author this PR?
Generated-by: [Tool Name and Version]