Uploaded image for project: 'Flink'
  1. Flink
  2. FLINK-3698

Scala Option can't be used as a key

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Minor
    • Resolution: Duplicate
    • None
    • None
    • None
    • None

    Description

      Discussion: http://mail-archives.apache.org/mod_mbox/flink-user/201603.mbox/%3CCAO0MGUjWQaovvUvAB%3DBYrwQzA0ocFtMy4%3DV%3DP--343Sy1V5BSg%40mail.gmail.com%3E

      Option should be treated the same way as other generic objects where it can be used as a key if generic argument implements Comparable.
      Here's a scalatest in FunSpec format that illustrates the issue:
      ```
      case class MyKey(x: Option[String])

      it("can't use options inside classes used as keys") {
      val a = env.fromCollection(Seq(MyKey(Some("a")), MyKey(Some("c"))))
      val b = env.fromCollection(Seq(MyKey(Some("a")), MyKey(Some("z"))))
      intercept[InvalidProgramException]

      { a.coGroup(b) .where(e => e) .equalTo(e => e) }

      // workaround
      a.coGroup(b)
      .where(e => e.toString) // `e` should be translated to any object that implements Comparable interface to be a valid key.
      .equalTo(e => e.toString)
      }
      ```

      Attachments

        Issue Links

          Activity

            People

              chiwanpark Chiwan Park
              timur.fairuzov@gmail.com Timur Fayruzov
              Votes:
              0 Vote for this issue
              Watchers:
              3 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: