Hbase之嘗試使用錯誤列族獲取數據


import com.google.common.base.Strings;
import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.hbase.HBaseConfiguration;
import org.apache.hadoop.hbase.TableName;
import org.apache.hadoop.hbase.client.*;
import org.apache.hadoop.hbase.util.Bytes;

import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

/**
 * 嘗試獲取數據使用錯誤的列族
 */
public class GetDataWithErrorColFamily {
    public static void main(String args[]) throws IOException {
        Configuration configuration = HBaseConfiguration.create();
        Connection connection = ConnectionFactory.createConnection(configuration);
        //建立表的連接
        Table table = connection.getTable(TableName.valueOf("testtable"));
        List<Get> gets = new ArrayList<Get>();
        //列族
        byte[] cf1 = Bytes.toBytes("colfam1");
        //列限定符
        byte[] qf1 = Bytes.toBytes("qual1");
        //列限定符
        byte[] qf2 = Bytes.toBytes("qual2");
        //行鍵
        byte[] row1 = Bytes.toBytes("10010");
        //行鍵
        byte[] row2 = Bytes.toBytes("10086");
        Get get1 = new Get(row1);
        get1.addColumn(cf1,qf1);
        gets.add(get1);

        Get get2 = new Get(row2);
        get2.addColumn(cf1,qf1);
        gets.add(get2);

        Get get3 = new Get(row2);
        get3.addColumn(cf1,qf2);
        gets.add(get3);

        Get get4 = new Get(row2);
        //這個列族根本不存在
        get4.addColumn(Bytes.toBytes("BOGUS"), qf2);
        gets.add(get4);

        //拋出異常 進程中斷
        //Exception in thread "main" org.apache.hadoop.hbase.client.RetriesExhaustedWithDetailsException: Failed 1 action: org.apache.hadoop.hbase.regionserver.NoSuchColumnFamilyException: Column family BOGUS does not exist in region testtable,,1470907049676.32bcdb9d8df5829ae7eda1ae06cc9dc0. in table 'testtable', {NAME => 'colfam1', 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'}
        Result[] results = table.get(gets);
        //下面的打印到達並了
        System.out.println("Result count: " + results.length);
    }
}

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM