org.apache.hadoop.hbase.TableName类的使用及代码示例

x33g5p2x  于2022-01-29 转载在 其他  
字(9.8k)|赞(0)|评价(0)|浏览(239)

本文整理了Java中org.apache.hadoop.hbase.TableName类的一些代码示例,展示了TableName类的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。TableName类的具体详情如下:
包路径:org.apache.hadoop.hbase.TableName
类名称:TableName

TableName介绍

[英]Immutable POJO class for representing a table name. Which is of the form: <table namespace>:<table qualifier> Two special namespaces: 1. hbase - system namespace, used to contain hbase internal tables 2. default - tables with no explicit specified namespace will automatically fall into this namespace. ie a) foo:bar, means namespace=foo and qualifier=bar b) bar, means namespace=default and qualifier=bar c) default:bar, means namespace=default and qualifier=bar

Internally, in this class, we cache the instances to limit the number of objects and make the "equals" faster. We try to minimize the number of objects created of the number of array copy to check if we already have an instance of this TableName. The code is not optimize for a new instance creation but is optimized to check for existence.
[中]用于表示表名的不可变POJO类。其形式为:<table namespace>:<table qualifier>两个特殊名称空间:1。hbase-系统名称空间,用于包含hbase内部表2。默认-没有显式指定名称空间的表将自动归入此名称空间。例如:a)foo:bar,意思是namespace=foo,qualifier=bar;b)bar,意思是namespace=default,qualifier=bar;c)default:bar,意思是namespace=default,qualifier=bar
在这个类内部,我们缓存实例以限制对象的数量,并使“equals”更快。我们尽量减少创建的对象数和数组副本数,以检查是否已经有这个TableName的实例。代码没有针对创建新实例进行优化,而是针对检查是否存在进行了优化。

代码示例

代码示例来源:origin: alibaba/canal

public void createTable(String tableName, String... familyNames) {
  try (HBaseAdmin admin = (HBaseAdmin) getConnection().getAdmin()) {
    HTableDescriptor desc = new HTableDescriptor(TableName.valueOf(tableName));
    // 添加列簇
    if (familyNames != null) {
      for (String familyName : familyNames) {
        HColumnDescriptor hcd = new HColumnDescriptor(familyName);
        desc.addFamily(hcd);
      }
    }
    admin.createTable(desc);
  } catch (IOException e) {
    throw new RuntimeException(e);
  }
}

代码示例来源:origin: apache/hbase

/**
 * Invokes Table#delete to delete test data (i.e. the row)
 *
 * @param table Standard Table object
 * @throws IOException If IO problem is encountered
 */
static void deleteRow(final Table table) throws IOException {
 System.out.println("Deleting row [" + Bytes.toString(MY_ROW_ID)
     + "] from Table ["
     + table.getName().getNameAsString() + "].");
 table.delete(new Delete(MY_ROW_ID));
}

代码示例来源:origin: apache/hbase

public static TableName valueOf(String namespaceAsString, String qualifierAsString) {
 if (namespaceAsString == null || namespaceAsString.length() < 1) {
  namespaceAsString = NamespaceDescriptor.DEFAULT_NAMESPACE_NAME_STR;
 }
 for (TableName tn : tableCache) {
  if (qualifierAsString.equals(tn.getQualifierAsString()) &&
    namespaceAsString.equals(tn.getNamespaceAsString())) {
   return tn;
  }
 }
 return createTableNameIfNecessary(
   ByteBuffer.wrap(Bytes.toBytes(namespaceAsString)),
   ByteBuffer.wrap(Bytes.toBytes(qualifierAsString)));
}

代码示例来源:origin: apache/hbase

public static String getFileNameCompatibleString(TableName table) {
 return table.getNamespaceAsString() + "-" + table.getQualifierAsString();
}

代码示例来源:origin: apache/hbase

/**
 * Ideally, getNameAsString should contain namespace within it,
 * but if the namespace is default, it just returns the name. This method
 * takes care of this corner case.
 */
public String getNameWithNamespaceInclAsString() {
 if(getNamespaceAsString().equals(NamespaceDescriptor.DEFAULT_NAMESPACE_NAME_STR)) {
  return NamespaceDescriptor.DEFAULT_NAMESPACE_NAME_STR +
    TableName.NAMESPACE_DELIM + getNameAsString();
 }
 return getNameAsString();
}

代码示例来源:origin: apache/hbase

