欧美三区_成人在线免费观看视频_欧美极品少妇xxxxⅹ免费视频_a级毛片免费播放_鲁一鲁中文字幕久久_亚洲一级特黄

Thrift 2中g(shù)et用法的詳細(xì)解析

系統(tǒng) 1961 0

Thrift2相比于Thrift 1改動(dòng)較大,這里不去描述改動(dòng)的地方,但是它的改動(dòng)確實(shí)比Thrift1方便了很多。但是不能理解的是Thrift2網(wǎng)上的資料和文檔相當(dāng)?shù)纳伲鸵訲hrift2操作Hbase為例,Thrift2提供的crud操作主要有Put, Get, Delete, Scan和Increment,網(wǎng)上及官網(wǎng)上對(duì)其使用也比較簡(jiǎn)單,對(duì)于實(shí)現(xiàn)一些復(fù)雜的操作無(wú)從下手,面對(duì)這么囧的狀況,沒(méi)辦法,只能去研究源碼了。通過(guò)研究源碼知道了Put, Get, Delete, Scan和Increment下一些復(fù)雜操作的使用,現(xiàn)以get為例進(jìn)行描述,其他的都和get相似。

先看hbase_types.js中TGet:

      
         1
      
       TGet = module.exports.TGet = 
      
        function
      
      
        (args) {


      
      
         2
      
      
        this
      
      .row = 
      
        null
      
      
        ;


      
      
         3
      
      
        this
      
      .columns = 
      
        null
      
      
        ;


      
      
         4
      
      
        this
      
      .timestamp = 
      
        null
      
      
        ;


      
      
         5
      
      
        this
      
      .timeRange = 
      
        null
      
      
        ;


      
      
         6
      
      
        this
      
      .maxVersions = 
      
        null
      
      
        ;


      
      
         7
      
      
        this
      
      .filterString = 
      
        null
      
      
        ;


      
      
         8
      
      
        this
      
      .attributes = 
      
        null
      
      
        ;


      
      
         9
      
      
        if
      
      
         (args) {


      
      
        10
      
      
        if
      
       (args.row !==
      
         undefined) {


      
      
        11
      
      
        this
      
      .row =
      
         args.row;


      
      
        12
      
      
            }


      
      
        13
      
      
        if
      
       (args.columns !==
      
         undefined) {


      
      
        14
      
      
        this
      
      .columns =
      
         args.columns;


      
      
        15
      
      
            }


      
      
        16
      
      
        if
      
       (args.timestamp !==
      
         undefined) {


      
      
        17
      
      
        this
      
      .timestamp =
      
         args.timestamp;


      
      
        18
      
      
            }


      
      
        19
      
      
        if
      
       (args.timeRange !==
      
         undefined) {


      
      
        20
      
      
        this
      
      .timeRange =
      
         args.timeRange;


      
      
        21
      
      
            }


      
      
        22
      
      
        if
      
       (args.maxVersions !==
      
         undefined) {


      
      
        23
      
      
        this
      
      .maxVersions =
      
         args.maxVersions;


      
      
        24
      
      
            }


      
      
        25
      
      
        if
      
       (args.filterString !==
      
         undefined) {


      
      
        26
      
      
        this
      
      .filterString =
      
         args.filterString;


      
      
        27
      
      
            }


      
      
        28
      
      
        if
      
       (args.attributes !==
      
         undefined) {


      
      
        29
      
      
        this
      
      .attributes =
      
         args.attributes;


      
      
        30
      
      
            }


      
      
        31
      
      
          }


      
      
        32
      
       };
    

THBase_Severce.js中g(shù)et部分代碼如下:

      
         1
      
       THBaseService_get_args = 
      
        function
      
      
        (args) {


      
      
         2
      
      
        this
      
      .table = 
      
        null
      
      
        ;


      
      
         3
      
      
        this
      
      .get = 
      
        null
      
      
        ;


      
      
         4
      
      
        if
      
      
         (args) {


      
      
         5
      
      
        if
      
       (args.table !==
      
         undefined) {


      
      
         6
      
      
        this
      
      .table =
      
         args.table;


      
      
         7
      
      
            }


      
      
         8
      
      
        if
      
       (args.get !==
      
         undefined) {


      
      
         9
      
      
        this
      
      .get =
      
         args.get;


      
      
        10
      
      
            }


      
      
        11
      
      
          }


      
      
        12
      
       };
    

