'How do I get the number of columns of a table in hbase with java
How can I get the number of columns of a table in HBASE using java
This is my code in java
HBASE Version
hbase(main):002:0> -version
2.0.0.3.0.1.0-187, re9fcf450949102de5069b257a6dee469b8f5aab3, Wed Sep 19 10:16:35 UTC 2018
Took 0.0004 seconds
NoMethodError: undefined method `-@' for nil:NilClass
I want to know if I am making the connection correctly or if something is missing or how can I correct On the other hand, the way to consult the name of the table and the number of columns is fine or something else should be added.
Java
package hbase;
import java.io.IOException;
import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.hbase.*;
import org.apache.hadoop.hbase.client.Connection;
import org.apache.hadoop.hbase.client.ConnectionFactory;
import org.apache.hadoop.hbase.client.Result;
import org.apache.hadoop.hbase.client.ResultScanner;
import org.apache.hadoop.hbase.client.Scan;
import org.apache.hadoop.hbase.client.Table;
import org.apache.hadoop.security.UserGroupInformation;
/**
*
* @author home
*/
public class HBase {
/**
* @param args the command line arguments
* @throws org.apache.hadoop.hbase.MasterNotRunningException
*/
protected static Connection conn;
public static void main(String[] args) throws MasterNotRunningException, IOException {
String hbaseZookeeperQuorum = "pgdacl-hdpmg01.sitio.com,pgdacl-hdpmg02.sitio.com,pgdacl-hdpmg03.sitio.com";
int hbaseZookeeperClientPort = 2181;
String znodeParent = "/hbase-secure";
String hadoopSecurity = "Kerberos";
String userLogin = "[email protected]";
String keyTab = "/etc/security/keytabs/gsioper.keytab";
String hbaseSite = "/usr/hdp/3.0.1.0-187/hbase/conf/hbase-site.xml";
//
Configuration config = HBaseConfiguration.create();
config.addResource(hbaseSite);
config.set("hbase.zookeeper.quorum", hbaseZookeeperQuorum);
config.setInt("hbase.zookeeper.property.clientPort", hbaseZookeeperClientPort);
config.set("zookeeper.znode.parent", znodeParent);
config.set("hadoop.security.authentication", hadoopSecurity);
UserGroupInformation.setConfiguration(config);
UserGroupInformation.loginUserFromKeytab(userLogin, keyTab);
Connection connection = ConnectionFactory.createConnection(config);
Table table = connection.getTable(TableName.valueOf("MONITOR:PARAMS_AIC"));
Scan scan = new Scan();
ResultScanner results = table.getScanner(scan);
int count = 0;
for (Result res : results) {
count += res.size();
}
results.close();
System.out.println("=========================================");
System.out.println(count);
}
}
hbase(main):001:0> !list
TABLE
MONITOR:BITACORA_CARGAS_SQOOP
MONITOR:CACHE_NIFI
MONITOR:CACHE_NIFI_EGCDR
MONITOR:CACHE_NIFI_PGWCDR_1
MONITOR:CACHE_NIFI_PGWCDR_2
MONITOR:EXAMPLE
MONITOR:LOGS
MONITOR:PARAMS_AIC
MONITOR:PARAMS_AIC3
MONITOR:PARTICIONES_DEPURACION
MONITOR:REPORTE_TMPORAL_01
MONITOR:STATS
I have this errors
what am I doing wrong
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|


