心得,写在前面的话,也许,中间会要多次执行,连接超时,多试试就好了。
前面的基础,如下
HBase编程 API入门系列之put(客户端而言)(1)
HBase编程 API入门系列之get(客户端而言)(2)
hbase(main):001:0> scan 'test_table2'
ROW COLUMN+CELL
row_04 column=f1:name, timestamp=1478117286377, value=Andy3
row_04 column=f2:name, timestamp=1478117286377, value=Andy3
1 row(s) in 1.5670 seconds
hbase(main):002:0>
如现在这样,不指定,默认把所有的列全会删除 (开发实际中,一定要加指定呀)
1 package zhouls.bigdata.HbaseProject.Test1; 2 3 import javax.xml.transform.Result; 4 5 import org.apache.hadoop.conf.Configuration; 6 import org.apache.hadoop.hbase.HBaseConfiguration; 7 import org.apache.hadoop.hbase.TableName; 8 import org.apache.hadoop.hbase.client.Delete; 9 import org.apache.hadoop.hbase.client.Get; 10 import org.apache.hadoop.hbase.client.HTable; 11 import org.apache.hadoop.hbase.client.Put; 12 import org.apache.hadoop.hbase.util.Bytes; 13 14 public class HBaseTest { 15 public static void main(String[] args) throws Exception { 16 HTable table = new HTable(getConfig(),TableName.valueOf("test_table2"));//表名是test_table 17 // Put put = new Put(Bytes.toBytes("row_04"));//行键是row_01 18 // put.add(Bytes.toBytes("f1"),Bytes.toBytes("name"),Bytes.toBytes("Andy3"));//列簇是f1,列修饰符是name,值是Andy3 19 // put.add(Bytes.toBytes("f2"),Bytes.toBytes("name"),Bytes.toBytes("Andy3"));//列簇是f2,列修饰符是name,值是Andy3 20 // table.put(put); 21 22 // Get get = new Get(Bytes.toBytes("row_04")); 23 // get.addColumn(Bytes.toBytes("f1"), Bytes.toBytes("age"));如现在这样,不指定,默认把所有的全拿出来 24 // org.apache.hadoop.hbase.client.Result rest = table.get(get); 25 // System.out.println(rest.toString()); 26 // table.close(); 27 28 Delete delete = new Delete(Bytes.toBytes("row_04")); 29 table.delete(delete); 30 table.close(); 31 } 32 33 public static Configuration getConfig(){ 34 Configuration configuration = new Configuration(); 35 // conf.set("hbase.rootdir","hdfs:HadoopMaster:9000/hbase"); 36 configuration.set("hbase.zookeeper.quorum", "HadoopMaster:2181,HadoopSlave1:2181,HadoopSlave2:2181"); 37 return configuration; 38 } 39 }
2016-12-10 15:37:29,818 INFO [org.apache.hadoop.hbase.zookeeper.RecoverableZooKeeper] - Process identifier=hconnection-0x5fc2fc59 connecting to ZooKeeper ensemble=HadoopMaster:2181,HadoopSlave1:2181,HadoopSlave2:2181
2016-12-10 15:37:29,838 INFO [org.apache.zookeeper.ZooKeeper] - Client environment:zookeeper.version=3.4.6-1569965, built on 02/20/2014 09:09 GMT
2016-12-10 15:37:29,838 INFO [org.apache.zookeeper.ZooKeeper] - Client environment:host.name=WIN-BQOBV63OBNM
2016-12-10 15:37:29,839 INFO [org.apache.zookeeper.ZooKeeper] - Client environment:java.version=1.7.0_51
2016-12-10 15:37:29,839 INFO [org.apache.zookeeper.ZooKeeper] - Client environment:java.vendor=Oracle Corporation
2016-12-10 15:37:29,839 INFO [org.apache.zookeeper.ZooKeeper] - Client environment:java.home=C:Program FilesJavajdk1.7.0_51jre
2016-12-10 15:37:29,839 INFO [org.apache.zookeeper.ZooKeeper] - Client environment:java.class.path=D:CodeMyEclipseJavaCodeHbaseProjectin;D:SoftWarehbase-1.2.3libactivation-1.1.jar;D:SoftWarehbase-1.2.3libaopalliance-1.0.jar;D:SoftWarehbase-1.2.3libapacheds-i18n-2.0.0-M15.jar;D:SoftWarehbase-1.2.3libapacheds-kerberos-codec-2.0.0-M15.jar;D:SoftWarehbase-1.2.3libapi-asn1-api-1.0.0-M20.jar;D:SoftWarehbase-1.2.3libapi-util-1.0.0-M20.jar;D:SoftWarehbase-1.2.3libasm-3.1.jar;D:SoftWarehbase-1.2.3libavro-1.7.4.jar;D:SoftWarehbase-1.2.3libcommons-beanutils-1.7.0.jar;D:SoftWarehbase-1.2.3libcommons-beanutils-core-1.8.0.jar;D:SoftWarehbase-1.2.3libcommons-cli-1.2.jar;D:SoftWarehbase-1.2.3libcommons-codec-1.9.jar;D:SoftWarehbase-1.2.3libcommons-collections-3.2.2.jar;D:SoftWarehbase-1.2.3libcommons-compress-1.4.1.jar;D:SoftWarehbase-1.2.3libcommons-configuration-1.6.jar;D:SoftWarehbase-1.2.3libcommons-daemon-1.0.13.jar;D:SoftWarehbase-1.2.3libcommons-digester-1.8.jar;D:SoftWarehbase-1.2.3libcommons-el-1.0.jar;D:SoftWarehbase-1.2.3libcommons-httpclient-3.1.jar;D:SoftWarehbase-1.2.3libcommons-io-2.4.jar;D:SoftWarehbase-1.2.3libcommons-lang-2.6.jar;D:SoftWarehbase-1.2.3libcommons-logging-1.2.jar;D:SoftWarehbase-1.2.3libcommons-math-2.2.jar;D:SoftWarehbase-1.2.3libcommons-math3-3.1.1.jar;D:SoftWarehbase-1.2.3libcommons-net-3.1.jar;D:SoftWarehbase-1.2.3libdisruptor-3.3.0.jar;D:SoftWarehbase-1.2.3libfindbugs-annotations-1.3.9-1.jar;D:SoftWarehbase-1.2.3libguava-12.0.1.jar;D:SoftWarehbase-1.2.3libguice-3.0.jar;D:SoftWarehbase-1.2.3libguice-servlet-3.0.jar;D:SoftWarehbase-1.2.3libhadoop-annotations-2.5.1.jar;D:SoftWarehbase-1.2.3libhadoop-auth-2.5.1.jar;D:SoftWarehbase-1.2.3libhadoop-client-2.5.1.jar;D:SoftWarehbase-1.2.3libhadoop-common-2.5.1.jar;D:SoftWarehbase-1.2.3libhadoop-hdfs-2.5.1.jar;D:SoftWarehbase-1.2.3libhadoop-mapreduce-client-app-2.5.1.jar;D:SoftWarehbase-1.2.3libhadoop-mapreduce-client-common-2.5.1.jar;D:SoftWarehbase-1.2.3libhadoop-mapreduce-client-core-2.5.1.jar;D:SoftWarehbase-1.2.3libhadoop-mapreduce-client-jobclient-2.5.1.jar;D:SoftWarehbase-1.2.3libhadoop-mapreduce-client-shuffle-2.5.1.jar;D:SoftWarehbase-1.2.3libhadoop-yarn-api-2.5.1.jar;D:SoftWarehbase-1.2.3libhadoop-yarn-client-2.5.1.jar;D:SoftWarehbase-1.2.3libhadoop-yarn-common-2.5.1.jar;D:SoftWarehbase-1.2.3libhadoop-yarn-server-common-2.5.1.jar;D:SoftWarehbase-1.2.3libhbase-annotations-1.2.3.jar;D:SoftWarehbase-1.2.3libhbase-annotations-1.2.3-tests.jar;D:SoftWarehbase-1.2.3libhbase-client-1.2.3.jar;D:SoftWarehbase-1.2.3libhbase-common-1.2.3.jar;D:SoftWarehbase-1.2.3libhbase-common-1.2.3-tests.jar;D:SoftWarehbase-1.2.3libhbase-examples-1.2.3.jar;D:SoftWarehbase-1.2.3libhbase-external-blockcache-1.2.3.jar;D:SoftWarehbase-1.2.3libhbase-hadoop2-compat-1.2.3.jar;D:SoftWarehbase-1.2.3libhbase-hadoop-compat-1.2.3.jar;D:SoftWarehbase-1.2.3libhbase-it-1.2.3.jar;D:SoftWarehbase-1.2.3libhbase-it-1.2.3-tests.jar;D:SoftWarehbase-1.2.3libhbase-prefix-tree-1.2.3.jar;D:SoftWarehbase-1.2.3libhbase-procedure-1.2.3.jar;D:SoftWarehbase-1.2.3libhbase-protocol-1.2.3.jar;D:SoftWarehbase-1.2.3libhbase-resource-bundle-1.2.3.jar;D:SoftWarehbase-1.2.3libhbase-rest-1.2.3.jar;D:SoftWarehbase-1.2.3libhbase-server-1.2.3.jar;D:SoftWarehbase-1.2.3libhbase-server-1.2.3-tests.jar;D:SoftWarehbase-1.2.3libhbase-shell-1.2.3.jar;D:SoftWarehbase-1.2.3libhbase-thrift-1.2.3.jar;D:SoftWarehbase-1.2.3libhtrace-core-3.1.0-incubating.jar;D:SoftWarehbase-1.2.3libhttpclient-4.2.5.jar;D:SoftWarehbase-1.2.3libhttpcore-4.4.1.jar;D:SoftWarehbase-1.2.3libjackson-core-asl-1.9.13.jar;D:SoftWarehbase-1.2.3libjackson-jaxrs-1.9.13.jar;D:SoftWarehbase-1.2.3libjackson-mapper-asl-1.9.13.jar;D:SoftWarehbase-1.2.3libjackson-xc-1.9.13.jar;D:SoftWarehbase-1.2.3libjamon-runtime-2.4.1.jar;D:SoftWarehbase-1.2.3libjasper-compiler-5.5.23.jar;D:SoftWarehbase-1.2.3libjasper-runtime-5.5.23.jar;D:SoftWarehbase-1.2.3libjavax.inject-1.jar;D:SoftWarehbase-1.2.3libjava-xmlbuilder-0.4.jar;D:SoftWarehbase-1.2.3libjaxb-api-2.2.2.jar;D:SoftWarehbase-1.2.3libjaxb-impl-2.2.3-1.jar;D:SoftWarehbase-1.2.3libjcodings-1.0.8.jar;D:SoftWarehbase-1.2.3libjersey-client-1.9.jar;D:SoftWarehbase-1.2.3libjersey-core-1.9.jar;D:SoftWarehbase-1.2.3libjersey-guice-1.9.jar;D:SoftWarehbase-1.2.3libjersey-json-1.9.jar;D:SoftWarehbase-1.2.3libjersey-server-1.9.jar;D:SoftWarehbase-1.2.3libjets3t-0.9.0.jar;D:SoftWarehbase-1.2.3libjettison-1.3.3.jar;D:SoftWarehbase-1.2.3libjetty-6.1.26.jar;D:SoftWarehbase-1.2.3libjetty-sslengine-6.1.26.jar;D:SoftWarehbase-1.2.3libjetty-util-6.1.26.jar;D:SoftWarehbase-1.2.3libjoni-2.1.2.jar;D:SoftWarehbase-1.2.3libjruby-complete-1.6.8.jar;D:SoftWarehbase-1.2.3libjsch-0.1.42.jar;D:SoftWarehbase-1.2.3libjsp-2.1-6.1.14.jar;D:SoftWarehbase-1.2.3libjsp-api-2.1-6.1.14.jar;D:SoftWarehbase-1.2.3libjunit-4.12.jar;D:SoftWarehbase-1.2.3libleveldbjni-all-1.8.jar;D:SoftWarehbase-1.2.3liblibthrift-0.9.3.jar;D:SoftWarehbase-1.2.3liblog4j-1.2.17.jar;D:SoftWarehbase-1.2.3libmetrics-core-2.2.0.jar;D:SoftWarehbase-1.2.3lib
etty-all-4.0.23.Final.jar;D:SoftWarehbase-1.2.3libparanamer-2.3.jar;D:SoftWarehbase-1.2.3libprotobuf-java-2.5.0.jar;D:SoftWarehbase-1.2.3libservlet-api-2.5.jar;D:SoftWarehbase-1.2.3libservlet-api-2.5-6.1.14.jar;D:SoftWarehbase-1.2.3libslf4j-api-1.7.7.jar;D:SoftWarehbase-1.2.3libslf4j-log4j12-1.7.5.jar;D:SoftWarehbase-1.2.3libsnappy-java-1.0.4.1.jar;D:SoftWarehbase-1.2.3libspymemcached-2.11.6.jar;D:SoftWarehbase-1.2.3libxmlenc-0.52.jar;D:SoftWarehbase-1.2.3libxz-1.0.jar;D:SoftWarehbase-1.2.3libzookeeper-3.4.6.jar
2016-12-10 15:37:29,840 INFO [org.apache.zookeeper.ZooKeeper] - Client environment:java.library.path=C:Program FilesJavajdk1.7.0_51in;C:WindowsSunJavain;C:Windowssystem32;C:Windows;C:ProgramDataOracleJavajavapath;C:Python27;C:Python27Scripts;C:Windowssystem32;C:Windows;C:WindowsSystem32Wbem;C:WindowsSystem32WindowsPowerShellv1.0;D:SoftWareMATLAB R2013a
untimewin64;D:SoftWareMATLAB R2013ain;C:Program Files (x86)IDM Computer SolutionsUltraCompare;C:Program FilesJavajdk1.7.0_51in;C:Program FilesJavajdk1.7.0_51jrein;D:SoftWareapache-ant-1.9.0in;HADOOP_HOMEin;D:SoftWareapache-maven-3.3.9in;D:SoftWareScalain;D:SoftWareScalajrein;%MYSQL_HOMEin;D:SoftWareMySQL ServerMySQL Server 5.0in;D:SoftWareapache-tomcat-7.0.69in;%C:WindowsSystem32;%C:WindowsSysWOW64;D:SoftWareSSH Secure Shell;.
2016-12-10 15:37:29,842 INFO [org.apache.zookeeper.ZooKeeper] - Client environment:java.io.tmpdir=C:UsersADMINI~1AppDataLocalTemp
2016-12-10 15:37:29,842 INFO [org.apache.zookeeper.ZooKeeper] - Client environment:java.compiler=<NA>
2016-12-10 15:37:29,842 INFO [org.apache.zookeeper.ZooKeeper] - Client environment:os.name=Windows 7
2016-12-10 15:37:29,843 INFO [org.apache.zookeeper.ZooKeeper] - Client environment:os.arch=amd64
2016-12-10 15:37:29,843 INFO [org.apache.zookeeper.ZooKeeper] - Client environment:os.version=6.1
2016-12-10 15:37:29,844 INFO [org.apache.zookeeper.ZooKeeper] - Client environment:user.name=Administrator
2016-12-10 15:37:29,844 INFO [org.apache.zookeeper.ZooKeeper] - Client environment:user.home=C:UsersAdministrator
2016-12-10 15:37:29,844 INFO [org.apache.zookeeper.ZooKeeper] - Client environment:user.dir=D:CodeMyEclipseJavaCodeHbaseProject
2016-12-10 15:37:29,847 INFO [org.apache.zookeeper.ZooKeeper] - Initiating client connection, connectString=HadoopMaster:2181,HadoopSlave1:2181,HadoopSlave2:2181 sessionTimeout=180000 watcher=hconnection-0x5fc2fc590x0, quorum=HadoopMaster:2181,HadoopSlave1:2181,HadoopSlave2:2181, baseZNode=/hbase
2016-12-10 15:37:29,925 INFO [org.apache.zookeeper.ClientCnxn] - Opening socket connection to server HadoopSlave1/192.168.80.11:2181. Will not attempt to authenticate using SASL (unknown error)
2016-12-10 15:37:29,971 INFO [org.apache.zookeeper.ClientCnxn] - Socket connection established to HadoopSlave1/192.168.80.11:2181, initiating session
2016-12-10 15:37:29,996 INFO [org.apache.zookeeper.ClientCnxn] - Session establishment complete on server HadoopSlave1/192.168.80.11:2181, sessionid = 0x2587338ecb4000e, negotiated timeout = 40000
2016-12-10 15:37:31,324 INFO [org.apache.hadoop.hbase.client.ConnectionManager$HConnectionImplementation] - Closing zookeeper sessionid=0x2587338ecb4000e
2016-12-10 15:37:31,340 INFO [org.apache.zookeeper.ZooKeeper] - Session: 0x2587338ecb4000e closed
2016-12-10 15:37:31,344 INFO [org.apache.zookeeper.ClientCnxn] - EventThread shut down
hbase(main):001:0> scan 'test_table2'
ROW COLUMN+CELL
row_04 column=f1:name, timestamp=1478117286377, value=Andy3
row_04 column=f2:name, timestamp=1478117286377, value=Andy3
1 row(s) in 1.5670 seconds
hbase(main):002:0> scan 'test_table2'
ROW COLUMN+CELL
0 row(s) in 0.1720 seconds
hbase(main):003:0>
hbase(main):003:0> put 'test_table2','row_1','f1:name','andy'
0 row(s) in 0.6390 seconds
hbase(main):004:0> put 'test_table2','row_1','f1:age','25'
0 row(s) in 0.0630 seconds
hbase(main):005:0> put 'test_table2','row_1','f1:email','10086@qq.com'
0 row(s) in 0.2040 seconds
hbase(main):006:0> scan 'test_table2'
ROW COLUMN+CELL
row_1 column=f1:age, timestamp=1478119757136, value=25
row_1 column=f1:email, timestamp=1478119978163, value=10086@qq.com
row_1 column=f1:name, timestamp=1478119459805, value=andy
1 row(s) in 0.1000 seconds
hbase(main):007:0> put 'test_table2','row_2','f1:email','10086@qq.com'
0 row(s) in 0.0290 seconds
hbase(main):008:0> put 'test_table2','row_2','f1:name','maizi'
0 row(s) in 0.0940 seconds
hbase(main):009:0> scan 'test_table2'
ROW COLUMN+CELL
row_1 column=f1:age, timestamp=1478119757136, value=25
row_1 column=f1:email, timestamp=1478119978163, value=10086@qq.com
row_1 column=f1:name, timestamp=1478119459805, value=andy
row_2 column=f1:email, timestamp=1478120078440, value=10086@qq.com
row_2 column=f1:name, timestamp=1478120133536, value=maizi
2 row(s) in 0.1280 seconds
hbase(main):010:0>
1 package zhouls.bigdata.HbaseProject.Test1; 2 3 import javax.xml.transform.Result; 4 5 import org.apache.hadoop.conf.Configuration; 6 import org.apache.hadoop.hbase.HBaseConfiguration; 7 import org.apache.hadoop.hbase.TableName; 8 import org.apache.hadoop.hbase.client.Delete; 9 import org.apache.hadoop.hbase.client.Get; 10 import org.apache.hadoop.hbase.client.HTable; 11 import org.apache.hadoop.hbase.client.Put; 12 import org.apache.hadoop.hbase.util.Bytes; 13 14 public class HBaseTest { 15 public static void main(String[] args) throws Exception { 16 HTable table = new HTable(getConfig(),TableName.valueOf("test_table2"));//表名是test_table 17 // Put put = new Put(Bytes.toBytes("row_04"));//行键是row_01 18 // put.add(Bytes.toBytes("f1"),Bytes.toBytes("name"),Bytes.toBytes("Andy3"));//列簇是f1,列修饰符是name,值是Andy3 19 // put.add(Bytes.toBytes("f2"),Bytes.toBytes("name"),Bytes.toBytes("Andy3"));//列簇是f2,列修饰符是name,值是Andy3 20 // table.put(put); 21 22 // Get get = new Get(Bytes.toBytes("row_04")); 23 // get.addColumn(Bytes.toBytes("f1"), Bytes.toBytes("age"));如现在这样,不指定,默认把所有的全拿出来 24 // org.apache.hadoop.hbase.client.Result rest = table.get(get); 25 // System.out.println(rest.toString()); 26 // table.close(); 27 28 Delete delete = new Delete(Bytes.toBytes("row_1")); 29 delete.deleteColumn(Bytes.toBytes("f1"), Bytes.toBytes("email")); 30 table.delete(delete); 31 table.close(); 32 } 33 34 public static Configuration getConfig(){ 35 Configuration configuration = new Configuration(); 36 // conf.set("hbase.rootdir","hdfs:HadoopMaster:9000/hbase"); 37 configuration.set("hbase.zookeeper.quorum", "HadoopMaster:2181,HadoopSlave1:2181,HadoopSlave2:2181"); 38 return configuration; 39 } 40 }
2016-12-10 16:01:36,462 INFO [org.apache.hadoop.hbase.zookeeper.RecoverableZooKeeper] - Process identifier=hconnection-0x27758c30 connecting to ZooKeeper ensemble=HadoopMaster:2181,HadoopSlave1:2181,HadoopSlave2:2181
2016-12-10 16:01:36,493 INFO [org.apache.zookeeper.ZooKeeper] - Client environment:zookeeper.version=3.4.6-1569965, built on 02/20/2014 09:09 GMT
2016-12-10 16:01:36,493 INFO [org.apache.zookeeper.ZooKeeper] - Client environment:host.name=WIN-BQOBV63OBNM
2016-12-10 16:01:36,493 INFO [org.apache.zookeeper.ZooKeeper] - Client environment:java.version=1.7.0_51
2016-12-10 16:01:36,494 INFO [org.apache.zookeeper.ZooKeeper] - Client environment:java.vendor=Oracle Corporation
2016-12-10 16:01:36,494 INFO [org.apache.zookeeper.ZooKeeper] - Client environment:java.home=C:Program FilesJavajdk1.7.0_51jre
2016-12-10 16:01:36,494 INFO [org.apache.zookeeper.ZooKeeper] - Client environment:java.class.path=D:CodeMyEclipseJavaCodeHbaseProjectin;D:SoftWarehbase-1.2.3libactivation-1.1.jar;D:SoftWarehbase-1.2.3libaopalliance-1.0.jar;D:SoftWarehbase-1.2.3libapacheds-i18n-2.0.0-M15.jar;D:SoftWarehbase-1.2.3libapacheds-kerberos-codec-2.0.0-M15.jar;D:SoftWarehbase-1.2.3libapi-asn1-api-1.0.0-M20.jar;D:SoftWarehbase-1.2.3libapi-util-1.0.0-M20.jar;D:SoftWarehbase-1.2.3libasm-3.1.jar;D:SoftWarehbase-1.2.3libavro-1.7.4.jar;D:SoftWarehbase-1.2.3libcommons-beanutils-1.7.0.jar;D:SoftWarehbase-1.2.3libcommons-beanutils-core-1.8.0.jar;D:SoftWarehbase-1.2.3libcommons-cli-1.2.jar;D:SoftWarehbase-1.2.3libcommons-codec-1.9.jar;D:SoftWarehbase-1.2.3libcommons-collections-3.2.2.jar;D:SoftWarehbase-1.2.3libcommons-compress-1.4.1.jar;D:SoftWarehbase-1.2.3libcommons-configuration-1.6.jar;D:SoftWarehbase-1.2.3libcommons-daemon-1.0.13.jar;D:SoftWarehbase-1.2.3libcommons-digester-1.8.jar;D:SoftWarehbase-1.2.3libcommons-el-1.0.jar;D:SoftWarehbase-1.2.3libcommons-httpclient-3.1.jar;D:SoftWarehbase-1.2.3libcommons-io-2.4.jar;D:SoftWarehbase-1.2.3libcommons-lang-2.6.jar;D:SoftWarehbase-1.2.3libcommons-logging-1.2.jar;D:SoftWarehbase-1.2.3libcommons-math-2.2.jar;D:SoftWarehbase-1.2.3libcommons-math3-3.1.1.jar;D:SoftWarehbase-1.2.3libcommons-net-3.1.jar;D:SoftWarehbase-1.2.3libdisruptor-3.3.0.jar;D:SoftWarehbase-1.2.3libfindbugs-annotations-1.3.9-1.jar;D:SoftWarehbase-1.2.3libguava-12.0.1.jar;D:SoftWarehbase-1.2.3libguice-3.0.jar;D:SoftWarehbase-1.2.3libguice-servlet-3.0.jar;D:SoftWarehbase-1.2.3libhadoop-annotations-2.5.1.jar;D:SoftWarehbase-1.2.3libhadoop-auth-2.5.1.jar;D:SoftWarehbase-1.2.3libhadoop-client-2.5.1.jar;D:SoftWarehbase-1.2.3libhadoop-common-2.5.1.jar;D:SoftWarehbase-1.2.3libhadoop-hdfs-2.5.1.jar;D:SoftWarehbase-1.2.3libhadoop-mapreduce-client-app-2.5.1.jar;D:SoftWarehbase-1.2.3libhadoop-mapreduce-client-common-2.5.1.jar;D:SoftWarehbase-1.2.3libhadoop-mapreduce-client-core-2.5.1.jar;D:SoftWarehbase-1.2.3libhadoop-mapreduce-client-jobclient-2.5.1.jar;D:SoftWarehbase-1.2.3libhadoop-mapreduce-client-shuffle-2.5.1.jar;D:SoftWarehbase-1.2.3libhadoop-yarn-api-2.5.1.jar;D:SoftWarehbase-1.2.3libhadoop-yarn-client-2.5.1.jar;D:SoftWarehbase-1.2.3libhadoop-yarn-common-2.5.1.jar;D:SoftWarehbase-1.2.3libhadoop-yarn-server-common-2.5.1.jar;D:SoftWarehbase-1.2.3libhbase-annotations-1.2.3.jar;D:SoftWarehbase-1.2.3libhbase-annotations-1.2.3-tests.jar;D:SoftWarehbase-1.2.3libhbase-client-1.2.3.jar;D:SoftWarehbase-1.2.3libhbase-common-1.2.3.jar;D:SoftWarehbase-1.2.3libhbase-common-1.2.3-tests.jar;D:SoftWarehbase-1.2.3libhbase-examples-1.2.3.jar;D:SoftWarehbase-1.2.3libhbase-external-blockcache-1.2.3.jar;D:SoftWarehbase-1.2.3libhbase-hadoop2-compat-1.2.3.jar;D:SoftWarehbase-1.2.3libhbase-hadoop-compat-1.2.3.jar;D:SoftWarehbase-1.2.3libhbase-it-1.2.3.jar;D:SoftWarehbase-1.2.3libhbase-it-1.2.3-tests.jar;D:SoftWarehbase-1.2.3libhbase-prefix-tree-1.2.3.jar;D:SoftWarehbase-1.2.3libhbase-procedure-1.2.3.jar;D:SoftWarehbase-1.2.3libhbase-protocol-1.2.3.jar;D:SoftWarehbase-1.2.3libhbase-resource-bundle-1.2.3.jar;D:SoftWarehbase-1.2.3libhbase-rest-1.2.3.jar;D:SoftWarehbase-1.2.3libhbase-server-1.2.3.jar;D:SoftWarehbase-1.2.3libhbase-server-1.2.3-tests.jar;D:SoftWarehbase-1.2.3libhbase-shell-1.2.3.jar;D:SoftWarehbase-1.2.3libhbase-thrift-1.2.3.jar;D:SoftWarehbase-1.2.3libhtrace-core-3.1.0-incubating.jar;D:SoftWarehbase-1.2.3libhttpclient-4.2.5.jar;D:SoftWarehbase-1.2.3libhttpcore-4.4.1.jar;D:SoftWarehbase-1.2.3libjackson-core-asl-1.9.13.jar;D:SoftWarehbase-1.2.3libjackson-jaxrs-1.9.13.jar;D:SoftWarehbase-1.2.3libjackson-mapper-asl-1.9.13.jar;D:SoftWarehbase-1.2.3libjackson-xc-1.9.13.jar;D:SoftWarehbase-1.2.3libjamon-runtime-2.4.1.jar;D:SoftWarehbase-1.2.3libjasper-compiler-5.5.23.jar;D:SoftWarehbase-1.2.3libjasper-runtime-5.5.23.jar;D:SoftWarehbase-1.2.3libjavax.inject-1.jar;D:SoftWarehbase-1.2.3libjava-xmlbuilder-0.4.jar;D:SoftWarehbase-1.2.3libjaxb-api-2.2.2.jar;D:SoftWarehbase-1.2.3libjaxb-impl-2.2.3-1.jar;D:SoftWarehbase-1.2.3libjcodings-1.0.8.jar;D:SoftWarehbase-1.2.3libjersey-client-1.9.jar;D:SoftWarehbase-1.2.3libjersey-core-1.9.jar;D:SoftWarehbase-1.2.3libjersey-guice-1.9.jar;D:SoftWarehbase-1.2.3libjersey-json-1.9.jar;D:SoftWarehbase-1.2.3libjersey-server-1.9.jar;D:SoftWarehbase-1.2.3libjets3t-0.9.0.jar;D:SoftWarehbase-1.2.3libjettison-1.3.3.jar;D:SoftWarehbase-1.2.3libjetty-6.1.26.jar;D:SoftWarehbase-1.2.3libjetty-sslengine-6.1.26.jar;D:SoftWarehbase-1.2.3libjetty-util-6.1.26.jar;D:SoftWarehbase-1.2.3libjoni-2.1.2.jar;D:SoftWarehbase-1.2.3libjruby-complete-1.6.8.jar;D:SoftWarehbase-1.2.3libjsch-0.1.42.jar;D:SoftWarehbase-1.2.3libjsp-2.1-6.1.14.jar;D:SoftWarehbase-1.2.3libjsp-api-2.1-6.1.14.jar;D:SoftWarehbase-1.2.3libjunit-4.12.jar;D:SoftWarehbase-1.2.3libleveldbjni-all-1.8.jar;D:SoftWarehbase-1.2.3liblibthrift-0.9.3.jar;D:SoftWarehbase-1.2.3liblog4j-1.2.17.jar;D:SoftWarehbase-1.2.3libmetrics-core-2.2.0.jar;D:SoftWarehbase-1.2.3lib
etty-all-4.0.23.Final.jar;D:SoftWarehbase-1.2.3libparanamer-2.3.jar;D:SoftWarehbase-1.2.3libprotobuf-java-2.5.0.jar;D:SoftWarehbase-1.2.3libservlet-api-2.5.jar;D:SoftWarehbase-1.2.3libservlet-api-2.5-6.1.14.jar;D:SoftWarehbase-1.2.3libslf4j-api-1.7.7.jar;D:SoftWarehbase-1.2.3libslf4j-log4j12-1.7.5.jar;D:SoftWarehbase-1.2.3libsnappy-java-1.0.4.1.jar;D:SoftWarehbase-1.2.3libspymemcached-2.11.6.jar;D:SoftWarehbase-1.2.3libxmlenc-0.52.jar;D:SoftWarehbase-1.2.3libxz-1.0.jar;D:SoftWarehbase-1.2.3libzookeeper-3.4.6.jar
2016-12-10 16:01:36,495 INFO [org.apache.zookeeper.ZooKeeper] - Client environment:java.library.path=C:Program FilesJavajdk1.7.0_51in;C:WindowsSunJavain;C:Windowssystem32;C:Windows;C:ProgramDataOracleJavajavapath;C:Python27;C:Python27Scripts;C:Windowssystem32;C:Windows;C:WindowsSystem32Wbem;C:WindowsSystem32WindowsPowerShellv1.0;D:SoftWareMATLAB R2013a
untimewin64;D:SoftWareMATLAB R2013ain;C:Program Files (x86)IDM Computer SolutionsUltraCompare;C:Program FilesJavajdk1.7.0_51in;C:Program FilesJavajdk1.7.0_51jrein;D:SoftWareapache-ant-1.9.0in;HADOOP_HOMEin;D:SoftWareapache-maven-3.3.9in;D:SoftWareScalain;D:SoftWareScalajrein;%MYSQL_HOMEin;D:SoftWareMySQL ServerMySQL Server 5.0in;D:SoftWareapache-tomcat-7.0.69in;%C:WindowsSystem32;%C:WindowsSysWOW64;D:SoftWareSSH Secure Shell;.
2016-12-10 16:01:36,496 INFO [org.apache.zookeeper.ZooKeeper] - Client environment:java.io.tmpdir=C:UsersADMINI~1AppDataLocalTemp
2016-12-10 16:01:36,496 INFO [org.apache.zookeeper.ZooKeeper] - Client environment:java.compiler=<NA>
2016-12-10 16:01:36,496 INFO [org.apache.zookeeper.ZooKeeper] - Client environment:os.name=Windows 7
2016-12-10 16:01:36,496 INFO [org.apache.zookeeper.ZooKeeper] - Client environment:os.arch=amd64
2016-12-10 16:01:36,496 INFO [org.apache.zookeeper.ZooKeeper] - Client environment:os.version=6.1
2016-12-10 16:01:36,496 INFO [org.apache.zookeeper.ZooKeeper] - Client environment:user.name=Administrator
2016-12-10 16:01:36,497 INFO [org.apache.zookeeper.ZooKeeper] - Client environment:user.home=C:UsersAdministrator
2016-12-10 16:01:36,497 INFO [org.apache.zookeeper.ZooKeeper] - Client environment:user.dir=D:CodeMyEclipseJavaCodeHbaseProject
2016-12-10 16:01:36,500 INFO [org.apache.zookeeper.ZooKeeper] - Initiating client connection, connectString=HadoopMaster:2181,HadoopSlave1:2181,HadoopSlave2:2181 sessionTimeout=180000 watcher=hconnection-0x27758c300x0, quorum=HadoopMaster:2181,HadoopSlave1:2181,HadoopSlave2:2181, baseZNode=/hbase
2016-12-10 16:01:36,664 INFO [org.apache.zookeeper.ClientCnxn] - Opening socket connection to server HadoopMaster/192.168.80.10:2181. Will not attempt to authenticate using SASL (unknown error)
2016-12-10 16:01:36,679 INFO [org.apache.zookeeper.ClientCnxn] - Socket connection established to HadoopMaster/192.168.80.10:2181, initiating session
2016-12-10 16:01:36,764 INFO [org.apache.zookeeper.ClientCnxn] - Session establishment complete on server HadoopMaster/192.168.80.10:2181, sessionid = 0x15825dedcf4000f, negotiated timeout = 40000
2016-12-10 16:01:38,454 INFO [org.apache.hadoop.hbase.client.ConnectionManager$HConnectionImplementation] - Closing zookeeper sessionid=0x15825dedcf4000f
2016-12-10 16:01:38,461 INFO [org.apache.zookeeper.ZooKeeper] - Session: 0x15825dedcf4000f closed
2016-12-10 16:01:38,461 INFO [org.apache.zookeeper.ClientCnxn] - EventThread shut down
hbase(main):015:0> scan 'test_table2'
ROW COLUMN+CELL
row_1 column=f1:age, timestamp=1478119757136, value=25
row_1 column=f1:email, timestamp=1478119978163, value=10086@qq.com
row_1 column=f1:name, timestamp=1478119459805, value=andy
row_2 column=f1:email, timestamp=1478120078440, value=10086@qq.com
row_2 column=f1:name, timestamp=1478120133536, value=maizi
2 row(s) in 0.3150 seconds
hbase(main):016:0> scan 'test_table2'
ROW COLUMN+CELL
row_1 column=f1:age, timestamp=1478119757136, value=25
row_1 column=f1:name, timestamp=1478119459805, value=andy
row_2 column=f1:email, timestamp=1478120078440, value=10086@qq.com
row_2 column=f1:name, timestamp=1478120133536, value=maizi
2 row(s) in 0.1080 seconds
hbase(main):017:0>
若是删除不存在的列修饰符,看下会是什么情况
1 package zhouls.bigdata.HbaseProject.Test1; 2 3 import javax.xml.transform.Result; 4 5 import org.apache.hadoop.conf.Configuration; 6 import org.apache.hadoop.hbase.HBaseConfiguration; 7 import org.apache.hadoop.hbase.TableName; 8 import org.apache.hadoop.hbase.client.Delete; 9 import org.apache.hadoop.hbase.client.Get; 10 import org.apache.hadoop.hbase.client.HTable; 11 import org.apache.hadoop.hbase.client.Put; 12 import org.apache.hadoop.hbase.util.Bytes; 13 14 public class HBaseTest { 15 public static void main(String[] args) throws Exception { 16 HTable table = new HTable(getConfig(),TableName.valueOf("test_table2"));//表名是test_table 17 // Put put = new Put(Bytes.toBytes("row_04"));//行键是row_01 18 // put.add(Bytes.toBytes("f1"),Bytes.toBytes("name"),Bytes.toBytes("Andy3"));//列簇是f1,列修饰符是name,值是Andy3 19 // put.add(Bytes.toBytes("f2"),Bytes.toBytes("name"),Bytes.toBytes("Andy3"));//列簇是f2,列修饰符是name,值是Andy3 20 // table.put(put); 21 22 // Get get = new Get(Bytes.toBytes("row_04")); 23 // get.addColumn(Bytes.toBytes("f1"), Bytes.toBytes("age"));如现在这样,不指定,默认把所有的全拿出来 24 // org.apache.hadoop.hbase.client.Result rest = table.get(get); 25 // System.out.println(rest.toString()); 26 // table.close(); 27 28 Delete delete = new Delete(Bytes.toBytes("row_1")); 29 delete.deleteColumn(Bytes.toBytes("f1"), Bytes.toBytes("email----"));//若是删除不存在的列修饰符,看下会是什么情况 30 table.delete(delete); 31 table.close(); 32 } 33 34 public static Configuration getConfig(){ 35 Configuration configuration = new Configuration(); 36 // conf.set("hbase.rootdir","hdfs:HadoopMaster:9000/hbase"); 37 configuration.set("hbase.zookeeper.quorum", "HadoopMaster:2181,HadoopSlave1:2181,HadoopSlave2:2181"); 38 return configuration; 39 } 40 }
2016-12-10 16:10:59,651 INFO [org.apache.hadoop.hbase.zookeeper.RecoverableZooKeeper] - Process identifier=hconnection-0x39ce5ac9 connecting to ZooKeeper ensemble=HadoopMaster:2181,HadoopSlave1:2181,HadoopSlave2:2181
2016-12-10 16:10:59,684 INFO [org.apache.zookeeper.ZooKeeper] - Client environment:zookeeper.version=3.4.6-1569965, built on 02/20/2014 09:09 GMT
2016-12-10 16:10:59,684 INFO [org.apache.zookeeper.ZooKeeper] - Client environment:host.name=WIN-BQOBV63OBNM
2016-12-10 16:10:59,684 INFO [org.apache.zookeeper.ZooKeeper] - Client environment:java.version=1.7.0_51
2016-12-10 16:10:59,685 INFO [org.apache.zookeeper.ZooKeeper] - Client environment:java.vendor=Oracle Corporation
2016-12-10 16:10:59,685 INFO [org.apache.zookeeper.ZooKeeper] - Client environment:java.home=C:Program FilesJavajdk1.7.0_51jre
2016-12-10 16:10:59,685 INFO [org.apache.zookeeper.ZooKeeper] - Client environment:java.class.path=D:CodeMyEclipseJavaCodeHbaseProjectin;D:SoftWarehbase-1.2.3libactivation-1.1.jar;D:SoftWarehbase-1.2.3libaopalliance-1.0.jar;D:SoftWarehbase-1.2.3libapacheds-i18n-2.0.0-M15.jar;D:SoftWarehbase-1.2.3libapacheds-kerberos-codec-2.0.0-M15.jar;D:SoftWarehbase-1.2.3libapi-asn1-api-1.0.0-M20.jar;D:SoftWarehbase-1.2.3libapi-util-1.0.0-M20.jar;D:SoftWarehbase-1.2.3libasm-3.1.jar;D:SoftWarehbase-1.2.3libavro-1.7.4.jar;D:SoftWarehbase-1.2.3libcommons-beanutils-1.7.0.jar;D:SoftWarehbase-1.2.3libcommons-beanutils-core-1.8.0.jar;D:SoftWarehbase-1.2.3libcommons-cli-1.2.jar;D:SoftWarehbase-1.2.3libcommons-codec-1.9.jar;D:SoftWarehbase-1.2.3libcommons-collections-3.2.2.jar;D:SoftWarehbase-1.2.3libcommons-compress-1.4.1.jar;D:SoftWarehbase-1.2.3libcommons-configuration-1.6.jar;D:SoftWarehbase-1.2.3libcommons-daemon-1.0.13.jar;D:SoftWarehbase-1.2.3libcommons-digester-1.8.jar;D:SoftWarehbase-1.2.3libcommons-el-1.0.jar;D:SoftWarehbase-1.2.3libcommons-httpclient-3.1.jar;D:SoftWarehbase-1.2.3libcommons-io-2.4.jar;D:SoftWarehbase-1.2.3libcommons-lang-2.6.jar;D:SoftWarehbase-1.2.3libcommons-logging-1.2.jar;D:SoftWarehbase-1.2.3libcommons-math-2.2.jar;D:SoftWarehbase-1.2.3libcommons-math3-3.1.1.jar;D:SoftWarehbase-1.2.3libcommons-net-3.1.jar;D:SoftWarehbase-1.2.3libdisruptor-3.3.0.jar;D:SoftWarehbase-1.2.3libfindbugs-annotations-1.3.9-1.jar;D:SoftWarehbase-1.2.3libguava-12.0.1.jar;D:SoftWarehbase-1.2.3libguice-3.0.jar;D:SoftWarehbase-1.2.3libguice-servlet-3.0.jar;D:SoftWarehbase-1.2.3libhadoop-annotations-2.5.1.jar;D:SoftWarehbase-1.2.3libhadoop-auth-2.5.1.jar;D:SoftWarehbase-1.2.3libhadoop-client-2.5.1.jar;D:SoftWarehbase-1.2.3libhadoop-common-2.5.1.jar;D:SoftWarehbase-1.2.3libhadoop-hdfs-2.5.1.jar;D:SoftWarehbase-1.2.3libhadoop-mapreduce-client-app-2.5.1.jar;D:SoftWarehbase-1.2.3libhadoop-mapreduce-client-common-2.5.1.jar;D:SoftWarehbase-1.2.3libhadoop-mapreduce-client-core-2.5.1.jar;D:SoftWarehbase-1.2.3libhadoop-mapreduce-client-jobclient-2.5.1.jar;D:SoftWarehbase-1.2.3libhadoop-mapreduce-client-shuffle-2.5.1.jar;D:SoftWarehbase-1.2.3libhadoop-yarn-api-2.5.1.jar;D:SoftWarehbase-1.2.3libhadoop-yarn-client-2.5.1.jar;D:SoftWarehbase-1.2.3libhadoop-yarn-common-2.5.1.jar;D:SoftWarehbase-1.2.3libhadoop-yarn-server-common-2.5.1.jar;D:SoftWarehbase-1.2.3libhbase-annotations-1.2.3.jar;D:SoftWarehbase-1.2.3libhbase-annotations-1.2.3-tests.jar;D:SoftWarehbase-1.2.3libhbase-client-1.2.3.jar;D:SoftWarehbase-1.2.3libhbase-common-1.2.3.jar;D:SoftWarehbase-1.2.3libhbase-common-1.2.3-tests.jar;D:SoftWarehbase-1.2.3libhbase-examples-1.2.3.jar;D:SoftWarehbase-1.2.3libhbase-external-blockcache-1.2.3.jar;D:SoftWarehbase-1.2.3libhbase-hadoop2-compat-1.2.3.jar;D:SoftWarehbase-1.2.3libhbase-hadoop-compat-1.2.3.jar;D:SoftWarehbase-1.2.3libhbase-it-1.2.3.jar;D:SoftWarehbase-1.2.3libhbase-it-1.2.3-tests.jar;D:SoftWarehbase-1.2.3libhbase-prefix-tree-1.2.3.jar;D:SoftWarehbase-1.2.3libhbase-procedure-1.2.3.jar;D:SoftWarehbase-1.2.3libhbase-protocol-1.2.3.jar;D:SoftWarehbase-1.2.3libhbase-resource-bundle-1.2.3.jar;D:SoftWarehbase-1.2.3libhbase-rest-1.2.3.jar;D:SoftWarehbase-1.2.3libhbase-server-1.2.3.jar;D:SoftWarehbase-1.2.3libhbase-server-1.2.3-tests.jar;D:SoftWarehbase-1.2.3libhbase-shell-1.2.3.jar;D:SoftWarehbase-1.2.3libhbase-thrift-1.2.3.jar;D:SoftWarehbase-1.2.3libhtrace-core-3.1.0-incubating.jar;D:SoftWarehbase-1.2.3libhttpclient-4.2.5.jar;D:SoftWarehbase-1.2.3libhttpcore-4.4.1.jar;D:SoftWarehbase-1.2.3libjackson-core-asl-1.9.13.jar;D:SoftWarehbase-1.2.3libjackson-jaxrs-1.9.13.jar;D:SoftWarehbase-1.2.3libjackson-mapper-asl-1.9.13.jar;D:SoftWarehbase-1.2.3libjackson-xc-1.9.13.jar;D:SoftWarehbase-1.2.3libjamon-runtime-2.4.1.jar;D:SoftWarehbase-1.2.3libjasper-compiler-5.5.23.jar;D:SoftWarehbase-1.2.3libjasper-runtime-5.5.23.jar;D:SoftWarehbase-1.2.3libjavax.inject-1.jar;D:SoftWarehbase-1.2.3libjava-xmlbuilder-0.4.jar;D:SoftWarehbase-1.2.3libjaxb-api-2.2.2.jar;D:SoftWarehbase-1.2.3libjaxb-impl-2.2.3-1.jar;D:SoftWarehbase-1.2.3libjcodings-1.0.8.jar;D:SoftWarehbase-1.2.3libjersey-client-1.9.jar;D:SoftWarehbase-1.2.3libjersey-core-1.9.jar;D:SoftWarehbase-1.2.3libjersey-guice-1.9.jar;D:SoftWarehbase-1.2.3libjersey-json-1.9.jar;D:SoftWarehbase-1.2.3libjersey-server-1.9.jar;D:SoftWarehbase-1.2.3libjets3t-0.9.0.jar;D:SoftWarehbase-1.2.3libjettison-1.3.3.jar;D:SoftWarehbase-1.2.3libjetty-6.1.26.jar;D:SoftWarehbase-1.2.3libjetty-sslengine-6.1.26.jar;D:SoftWarehbase-1.2.3libjetty-util-6.1.26.jar;D:SoftWarehbase-1.2.3libjoni-2.1.2.jar;D:SoftWarehbase-1.2.3libjruby-complete-1.6.8.jar;D:SoftWarehbase-1.2.3libjsch-0.1.42.jar;D:SoftWarehbase-1.2.3libjsp-2.1-6.1.14.jar;D:SoftWarehbase-1.2.3libjsp-api-2.1-6.1.14.jar;D:SoftWarehbase-1.2.3libjunit-4.12.jar;D:SoftWarehbase-1.2.3libleveldbjni-all-1.8.jar;D:SoftWarehbase-1.2.3liblibthrift-0.9.3.jar;D:SoftWarehbase-1.2.3liblog4j-1.2.17.jar;D:SoftWarehbase-1.2.3libmetrics-core-2.2.0.jar;D:SoftWarehbase-1.2.3lib
etty-all-4.0.23.Final.jar;D:SoftWarehbase-1.2.3libparanamer-2.3.jar;D:SoftWarehbase-1.2.3libprotobuf-java-2.5.0.jar;D:SoftWarehbase-1.2.3libservlet-api-2.5.jar;D:SoftWarehbase-1.2.3libservlet-api-2.5-6.1.14.jar;D:SoftWarehbase-1.2.3libslf4j-api-1.7.7.jar;D:SoftWarehbase-1.2.3libslf4j-log4j12-1.7.5.jar;D:SoftWarehbase-1.2.3libsnappy-java-1.0.4.1.jar;D:SoftWarehbase-1.2.3libspymemcached-2.11.6.jar;D:SoftWarehbase-1.2.3libxmlenc-0.52.jar;D:SoftWarehbase-1.2.3libxz-1.0.jar;D:SoftWarehbase-1.2.3libzookeeper-3.4.6.jar
2016-12-10 16:10:59,687 INFO [org.apache.zookeeper.ZooKeeper] - Client environment:java.library.path=C:Program FilesJavajdk1.7.0_51in;C:WindowsSunJavain;C:Windowssystem32;C:Windows;C:ProgramDataOracleJavajavapath;C:Python27;C:Python27Scripts;C:Windowssystem32;C:Windows;C:WindowsSystem32Wbem;C:WindowsSystem32WindowsPowerShellv1.0;D:SoftWareMATLAB R2013a
untimewin64;D:SoftWareMATLAB R2013ain;C:Program Files (x86)IDM Computer SolutionsUltraCompare;C:Program FilesJavajdk1.7.0_51in;C:Program FilesJavajdk1.7.0_51jrein;D:SoftWareapache-ant-1.9.0in;HADOOP_HOMEin;D:SoftWareapache-maven-3.3.9in;D:SoftWareScalain;D:SoftWareScalajrein;%MYSQL_HOMEin;D:SoftWareMySQL ServerMySQL Server 5.0in;D:SoftWareapache-tomcat-7.0.69in;%C:WindowsSystem32;%C:WindowsSysWOW64;D:SoftWareSSH Secure Shell;.
2016-12-10 16:10:59,688 INFO [org.apache.zookeeper.ZooKeeper] - Client environment:java.io.tmpdir=C:UsersADMINI~1AppDataLocalTemp
2016-12-10 16:10:59,688 INFO [org.apache.zookeeper.ZooKeeper] - Client environment:java.compiler=<NA>
2016-12-10 16:10:59,688 INFO [org.apache.zookeeper.ZooKeeper] - Client environment:os.name=Windows 7
2016-12-10 16:10:59,689 INFO [org.apache.zookeeper.ZooKeeper] - Client environment:os.arch=amd64
2016-12-10 16:10:59,689 INFO [org.apache.zookeeper.ZooKeeper] - Client environment:os.version=6.1
2016-12-10 16:10:59,689 INFO [org.apache.zookeeper.ZooKeeper] - Client environment:user.name=Administrator
2016-12-10 16:10:59,690 INFO [org.apache.zookeeper.ZooKeeper] - Client environment:user.home=C:UsersAdministrator
2016-12-10 16:10:59,690 INFO [org.apache.zookeeper.ZooKeeper] - Client environment:user.dir=D:CodeMyEclipseJavaCodeHbaseProject
2016-12-10 16:10:59,696 INFO [org.apache.zookeeper.ZooKeeper] - Initiating client connection, connectString=HadoopMaster:2181,HadoopSlave1:2181,HadoopSlave2:2181 sessionTimeout=180000 watcher=hconnection-0x39ce5ac90x0, quorum=HadoopMaster:2181,HadoopSlave1:2181,HadoopSlave2:2181, baseZNode=/hbase
2016-12-10 16:10:59,928 INFO [org.apache.zookeeper.ClientCnxn] - Opening socket connection to server HadoopMaster/192.168.80.10:2181. Will not attempt to authenticate using SASL (unknown error)
2016-12-10 16:11:00,063 INFO [org.apache.zookeeper.ClientCnxn] - Socket connection established to HadoopMaster/192.168.80.10:2181, initiating session
2016-12-10 16:11:00,154 INFO [org.apache.zookeeper.ClientCnxn] - Session establishment complete on server HadoopMaster/192.168.80.10:2181, sessionid = 0x15825dedcf40012, negotiated timeout = 40000
2016-12-10 16:11:02,018 INFO [org.apache.hadoop.hbase.client.ConnectionManager$HConnectionImplementation] - Closing zookeeper sessionid=0x15825dedcf40012
2016-12-10 16:11:02,029 INFO [org.apache.zookeeper.ZooKeeper] - Session: 0x15825dedcf40012 closed
2016-12-10 16:11:02,029 INFO [org.apache.zookeeper.ClientCnxn] - EventThread shut down
若是删除不存在的列族,则会出现什么情况?
1 package zhouls.bigdata.HbaseProject.Test1; 2 3 import javax.xml.transform.Result; 4 5 import org.apache.hadoop.conf.Configuration; 6 import org.apache.hadoop.hbase.HBaseConfiguration; 7 import org.apache.hadoop.hbase.TableName; 8 import org.apache.hadoop.hbase.client.Delete; 9 import org.apache.hadoop.hbase.client.Get; 10 import org.apache.hadoop.hbase.client.HTable; 11 import org.apache.hadoop.hbase.client.Put; 12 import org.apache.hadoop.hbase.util.Bytes; 13 14 public class HBaseTest { 15 public static void main(String[] args) throws Exception { 16 HTable table = new HTable(getConfig(),TableName.valueOf("test_table2"));//表名是test_table 17 // Put put = new Put(Bytes.toBytes("row_04"));//行键是row_01 18 // put.add(Bytes.toBytes("f1"),Bytes.toBytes("name"),Bytes.toBytes("Andy3"));//列簇是f1,列修饰符是name,值是Andy3 19 // put.add(Bytes.toBytes("f2"),Bytes.toBytes("name"),Bytes.toBytes("Andy3"));//列簇是f2,列修饰符是name,值是Andy3 20 // table.put(put); 21 22 // Get get = new Get(Bytes.toBytes("row_04")); 23 // get.addColumn(Bytes.toBytes("f1"), Bytes.toBytes("age"));如现在这样,不指定,默认把所有的全拿出来 24 // org.apache.hadoop.hbase.client.Result rest = table.get(get); 25 // System.out.println(rest.toString()); 26 // table.close(); 27 28 Delete delete = new Delete(Bytes.toBytes("row_1")); 29 delete.deleteColumn(Bytes.toBytes("f3"), Bytes.toBytes("email"));//若是删除不存在的列族,则会出现什么情况? 30 table.delete(delete); 31 table.close(); 32 } 33 34 public static Configuration getConfig(){ 35 Configuration configuration = new Configuration(); 36 // conf.set("hbase.rootdir","hdfs:HadoopMaster:9000/hbase"); 37 configuration.set("hbase.zookeeper.quorum", "HadoopMaster:2181,HadoopSlave1:2181,HadoopSlave2:2181"); 38 return configuration; 39 } 40 }
2016-12-10 16:13:54,520 INFO [org.apache.hadoop.hbase.zookeeper.RecoverableZooKeeper] - Process identifier=hconnection-0x1646b78d connecting to ZooKeeper ensemble=HadoopMaster:2181,HadoopSlave1:2181,HadoopSlave2:2181
2016-12-10 16:13:54,560 INFO [org.apache.zookeeper.ZooKeeper] - Client environment:zookeeper.version=3.4.6-1569965, built on 02/20/2014 09:09 GMT
2016-12-10 16:13:54,561 INFO [org.apache.zookeeper.ZooKeeper] - Client environment:host.name=WIN-BQOBV63OBNM
2016-12-10 16:13:54,561 INFO [org.apache.zookeeper.ZooKeeper] - Client environment:java.version=1.7.0_51
2016-12-10 16:13:54,561 INFO [org.apache.zookeeper.ZooKeeper] - Client environment:java.vendor=Oracle Corporation
2016-12-10 16:13:54,564 INFO [org.apache.zookeeper.ZooKeeper] - Client environment:java.home=C:Program FilesJavajdk1.7.0_51jre
2016-12-10 16:13:54,566 INFO [org.apache.zookeeper.ZooKeeper] - Client environment:java.class.path=D:CodeMyEclipseJavaCodeHbaseProjectin;D:SoftWarehbase-1.2.3libactivation-1.1.jar;D:SoftWarehbase-1.2.3libaopalliance-1.0.jar;D:SoftWarehbase-1.2.3libapacheds-i18n-2.0.0-M15.jar;D:SoftWarehbase-1.2.3libapacheds-kerberos-codec-2.0.0-M15.jar;D:SoftWarehbase-1.2.3libapi-asn1-api-1.0.0-M20.jar;D:SoftWarehbase-1.2.3libapi-util-1.0.0-M20.jar;D:SoftWarehbase-1.2.3libasm-3.1.jar;D:SoftWarehbase-1.2.3libavro-1.7.4.jar;D:SoftWarehbase-1.2.3libcommons-beanutils-1.7.0.jar;D:SoftWarehbase-1.2.3libcommons-beanutils-core-1.8.0.jar;D:SoftWarehbase-1.2.3libcommons-cli-1.2.jar;D:SoftWarehbase-1.2.3libcommons-codec-1.9.jar;D:SoftWarehbase-1.2.3libcommons-collections-3.2.2.jar;D:SoftWarehbase-1.2.3libcommons-compress-1.4.1.jar;D:SoftWarehbase-1.2.3libcommons-configuration-1.6.jar;D:SoftWarehbase-1.2.3libcommons-daemon-1.0.13.jar;D:SoftWarehbase-1.2.3libcommons-digester-1.8.jar;D:SoftWarehbase-1.2.3libcommons-el-1.0.jar;D:SoftWarehbase-1.2.3libcommons-httpclient-3.1.jar;D:SoftWarehbase-1.2.3libcommons-io-2.4.jar;D:SoftWarehbase-1.2.3libcommons-lang-2.6.jar;D:SoftWarehbase-1.2.3libcommons-logging-1.2.jar;D:SoftWarehbase-1.2.3libcommons-math-2.2.jar;D:SoftWarehbase-1.2.3libcommons-math3-3.1.1.jar;D:SoftWarehbase-1.2.3libcommons-net-3.1.jar;D:SoftWarehbase-1.2.3libdisruptor-3.3.0.jar;D:SoftWarehbase-1.2.3libfindbugs-annotations-1.3.9-1.jar;D:SoftWarehbase-1.2.3libguava-12.0.1.jar;D:SoftWarehbase-1.2.3libguice-3.0.jar;D:SoftWarehbase-1.2.3libguice-servlet-3.0.jar;D:SoftWarehbase-1.2.3libhadoop-annotations-2.5.1.jar;D:SoftWarehbase-1.2.3libhadoop-auth-2.5.1.jar;D:SoftWarehbase-1.2.3libhadoop-client-2.5.1.jar;D:SoftWarehbase-1.2.3libhadoop-common-2.5.1.jar;D:SoftWarehbase-1.2.3libhadoop-hdfs-2.5.1.jar;D:SoftWarehbase-1.2.3libhadoop-mapreduce-client-app-2.5.1.jar;D:SoftWarehbase-1.2.3libhadoop-mapreduce-client-common-2.5.1.jar;D:SoftWarehbase-1.2.3libhadoop-mapreduce-client-core-2.5.1.jar;D:SoftWarehbase-1.2.3libhadoop-mapreduce-client-jobclient-2.5.1.jar;D:SoftWarehbase-1.2.3libhadoop-mapreduce-client-shuffle-2.5.1.jar;D:SoftWarehbase-1.2.3libhadoop-yarn-api-2.5.1.jar;D:SoftWarehbase-1.2.3libhadoop-yarn-client-2.5.1.jar;D:SoftWarehbase-1.2.3libhadoop-yarn-common-2.5.1.jar;D:SoftWarehbase-1.2.3libhadoop-yarn-server-common-2.5.1.jar;D:SoftWarehbase-1.2.3libhbase-annotations-1.2.3.jar;D:SoftWarehbase-1.2.3libhbase-annotations-1.2.3-tests.jar;D:SoftWarehbase-1.2.3libhbase-client-1.2.3.jar;D:SoftWarehbase-1.2.3libhbase-common-1.2.3.jar;D:SoftWarehbase-1.2.3libhbase-common-1.2.3-tests.jar;D:SoftWarehbase-1.2.3libhbase-examples-1.2.3.jar;D:SoftWarehbase-1.2.3libhbase-external-blockcache-1.2.3.jar;D:SoftWarehbase-1.2.3libhbase-hadoop2-compat-1.2.3.jar;D:SoftWarehbase-1.2.3libhbase-hadoop-compat-1.2.3.jar;D:SoftWarehbase-1.2.3libhbase-it-1.2.3.jar;D:SoftWarehbase-1.2.3libhbase-it-1.2.3-tests.jar;D:SoftWarehbase-1.2.3libhbase-prefix-tree-1.2.3.jar;D:SoftWarehbase-1.2.3libhbase-procedure-1.2.3.jar;D:SoftWarehbase-1.2.3libhbase-protocol-1.2.3.jar;D:SoftWarehbase-1.2.3libhbase-resource-bundle-1.2.3.jar;D:SoftWarehbase-1.2.3libhbase-rest-1.2.3.jar;D:SoftWarehbase-1.2.3libhbase-server-1.2.3.jar;D:SoftWarehbase-1.2.3libhbase-server-1.2.3-tests.jar;D:SoftWarehbase-1.2.3libhbase-shell-1.2.3.jar;D:SoftWarehbase-1.2.3libhbase-thrift-1.2.3.jar;D:SoftWarehbase-1.2.3libhtrace-core-3.1.0-incubating.jar;D:SoftWarehbase-1.2.3libhttpclient-4.2.5.jar;D:SoftWarehbase-1.2.3libhttpcore-4.4.1.jar;D:SoftWarehbase-1.2.3libjackson-core-asl-1.9.13.jar;D:SoftWarehbase-1.2.3libjackson-jaxrs-1.9.13.jar;D:SoftWarehbase-1.2.3libjackson-mapper-asl-1.9.13.jar;D:SoftWarehbase-1.2.3libjackson-xc-1.9.13.jar;D:SoftWarehbase-1.2.3libjamon-runtime-2.4.1.jar;D:SoftWarehbase-1.2.3libjasper-compiler-5.5.23.jar;D:SoftWarehbase-1.2.3libjasper-runtime-5.5.23.jar;D:SoftWarehbase-1.2.3libjavax.inject-1.jar;D:SoftWarehbase-1.2.3libjava-xmlbuilder-0.4.jar;D:SoftWarehbase-1.2.3libjaxb-api-2.2.2.jar;D:SoftWarehbase-1.2.3libjaxb-impl-2.2.3-1.jar;D:SoftWarehbase-1.2.3libjcodings-1.0.8.jar;D:SoftWarehbase-1.2.3libjersey-client-1.9.jar;D:SoftWarehbase-1.2.3libjersey-core-1.9.jar;D:SoftWarehbase-1.2.3libjersey-guice-1.9.jar;D:SoftWarehbase-1.2.3libjersey-json-1.9.jar;D:SoftWarehbase-1.2.3libjersey-server-1.9.jar;D:SoftWarehbase-1.2.3libjets3t-0.9.0.jar;D:SoftWarehbase-1.2.3libjettison-1.3.3.jar;D:SoftWarehbase-1.2.3libjetty-6.1.26.jar;D:SoftWarehbase-1.2.3libjetty-sslengine-6.1.26.jar;D:SoftWarehbase-1.2.3libjetty-util-6.1.26.jar;D:SoftWarehbase-1.2.3libjoni-2.1.2.jar;D:SoftWarehbase-1.2.3libjruby-complete-1.6.8.jar;D:SoftWarehbase-1.2.3libjsch-0.1.42.jar;D:SoftWarehbase-1.2.3libjsp-2.1-6.1.14.jar;D:SoftWarehbase-1.2.3libjsp-api-2.1-6.1.14.jar;D:SoftWarehbase-1.2.3libjunit-4.12.jar;D:SoftWarehbase-1.2.3libleveldbjni-all-1.8.jar;D:SoftWarehbase-1.2.3liblibthrift-0.9.3.jar;D:SoftWarehbase-1.2.3liblog4j-1.2.17.jar;D:SoftWarehbase-1.2.3libmetrics-core-2.2.0.jar;D:SoftWarehbase-1.2.3lib
etty-all-4.0.23.Final.jar;D:SoftWarehbase-1.2.3libparanamer-2.3.jar;D:SoftWarehbase-1.2.3libprotobuf-java-2.5.0.jar;D:SoftWarehbase-1.2.3libservlet-api-2.5.jar;D:SoftWarehbase-1.2.3libservlet-api-2.5-6.1.14.jar;D:SoftWarehbase-1.2.3libslf4j-api-1.7.7.jar;D:SoftWarehbase-1.2.3libslf4j-log4j12-1.7.5.jar;D:SoftWarehbase-1.2.3libsnappy-java-1.0.4.1.jar;D:SoftWarehbase-1.2.3libspymemcached-2.11.6.jar;D:SoftWarehbase-1.2.3libxmlenc-0.52.jar;D:SoftWarehbase-1.2.3libxz-1.0.jar;D:SoftWarehbase-1.2.3libzookeeper-3.4.6.jar
2016-12-10 16:13:54,568 INFO [org.apache.zookeeper.ZooKeeper] - Client environment:java.library.path=C:Program FilesJavajdk1.7.0_51in;C:WindowsSunJavain;C:Windowssystem32;C:Windows;C:ProgramDataOracleJavajavapath;C:Python27;C:Python27Scripts;C:Windowssystem32;C:Windows;C:WindowsSystem32Wbem;C:WindowsSystem32WindowsPowerShellv1.0;D:SoftWareMATLAB R2013a
untimewin64;D:SoftWareMATLAB R2013ain;C:Program Files (x86)IDM Computer SolutionsUltraCompare;C:Program FilesJavajdk1.7.0_51in;C:Program FilesJavajdk1.7.0_51jrein;D:SoftWareapache-ant-1.9.0in;HADOOP_HOMEin;D:SoftWareapache-maven-3.3.9in;D:SoftWareScalain;D:SoftWareScalajrein;%MYSQL_HOMEin;D:SoftWareMySQL ServerMySQL Server 5.0in;D:SoftWareapache-tomcat-7.0.69in;%C:WindowsSystem32;%C:WindowsSysWOW64;D:SoftWareSSH Secure Shell;.
2016-12-10 16:13:54,569 INFO [org.apache.zookeeper.ZooKeeper] - Client environment:java.io.tmpdir=C:UsersADMINI~1AppDataLocalTemp
2016-12-10 16:13:54,569 INFO [org.apache.zookeeper.ZooKeeper] - Client environment:java.compiler=<NA>
2016-12-10 16:13:54,570 INFO [org.apache.zookeeper.ZooKeeper] - Client environment:os.name=Windows 7
2016-12-10 16:13:54,570 INFO [org.apache.zookeeper.ZooKeeper] - Client environment:os.arch=amd64
2016-12-10 16:13:54,570 INFO [org.apache.zookeeper.ZooKeeper] - Client environment:os.version=6.1
2016-12-10 16:13:54,571 INFO [org.apache.zookeeper.ZooKeeper] - Client environment:user.name=Administrator
2016-12-10 16:13:54,571 INFO [org.apache.zookeeper.ZooKeeper] - Client environment:user.home=C:UsersAdministrator
2016-12-10 16:13:54,572 INFO [org.apache.zookeeper.ZooKeeper] - Client environment:user.dir=D:CodeMyEclipseJavaCodeHbaseProject
2016-12-10 16:13:54,576 INFO [org.apache.zookeeper.ZooKeeper] - Initiating client connection, connectString=HadoopMaster:2181,HadoopSlave1:2181,HadoopSlave2:2181 sessionTimeout=180000 watcher=hconnection-0x1646b78d0x0, quorum=HadoopMaster:2181,HadoopSlave1:2181,HadoopSlave2:2181, baseZNode=/hbase
2016-12-10 16:13:54,768 INFO [org.apache.zookeeper.ClientCnxn] - Opening socket connection to server HadoopMaster/192.168.80.10:2181. Will not attempt to authenticate using SASL (unknown error)
2016-12-10 16:13:54,778 INFO [org.apache.zookeeper.ClientCnxn] - Socket connection established to HadoopMaster/192.168.80.10:2181, initiating session
2016-12-10 16:13:54,855 INFO [org.apache.zookeeper.ClientCnxn] - Session establishment complete on server HadoopMaster/192.168.80.10:2181, sessionid = 0x15825dedcf40013, negotiated timeout = 40000
Exception in thread "main" org.apache.hadoop.hbase.regionserver.NoSuchColumnFamilyException: org.apache.hadoop.hbase.regionserver.NoSuchColumnFamilyException: Column family f3 does not exist in region test_table2,,1478116411036.086c41857c60fbce5f79f61c45269784. in table 'test_table2', {NAME => 'f1', DATA_BLOCK_ENCODING => 'NONE', BLOOMFILTER => 'ROW', REPLICATION_SCOPE => '0', COMPRESSION => 'NONE', VERSIONS => '1', TTL => 'FOREVER', MIN_VERSIONS => '0', KEEP_DELETED_CELLS => 'FALSE', BLOCKSIZE => '65536', IN_MEMORY => 'false', BLOCKCACHE => 'true'}, {NAME => 'f2', DATA_BLOCK_ENCODING => 'NONE', BLOOMFILTER => 'ROW', REPLICATION_SCOPE => '0', COMPRESSION => 'NONE', VERSIONS => '1', TTL => 'FOREVER', MIN_VERSIONS => '0', KEEP_DELETED_CELLS => 'FALSE', BLOCKSIZE => '65536', IN_MEMORY => 'false', BLOCKCACHE => 'true'}
at org.apache.hadoop.hbase.regionserver.HRegion.doBatchMutate(HRegion.java:3562)
at org.apache.hadoop.hbase.regionserver.HRegion.delete(HRegion.java:2604)
at org.apache.hadoop.hbase.regionserver.RSRpcServices.mutate(RSRpcServices.java:2283)
at org.apache.hadoop.hbase.protobuf.generated.ClientProtos$ClientService$2.callBlockingMethod(ClientProtos.java:33646)
at org.apache.hadoop.hbase.ipc.RpcServer.call(RpcServer.java:2178)
at org.apache.hadoop.hbase.ipc.CallRunner.run(CallRunner.java:112)
at org.apache.hadoop.hbase.ipc.RpcExecutor.consumerLoop(RpcExecutor.java:133)
at org.apache.hadoop.hbase.ipc.RpcExecutor$1.run(RpcExecutor.java:108)
at java.lang.Thread.run(Thread.java:745)
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:57)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.lang.reflect.Constructor.newInstance(Constructor.java:526)
at org.apache.hadoop.ipc.RemoteException.instantiateException(RemoteException.java:106)
at org.apache.hadoop.ipc.RemoteException.unwrapRemoteException(RemoteException.java:95)
at org.apache.hadoop.hbase.protobuf.ProtobufUtil.getRemoteException(ProtobufUtil.java:329)
at org.apache.hadoop.hbase.client.HTable$4.call(HTable.java:978)
at org.apache.hadoop.hbase.client.HTable$4.call(HTable.java:965)
at org.apache.hadoop.hbase.client.RpcRetryingCaller.callWithRetries(RpcRetryingCaller.java:136)
at org.apache.hadoop.hbase.client.HTable.delete(HTable.java:982)
at zhouls.bigdata.HbaseProject.Test1.HBaseTest.main(HBaseTest.java:31)
Caused by: org.apache.hadoop.hbase.ipc.RemoteWithExtrasException(org.apache.hadoop.hbase.regionserver.NoSuchColumnFamilyException): org.apache.hadoop.hbase.regionserver.NoSuchColumnFamilyException: Column family f3 does not exist in region test_table2,,1478116411036.086c41857c60fbce5f79f61c45269784. in table 'test_table2', {NAME => 'f1', DATA_BLOCK_ENCODING => 'NONE', BLOOMFILTER => 'ROW', REPLICATION_SCOPE => '0', COMPRESSION => 'NONE', VERSIONS => '1', TTL => 'FOREVER', MIN_VERSIONS => '0', KEEP_DELETED_CELLS => 'FALSE', BLOCKSIZE => '65536', IN_MEMORY => 'false', BLOCKCACHE => 'true'}, {NAME => 'f2', DATA_BLOCK_ENCODING => 'NONE', BLOOMFILTER => 'ROW', REPLICATION_SCOPE => '0', COMPRESSION => 'NONE', VERSIONS => '1', TTL => 'FOREVER', MIN_VERSIONS => '0', KEEP_DELETED_CELLS => 'FALSE', BLOCKSIZE => '65536', IN_MEMORY => 'false', BLOCKCACHE => 'true'}
at org.apache.hadoop.hbase.regionserver.HRegion.doBatchMutate(HRegion.java:3562)
at org.apache.hadoop.hbase.regionserver.HRegion.delete(HRegion.java:2604)
at org.apache.hadoop.hbase.regionserver.RSRpcServices.mutate(RSRpcServices.java:2283)
at org.apache.hadoop.hbase.protobuf.generated.ClientProtos$ClientService$2.callBlockingMethod(ClientProtos.java:33646)
at org.apache.hadoop.hbase.ipc.RpcServer.call(RpcServer.java:2178)
at org.apache.hadoop.hbase.ipc.CallRunner.run(CallRunner.java:112)
at org.apache.hadoop.hbase.ipc.RpcExecutor.consumerLoop(RpcExecutor.java:133)
at org.apache.hadoop.hbase.ipc.RpcExecutor$1.run(RpcExecutor.java:108)
at java.lang.Thread.run(Thread.java:745)
at org.apache.hadoop.hbase.ipc.RpcClientImpl.call(RpcClientImpl.java:1267)
at org.apache.hadoop.hbase.ipc.AbstractRpcClient.callBlockingMethod(AbstractRpcClient.java:227)
at org.apache.hadoop.hbase.ipc.AbstractRpcClient$BlockingRpcChannelImplementation.callBlockingMethod(AbstractRpcClient.java:336)
at org.apache.hadoop.hbase.protobuf.generated.ClientProtos$ClientService$BlockingStub.mutate(ClientProtos.java:34082)
at org.apache.hadoop.hbase.client.HTable$4.call(HTable.java:975)
... 4 more
这也是,
证明,为什么HBase在创建表时,列簇是必须要,列可不要?
1 package zhouls.bigdata.HbaseProject.Test1; 2 3 import javax.xml.transform.Result; 4 5 import org.apache.hadoop.conf.Configuration; 6 import org.apache.hadoop.hbase.HBaseConfiguration; 7 import org.apache.hadoop.hbase.TableName; 8 import org.apache.hadoop.hbase.client.Delete; 9 import org.apache.hadoop.hbase.client.Get; 10 import org.apache.hadoop.hbase.client.HTable; 11 import org.apache.hadoop.hbase.client.Put; 12 import org.apache.hadoop.hbase.util.Bytes; 13 14 public class HBaseTest { 15 public static void main(String[] args) throws Exception { 16 HTable table = new HTable(getConfig(),TableName.valueOf("test_table2"));//表名是test_table 17 // Put put = new Put(Bytes.toBytes("row_04"));//行键是row_01 18 // put.add(Bytes.toBytes("f1"),Bytes.toBytes("name"),Bytes.toBytes("Andy3"));//列簇是f1,列修饰符是name,值是Andy3 19 // put.add(Bytes.toBytes("f2"),Bytes.toBytes("name"),Bytes.toBytes("Andy3"));//列簇是f2,列修饰符是name,值是Andy3 20 // table.put(put); 21 22 // Get get = new Get(Bytes.toBytes("row_04")); 23 // get.addColumn(Bytes.toBytes("f1"), Bytes.toBytes("age"));如现在这样,不指定,默认把所有的全拿出来 24 // org.apache.hadoop.hbase.client.Result rest = table.get(get); 25 // System.out.println(rest.toString()); 26 // table.close(); 27 28 Delete delete = new Delete(Bytes.toBytes("row_2")); 29 delete.deleteColumn(Bytes.toBytes("f1"), Bytes.toBytes("email")); 30 delete.deleteColumn(Bytes.toBytes("f1"), Bytes.toBytes("name")); 31 table.delete(delete); 32 table.close(); 33 } 34 35 public static Configuration getConfig(){ 36 Configuration configuration = new Configuration(); 37 // conf.set("hbase.rootdir","hdfs:HadoopMaster:9000/hbase"); 38 configuration.set("hbase.zookeeper.quorum", "HadoopMaster:2181,HadoopSlave1:2181,HadoopSlave2:2181"); 39 return configuration; 40 } 41 }
2016-12-10 16:20:39,421 INFO [org.apache.hadoop.hbase.zookeeper.RecoverableZooKeeper] - Process identifier=hconnection-0x27758c30 connecting to ZooKeeper ensemble=HadoopMaster:2181,HadoopSlave1:2181,HadoopSlave2:2181
2016-12-10 16:20:39,445 INFO [org.apache.zookeeper.ZooKeeper] - Client environment:zookeeper.version=3.4.6-1569965, built on 02/20/2014 09:09 GMT
2016-12-10 16:20:39,446 INFO [org.apache.zookeeper.ZooKeeper] - Client environment:host.name=WIN-BQOBV63OBNM
2016-12-10 16:20:39,446 INFO [org.apache.zookeeper.ZooKeeper] - Client environment:java.version=1.7.0_51
2016-12-10 16:20:39,446 INFO [org.apache.zookeeper.ZooKeeper] - Client environment:java.vendor=Oracle Corporation
2016-12-10 16:20:39,446 INFO [org.apache.zookeeper.ZooKeeper] - Client environment:java.home=C:Program FilesJavajdk1.7.0_51jre
2016-12-10 16:20:39,447 INFO [org.apache.zookeeper.ZooKeeper] - Client environment:java.class.path=D:CodeMyEclipseJavaCodeHbaseProjectin;D:SoftWarehbase-1.2.3libactivation-1.1.jar;D:SoftWarehbase-1.2.3libaopalliance-1.0.jar;D:SoftWarehbase-1.2.3libapacheds-i18n-2.0.0-M15.jar;D:SoftWarehbase-1.2.3libapacheds-kerberos-codec-2.0.0-M15.jar;D:SoftWarehbase-1.2.3libapi-asn1-api-1.0.0-M20.jar;D:SoftWarehbase-1.2.3libapi-util-1.0.0-M20.jar;D:SoftWarehbase-1.2.3libasm-3.1.jar;D:SoftWarehbase-1.2.3libavro-1.7.4.jar;D:SoftWarehbase-1.2.3libcommons-beanutils-1.7.0.jar;D:SoftWarehbase-1.2.3libcommons-beanutils-core-1.8.0.jar;D:SoftWarehbase-1.2.3libcommons-cli-1.2.jar;D:SoftWarehbase-1.2.3libcommons-codec-1.9.jar;D:SoftWarehbase-1.2.3libcommons-collections-3.2.2.jar;D:SoftWarehbase-1.2.3libcommons-compress-1.4.1.jar;D:SoftWarehbase-1.2.3libcommons-configuration-1.6.jar;D:SoftWarehbase-1.2.3libcommons-daemon-1.0.13.jar;D:SoftWarehbase-1.2.3libcommons-digester-1.8.jar;D:SoftWarehbase-1.2.3libcommons-el-1.0.jar;D:SoftWarehbase-1.2.3libcommons-httpclient-3.1.jar;D:SoftWarehbase-1.2.3libcommons-io-2.4.jar;D:SoftWarehbase-1.2.3libcommons-lang-2.6.jar;D:SoftWarehbase-1.2.3libcommons-logging-1.2.jar;D:SoftWarehbase-1.2.3libcommons-math-2.2.jar;D:SoftWarehbase-1.2.3libcommons-math3-3.1.1.jar;D:SoftWarehbase-1.2.3libcommons-net-3.1.jar;D:SoftWarehbase-1.2.3libdisruptor-3.3.0.jar;D:SoftWarehbase-1.2.3libfindbugs-annotations-1.3.9-1.jar;D:SoftWarehbase-1.2.3libguava-12.0.1.jar;D:SoftWarehbase-1.2.3libguice-3.0.jar;D:SoftWarehbase-1.2.3libguice-servlet-3.0.jar;D:SoftWarehbase-1.2.3libhadoop-annotations-2.5.1.jar;D:SoftWarehbase-1.2.3libhadoop-auth-2.5.1.jar;D:SoftWarehbase-1.2.3libhadoop-client-2.5.1.jar;D:SoftWarehbase-1.2.3libhadoop-common-2.5.1.jar;D:SoftWarehbase-1.2.3libhadoop-hdfs-2.5.1.jar;D:SoftWarehbase-1.2.3libhadoop-mapreduce-client-app-2.5.1.jar;D:SoftWarehbase-1.2.3libhadoop-mapreduce-client-common-2.5.1.jar;D:SoftWarehbase-1.2.3libhadoop-mapreduce-client-core-2.5.1.jar;D:SoftWarehbase-1.2.3libhadoop-mapreduce-client-jobclient-2.5.1.jar;D:SoftWarehbase-1.2.3libhadoop-mapreduce-client-shuffle-2.5.1.jar;D:SoftWarehbase-1.2.3libhadoop-yarn-api-2.5.1.jar;D:SoftWarehbase-1.2.3libhadoop-yarn-client-2.5.1.jar;D:SoftWarehbase-1.2.3libhadoop-yarn-common-2.5.1.jar;D:SoftWarehbase-1.2.3libhadoop-yarn-server-common-2.5.1.jar;D:SoftWarehbase-1.2.3libhbase-annotations-1.2.3.jar;D:SoftWarehbase-1.2.3libhbase-annotations-1.2.3-tests.jar;D:SoftWarehbase-1.2.3libhbase-client-1.2.3.jar;D:SoftWarehbase-1.2.3libhbase-common-1.2.3.jar;D:SoftWarehbase-1.2.3libhbase-common-1.2.3-tests.jar;D:SoftWarehbase-1.2.3libhbase-examples-1.2.3.jar;D:SoftWarehbase-1.2.3libhbase-external-blockcache-1.2.3.jar;D:SoftWarehbase-1.2.3libhbase-hadoop2-compat-1.2.3.jar;D:SoftWarehbase-1.2.3libhbase-hadoop-compat-1.2.3.jar;D:SoftWarehbase-1.2.3libhbase-it-1.2.3.jar;D:SoftWarehbase-1.2.3libhbase-it-1.2.3-tests.jar;D:SoftWarehbase-1.2.3libhbase-prefix-tree-1.2.3.jar;D:SoftWarehbase-1.2.3libhbase-procedure-1.2.3.jar;D:SoftWarehbase-1.2.3libhbase-protocol-1.2.3.jar;D:SoftWarehbase-1.2.3libhbase-resource-bundle-1.2.3.jar;D:SoftWarehbase-1.2.3libhbase-rest-1.2.3.jar;D:SoftWarehbase-1.2.3libhbase-server-1.2.3.jar;D:SoftWarehbase-1.2.3libhbase-server-1.2.3-tests.jar;D:SoftWarehbase-1.2.3libhbase-shell-1.2.3.jar;D:SoftWarehbase-1.2.3libhbase-thrift-1.2.3.jar;D:SoftWarehbase-1.2.3libhtrace-core-3.1.0-incubating.jar;D:SoftWarehbase-1.2.3libhttpclient-4.2.5.jar;D:SoftWarehbase-1.2.3libhttpcore-4.4.1.jar;D:SoftWarehbase-1.2.3libjackson-core-asl-1.9.13.jar;D:SoftWarehbase-1.2.3libjackson-jaxrs-1.9.13.jar;D:SoftWarehbase-1.2.3libjackson-mapper-asl-1.9.13.jar;D:SoftWarehbase-1.2.3libjackson-xc-1.9.13.jar;D:SoftWarehbase-1.2.3libjamon-runtime-2.4.1.jar;D:SoftWarehbase-1.2.3libjasper-compiler-5.5.23.jar;D:SoftWarehbase-1.2.3libjasper-runtime-5.5.23.jar;D:SoftWarehbase-1.2.3libjavax.inject-1.jar;D:SoftWarehbase-1.2.3libjava-xmlbuilder-0.4.jar;D:SoftWarehbase-1.2.3libjaxb-api-2.2.2.jar;D:SoftWarehbase-1.2.3libjaxb-impl-2.2.3-1.jar;D:SoftWarehbase-1.2.3libjcodings-1.0.8.jar;D:SoftWarehbase-1.2.3libjersey-client-1.9.jar;D:SoftWarehbase-1.2.3libjersey-core-1.9.jar;D:SoftWarehbase-1.2.3libjersey-guice-1.9.jar;D:SoftWarehbase-1.2.3libjersey-json-1.9.jar;D:SoftWarehbase-1.2.3libjersey-server-1.9.jar;D:SoftWarehbase-1.2.3libjets3t-0.9.0.jar;D:SoftWarehbase-1.2.3libjettison-1.3.3.jar;D:SoftWarehbase-1.2.3libjetty-6.1.26.jar;D:SoftWarehbase-1.2.3libjetty-sslengine-6.1.26.jar;D:SoftWarehbase-1.2.3libjetty-util-6.1.26.jar;D:SoftWarehbase-1.2.3libjoni-2.1.2.jar;D:SoftWarehbase-1.2.3libjruby-complete-1.6.8.jar;D:SoftWarehbase-1.2.3libjsch-0.1.42.jar;D:SoftWarehbase-1.2.3libjsp-2.1-6.1.14.jar;D:SoftWarehbase-1.2.3libjsp-api-2.1-6.1.14.jar;D:SoftWarehbase-1.2.3libjunit-4.12.jar;D:SoftWarehbase-1.2.3libleveldbjni-all-1.8.jar;D:SoftWarehbase-1.2.3liblibthrift-0.9.3.jar;D:SoftWarehbase-1.2.3liblog4j-1.2.17.jar;D:SoftWarehbase-1.2.3libmetrics-core-2.2.0.jar;D:SoftWarehbase-1.2.3lib
etty-all-4.0.23.Final.jar;D:SoftWarehbase-1.2.3libparanamer-2.3.jar;D:SoftWarehbase-1.2.3libprotobuf-java-2.5.0.jar;D:SoftWarehbase-1.2.3libservlet-api-2.5.jar;D:SoftWarehbase-1.2.3libservlet-api-2.5-6.1.14.jar;D:SoftWarehbase-1.2.3libslf4j-api-1.7.7.jar;D:SoftWarehbase-1.2.3libslf4j-log4j12-1.7.5.jar;D:SoftWarehbase-1.2.3libsnappy-java-1.0.4.1.jar;D:SoftWarehbase-1.2.3libspymemcached-2.11.6.jar;D:SoftWarehbase-1.2.3libxmlenc-0.52.jar;D:SoftWarehbase-1.2.3libxz-1.0.jar;D:SoftWarehbase-1.2.3libzookeeper-3.4.6.jar
2016-12-10 16:20:39,448 INFO [org.apache.zookeeper.ZooKeeper] - Client environment:java.library.path=C:Program FilesJavajdk1.7.0_51in;C:WindowsSunJavain;C:Windowssystem32;C:Windows;C:ProgramDataOracleJavajavapath;C:Python27;C:Python27Scripts;C:Windowssystem32;C:Windows;C:WindowsSystem32Wbem;C:WindowsSystem32WindowsPowerShellv1.0;D:SoftWareMATLAB R2013a
untimewin64;D:SoftWareMATLAB R2013ain;C:Program Files (x86)IDM Computer SolutionsUltraCompare;C:Program FilesJavajdk1.7.0_51in;C:Program FilesJavajdk1.7.0_51jrein;D:SoftWareapache-ant-1.9.0in;HADOOP_HOMEin;D:SoftWareapache-maven-3.3.9in;D:SoftWareScalain;D:SoftWareScalajrein;%MYSQL_HOMEin;D:SoftWareMySQL ServerMySQL Server 5.0in;D:SoftWareapache-tomcat-7.0.69in;%C:WindowsSystem32;%C:WindowsSysWOW64;D:SoftWareSSH Secure Shell;.
2016-12-10 16:20:39,448 INFO [org.apache.zookeeper.ZooKeeper] - Client environment:java.io.tmpdir=C:UsersADMINI~1AppDataLocalTemp
2016-12-10 16:20:39,448 INFO [org.apache.zookeeper.ZooKeeper] - Client environment:java.compiler=<NA>
2016-12-10 16:20:39,449 INFO [org.apache.zookeeper.ZooKeeper] - Client environment:os.name=Windows 7
2016-12-10 16:20:39,449 INFO [org.apache.zookeeper.ZooKeeper] - Client environment:os.arch=amd64
2016-12-10 16:20:39,449 INFO [org.apache.zookeeper.ZooKeeper] - Client environment:os.version=6.1
2016-12-10 16:20:39,449 INFO [org.apache.zookeeper.ZooKeeper] - Client environment:user.name=Administrator
2016-12-10 16:20:39,450 INFO [org.apache.zookeeper.ZooKeeper] - Client environment:user.home=C:UsersAdministrator
2016-12-10 16:20:39,450 INFO [org.apache.zookeeper.ZooKeeper] - Client environment:user.dir=D:CodeMyEclipseJavaCodeHbaseProject
2016-12-10 16:20:39,452 INFO [org.apache.zookeeper.ZooKeeper] - Initiating client connection, connectString=HadoopMaster:2181,HadoopSlave1:2181,HadoopSlave2:2181 sessionTimeout=180000 watcher=hconnection-0x27758c300x0, quorum=HadoopMaster:2181,HadoopSlave1:2181,HadoopSlave2:2181, baseZNode=/hbase
2016-12-10 16:20:39,562 INFO [org.apache.zookeeper.ClientCnxn] - Opening socket connection to server HadoopSlave1/192.168.80.11:2181. Will not attempt to authenticate using SASL (unknown error)
2016-12-10 16:20:39,567 INFO [org.apache.zookeeper.ClientCnxn] - Socket connection established to HadoopSlave1/192.168.80.11:2181, initiating session
2016-12-10 16:20:39,595 INFO [org.apache.zookeeper.ClientCnxn] - Session establishment complete on server HadoopSlave1/192.168.80.11:2181, sessionid = 0x2587338ecb40011, negotiated timeout = 40000
2016-12-10 16:20:41,278 INFO [org.apache.hadoop.hbase.client.ConnectionManager$HConnectionImplementation] - Closing zookeeper sessionid=0x2587338ecb40011
2016-12-10 16:20:41,283 INFO [org.apache.zookeeper.ZooKeeper] - Session: 0x2587338ecb40011 closed
2016-12-10 16:20:41,284 INFO [org.apache.zookeeper.ClientCnxn] - EventThread shut down
hbase(main):017:0> scan 'test_table2'
ROW COLUMN+CELL
row_1 column=f1:age, timestamp=1478119757136, value=25
row_1 column=f1:name, timestamp=1478119459805, value=andy
row_2 column=f1:email, timestamp=1478120078440, value=10086@qq.com
row_2 column=f1:name, timestamp=1478120133536, value=maizi
2 row(s) in 0.1520 seconds
hbase(main):018:0> scan 'test_table2'
ROW COLUMN+CELL
row_1 column=f1:age, timestamp=1478119757136, value=25
row_1 column=f1:name, timestamp=1478119459805, value=andy
1 row(s) in 0.1110 seconds
hbase(main):019:0>
这就是,若不指定删除的列,则
Delete delete = new Delete(Bytes.toBytes("row_2"));
会删除,全部的列。
这就是,若指定删除的列,则
delete.deleteColumn(Bytes.toBytes("f1"), Bytes.toBytes("email"));
delete.deleteColumn(Bytes.toBytes("f1"), Bytes.toBytes("name"));
只删除,被指定的列