由以上的部分源碼可知,使用get要用到TGet,TGet中有7個(gè)參數(shù),分別為row、columns、timestamp、timeRange、maxVersions、filterString、attributes。

如果只是簡(jiǎn)單的在Hbase取某一行的數(shù)據(jù),代碼如下:

      
         1
      
      
        var
      
       thrift = require('thrift'
      
        );


      
      
         2
      
      
        var
      
       HBase = require('./gen-nodejs/THBaseService'
      
        );


      
      
         3
      
      
        var
      
       HBaseTypes = require('./gen-nodejs/hbase_types'
      
        );


      
      
         4
      
      
         5
      
      
        var
      
       connection = thrift.createConnection('localhost', 9090
      
        , {


      
      
         6
      
      
          transport: thrift.TFramedTransport,


      
      
         7
      
      
          protocol: thrift.TBinaryProtocol


      
      
         8
      
      
        });


      
      
         9
      
      
        10
      
       connection.on('connect', 
      
        function
      
      
         () {


      
      
        11
      
         console.log('connected'
      
        );


      
      
        12
      
      
        var
      
       client =
      
         thrift.createClient(HBase, connection);


      
      
        13
      
      
        14
      
      
        15
      
      
        var
      
       tGet = 
      
        new
      
       HBaseTypes.TGet({row: '10_20121208'
      
        ,


      
      
        16
      
           columns: [
      
        new
      
       HBaseTypes.TColumn({family: 'DATA'
      
        })]});


      
      
        17
      
         client.get('tablename', tGet, 
      
        function
      
      
         (err, data) {


      
      
        18
      
      
        if
      
      
         (err) {


      
      
        19
      
      
              console.log(err);


      
      
        20
      
           } 
      
        else
      
      
         {


      
      
        21
      
      
              console.log(data);


      
      
        22
      
      
            }


      
      
        23
      
      
            connection.end();


      
      
        24
      
      
          });


      
      
        25
      
      
        26
      
      
        });


      
      
        27
      
      
        28
      
       connection.on('error', 
      
        function
      
      
        (err){


      
      
        29
      
         console.log('error'
      
        , err);


      
      
        30
      
       });
    

當(dāng)然如果想對(duì)輸出數(shù)據(jù)的個(gè)數(shù)加以限制的話,可以通過(guò)maxVersions的值來(lái)設(shè)定,這里就不解釋了。但是對(duì)于復(fù)雜的情況,例如我想查詢(xún)指定時(shí)間戳范圍內(nèi)的data,該怎么辦?

方法就會(huì)用到timeRange參數(shù),至于timeRange的形式如何寫(xiě)就要看源碼了,經(jīng)過(guò)調(diào)試,最終timeRange的使用方法的代碼實(shí)現(xiàn)如下:

      
         1
      
      
        var
      
       thrift = require('thrift'
      
        );


      
      
         2
      
      
        var
      
       HBase = require('./gen-nodejs/THBaseService'
      
        );


      
      
         3
      
      
        var
      
       HBaseTypes = require('./gen-nodejs/hbase_types'
      
        );


      
      
         4
      
      
         5
      
      
        var
      
       connection = thrift.createConnection('localhost', 9090
      
        , {


      
      
         6
      
      
          transport: thrift.TFramedTransport,


      
      
         7
      
      
          protocol: thrift.TBinaryProtocol


      
      
         8
      
      
        });


      
      
         9
      
      
        10
      
       connection.on('connect', 
      
        function
      
      
         () {


      
      
        11
      
         console.log('connected'
      
        );


      
      
        12
      
      
        var
      
       client =
      
         thrift.createClient(HBase, connection);


      
      
        13
      
      
        14
      
      
        15
      
      
        var
      
       tGet = 
      
        new
      
       HBaseTypes.TGet({row: '10_20121002'
      
        ,


      
      
        16
      
                       columns: [
      
        new
      
       HBaseTypes.TColumn({family: 'PLATE'
      
        })],


      
      
        17
      
                       timeRange: 
      
        new
      
       HBaseTypes.TTimeRange({minStamp:1349138457,maxStamp:1349153466
      
         })


      
      
        18
      
      
                       });


      
      
        19
      
               client.get('rdga_by_ymd', tGet, 
      
        function
      
      
         (err, data) {


      
      
        20
      
      
        if
      
      
         (err) {


      
      
        21
      
      
              console.log(err);


      
      
        22
      
           } 
      
        else
      
      
         {


      
      
        23
      
      
              console.log(data);


      
      
        24
      
      
            }


      
      
        25
      
      
            connection.end();


      
      
        26
      
      
          });


      
      
        27
      
      
        28
      
      
        });


      
      
        29
      
      
        30
      
       connection.on('error', 
      
        function
      
      
        (err){


      
      
        31
      
         console.log('error'
      
        , err);


      
      
        32
      
       });
    

