我对 HDP 很陌生,我想创建一个包含多列的 hbase 表,并从 csv 文件加载数据,如下所示
如您所见,我有每个示例列族“信息人员”,其中包含多个列,例如“nom”“prenom”等。
所以我的问题是: - 如何在 hdp 沙箱上使用 java api 创建表 hbase?- 如何从我的 csv 文件中加载数据?
ps:我尝试创建表,但我不知道如何在沙盒上运行它?把我的java类放在哪里?我需要配置一些东西吗?
这是我的代码
import java.io.IOException;
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.TableName;
import org.apache.hadoop.conf.Configuration;
public class CreateTable {
public static void main(String[] args) throws IOException {
// Instantiating configuration class
Configuration con = HBaseConfiguration.create();
con.set("hbase.zookeeper.property.clientPort", "2181");
con.set("hbase.zookeeper.quorum", "hortonworks.hbase.vm");
con.set("zookeeper.znode.parent", "/hbase-unsecure");
System.out.println("HBase is running!");
// Instantiating HbaseAdmin class
HBaseAdmin admin = new HBaseAdmin(con);
// Instantiating table descriptor class
HTableDescriptor tableDescriptor = new
TableDescriptor(TableName.valueOf("competence"));
// Adding column families to table descriptor
tableDescriptor.addFamily(new HColumnDescriptor("Infos_collaborateur"));
tableDescriptor.addFamily(new HColumnDescriptor("Infos_Rh"));
tableDescriptor.addFamily(new HColumnDescriptor("Savoir_faire"));
tableDescriptor.addFamily(new HColumnDescriptor("Savoir_etre"));
tableDescriptor.addFamily(new HColumnDescriptor("Langues"));
tableDescriptor.addFamily(new HColumnDescriptor("Java:Developpement/Librairies/API/Frameworks/CMS"));
tableDescriptor.addFamily(new HColumnDescriptor("PHP/Frameworks"));
tableDescriptor.addFamily(new HColumnDescriptor("Techno_Web/Frameworks"));
tableDescriptor.addFamily(new HColumnDescriptor("Autres"));
tableDescriptor.addFamily(new HColumnDescriptor("ERP:Language/Outils"));
tableDescriptor.addFamily(new HColumnDescriptor("Mobile:natif"));
tableDescriptor.addFamily(new HColumnDescriptor("Mobile:Cross"));
tableDescriptor.addFamily(new HColumnDescriptor("Infographie/creas"));
tableDescriptor.addFamily(new HColumnDescriptor("Outils_de_developpement/Software"));
tableDescriptor.addFamily(new HColumnDescriptor("Analytics"));
tableDescriptor.addFamily(new HColumnDescriptor("Outils_Microsoft"));
tableDescriptor.addFamily(new HColumnDescriptor("Developpements/Librairies"));
tableDescriptor.addFamily(new HColumnDescriptor("BaseDeDonnees/FluxDeDonnees"));
tableDescriptor.addFamily(new HColumnDescriptor("Windows:SystemeDexploitation/serveur"));
tableDescriptor.addFamily(new HColumnDescriptor("AutresOS"));
tableDescriptor.addFamily(new HColumnDescriptor("Plateforms"));
tableDescriptor.addFamily(new HColumnDescriptor("Serveur_web_parametrage"));
tableDescriptor.addFamily(new HColumnDescriptor("Serveur_Application_parametrage"));
tableDescriptor.addFamily(new HColumnDescriptor("Integration/fonctionnel"));
tableDescriptor.addFamily(new HColumnDescriptor("Outils_de_conception/de_gestion_projet"));
tableDescriptor.addFamily(new HColumnDescriptor("AMOA"));
tableDescriptor.addFamily(new HColumnDescriptor("Experience"));
tableDescriptor.addFamily(new HColumnDescriptor("Interventions"));
// Execute the table through admin
admin.createTable(tableDescriptor);
System.out.println(" Table created ");
}
}
谢谢提前