如何在hdp hortonworks上创建具有多列族的hbase表?

qvk1mo1f  于 2021-06-10  发布在  Hbase
关注(0)|答案(1)|浏览(567)

我对hdp非常陌生,我想创建一个包含多列的hbase表,并从csv文件加载数据,如下所示
csv文件
如您所见,我有每个示例列族“informations personelles”,其中包含多个列,如“nom”“prenom”等。
所以我的问题是:-如何在hdp沙盒上用javaapi创建表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 ");
   }
}

谢谢你的预付款

9gm1akwq

9gm1akwq1#

如果您试图从本地计算机运行java程序以连接到沙盒hbase和zookeeper,则需要在“沙盒设置”>“网络”>“高级”>“端口转发”中为2181端口执行端口转发。叫zk之类的名字,protocol:tcp,历史ip:127.0.0.1,主机port:2181,客港:2181。然后在程序中按如下所示设置conf并运行程序:

con.set("hbase.zookeeper.property.clientPort", "2181");
con.set("hbase.zookeeper.quorum", "127.0.0.1");

在java程序中,可以使用ScannerAPI读取csv文件作为参考http://www.journaldev.com/2335/read-csv-file-java-scanner 并使用javahbaseapi来存储数据作为参考https://autofei.wordpress.com/2012/04/02/java-example-code-using-hbase-data-model-operations/
另一种选择是将文件和java程序jar发送到sandbox并在那里运行。要复制或ssh到sandbox,您需要像上面一样进行端口转发port:2222,访客端口:22
希望这对你有帮助。。。

相关问题