[
https://issues.apache.org/jira/browse/HBASE-13599?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=14520722#comment-14520722
]
David Newcomer commented on HBASE-13599:
----------------------------------------
I'm not sure if this is exactly what y'all were looking for, but here's a
modified version of the example that I was able to build and run:
<CODE>
import org.apache.hadoop.hbase.HColumnDescriptor;
import org.apache.hadoop.hbase.HTableDescriptor;
import org.apache.hadoop.hbase.TableName;
import org.apache.hadoop.hbase.client.Admin;
import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.Path;
import org.apache.hadoop.hbase.HBaseConfiguration;
import org.apache.hadoop.hbase.client.Connection;
import org.apache.hadoop.hbase.client.ConnectionFactory;
public class CreateSchema {
private static final String TABLE_NAME = "MY_TABLE_NAME_TOO";
private static final String CF_DEFAULT = "DEFAULT_COLUMN_FAMILY";
public static void createOrOverwrite(Admin admin, HTableDescriptor table)
throws Exception {
if (admin.tableExists(table.getTableName())) {
admin.disableTable(table.getTableName());
admin.deleteTable(table.getTableName());
}
admin.createTable(table);
}
public static void createSchemaTables(Configuration config) throws
Exception {
try (Connection connection = ConnectionFactory.createConnection(config);
Admin admin = connection.getAdmin();) {
HTableDescriptor table = new
HTableDescriptor(TableName.valueOf(TABLE_NAME));
//Enables table compression, if SNAPPY is installed.
// table.addFamily(new
HColumnDescriptor(CF_DEFAULT).setCompressionType(Algorithm.SNAPPY));
table.addFamily(new HColumnDescriptor(CF_DEFAULT));
System.out.print("Creating table. ");
createOrOverwrite(admin, table);
System.out.println(" Done.");
admin.close();
}
}
public static void main(String... args) throws Exception {
Configuration config = HBaseConfiguration.create();
//Add any necessary configuration files (hbase-site.xml, core-site.xml)
config.addResource(new Path(System.getenv("HBASE_CONF_DIR"),
"hbase-site.xml"));
config.addResource(new Path(System.getenv("HADOOP_CONF_DIR"),
"core-site.xml"));
createSchemaTables(config);
}
}
</CODE>
> The Example Provided in Section 69: Examples of the Documentation Does Not
> Compile
> ----------------------------------------------------------------------------------
>
> Key: HBASE-13599
> URL: https://issues.apache.org/jira/browse/HBASE-13599
> Project: HBase
> Issue Type: Bug
> Components: documentation
> Affects Versions: 1.0.0
> Reporter: David Newcomer
> Priority: Minor
>
> I'm trying to build and run the example java code I found in the HBase
> Documentation, and I'm running into several issues.
> 1. I don't have the code/library used in the following import:
> import static com.example.hbase.Constants.*;
> I don't believe it is included in any of the HBase libraries or documentation.
> 2. All of the methods in createOrOverwrite() that use table.getName() should
> instead be using table.getTableName()
> 3. The interface org.apache.hadoop.hbase.client.Admin is abstract, and can't
> be instantiated with a Configuration. Constructing an
> org.apache.hadoop.hbase.client.HBaseAdmin would allow the code to compile,
> but that constructor is deprecated.
> 4. I have no references to the field "TABLE_NAME" or "CF_DEFAULT". I'm
> assuming they are Strings in com.example.hbase.Constants. Perhaps those
> variables should simply be copied into the the Example?
> Link to the documentation section:
> http://hbase.apache.org/book.html#_examples
> <code>
> package com.example.hbase.admin;
> 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.TableName;
> import org.apache.hadoop.hbase.client.Admin;
> import org.apache.hadoop.hbase.io.compress.Compression.Algorithm;
> import org.apache.hadoop.conf.Configuration;
> import static com.example.hbase.Constants.*;
> public class CreateSchema {
> public static void createOrOverwrite(Admin admin, HTableDescriptor table)
> throws IOException {
> if (admin.tableExists(table.getName())) {
> admin.disableTable(table.getName());
> admin.deleteTable(table.getName());
> }
> admin.createTable(table);
> }
> public static void createSchemaTables (Configuration config) {
> try {
> final Admin admin = new Admin(config);
> HTableDescriptor table = new
> HTableDescriptor(TableName.valueOf(TABLE_NAME));
> table.addFamily(new
> HColumnDescriptor(CF_DEFAULT).setCompressionType(Algorithm.SNAPPY));
> System.out.print("Creating table. ");
> createOrOverwrite(admin, table);
> System.out.println(" Done.");
> admin.close();
> } catch (Exception e) {
> e.printStackTrace();
> System.exit(-1);
> }
> }
> }
> </code>
--
This message was sent by Atlassian JIRA
(v6.3.4#6332)