You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
@@ -8,44 +8,52 @@ An ultra-light-weight HBase ORM library that enables:
8
8
9
9
10
10
## Usage
11
-
Let's say you've an HBase table `citizens` with row-key format of `country_code#UID`. Now, let's say your table is created with three column families `main`, `optional` and `tracked`, which may have columns `uid`, `name`, `salary` etc.
11
+
Let's say you've an HBase table `citizens` with row-key format of `country_code#UID`. Now, let's say this table is created with three column families `main`, `optional` and `tracked`, which may have columns (qualifiers)`uid`, `name`, `salary` etc.
12
12
13
-
This library enables to you represent your HBase table as a bean-like class, as below:
13
+
This library enables to you represent your HBase table as a *bean-like class*, as below:
@@ -57,22 +65,23 @@ public class Citizen implements HBRecord<String> {
57
65
this.countryCode = pieces[0];
58
66
this.uid =Integer.parseInt(pieces[1]);
59
67
}
60
-
68
+
61
69
// Constructors, getters and setters
62
70
}
63
71
```
64
72
That is,
65
73
66
74
* The above class `Citizen` represents the HBase table `citizens`, using the `@HBTable` annotation.
67
75
* Logics for conversion of HBase row key to member variables of `Citizen` objects and vice-versa are implemented using `parseRowKey` and `composeRowKey` methods respectively.
68
-
* The data type representing row key is the type parameter to `HBRecord` generic interface (in above case, `String`). Fields that form row key are annotated with `@HBRowKey`.
76
+
* The data type representing row key is the type parameter to `HBRecord` generic interface (in above case, `String`).
77
+
* Fields that form row key are annotated with `@HBRowKey` (just a marker annotation).
69
78
* Names of columns and their column families are specified using `@HBColumn` or `@HBColumnMultiVersion` annotations.
70
79
* The class may contain fields of simple data types (e.g. `String`, `Integer`), generic data types (e.g. `Map`, `List`), custom class (e.g. `Dependents`) or even generics of custom class (e.g. `List<Dependent>`)
71
80
* The `@HBColumnMultiVersion` annotation allows you to map multiple versions of column in a `NavigableMap<Long, ?>`. In above example, field `phoneNumber` is mapped to column `phone_number` within the column family `tracked` (which is configured for multiple versions)
72
81
73
82
See source files [Citizen.java](./src/test/java/com/flipkart/hbaseobjectmapper/testcases/entities/Citizen.java) and [Employee.java](./src/test/java/com/flipkart/hbaseobjectmapper/testcases/entities/Employee.java) for detailed examples. Specifically, [Employee.java](./src/test/java/com/flipkart/hbaseobjectmapper/testcases/entities/Employee.java) demonstrates using "column inheritance" of this library, a useful feature if you have many HBase tables with common set of columns.
74
83
75
-
Alternatively, you can model the class as below:
84
+
Alternatively, you can model your class as below:
76
85
77
86
```java
78
87
...
@@ -82,9 +91,23 @@ public class Citizen implements HBRecord<CitizenKey> {
82
91
String countryCode;
83
92
Integer uid;
84
93
}
94
+
95
+
@HBRowKey
96
+
privateCitizenKey rowKey;
97
+
98
+
...
99
+
100
+
@Override
101
+
publicCitizenKeycomposeRowKey() {
102
+
returnreturn rowKey;
103
+
}
104
+
105
+
@Override
106
+
publicvoidparseRowKey(CitizenKeyrowKey) {
107
+
this.rowKey = rowKey;
108
+
}
85
109
...
86
110
}
87
-
...
88
111
```
89
112
90
113
@@ -95,38 +118,34 @@ public class Citizen implements HBRecord<CitizenKey> {
95
118
* uses [Jackson's JSON serializer](https://en.wikipedia.org/wiki/Jackson_(API)) for all other data types
96
119
* serializes `null` as `null`
97
120
* To customize serialization/deserialization behavior, you may define your own codec (by implementing the [Codec](./src/main/java/com/flipkart/hbaseobjectmapper/codec/Codec.java) interface) or you may extend the default codec.
98
-
* The optional parameter `codecFlags` (supported by both `@HBColumn` and `@HBColumnMultiVersion` annotations) can be used to pass custom flags to the underlying codec. (e.g. You may write your codec to serialize field `Integer id` in `Citizen` class differently from field `Integer id` in `Employee` class)
121
+
* The optional parameter `codecFlags` (supported by both `@HBColumn` and `@HBColumnMultiVersion` annotations) can be used to pass custom flags to the underlying codec. (e.g. You may want your codec to serialize field `Integer id` in `Citizen` class differently from field `Integer id` in `Employee` class)
99
122
* The default codec class `BestSuitCodec` takes a flag `BestSuitCodec.SERIALIZE_AS_STRING`, whose value is "serializeAsString" (as in the above `Citizen` class example). When this flag is set to `true` on a field, the default codec serializes that field (even numerical fields) as strings.
100
123
* Your custom codec may take other such flags to customize serialization/deserialization behavior at a **class field level**.
101
124
102
125
## Using this library for database access (DAO)
103
126
This library provides an abstract class to define your own [data access object](https://en.wikipedia.org/wiki/Data_access_object). For example, you can create one for `Citizen` class in the above example as follows:
// using try-with-resources above to close the resources after iteration
186
+
for (Citizen citizen : citizens) {
187
+
// your code
188
+
}
189
+
}
190
+
```
191
+
**Note:** All the `.records(...)` methods efficiently use iterators internally and do not load records upfront into memory. Hence, it's safe to fetch millions of records using them.
145
192
146
-
// In below, note that "IND#1" is inclusive and "IND#5" is exclusive
147
-
List<Citizen> lpe = citizenDao.get("IND#1", "IND#5"); //range get
148
-
// ('versioned' variant above method is available)
193
+
Fetch records by row key prefix:
149
194
150
-
// for row keys in range ["IND#1", "IND#5"), fetch 3 versions of field 'phoneNumber' as a NavigableMap<row key, NavigableMap<timestamp, column value>>:
* Your application code will be clean and minimal.
298
375
* Your code need not worry about HBase methods or serialization/deserialization at all, thereby helping you maintain clear [separation of concerns](https://en.wikipedia.org/wiki/Separation_of_concerns).
299
-
* Classes are **thread-safe**. You can just have to instantiate your DAO classes once at the start of your application and use them anywhere.
376
+
* Classes are **thread-safe**. You just have to instantiate your DAO classes once at the start of your application and use them anywhere!
300
377
* Light weight: This library depends on just HBase Client and few other small libraries. It has very low overhead and hence is very fast.
301
378
* Customizability/Extensibility: Want to use HBase native methods directly in some cases? No problem. Want to customize ser/deser in general or for a given class field? No problem. This library is high flexible.
302
379
@@ -313,21 +390,22 @@ Add below entry within the `dependencies` section of your `pom.xml`:
313
390
<dependency>
314
391
<groupId>com.flipkart</groupId>
315
392
<artifactId>hbase-object-mapper</artifactId>
316
-
<version>1.12.1</version>
393
+
<version>1.13</version>
317
394
</dependency>
318
395
```
396
+
319
397
See artifact details: [com.flipkart:hbase-object-mapper on **Maven Central**](https://search.maven.org/search?q=g:com.flipkart%20AND%20a:hbase-object-mapper&core=gav) or
320
398
[com.flipkart:hbase-object-mapper on **MVN Repository**](https://mvnrepository.com/artifact/com.flipkart/hbase-object-mapper).
321
399
## How to build?
322
400
To build this project, follow below simple steps:
323
401
324
402
1. Do a `git clone` of this repository
325
-
2. Checkout latest stable version `git checkout v1.12.1`
403
+
2. Checkout latest stable version `git checkout v1.13`
326
404
3. Execute `mvn clean install` from shell
327
405
328
406
### Please note:
329
407
330
-
* Currently, projects that use this library are running on [Hortonworks Data Platform v3.1](https://docs.cloudera.com/HDPDocuments/HDP3/HDP-3.1.0/index.html) (corresponds to Hadoop 3.1 and HBase 2.0). However, if you are using a different version of Hadoop, you may change the versions in [pom.xml](./pom.xml) to desired ones and build the project.
408
+
* Currently, projects that use this library are running on [Hortonworks Data Platform v3.1](https://docs.cloudera.com/HDPDocuments/HDP3/HDP-3.1.0/index.html) (corresponds to Hadoop 3.1 and HBase 2.0). However, if you are using a different version of Hadoop/HBase, you may change the versions in [pom.xml](./pom.xml) to desired ones and build the project.
331
409
* Test cases are **very comprehensive**. So, `mvn` build times can sometimes be longer, depending on your machine configuration.
332
410
* By default, test cases spin an [in-memory HBase test cluster](https://github.com/apache/hbase/blob/master/hbase-server/src/test/java/org/apache/hadoop/hbase/HBaseTestingUtility.java) to run data access related test cases (near-realworld scenario).
333
411
* If test cases are failing with time out errors, you may increase the timeout by setting environment variable `INMEMORY_CLUSTER_START_TIMEOUT` (seconds). For example, on Linux you may run the command `export INMEMORY_CLUSTER_START_TIMEOUT=8` on terminal, before running the aforementioned `mvn` command.
0 commit comments