Coder Social home page Coder Social logo

cyvaction / hbaseapi Goto Github PK

View Code? Open in Web Editor NEW

This project forked from jacksoup/hbaseapi

1.0 1.0 0.0 130 KB

基于Java,封装了hbase的底层api,提供了基于注解的ORM支持,只需定义实体类对象,即可完成对hbase的各种操作。同时对List、Set、Map等复杂数据类型提供了支持

Java 100.00%

hbaseapi's Introduction

enhanceHbase ( Java版,增强型Hbase API)

##特点:

  • 基于Java,封装了hbase的底层api,提供了基于注解的ORM支持,只需定义实体类对象,即可完成对hbase的各种操作。同时对List、Set、Map等复杂数据类型提供了支持。

##使用说明:

  • 1.下载
  • 2.修改配置文件参考:
    • (1).resources/hbase-site.xml:
   <?xml version="1.0"?>
   <?xml-stylesheet type="text/xsl" href="configuration.xsl"?>
   <configuration>
        <property>
             <name>hbase.zookeeper.quorum</name>
            <!--zookeeper 地址-->
            <value>namenode1,namenode2,datanode1,datanode2,datanode3</value>
        </property>
   </configuration>
  • 3.定义实体类,参考如下:
   //定义表名和列簇名(目前只支持单个表对应一个列簇)
   @HbaseDocument(table = "my-table-user",family = "col_0")
   public class UserModel {
       @HbaseRowKey
       @HbaseField
       private Long userId;
       @HbaseField
       private String userName;
       @HbaseField
       private Integer age;
       @HbaseField
       private Map<String,Integer> scoresMap;
       @HbaseField
       private List<String> hobiesList;
       @HbaseField
       private Double schooling;
       @HbaseField
       private Set<Integer> years;
       @HbaseField
       private Boolean end;

       getter and setter(省略)
  • 4.访问hbase:
   //获得访问hbase的accessor对象
   IAccessor accessor = new HbaseAccessorImpl();
   //删除表
   accessor.deleteTable(UserModel.class);
   //创建表
   accessor.createTable(UserModel.class);
   //判断表是否存在
   System.out.println(accessor.hasTable(UserModel.class));
   //new实体类并设置相关属性
   UserModel user = new UserModel();
   user.setUserId(1010001L);
   user.setUserName("caesar.zhu");
   user.setAge(30);
   Map<String,Integer> scoresMap = new HashMap();
   scoresMap.put("history",95);
   scoresMap.put("geography",98);
   scoresMap.put("math",100);
   user.setScoresMap(scoresMap);
   List<String> hobiesList = new ArrayList<>();
   hobiesList.add("basketball");
   hobiesList.add("swimming");
   hobiesList.add("shoot");
   user.setHobiesList(hobiesList);
   Set<Integer> yearsSet = new HashSet<>();
   yearsSet.add(10);
   yearsSet.add(25);
   yearsSet.add(65);
   user.setYears(yearsSet);
   user.setEnd(true);
   //添加记录
   accessor.put(user);
   //根据key进行查询
   UserModel ins = accessor.get(1010001L, UserModel.class);
   System.out.println(ins);
   //根据key判断记录是否存在
   System.out.println(accessor.hasRow(1010001L,UserModel.class));
   //删除指定记录
   System.out.println(accessor.delete(1010001L,UserModel.class));
   //批量删除
   //System.out.println(accessor.deleteBatch(list...,UserModel.class));
   //扫描记录
   //System.out.println(accessor.scan(....));

hbaseapi's People

Contributors

cnfire avatar

Stargazers

 avatar

Watchers

 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.