Giter Club home page Giter Club logo

ro.devpool.hbase's Introduction

Info

This project aims to simplify the interaction between HBase and an application written in C#.

What can you do with this project:

  1. Map an object to a hbase row
    • Map a column from a column family to a property
    • Map an entire column family into a list of objects or a dictionary.
  2. Issue SCAN commands that return a list of objects or an object (With filters as delegates)
  3. Issue GET commands that return one or more objects.
  4. Issue PUT commands to persist objects into HBase rows
  5. Issue DELETE commands for row/columns removal.

This project is currently a work in progress and should NOT be used in a production environment.

NOTE: This project DOES NOT provide relational mapping!

How to use

  1. Create a configuration object and add the relevant information in it:
    var configuration = new HBaseConfiguration()
            {
                ThriftHost = "localhost",
                ThriftPort = 9090
            };
  2. Create the factory object and configure it with the above configuration object and the relevant mappings:
    var factory = new HBaseSessionFactory();
    factory.Configure(configuration);
    factory.Map(new UserConfig());
  3. Register the factory object as a singleton with your favorite DI container.
  4. Inject the factory as a dependency in your constructor by using the interface:
 private readonly IHBaseSessionFactory _repoFactory;
 
 public MyConsumerObject(IHBaseSessionFactory repoFactory)
 {
   _repoFactory = repoFactory;
 }
  1. Use the repository like this:
private void MyDalMethod()
{
   var repo = factory.BuildSession();
   
   //Get command - single row
   var user = repo.Get<User>().Row("my-row-key").SingleOrDefault();
   
   //Get command - multiple rows
   var users = repo.Get<User>().Rows("my-row-key-1","my-row-key-2","my-row-key-3").List();
   
   // or
   var sameUsers = repo.Get<User>().Row("my-row-key-1").Row("my-row-key-2").Row("my-row-key-3").List();
   
   //Scan - no filters
   var usersScan = repo.Scan<User>().List();
   
   //Scan - ValueFilter NOTE: all of the filters are implemented as methods of x
    var usersScanValueFilter = repo.Scan<User>().Filter(x=> x.ValueFilter().Value("Test Name")
                                                                           .Comparator(Comparator.Binary)
                                                                           .ComparisonOperator(ComparisonOperator.Equal)).List();
   
   
   // Put - Single object
   repo.Put<User>().Entity(user).Execute();
   
   // Put - List
   repo.Put<User>().Entities(users).Execute();
   
   
   }

Mapping

In order to map a c# object to a HBase row you need to create:

  1. The domain entity or entities. For example:
   public class User
   {
       public virtual string Rowkey { get; set; }
       public virtual bool IsActive { get; set; }
       public virtual string Name { get; set; }
       public virtual string Email { get; set; }
       
       public virtual List<Permission> Permissions { get; set; }
       public virtual List<Role> Roles { get; set; }
               
       public override string ToString() => $"{Name} (Active: {IsActive})";

   }
   
   public class Permission
   {
       public virtual string Name { get; set; }
       public virtual int Id { get; set; }
       public override string ToString() => $"({Id}) {Name}";
   }
   
   public class Role
   {
       public virtual string Name { get; set; }
       public virtual int Id { get; set; }

       public override string ToString() => $"({Id}) {Name}";

   }
  1. The mapping configuration(s):

If you want to map an entire row then create a new class that extends ClassMap like so:

    public class UserConfig : ClassMap<User>
     {
         public UserConfig()
         {
             Table("ai_Users");
             RowKey(x=> x.Email);

             Property(x => x.Name).FromColumnFamily("u").WithColumn("Name");
             Property(x => x.IsActive).FromColumnFamily("u").WithColumn("IsActive");
         
             //Note: this transforms a column family to a IEnumerable<T> if you specify what property is the column name and what property is the column value.
             Property(x => x.Roles).EntireCFAsObject("r", x => x.Name, x => x.Id); 
             Property(x => x.Permissions).EntireCFAsObject("p", x => x.Name, x => x.Id);
         }
     }

ro.devpool.hbase's People

Contributors

denis-susan avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.