0
votes

The code below throws the following error: type mismatch; found : scala.collection.mutable.Buffer[scala.collection.immutable.Map[String,String]] required: Map[String,String]

def getRecordsByRegExp(table: String, family: String, regExp: String): Future[Seq[SomeClass]] = {
    val scanner = hBaseClient.newScanner(table)

    scanner.setFamily(family)
    scanner.setFilter(new KeyRegexpFilter(regExp))

    scanner.nextRows.map(arrayList =>
      arrayList.flatten.map(x =>
        Record(
          table,
          new String(x.key),
          arrayList.map(keyValues =>
            keyValues.map(kv => new String(kv.qualifier) -> new String(kv.value)).toMap))))

  }

SomeClass definition: SomeClass(table: String, key: String, values: Map[String, String])

Any tips on how to get over this?

Later edit: added all the code

2
what is the type of scanner?Till Rohrmann
do you want to construct the map over all elements in arrayList? If so, then you should probably call first arrayList.flatten before applying the map call where you create the Map. If not, then you should select the element of arrayList for which you want to construct the Map.Till Rohrmann
You might make this easier to debug for yourself by breaking this into multiple functions with type annotations.Daenyth
@TillRohrmann scanner is of type org.hbase.async.Scanner. It's from the asynchbase client.anghel adrian
@TillRohrmann yes, I want to construct the map over all elements in arrayList. But since table and key is the same for all the elements I first tought to flatten the arraylist to get the key, and then creating the Map by calling arrayList.mapanghel adrian

2 Answers

0
votes

Thanks to Till, I also made it work with:

scanner.nextRows.map(arrayList =>
      arrayList.flatten.map(x =>
        SomeClass(
          table,
          new String(x.key),
          Map(new String(x.qualifier) -> new String(x.value)))))
0
votes

If I understood it correctly, then this could solve your problem:

scanner.nextRows.map{
  arrayList =>
    val map = arrayList.flatten.map{
      kv =>
        new String(kv.qualifier) -> new String(kv.value)
    }.toMap
    arrayList.flatten.map{
      x =>
      SomeClass(
        table,
        new String(x.key),
        map)
    }
}