Insert Json into Hbase as JSON - Scala

后端 未结 1 404
栀梦
栀梦 2021-01-29 02:07

I would like to insert a json object into a Hbase cellusing scala, presently i\'m able to insert values using the below code but would like to know how i may be able to insert t

相关标签:
1条回答
  • 2021-01-29 02:37

    You can encode your json object as a string. then encode this string as byte array. then put this byte array in Hbase. pseudo code will be like this:

    json = createYourJson()
    jsonString = json.toString
    jsonBytyes = Bytes.toBytes(jsonString)
    put.add(yourColumnFamily, yourQualifier, jsonBytes)
    

    and when loading the value from hbase you have to reverse this order. Pseudo code will be like this:

    jsonBytes = hbase.get(table, columnFamily, qualifier)
    jsonString = Bytes.toString(jsonBytes)
    json = Json.parse(jsonString)
    
    0 讨论(0)
提交回复
热议问题