/**
 * Gets the table name used in the table lock.
 * The table lock name is a dummy one, it's not a table name. It's tableName + ".mobLock".
 * @param tn The table name.
 * @return The table name used in table lock.
 */
public static TableName getTableLockName(TableName tn) {
 byte[] tableName = tn.getName();
 return TableName.valueOf(Bytes.add(tableName, MobConstants.MOB_TABLE_LOCK_SUFFIX));
}

代码示例来源:origin: apache/hbase

@Before
public void setUp() throws Exception {
 DELAY_GET = 0;
 DELAY_SCAN = 0;
 DELAY_MUTATE = 0;
 table = TESTING_UTIL.createTable(TableName.valueOf(name.getMethodName()), FAMILY);
 Put put = new Put(ROW);
 put.addColumn(FAMILY, QUALIFIER, VALUE);
 table.put(put);
}

代码示例来源:origin: apache/hbase

@Override
protected Table createTable(byte[] fam) throws IOException {
 TableName tableName = TableName.valueOf(testName.getMethodName());
 TEST_UTIL.getAdmin().createTable(TableDescriptorBuilder.newBuilder(tableName)
   .setColumnFamily(ColumnFamilyDescriptorBuilder.of(fam)).build());
 return TEST_UTIL.getConnection().getTable(tableName);
}

代码示例来源:origin: apache/hbase

@Test
public void createTableInDefaultNamespace() throws Exception {
 HTableDescriptor desc = new HTableDescriptor(TableName.valueOf(name.getMethodName()));
 HColumnDescriptor colDesc = new HColumnDescriptor("cf1");
 desc.addFamily(colDesc);
 admin.createTable(desc);
 assertTrue(admin.listTables().length == 1);
 admin.disableTable(desc.getTableName());
 admin.deleteTable(desc.getTableName());
}

代码示例来源:origin: apache/hbase

@Test
public void testDisableCatalogTable() throws Exception {
 try {
  this.admin.disableTable(TableName.META_TABLE_NAME);
  fail("Expected to throw ConstraintException");
 } catch (ConstraintException e) {
 }
 // Before the fix for HBASE-6146, the below table creation was failing as the hbase:meta table
 // actually getting disabled by the disableTable() call.
 HTableDescriptor htd =
   new HTableDescriptor(TableName.valueOf(Bytes.toBytes(name.getMethodName())));
 HColumnDescriptor hcd = new HColumnDescriptor(Bytes.toBytes("cf1"));
 htd.addFamily(hcd);
 TEST_UTIL.getHBaseAdmin().createTable(htd);
}

代码示例来源:origin: apache/hbase

@Test(expected=IllegalArgumentException.class)
public void testAddDuplicateFamilies() {
 HTableDescriptor htd = new HTableDescriptor(TableName.valueOf(name.getMethodName()));
 byte[] familyName = Bytes.toBytes("cf");
 HColumnDescriptor hcd = new HColumnDescriptor(familyName);
 hcd.setBlocksize(1000);
 htd.addFamily(hcd);
 assertEquals(1000, htd.getFamily(familyName).getBlocksize());
 hcd = new HColumnDescriptor(familyName);
 hcd.setBlocksize(2000);
 htd.addFamily(hcd);
}

代码示例来源:origin: apache/hbase

@Test
public void testImmutableHColumnDescriptor() {
 HTableDescriptor htd = new HTableDescriptor(TableName.valueOf(name.getMethodName()));
 htd.addFamily(new HColumnDescriptor(Bytes.toBytes("family")));
 ImmutableHTableDescriptor immutableHtd = new ImmutableHTableDescriptor(htd);
 for (HColumnDescriptor hcd : immutableHtd.getColumnFamilies()) {
  assertReadOnly(hcd);
 }
 for (HColumnDescriptor hcd : immutableHtd.getFamilies()) {
  assertReadOnly(hcd);
 }
}

代码示例来源:origin: apache/hbase

@Test
public void testHTableExistsBeforeGet() throws Exception {
 Table table = TEST_UTIL.createTable(TableName.valueOf(name.getMethodName()),
   new byte[][] { FAMILY });
 try {
  Put put = new Put(ROW);
  put.addColumn(FAMILY, QUALIFIER, VALUE);
  table.put(put);
  Get get = new Get(ROW);
  boolean exist = table.exists(get);
  assertEquals(true, exist);
  Result result = table.get(get);
  assertEquals(false, result.isEmpty());
  assertTrue(Bytes.equals(VALUE, result.getValue(FAMILY, QUALIFIER)));
 } finally {
  table.close();
 }
}

