gpt4 book ai didi

hadoop - Hbase:需要适合cloudera-quickstart-vm-5.4.2-0的jar文件

转载 作者:行者123 更新时间:2023-12-02 21:36:02 25 4
gpt4 key购买 nike

我正在尝试通过API将数据从平面文件加载到Hbase,但是出现以下错误
================================================== ======
java.lang.NumberFormatException.forInputString
(NumberFormatException.java:65)
在java.lang.Integer.parseInt(Integer.java:492)
在java.lang.Integer.parseInt(Integer.java:527)
在org.apache.hadoop.hbase.HServerAddress。(HServerAddress.java:63)
在org.apache.hadoop.hbase.MasterAddressTracker.getMasterAddress(MasterAddressTracker.java:63)
在org.apache.hadoop.hbase.client.HConnectionManager $ HConnectionImplementation.getMaster(HConnectionManager.java:354)
在org.apache.hadoop.hbase.client.HBaseAdmin。(HBaseAdmin.java:94)
在Hbase.readFromFile.main(readFromFile.java:16)

代码:

     package Hbase;

import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import java.io.IOException;
import java.util.StringTokenizer;

import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.hbase.HBaseConfiguration;
import org.apache.hadoop.hbase.HColumnDescriptor;
import org.apache.hadoop.hbase.HTableDescriptor;
import org.apache.hadoop.hbase.client.HBaseAdmin;
import org.apache.hadoop.hbase.client.HTable;
import org.apache.hadoop.hbase.client.Put;
import org.apache.hadoop.hbase.util.Bytes;


public class readFromFile {
public static void main(String[] args) throws IOException{
if(args.length==1)
{
Configuration conf = HBaseConfiguration.create(new Configuration());
HBaseAdmin hba = new HBaseAdmin(conf);
if(!hba.tableExists(args[0])){
HTableDescriptor ht = new HTableDescriptor(args[0]);
ht.addFamily(new HColumnDescriptor("sample"));
ht.addFamily(new HColumnDescriptor("region"));
ht.addFamily(new HColumnDescriptor("time"));
ht.addFamily(new HColumnDescriptor("product"));
ht.addFamily(new HColumnDescriptor("sale"));
ht.addFamily(new HColumnDescriptor("profit"));
hba.createTable(ht);
System.out.println("New Table Created");

HTable table = new HTable(conf,args[0]);

File f = new File("/home/training/Desktop/data");
BufferedReader br = new BufferedReader(new FileReader(f));
String line = br.readLine();
int i =1;
String rowname="row";
while(line!=null && line.length()!=0){
System.out.println("Ok till here");
StringTokenizer tokens = new StringTokenizer(line,",");
rowname = "row"+i;
Put p = new Put(Bytes.toBytes(rowname));
p.add(Bytes.toBytes("sample"),Bytes.toBytes("sampleNo."),
Bytes.toBytes(Integer.parseInt(tokens.nextToken())));
p.add(Bytes.toBytes("region"),Bytes.toBytes("country"),
Bytes.toBytes(tokens.nextToken()));
p.add(Bytes.toBytes("region"),Bytes.toBytes("state"),
Bytes.toBytes(tokens.nextToken()));
p.add(Bytes.toBytes("region"),Bytes.toBytes("city"),
Bytes.toBytes(tokens.nextToken()));
p.add(Bytes.toBytes("time"),Bytes.toBytes("year"),
Bytes.toBytes(Integer.parseInt(tokens.nextToken())));
p.add(Bytes.toBytes("time"),Bytes.toBytes("month"),
Bytes.toBytes(tokens.nextToken()));
p.add(Bytes.toBytes("product"),Bytes.toBytes("productNo."),
Bytes.toBytes(tokens.nextToken()));
p.add(Bytes.toBytes("sale"),Bytes.toBytes("quantity"),
Bytes.toBytes(Integer.parseInt(tokens.nextToken())));
p.add(Bytes.toBytes("profit"),Bytes.toBytes("earnings"),
Bytes.toBytes(tokens.nextToken()));
i++;
table.put(p);
line = br.readLine();
}
br.close();
table.close();
}
else
System.out.println("Table Already exists.
Please enter another table name");
}
else
System.out.println("Please Enter the table
name through command line");
}
}

请让我知道我们是否需要添加任何合适的jar ..我正在使用cloudera cloudera-quickstart-vm-5.4.2-0

谢谢,
VJ

最佳答案

如果阅读此错误,则表明Integer.parseInt方法引发了NumberFormatException。这意味着您试图将无效格式的字符串转换为Integer。在代码中,您可以在以下行中调用该方法:
Bytes.toBytes(Integer.parseInt(tokens.nextToken())));
您需要查看通过tokens.nextToken()传递给此方法的 token ,并确保每个 token 都可以转换为Integer。

关于hadoop - Hbase:需要适合cloudera-quickstart-vm-5.4.2-0的jar文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32147560/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com