【问题标题】:Hbase table populated with value=\x00\x00\x00\x00\x00\x00\x00\x00 from scala code使用 scala 代码中的 value=\x00\x00\x00\x00\x00\x00\x00\x00 填充的 Hbase 表
【发布时间】:2017-06-02 09:56:59
【问题描述】:

当我尝试通过 scala 程序将一列作为 Double 的 Row 键放入 Hbase 表中时,我在输出文件(Hbase 表)中看到这种 32 位表示。这完全停止了我的工作。

请告知我们如何在 Hbase 表中获得“双”类型字段的正确表示。

与此相关的代码如下:我在这里遗漏了什么吗?

VarValue_Output: Double
p(3).toDouble
final val colVarValueBytes = Bytes.toBytes("VarValue_Output")
put.add(cfDataBytes, colVarValueBytes, Bytes.toBytes(Data.VarValue_Output)

谢谢 Vijaya Kumar Pabothu

【问题讨论】:

    标签: hbase


    【解决方案1】:

    这是预期的行为。 您已经保存了 Double 数据类型,但是 HBase shell(我假设您正在使用它)对此一无所知(HBase 中的所有内容都表示为字节数组)。因此,默认情况下,它会尝试从您的字节数组中提取字符串,并且显然会显示一些无信息的 unicode 符号列表:

    Bytes.toBytes("15.0") 不等于 Bytes.toBytes(15.0)

    1. 尝试将其保存为字符串,转换为字节数组(您将能够在基本 shell 中读取)
    2. 从您的应用程序中读取它,并确保您正在转换您的列值Bytes.toDouble

    【讨论】:

    • 请看我下面的代码,请指教我哪里做错了。
    • def convertToPut(sensor: Sensor): (ImmutableBytesWritable, Put) = { val dateTime = sensor.TimeStamp_Output val rowkey = sensor.ToolName_Output + "_" + dateTime val put = new Put(Bytes.toBytes (rowkey)) put.add(cfDataBytes, colLookupBytes, Bytes.toBytes(sensor.Lookup)) put.add(cfDataBytes, colVarNameBytes, Bytes.toBytes(sensor.VarName_Output)) put.add(cfDataBytes, colVarValueBytes, Bytes.toBytes( sensor.VarValue_Output)) return (new ImmutableBytesWritable(Bytes.toBytes(rowkey)), put) }
    • 定义--final val colVarValueBytes = Bytes.toBytes("VarValue_Output")
    • 案例类 Sensor(Lookup: String, ToolName_Output: String,VarName_Output: String, VarValue_Output:Double , TimeStamp_Output: String)
    • object Sensor extends Serializable { def parseSensor(str: String): Sensor = { val p = str.split(",") Sensor(p(0), p(1), p(2 ), p(3).toDouble, p(4)) }
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2012-07-09
    • 1970-01-01
    • 1970-01-01
    • 2023-03-16
    • 1970-01-01
    • 2019-09-25
    • 2021-11-10
    相关资源
    最近更新 更多