You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@flink.apache.org by "Dawid Wysakowicz (Jira)" <ji...@apache.org> on 2020/03/02 14:33:00 UTC
[jira] [Commented] (FLINK-16385) Use LinkedHashMap in
SqlFunctionUtils.java
[ https://issues.apache.org/jira/browse/FLINK-16385?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17049254#comment-17049254 ]
Dawid Wysakowicz commented on FLINK-16385:
------------------------------------------
Hi [~cpugputpu] I've seen you open a few similar tasks. I don't think it is a good solution to fix production code in order for the tests to pass. We should first check if it makes sense to require strict order in those cases. My gut feeling is we should rather fix tests.
> Use LinkedHashMap in SqlFunctionUtils.java
> ------------------------------------------
>
> Key: FLINK-16385
> URL: https://issues.apache.org/jira/browse/FLINK-16385
> Project: Flink
> Issue Type: Test
> Components: Table SQL / Runtime
> Reporter: cpugputpu
> Priority: Minor
>
> The tests in _org.apache.flink.table.planner.expressions.ScalarFunctionsTest#testStringToMap_ can fail due to a different iteration order of a HashMap. The failure is presented as follows.
> [ERROR] testStringToMap(org.apache.flink.table.planner.expressions.ScalarFunctionsTest)
> org.junit.ComparisonFailure: Wrong result for: [STR_TO_MAP(f46)] optimized to: [STR_TO_MAP($46)]
> expected:<\{test1=1, test2=2, test3=3}> but was:<\{test2=2, test1=1, test3=3}>
>
> The root cause of this failure lies in a HashMap initialized in _flink-table/flink-table-runtime-blink/src/main/java/org/apache/flink/table/runtime/functions/SqlFunctionUtils.java_ and a brief stack trace of the HashMap's iterator is presented for your reference:
> _java.util.HashMap$EntrySet.iterator(HashMap.java:1014)_
> _org.apache.flink.table.dataformat.DataFormatConverters$MapConverter.toBinaryMap(DataFormatConverters.java:1174)_
> _org.apache.flink.table.dataformat.DataFormatConverters$MapConverter.toInternalImpl(DataFormatConverters.java:1157)_
> _org.apache.flink.table.dataformat.DataFormatConverters$MapConverter.toInternalImpl(DataFormatConverters.java:1114)_
> _org.apache.flink.table.dataformat.DataFormatConverters$DataFormatConverter.toInternal(DataFormatConverters.java:290)_
> _TestFunction$144.map(Unknown Source)_
> _org.apache.flink.table.planner.expressions.utils.ExpressionTestBase.evaluateExprs(ExpressionTestBase.scala:152)_
>
> The specification about HashMap says that "this class makes no guarantees as to the order of the map; in particular, it does not guarantee that the order will remain constant over time". The documentation is here for your reference: https://docs.oracle.com/javase/8/docs/api/java/util/HashMap.html
>
> The fix is to use LinkedHashMap instead of HashMap. In this way, the test will not suffer from the failure any more and the code will be more stable, free of this non-deterministic behaviour.
>
>
--
This message was sent by Atlassian Jira
(v8.3.4#803005)