当前位置: 代码迷 >> 综合 >> 【C#】通过Thrift操作HBase系列(3)
  详细解决方案

【C#】通过Thrift操作HBase系列(3)

热度:71   发布时间:2024-01-17 21:01:33.0

#最近无论工作还是生活都弄的一团糟,可能是我太浮躁了,整天游戏人生浑浑噩噩的过。算了不说这些扫兴的事情了。

关于C#访问Thrift的文章,这应该是第三篇了,也是最后一篇了吧。Thrfit 最麻烦的应该是查询那部分,第二篇我也详细的说了一下,这一篇文章,说一下Thrift中使用很平凡的API(新建表,删除表,插入数据,更新数据,删除数据),最后发一下,为了方便使用Thrift写的一个Helper类。


            void createTable(byte[] tableName, List<ColumnDescriptor> columnFamilies);void mutateRow(byte[] tableName, byte[] row, List<Mutation> mutations, Dictionary<byte[], byte[]> attributes);void mutateRowTs(byte[] tableName, byte[] row, List<Mutation> mutations, long timestamp, Dictionary<byte[], byte[]> attributes);void mutateRows(byte[] tableName, List<BatchMutation> rowBatches, Dictionary<byte[], byte[]> attributes);void mutateRowsTs(byte[] tableName, List<BatchMutation> rowBatches, long timestamp, Dictionary<byte[], byte[]> attributes);void deleteTable(byte[] tableName);void deleteAll(byte[] tableName, byte[] row, byte[] column, Dictionary<byte[], byte[]> attributes);void deleteAllTs(byte[] tableName, byte[] row, byte[] column, long timestamp, Dictionary<byte[], byte[]> attributes);void deleteAllRow(byte[] tableName, byte[] row, Dictionary<byte[], byte[]> attributes);void deleteAllRowTs(byte[] tableName, byte[] row, long timestamp, Dictionary<byte[], byte[]> attributes);


值得注意的是,Thrift 插入行和更新行使用的同一函数(mutateRow等一类函数),使用过HBaseAPI的童鞋,这点不足为奇。这几个API都比较简单,下面我就直接贴出Helper类及简单的测试类。


using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using ThriftHelper;
using IThrift;
using Thrift.Transport;
using Thrift.Protocol;
namespace Test
{class Program{/**   表名: HTest*   列簇: i*   子列: Data*/static void Main(