Giter Site home page Giter Site logo

orm-hbase's Introduction

orm-hbase

an ORM framework for operating hbase easily. It worked like Hibernate,you can just include the jar and annotate your PO(persistent object),it will works well.

some features:

  1. annotate the PO with @Table/@Column/@RowKey, it can automatically mapping your hbase table
  2. supply CRUD function:create,research,update,delete
  3. supply aggregator function:sum,count (need config org.apache.hadoop.hbase.coprocessor.AggregateImplementation coprocessor in hbase)
  4. supply query data by page(pagination)
  5. supply Criteria style to operate hbase like hibernate Criteria

one word,you can use HBase like use hibernate.

Demo:

only 2 steps to master this framwork

1.just annotate the @Table,@RowKey,@Column in your pojo

 @Table(name = "user")</br>
 public class User {

  @RowKey
  private int id;

  @Column(family = "info")
  private int userId;

  @Column(family = "info", name = "user_name1")
  private String userName;

  @Column(family = "info")
  private long age;

}

2.use HBaseColumnarClient instance to handle the po,like below code

  HBaseColumnarClient client = new HBaseColumnarClient(scanCaching, scanBatch);
  DataSourceConfig config = new DataSourceConfig("hbase.properties");
  HBaseSource source = new HBaseSource(config.getProperties());
  client.setHBaseSource(source);
  client.putObject(user);

3.Criteria style to operat hbase like hibernate criteria

  // count the data
  Filter[] filters = null;
  long count =
               Criteria.aggregate(User.class).fromRow(startRow).toRow(endRow)
                               .filters(filters).build().count(client);
                               
  // sum the column value
  long sum =
               Criteria.aggregate(User.class).fromRow(startRow).toRow(endRow)
                               .filters(filters).propertyName("age").build().sum(client);
                               
   // query by rowKey
             User queryUser =
                         Criteria.find(User.class).byRowKey(Bytes.toBytes(id)).build().query(client);
                    
   // query from startRow to endRow
  List<User> queryList =
               Criteria.find(User.class).fromRow(startRow).toRow(endRow).build()
                               .queryList(client);
                               
  // query by page
  PageBean<User> pageBean = new PageBean<User>() {};
  pageBean.setPageSize(10);
  pageBean.setStartRow(startRow);
  pageBean.setStopRow(endRow);
  PageBean<User> queryPage =
               Criteria.find(User.class).pageBean(pageBean).build().queryPage(client);
               
  // delete data
  byte[] rowKey = Bytes.toBytes(id);
  Criteria.delete(User.class).byRowKey(rowKey).build().excute(client); 

orm-hbase's People

Contributors

zacharyzhanghao avatar

Watchers

James Cloos avatar  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.