代码示例来源:origin: apache/hbase

@Test
 public void testFlush() throws IOException {
  byte[] row = Bytes.toBytes("row");
  byte[] cf = Bytes.toBytes("cf");
  byte[] cq = Bytes.toBytes("cq");
  byte[] value = Bytes.toBytes("value");

  TableName name = TableName.valueOf(getClass().getSimpleName());

  Table t = util.createTable(name, cf);
  t.put(new Put(row).addColumn(cf, cq, value));

  util.getAdmin().flush(name);

  assertArrayEquals(value, t.get(new Get(row)).getValue(cf, cq));
 }
}

代码示例来源:origin: apache/hbase

@Test(expected=IllegalArgumentException.class)
public void testModifyInexistentFamily() {
 HTableDescriptor htd = new HTableDescriptor(TableName.valueOf(name.getMethodName()));
 byte[] familyName = Bytes.toBytes("cf");
 HColumnDescriptor hcd = new HColumnDescriptor(familyName);
 htd.modifyFamily(hcd);
}

代码示例来源:origin: apache/hbase

@Test(expected = DoNotRetryIOException.class)
public void testScanOnCorruptHFile() throws IOException {
 TableName tableName = TableName.valueOf(name.getMethodName());
 HTableDescriptor htd = new HTableDescriptor(tableName);
 htd.addCoprocessor(CorruptHFileCoprocessor.class.getName());
 htd.addFamily(new HColumnDescriptor(FAMILY_NAME));
 Table table = TEST_UTIL.createTable(htd, null);
 try {
  loadTable(table, 1);
  scan(table);
 } finally {
  table.close();
 }
}

代码示例来源:origin: apache/hbase

@Override
 public Void call() throws Exception {
  HTableDescriptor htd =
    new HTableDescriptor(TableName.valueOf("non_existing_namespace", name.getMethodName()));
  htd.addFamily(new HColumnDescriptor("family1"));
  admin.createTable(htd);
  return null;
 }
}, NamespaceNotFoundException.class);

代码示例来源:origin: apache/hbase

private Table createTable() throws IOException {
 TableName tableName = TableName.valueOf(name.getMethodName());
 HTableDescriptor table = new HTableDescriptor(tableName);
 HColumnDescriptor fam = new HColumnDescriptor(FAMILY);
 fam.setNewVersionBehavior(true);
 fam.setMaxVersions(3);
 table.addFamily(fam);
 TEST_UTIL.getHBaseAdmin().createTable(table);
 return TEST_UTIL.getConnection().getTable(tableName);
}

代码示例来源:origin: apache/hbase

@Test
public void testSuperSimple() throws Exception {
 final TableName tableName = TableName.valueOf(name.getMethodName());
 Table ht = TEST_UTIL.createTable(tableName, FAMILY);
 Put put = new Put(ROW);
 put.addColumn(FAMILY, QUALIFIER, VALUE);
 ht.put(put);
 Scan scan = new Scan();
 scan.addColumn(FAMILY, tableName.toBytes());
 ResultScanner scanner = ht.getScanner(scan);
 Result result = scanner.next();
 assertTrue("Expected null result", result == null);
 scanner.close();
}

代码示例来源:origin: apache/hbase

@Test(expected=RetriesExhaustedException.class)
 public void testSocketClosed() throws IOException, InterruptedException {
  TableName tableName = TableName.valueOf(name.getMethodName());
  UTIL.createTable(tableName, fam1).close();

  Configuration conf = new Configuration(UTIL.getConfiguration());
  conf.set(RpcClientFactory.CUSTOM_RPC_CLIENT_IMPL_CONF_KEY,
   MyRpcClientImpl.class.getName());
  conf.setInt(HConstants.HBASE_CLIENT_RETRIES_NUMBER, 2);
  Connection connection = ConnectionFactory.createConnection(conf);
  Table table = connection.getTable(TableName.valueOf(name.getMethodName()));
  table.get(new Get(Bytes.toBytes("asd")));
  connection.close();
  for (Socket socket : MyRpcClientImpl.savedSockets) {
   assertTrue("Socket + " +  socket + " is not closed", socket.isClosed());
  }
 }
}

相关文章