TsReaper commented on a change in pull request #8682: [FLINK-12796][table-planner-blink] Introduce BaseArray and BaseMap to reduce conversion overhead to blink URL: https://github.com/apache/flink/pull/8682#discussion_r300528464
########## File path: flink-table/flink-table-planner-blink/src/main/scala/org/apache/flink/table/codegen/calls/ScalarOperatorGens.scala ########## @@ -1900,8 +1932,72 @@ object ScalarOperatorGens { args => val leftTerm = args.head val rightTerm = args(1) + val resultTerm = newName("compareResult") - val stmt = s"boolean $resultTerm = $leftTerm.equals($rightTerm);" + val binaryMapCls = classOf[BinaryMap].getCanonicalName + + val mapType = left.resultType.asInstanceOf[MapType] + val mapCls = classOf[java.util.Map[AnyRef, AnyRef]].getCanonicalName + val keyCls = boxedTypeTermForType(mapType.getKeyType) + val valueCls = boxedTypeTermForType(mapType.getValueType) + + val leftMapTerm = newName("leftMap") + val leftKeyTerm = newName("leftKey") + val leftValueTerm = newName("leftValue") + val leftValueNullTerm = newName("leftValueIsNull") + val leftValueExpr = + GeneratedExpression(leftValueTerm, leftValueNullTerm, "", mapType.getValueType) + + val rightMapTerm = newName("rightMap") + val rightValueTerm = newName("rightValue") + val rightValueNullTerm = newName("rightValueIsNull") + val rightValueExpr = + GeneratedExpression(rightValueTerm, rightValueNullTerm, "", mapType.getValueType) + + val entryTerm = newName("entry") + val entryCls = classOf[java.util.Map.Entry[AnyRef, AnyRef]].getCanonicalName + val valueEqualsExpr = generateEquals(ctx, leftValueExpr, rightValueExpr) + + val internalTypeCls = classOf[LogicalType].getCanonicalName + val keyTypeTerm = + ctx.addReusableObject(mapType.getKeyType, "keyType", internalTypeCls) + val valueTypeTerm = + ctx.addReusableObject(mapType.getValueType, "valueType", internalTypeCls) + + val stmt = + s""" + |boolean $resultTerm; + |if ($leftTerm instanceof $binaryMapCls && $rightTerm instanceof $binaryMapCls) { + | $resultTerm = $leftTerm.equals($rightTerm); + |} else { + | if ($leftTerm.numElements() == $rightTerm.numElements()) { + | $resultTerm = true; + | $mapCls $leftMapTerm = $leftTerm.toJavaMap($keyTypeTerm, $valueTypeTerm); + | $mapCls $rightMapTerm = $rightTerm.toJavaMap($keyTypeTerm, $valueTypeTerm); + | Review comment: Is it possible to first compare the classes of `leftMapTerm` and `rightMapTerm`? If they are equal, just use the `equals` method of Java maps, otherwise compare the keys and values one by one. ---------------------------------------------------------------- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. For queries about this service, please contact Infrastructure at: us...@infra.apache.org With regards, Apache Git Services