Es-hbase-hbase-create-data

提供:Dev Guides
移動先:案内検索

HBase-クレアダトス

HBaseのタブミュージカルミュージシャンのリストです。 タブラHBaseのデータを使用して、実用的なコマンドを実行します:

  • *プット*コマンド
  • * add()*Métodode clase y
  • * Put()*メトードHTable de clase。

コモイェメンプロ、タブモとHBaseのバモス。

Tablas HBase

Con el comando put、puede insertar filas en una tabla。 Su sintaxis es la siguiente:

put ’<table name>’,’row1’,’<colfamily:colname>’,’<value>’

プリメーラ・フィラ通り

入門編のフィラ・ロス・バロレス・デ・ラ・タブラ・エンプ・コム・ミューゼストラ・ア・コンティニュアス。

hbase(main):005:0> put 'emp','1','personal data:name','raju'
0 row(s) in 0.6600 seconds
hbase(main):006:0> put 'emp','1','personal data:city','hyderabad'
0 row(s) in 0.0410 seconds
hbase(main):007:0> put 'emp','1','professional
data:designation','manager'
0 row(s) in 0.0240 seconds
hbase(main):007:0> put 'emp','1','professional data:salary','50000'
0 row(s) in 0.0240 seconds

インサーターラスフィラスレストランユーティリザンドエルコマンドプットデラミスママネラ。 挿入と削除、結果の表示を行います。

hbase(main):022:0> scan 'emp'

   ROW                        COLUMN+CELL
1 column=personal data:city, timestamp=1417524216501, value=hyderabad

1 column=personal data:name, timestamp=1417524185058, value=ramu

1 column=professional data:designation, timestamp=1417524232601,

 value=manager

1 column=professional data:salary, timestamp=1417524244109, value=50000

2 column=personal data:city, timestamp=1417524574905, value=chennai

2 column=personal data:name, timestamp=1417524556125, value=ravi

2 column=professional data:designation, timestamp=1417524592204,

 value=sr:engg

2 column=professional data:salary, timestamp=1417524604221, value=30000

3 column=personal data:city, timestamp=1417524681780, value=delhi

3 column=personal data:name, timestamp=1417524672067, value=rajesh

3 column=professional data:designation, timestamp=1417524693187,

value=jr:engg
3 column=professional data:salary, timestamp=1417524702514,

value=25000

JavaのAPIを使用してデータを挿入する

  • add()メトド・デ・ラ *put claseを使用して、ファイルを挿入します。 usted puede ahorrar mediante el * put()métodode la *HTable clase。 Estasはorg.apache.hadoop.hbase。 paquete del clienteの前身です。 HBaseのタブラの連続したパラグラフの連続した損失。

手順1:構成のクラスを作成する

構成は、HBaseアーカイブの構成を集約します。 中間構成のオブジェクトを作成します* create()メタデータの *HbaseConfiguration を継続的に実行します。

Configuration conf = HbaseConfiguration.create();

手順2:HTableのクラスをインスタンス化する

*HTable* 、HBaseのタブラ実装のテンプレート。 単独のHBaseタブラを使用して、共通のユーティリティを作成します。 インスタシアのクラスの概要、構成パラメータの設定が可能です。 HTableは、継続的であり、継続的です。
HTable hTable = new HTable(conf, tableName);

手順3:PutClassのインスタンス化

タブベースのHBase、および* add()の各メソッドのバリアントに追加します。 エステメトドは、*タン、ポルロタントクレア、インスタンシアデラクラーセクエを順守します。 Esta clase requiere el nombre de la fila que desea insertar los datos en formato de cadena。 Puede crear instancias de la put clase que tal como se muestra acontinuación。

Put p = new Put(Bytes.toBytes("row1"));

手順4:InsertData

El * add()métodode *Put は、挿入データの使用を追跡します。 バイト列を表す3マトリックスのバイト列、列柱を表す列(列列)、挿入列、敬意を表す列。 HBaseにデータを挿入し、連続してadd()を使用して追加することができます。

p.add(Bytes.toBytes("coloumn family "), Bytes.toBytes("column
name"),Bytes.toBytes("value"));

手順5:パルスガーダーロスダトスデラタブラ

挿入されたラス・ネセサリア、ガード・ロス・カンビオスのメディアは、インディシア・パラ・ポーナーの中央に位置します。

hTable.put(p);

手順6:Cerrar la Instancia HTable

HBase、HTable、Ciere la HTableを使用して、データを閉じることができます。

hTable.close();

HBase Tablaのプログラムの完全な継続的なインクルージョンを含む。

import java.io.IOException;

import org.apache.hadoop.conf.Configuration;

import org.apache.hadoop.hbase.HBaseConfiguration;
import org.apache.hadoop.hbase.client.HTable;
import org.apache.hadoop.hbase.client.Put;
import org.apache.hadoop.hbase.util.Bytes;

public class InsertData{

   public static void main(String[] args) throws IOException {

     //Instantiating Configuration class
      Configuration config = HBaseConfiguration.create();

     //Instantiating HTable class
      HTable hTable = new HTable(config, "emp");

     //Instantiating Put class
     //accepts a row name.
      Put p = new Put(Bytes.toBytes("row1"));

     //adding values using add() method
     //accepts column family name, qualifier/row name ,value
      p.add(Bytes.toBytes("personal"),
      Bytes.toBytes("name"),Bytes.toBytes("raju"));

      p.add(Bytes.toBytes("personal"),
      Bytes.toBytes("city"),Bytes.toBytes("hyderabad"));

      p.add(Bytes.toBytes("professional"),Bytes.toBytes("designation"),
      Bytes.toBytes("manager"));

      p.add(Bytes.toBytes("professional"),Bytes.toBytes("salary"),
      Bytes.toBytes("50000"));

     //Saving the put Instance to the HTable.
      hTable.put(p);
      System.out.println("data inserted");

     //closing HTable
      hTable.close();
   }
}

連続したプログラムの比較プログラム。

$javac InsertData.java
$java InsertData

Lo siguiente debe ser el producto:

data inserted