其他的參數(shù)的使用方法可通過(guò)上述介紹的方法看源碼就可以很快的寫(xiě)出相應(yīng)的形式,希望上述介紹的方法能幫到你,歡迎轉(zhuǎn)載,轉(zhuǎn)載請(qǐng)注明出處http://www.cnblogs.com/cocos2014/p/4539092.html。

Thrift 2中g(shù)et用法的詳細(xì)解析


更多文章、技術(shù)交流、商務(wù)合作、聯(lián)系博主

微信掃碼或搜索:z360901061

微信掃一掃加我為好友

QQ號(hào)聯(lián)系: 360901061

您的支持是博主寫(xiě)作最大的動(dòng)力,如果您喜歡我的文章,感覺(jué)我的文章對(duì)您有幫助,請(qǐng)用微信掃描下面二維碼支持博主2元、5元、10元、20元等您想捐的金額吧,狠狠點(diǎn)擊下面給點(diǎn)支持吧,站長(zhǎng)非常感激您!手機(jī)微信長(zhǎng)按不能支付解決辦法:請(qǐng)將微信支付二維碼保存到相冊(cè),切換到微信,然后點(diǎn)擊微信右上角掃一掃功能,選擇支付二維碼完成支付。

【本文對(duì)您有幫助就好】

您的支持是博主寫(xiě)作最大的動(dòng)力,如果您喜歡我的文章,感覺(jué)我的文章對(duì)您有幫助,請(qǐng)用微信掃描上面二維碼支持博主2元、5元、10元、自定義金額等您想捐的金額吧,站長(zhǎng)會(huì)非常 感謝您的哦!!!

發(fā)表我的評(píng)論
最新評(píng)論 總共0條評(píng)論
主站蜘蛛池模板: 高清国产一区二区三区 | 国产拍视频 | 日韩在线精品视频 | 欧美成人手机在线视频 | 成人激情免费视频 | 污片免费看 | 久久久99国产精品免费 | 亚洲区在线播放 | 欧美性a视频 | 亚洲国产天堂久久综合9999 | 偷偷要色偷偷 | 麻豆专区一区二区三区四区五区 | 国产成人精品一区二区三区电影 | 777久久婷婷成人综合色 | 久久久久亚洲精品影视 | 毛片毛片毛片毛片毛片毛片 | 午夜寂寞少妇aaa片毛片 | 亚洲视频免费 | 日韩久操 | 一级片免费 | 午夜性福 | 日韩精品手机在线 | 久久久人成影片一区二区三区 | 男女爽爽无遮挡午夜动态图 | 最新中文在线视频 | 91精品久久久久久久 | 国产日韩一区二区三免费高清 | 欧美一区二区在线播放 | 亚洲欧洲中文日韩 | 亚洲日本视频在线 | 久久久久国产一区二区三区 | 久久机热综合久久国产 | 97人人澡人人爽91综合色 | 国产精品高清在线观看 | 日本国产最新一区二区三区 | 毛片一区二区三区四区 | 伊人亚洲 | 免费一级毛片在线播放欧美 | 欧美日韩国产一区二区三区不卡 | 国产福利视频一区美女 | www.夜夜骑|