【问题标题】:access hbase table from java从java访问hbase表
【发布时间】:2012-03-08 09:25:55
【问题描述】:

我在 hbase 中创建了一个表,每行有 12 列,每列有 8 个限定符。当我尝试读取完整行时,它在第 1 行返回正确的 1:1 值,但对于 1:2 返回 null 它正确读取了从 2 到 10 的所有列...... 请帮助如何解决这个问题 我正在使用此代码进行阅读....它在 for 循环中运行,从 1 到 12..

train[0][i] = Double.parseDouble(Bytes.toString (r.getValue(Bytes.toBytes(Integer.toString(i)), Bytes.toBytes("1"))));
train[1][i] = Double.parseDouble (Bytes.toString (r.getValue(Bytes.toBytes(Integer.toString(i)), Bytes.toBytes("2"))));
train[2][i] = Double.parseDouble (Bytes.toString (r.getValue(Bytes.toBytes(Integer.toString(i)), Bytes.toBytes("3"))));
System.out.println("train" + i + ": " + train[2][i]);
train[3][i] = Double.parseDouble (Bytes.toString (r.getValue(Bytes.toBytes(Integer.toString(i)), Bytes.toBytes("4"))));
train[4][i] = Double.parseDouble (Bytes.toString (r.getValue(Bytes.toBytes(Integer.toString(i)), Bytes.toBytes("5"))));
train[5][i] = Double.parseDouble (Bytes.toString (r.getValue(Bytes.toBytes(Integer.toString(i)), Bytes.toBytes("6"))));


train[6][i] = Double.parseDouble (Bytes.toString (r.getValue(Bytes.toBytes(Integer.toString(i)), Bytes.toBytes("7"))));
train[7][i] = Double.parseDouble (Bytes.toString (r.getValue(Bytes.toBytes(Integer.toString(i)), Bytes.toBytes("8"))));

【问题讨论】:

    标签: hbase


    【解决方案1】:

    我认为没有任何理由将此数据放入多个列族。看来您可以将它们全部放在一列中并使用像“i_j”这样的寻址方案,其中 i 和 j 被您的索引替换。将事物放入多个列族的问题是每个列族都有自己的存储文件,因此会占用更多的集群资源。还可以考虑为列族名称使用最小字节数。

    如果不查看将数据插入表中的代码以及从表中检索数据的完整代码,则无法诊断此处的问​​题。当然,你不需要如此无端地重复台词。尝试一些更简单的方法,例如:

    byte[] column_family = Bytes.toBytes("a");
    for (int i = 0; i < MAX_I; i++) {
      for (int j = 0; j < MAX_J; j++) {
        train[i][j] = Double.parseDouble(Bytes.toString(r.getValue(column_family, Bytes.toBytes(i+"_"+j);
        System.out.println("train["+i+"]["+j+"]: "+train[i][j]);
      }
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2023-04-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-07-19
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多