簡體   English   中英

理解在Cassandra鍵空間中插入列族的代碼?

[英]understanding the code for inserting column family in Cassandra keyspace?

我正在閱讀Cassandra- The definitive guide by E.Hewitt 我在第四章中描述了示例酒店應用程序的代碼。 這本書的圖像在此提供參考。 在此處輸入圖片說明

這是在column Family HotelByCity column Family插入行rowkeys的方法

    private void insertByCityIndex(String rowKey, String hotelName) throws Exception {
    Clock clock = new Clock(System.nanoTime());
    Column nameCol = new Column(hotelName.getBytes(UTF8), new byte[0], clock);
    ColumnOrSuperColumn nameCosc = new ColumnOrSuperColumn(); 
    nameCosc.column = nameCol;
    Mutation nameMut = new Mutation(); 
    nameMut.column_or_supercolumn = nameCosc;
    //set up the batch
    Map<String, Map<String, List<Mutation>>> mutationMap =
    new HashMap<String, Map<String, List<Mutation>>>();
    Map<String, List<Mutation>> muts =
    new HashMap<String, List<Mutation>>();
    List<Mutation> cols = new ArrayList<Mutation>();
    cols.add(nameMut);
    String columnFamily = "HotelByCity";
    muts.put(columnFamily, cols);
    //outer map key is a row key
    //inner map key is the column family name 
   mutationMap.put(rowKey, muts);
    //create representation of the column 
    ColumnPath cp = new ColumnPath(columnFamily); 
    cp.setColumn(hotelName.getBytes(UTF8));
    ColumnParent parent = new ColumnParent(columnFamily);
    //here, the column name IS the value (there's no value)
    Column col = new Column(hotelName.getBytes(UTF8), new byte[0], clock);
    client.insert(rowKey.getBytes(), parent, col, CL);
    LOG.debug("Inserted HotelByCity index for " + hotelName); } //end inserting ByCity index

我在遵循代碼方面遇到困難。 特別是為什么要創建這么多容器(地圖)。 Mutation對象等的目的是什么? 插入行鍵的精確度如何?

如果您能解釋的話,那么代碼的每個步驟都在做什么,那就太好了。 這本書沒有解釋,我無法了解如何完成此操作。

PS:我是Java開發人員。 所以我很熟悉Maps等。但是我只是不理解為什么將Map填充到另一個Map中以及其他詳細信息

謝謝

這本書描述了與Cassandra的Thrift接口。 一次很棒,因為它允許通過將Thrift API編譯成您選擇的語言來支持許多客戶。 因此,使用Thrift編寫的單個服務器API允許開箱即用的N個客戶端。

但是,節儉很難理解,並且與二進制本機協議相比要慢得多。 Thrift也是舊版API ,不應用於新的應用程序開發。 開發了新的二進制協議,並將其集成到Cassandra的更高版本中。

很難理解的不僅是您。 它是機器生成的界面,在此時此刻可能沒有什么意義,因此請不要打擾,而要看一下Java驅動程序

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM