├── .gitignore
├── .travis.yml
├── CONTRIBUTORS.md
├── LICENSE.md
├── README.md
├── pho.png
├── pom.xml
└── src
├── main
├── config
│ └── log4j.properties
├── java
│ └── com
│ │ └── eharmony
│ │ └── pho
│ │ ├── api
│ │ ├── DataStoreApi.java
│ │ └── DataStoreException.java
│ │ ├── hbase
│ │ ├── PhoenixHBaseDataStoreApiImpl.java
│ │ ├── mapper
│ │ │ └── PhoenixProjectedResultMapper.java
│ │ ├── query
│ │ │ └── PhoenixHBaseQueryExecutor.java
│ │ ├── translator
│ │ │ ├── MorphiaEntityResolver.java
│ │ │ ├── PhoenixHBaseAggregate.java
│ │ │ ├── PhoenixHBaseClauses.java
│ │ │ ├── PhoenixHBaseOperator.java
│ │ │ └── PhoenixHBaseQueryTranslator.java
│ │ └── util
│ │ │ ├── PhoenixConnectionManager.java
│ │ │ └── PhoenixDateFormatUtil.java
│ │ ├── mapper
│ │ ├── EntityPropertiesMappingContext.java
│ │ ├── EntityPropertiesResolver.java
│ │ ├── EntityPropertyBinding.java
│ │ ├── EntityPropertyValueBinding.java
│ │ └── ProjectedResultMapper.java
│ │ ├── query
│ │ ├── QueryOperationType.java
│ │ ├── QuerySelect.java
│ │ ├── QuerySelectImpl.java
│ │ ├── QueryUpdate.java
│ │ ├── QueryUpdateImpl.java
│ │ ├── builder
│ │ │ ├── QueryBuilder.java
│ │ │ └── QueryUpdateBuilder.java
│ │ └── criterion
│ │ │ ├── Aggregate.java
│ │ │ ├── Criterion.java
│ │ │ ├── GroupCriterion.java
│ │ │ ├── GroupRestrictions.java
│ │ │ ├── Operator.java
│ │ │ ├── Ordering.java
│ │ │ ├── Orderings.java
│ │ │ ├── Projections.java
│ │ │ ├── Restrictions.java
│ │ │ ├── Symbolic.java
│ │ │ ├── SymbolicLookup.java
│ │ │ ├── WithAggregateFunction.java
│ │ │ ├── WithOperator.java
│ │ │ ├── WithProperty.java
│ │ │ ├── expression
│ │ │ ├── EqualityExpression.java
│ │ │ ├── Expression.java
│ │ │ ├── NativeExpression.java
│ │ │ ├── RangeExpression.java
│ │ │ ├── SetExpression.java
│ │ │ └── UnaryExpression.java
│ │ │ ├── junction
│ │ │ ├── Conjunction.java
│ │ │ ├── Disjunction.java
│ │ │ └── Junction.java
│ │ │ └── projection
│ │ │ ├── AggregateProjection.java
│ │ │ ├── AvgProjection.java
│ │ │ ├── CountProjection.java
│ │ │ ├── GroupProjection.java
│ │ │ ├── MaxProjection.java
│ │ │ ├── MinProjection.java
│ │ │ └── Projection.java
│ │ └── translator
│ │ ├── AbstractQueryTranslator.java
│ │ ├── EntityResolver.java
│ │ ├── PropertyResolver.java
│ │ ├── QueryTranslator.java
│ │ └── SimpleEntityResolver.java
└── resources
│ ├── META-INF
│ └── spring
│ │ └── application-context.xml
│ └── hbase.properties
└── test
└── java
└── com
└── eharmony
└── pho
└── hbase
├── mapper
├── EntityPropertiesResolverTest.java
└── PhoenixProjectedResultMapperTest.java
├── model
├── EmbededEntityExample.java
├── NestedEntity.java
└── TranslationTestClass.java
└── translator
└── PhoenixHBaseQueryTranslatorTest.java
/.gitignore:
--------------------------------------------------------------------------------
1 | # Compiled source #
2 | # ###################
3 | *.com
4 | *.class
5 | *.dll
6 | *.exe
7 | *.o
8 | *.so
9 | #
10 | # # Packages #
11 | # ############
12 | # # it's better to unpack these files and commit the raw source
13 | # # git has its own built in compression methods
14 | *.7z
15 | *.dmg
16 | *.gz
17 | *.iso
18 | *.jar
19 | *.rar
20 | *.tar
21 | *.zip
22 | #
23 | # Logs and databases #
24 | *.log
25 | *.sql
26 | *.sqlite
27 | #
28 | # OS generated files #
29 | .DS_Store*
30 | ehthumbs.db
31 | Icon?
32 | Thumbs.db
33 |
34 | # java generated stuff
35 | .classpath
36 | .groovy/
37 | .project
38 | .settings/
39 | .idea/
40 | *.iml
41 | logs/
42 | target/
43 | /bin/
44 | .springBeans
45 |
--------------------------------------------------------------------------------
/.travis.yml:
--------------------------------------------------------------------------------
1 | language: java
2 | jdk:
3 | - oraclejdk8
4 |
5 |
--------------------------------------------------------------------------------
/CONTRIBUTORS.md:
--------------------------------------------------------------------------------
1 | Vijay Vangapandu
2 | Adam Richeimer
--------------------------------------------------------------------------------
/LICENSE.md:
--------------------------------------------------------------------------------
1 |
2 | Apache License
3 | Version 2.0, January 2004
4 | http://www.apache.org/licenses/
5 |
6 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
7 |
8 | 1. Definitions.
9 |
10 | "License" shall mean the terms and conditions for use, reproduction,
11 | and distribution as defined by Sections 1 through 9 of this document.
12 |
13 | "Licensor" shall mean the copyright owner or entity authorized by
14 | the copyright owner that is granting the License.
15 |
16 | "Legal Entity" shall mean the union of the acting entity and all
17 | other entities that control, are controlled by, or are under common
18 | control with that entity. For the purposes of this definition,
19 | "control" means (i) the power, direct or indirect, to cause the
20 | direction or management of such entity, whether by contract or
21 | otherwise, or (ii) ownership of fifty percent (50%) or more of the
22 | outstanding shares, or (iii) beneficial ownership of such entity.
23 |
24 | "You" (or "Your") shall mean an individual or Legal Entity
25 | exercising permissions granted by this License.
26 |
27 | "Source" form shall mean the preferred form for making modifications,
28 | including but not limited to software source code, documentation
29 | source, and configuration files.
30 |
31 | "Object" form shall mean any form resulting from mechanical
32 | transformation or translation of a Source form, including but
33 | not limited to compiled object code, generated documentation,
34 | and conversions to other media types.
35 |
36 | "Work" shall mean the work of authorship, whether in Source or
37 | Object form, made available under the License, as indicated by a
38 | copyright notice that is included in or attached to the work
39 | (an example is provided in the Appendix below).
40 |
41 | "Derivative Works" shall mean any work, whether in Source or Object
42 | form, that is based on (or derived from) the Work and for which the
43 | editorial revisions, annotations, elaborations, or other modifications
44 | represent, as a whole, an original work of authorship. For the purposes
45 | of this License, Derivative Works shall not include works that remain
46 | separable from, or merely link (or bind by name) to the interfaces of,
47 | the Work and Derivative Works thereof.
48 |
49 | "Contribution" shall mean any work of authorship, including
50 | the original version of the Work and any modifications or additions
51 | to that Work or Derivative Works thereof, that is intentionally
52 | submitted to Licensor for inclusion in the Work by the copyright owner
53 | or by an individual or Legal Entity authorized to submit on behalf of
54 | the copyright owner. For the purposes of this definition, "submitted"
55 | means any form of electronic, verbal, or written communication sent
56 | to the Licensor or its representatives, including but not limited to
57 | communication on electronic mailing lists, source code control systems,
58 | and issue tracking systems that are managed by, or on behalf of, the
59 | Licensor for the purpose of discussing and improving the Work, but
60 | excluding communication that is conspicuously marked or otherwise
61 | designated in writing by the copyright owner as "Not a Contribution."
62 |
63 | "Contributor" shall mean Licensor and any individual or Legal Entity
64 | on behalf of whom a Contribution has been received by Licensor and
65 | subsequently incorporated within the Work.
66 |
67 | 2. Grant of Copyright License. Subject to the terms and conditions of
68 | this License, each Contributor hereby grants to You a perpetual,
69 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable
70 | copyright license to reproduce, prepare Derivative Works of,
71 | publicly display, publicly perform, sublicense, and distribute the
72 | Work and such Derivative Works in Source or Object form.
73 |
74 | 3. Grant of Patent License. Subject to the terms and conditions of
75 | this License, each Contributor hereby grants to You a perpetual,
76 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable
77 | (except as stated in this section) patent license to make, have made,
78 | use, offer to sell, sell, import, and otherwise transfer the Work,
79 | where such license applies only to those patent claims licensable
80 | by such Contributor that are necessarily infringed by their
81 | Contribution(s) alone or by combination of their Contribution(s)
82 | with the Work to which such Contribution(s) was submitted. If You
83 | institute patent litigation against any entity (including a
84 | cross-claim or counterclaim in a lawsuit) alleging that the Work
85 | or a Contribution incorporated within the Work constitutes direct
86 | or contributory patent infringement, then any patent licenses
87 | granted to You under this License for that Work shall terminate
88 | as of the date such litigation is filed.
89 |
90 | 4. Redistribution. You may reproduce and distribute copies of the
91 | Work or Derivative Works thereof in any medium, with or without
92 | modifications, and in Source or Object form, provided that You
93 | meet the following conditions:
94 |
95 | (a) You must give any other recipients of the Work or
96 | Derivative Works a copy of this License; and
97 |
98 | (b) You must cause any modified files to carry prominent notices
99 | stating that You changed the files; and
100 |
101 | (c) You must retain, in the Source form of any Derivative Works
102 | that You distribute, all copyright, patent, trademark, and
103 | attribution notices from the Source form of the Work,
104 | excluding those notices that do not pertain to any part of
105 | the Derivative Works; and
106 |
107 | (d) If the Work includes a "NOTICE" text file as part of its
108 | distribution, then any Derivative Works that You distribute must
109 | include a readable copy of the attribution notices contained
110 | within such NOTICE file, excluding those notices that do not
111 | pertain to any part of the Derivative Works, in at least one
112 | of the following places: within a NOTICE text file distributed
113 | as part of the Derivative Works; within the Source form or
114 | documentation, if provided along with the Derivative Works; or,
115 | within a display generated by the Derivative Works, if and
116 | wherever such third-party notices normally appear. The contents
117 | of the NOTICE file are for informational purposes only and
118 | do not modify the License. You may add Your own attribution
119 | notices within Derivative Works that You distribute, alongside
120 | or as an addendum to the NOTICE text from the Work, provided
121 | that such additional attribution notices cannot be construed
122 | as modifying the License.
123 |
124 | You may add Your own copyright statement to Your modifications and
125 | may provide additional or different license terms and conditions
126 | for use, reproduction, or distribution of Your modifications, or
127 | for any such Derivative Works as a whole, provided Your use,
128 | reproduction, and distribution of the Work otherwise complies with
129 | the conditions stated in this License.
130 |
131 | 5. Submission of Contributions. Unless You explicitly state otherwise,
132 | any Contribution intentionally submitted for inclusion in the Work
133 | by You to the Licensor shall be under the terms and conditions of
134 | this License, without any additional terms or conditions.
135 | Notwithstanding the above, nothing herein shall supersede or modify
136 | the terms of any separate license agreement you may have executed
137 | with Licensor regarding such Contributions.
138 |
139 | 6. Trademarks. This License does not grant permission to use the trade
140 | names, trademarks, service marks, or product names of the Licensor,
141 | except as required for reasonable and customary use in describing the
142 | origin of the Work and reproducing the content of the NOTICE file.
143 |
144 | 7. Disclaimer of Warranty. Unless required by applicable law or
145 | agreed to in writing, Licensor provides the Work (and each
146 | Contributor provides its Contributions) on an "AS IS" BASIS,
147 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
148 | implied, including, without limitation, any warranties or conditions
149 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
150 | PARTICULAR PURPOSE. You are solely responsible for determining the
151 | appropriateness of using or redistributing the Work and assume any
152 | risks associated with Your exercise of permissions under this License.
153 |
154 | 8. Limitation of Liability. In no event and under no legal theory,
155 | whether in tort (including negligence), contract, or otherwise,
156 | unless required by applicable law (such as deliberate and grossly
157 | negligent acts) or agreed to in writing, shall any Contributor be
158 | liable to You for damages, including any direct, indirect, special,
159 | incidental, or consequential damages of any character arising as a
160 | result of this License or out of the use or inability to use the
161 | Work (including but not limited to damages for loss of goodwill,
162 | work stoppage, computer failure or malfunction, or any and all
163 | other commercial damages or losses), even if such Contributor
164 | has been advised of the possibility of such damages.
165 |
166 | 9. Accepting Warranty or Additional Liability. While redistributing
167 | the Work or Derivative Works thereof, You may choose to offer,
168 | and charge a fee for, acceptance of support, warranty, indemnity,
169 | or other liability obligations and/or rights consistent with this
170 | License. However, in accepting such obligations, You may act only
171 | on Your own behalf and on Your sole responsibility, not on behalf
172 | of any other Contributor, and only if You agree to indemnify,
173 | defend, and hold each Contributor harmless for any liability
174 | incurred by, or claims asserted against, such Contributor by reason
175 | of your accepting any such warranty or additional liability.
176 |
177 | END OF TERMS AND CONDITIONS
178 |
179 | APPENDIX: How to apply the Apache License to your work.
180 |
181 | To apply the Apache License to your work, attach the following
182 | boilerplate notice, with the fields enclosed by brackets "[]"
183 | replaced with your own identifying information. (Don't include
184 | the brackets!) The text should be enclosed in the appropriate
185 | comment syntax for the file format. We also recommend that a
186 | file or class name and description of purpose be included on the
187 | same "printed page" as the copyright notice for easier
188 | identification within third-party archives.
189 |
190 | Copyright 2016 eHarmony, Inc
191 |
192 | Licensed under the Apache License, Version 2.0 (the "License");
193 | you may not use this file except in compliance with the License.
194 | You may obtain a copy of the License at
195 |
196 | http://www.apache.org/licenses/LICENSE-2.0
197 |
198 | Unless required by applicable law or agreed to in writing, software
199 | distributed under the License is distributed on an "AS IS" BASIS,
200 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
201 | See the License for the specific language governing permissions and
202 | limitations under the License.
203 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | PHO (Phoenix-HBase ORM)
5 | =======================
6 |
7 | [](https://travis-ci.org/eHarmony/pho)
8 |
9 | PHO is a library for building and executing queries on HBase using Apache Phoenix.
10 | It provides ORM-like mappings and DSL-style query building.
11 |
12 | Its Interfaces and generic annotations allows the ability to switch the data store api in the future without changing the queries.
13 | Currently, it only supports Hbase integration using Apache Phoenix. However, it's very easy to plugin other implementations if need be.
14 |
15 | # Entity Class
16 | Suppose we have the following TestClass we want to query against in our data store:
17 |
18 | ```java
19 | //class must be annotated with Entity
20 | import com.google.code.morphia.annotations.Embedded;
21 | import com.google.code.morphia.annotations.Entity;
22 | @Entity(value="user_matches")
23 | public class MatchDataFeedItemDto {
24 | @Embedded
25 | private MatchCommunicationElement communication;
26 | @Embedded
27 | private MatchElement match;
28 | @Embedded
29 | private MatchProfileElement matchedUser;
30 | }
31 |
32 | public class MatchElement {
33 | // row key
34 | @Property(value = "UID")
35 | private long userId;
36 | @Property(value = "MID")
37 | private long matchId;
38 | @Property(value = "DLVRYDT")
39 | private Date deliveredDate;
40 | @Property(value = "STATUS")
41 | private int status;
42 | }
43 | ```
44 |
45 | # Query Building
46 |
47 | Query building can be done in DSL style. More advanced query building is under development but, for now, we will use a combination of the QueryBuilder and the static, Hibernate-style Restrictions methods to construct our queries.
48 |
49 | ### Simple Queries
50 |
51 | Construct a query to find all user matches which are delivered in past 2 days and not in closed state
52 |
53 | ```java
54 | import com.eharmony.datastore.api.DataStoreApi;
55 | import com.eharmony.datastore.model.MatchDataFeedItemDto;
56 | import com.eharmony.datastore.query.QuerySelect;
57 | import com.eharmony.datastore.query.builder.QueryBuilder;
58 | import com.eharmony.datastore.query.criterion.Restrictions;
59 | @Repository
60 | public class MatchStoreQueryRepositoryImpl implements MatchStoreQueryRepository {
61 | final QuerySelect query = QueryBuilder
62 | .builderFor(MatchDataFeedItemDto.class)
63 | .select()
64 | .add(Restrictions.eq("userId", userId))
65 | .add(Restrictions.eq("status", 2))
66 | .add(Restrictions.gt("deliveredDate", timeThreshold.getTime())).build();
67 | Iterable feedItems = dataStoreApi.findAll(query);
68 | ```
69 |
70 | ### Compound Queries
71 |
72 | Construct a more complex query where not only do we want to find items with a date older than a day ago, but also find the matches in different status and order the results by deliveryDate and limit the results size to 10:
73 |
74 | ```java
75 | //provided
76 | List statusFilters = request.getMatchStatusFilters();
77 | String sortBy = request.getSortBy()
78 | Disjunction disjunction = new Disjunction();
79 | for (Integer statusFilter : statusFilters) {
80 | disjunction.add(Restrictions.eq("status", statusFilter));
81 | }
82 | final QuerySelect query = QueryBuilder
83 | .builderFor(MatchDataFeedItemDto.class)
84 | .select()
85 | .add(Restrictions.eq("userId", userId))
86 | .add(Restrictions.gt("deliveredDate", timeThreshold.getTime()));
87 | .add(disjunction);
88 | .addOrder(new Ordering(sortBy, Order.DESCENDING)).build();
89 | Iterable feedItems = dataStoreApi.findAll(query);
90 | ```
91 |
92 | *Note:* by default, expressions will be ANDed together when added separately.
93 |
94 | ### Query Interface
95 | The following query components are supported:
96 |
97 | ```java
98 | // equals
99 | EqualityExpression eq(String propertyName, Object value);
100 |
101 | // does not equal (not equals);
102 | EqualityExpression ne(String propertyName, Object value);
103 |
104 | // less than
105 | EqualityExpression lt(String propertyName, Object value);
106 |
107 | // less than or equal
108 | EqualityExpression lte(String propertyName, Object value);
109 |
110 | // greater than
111 | EqualityExpression gt(String propertyName, Object value);
112 |
113 | // greater than or equal
114 | EqualityExpression gte(String propertyName, Object value);
115 |
116 | // between from and to (inclusive)
117 | RangeExpression between(String propertyName, Object from, Object to);
118 |
119 | // and - takes a variable list of expressions as arguments
120 | Conjunction and(Criterion... criteria);
121 |
122 | // or - takes a variable list of expressions as arguments
123 | Disjunction or(Criterion... criteria);
124 |
125 | ```
126 |
127 | ### Resolving Entity and Property Names
128 |
129 | Always use the property names of your Java objects in your queries.
130 | If these names differ from those used in your datastore you will use annotations to provide the mappings.
131 | Entity Resolvers are configured to map the entity classes to table/collection names.
132 | Property Resolvers are configured to map the names of your object variables to column/field names.
133 |
134 | The following annotations are currently supported for the indicated data store type.
135 | Custom EntityResolvers and PropertyResolvers are easy to configure and create.
136 |
137 | see [Morphia Annotations](https://code.google.com/p/morphia/wiki/AllAnnotations) for entity class annotation mappings
138 |
139 |
140 | ## Query Execution
141 |
142 | The QueryExecutor interface supports the following operations:
143 |
144 | ```java
145 | // return an iterable of type R from the query against type T (R and T will often be the same type)
146 | Iterable findAll(QuerySelect query);
147 |
148 | // return aone R from the query against type T
149 | R findOne(QuerySelect query)
150 |
151 | // save the entity of type T to the data store
152 | T save(T entity);
153 |
154 | // save all of the entities in the provided iterable to data store
155 | Iterable save(Iterable entities);
156 |
157 | // saves all the entities in batches with configured batch size
158 | int[] saveBatch(Iterable entities);
159 | ```
160 |
161 | ## Configuration
162 |
163 | Here are some example Spring configuration files for Hbase using apache phoenix.
164 |
165 | ### HBase
166 | configuration proeprties
167 | hbase.connection.url=jdbc:phoenix:zkhost:2181
168 |
169 | ```xml
170 |
171 |
172 | com.eharmony.datastore.model.MatchDataFeedItemDto
173 |
174 |
175 |
176 |
177 |
178 |
179 |
180 |
181 |
182 |
183 |
184 |
185 |
186 |
187 |
188 |
189 |
190 |
191 |
192 |
193 |
194 |
195 |
196 |
197 |
198 |
199 |
200 | ```
201 |
202 |
--------------------------------------------------------------------------------
/pho.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/eHarmony/pho/40b50640a9c80f7e6342bb8046eecb402ad44165/pho.png
--------------------------------------------------------------------------------
/src/main/config/log4j.properties:
--------------------------------------------------------------------------------
1 | # Direct log messages to stdout
2 | log4j.appender.stdout=org.apache.log4j.ConsoleAppender
3 | log4j.appender.stdout.Target=System.out
4 | log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
5 | log4j.appender.stdout.layout.ConversionPattern=%d{ABSOLUTE} %5p %40.40c:%4L - %m%n
6 |
7 | # Root logger option
8 | log4j.rootLogger=INFO, stdout
9 |
10 | #log4j.logger.org.springframework.data.hadoop=DEBUG
11 |
--------------------------------------------------------------------------------
/src/main/java/com/eharmony/pho/api/DataStoreApi.java:
--------------------------------------------------------------------------------
1 | package com.eharmony.pho.api;
2 |
3 | import java.util.List;
4 |
5 | import com.eharmony.pho.query.QuerySelect;
6 | /**
7 | * Provides methods to operate with datastore.
8 | * @author vvangapandu
9 | *
10 | */
11 | public interface DataStoreApi {
12 |
13 | /**
14 | * Saves given item to store.
15 | *
16 | * @param
17 | * class type
18 | * @param entity
19 | * T
20 | * @return T
21 | */
22 |
23 | T save(T entity);
24 |
25 | /**
26 | * Saves all items in iterable, saves will be issues item by item
27 | *
28 | * @param
29 | * class type
30 | * @param entities
31 | * Iterable
32 | * @return Iterable
33 | */
34 | Iterable save(Iterable entities);
35 |
36 | /**
37 | * Saves all items in iterable in batches, batch size is same as number of items in the Iterable.
38 | *
39 | * @param
40 | * entity class
41 | * @param entities
42 | * Iterable
43 | * @return Iterable
44 | */
45 | int[] saveBatch(Iterable entities);
46 |
47 | /**
48 | * Find records that satisfy the provided query.
49 | *
50 | * @param
51 | * class type
52 | * @param return param type
53 | * @param query
54 | * Query
55 | * @return an {@link Iterable} of entity type T
56 | *
57 | * @throws DataStoreException
58 | * if an error occurs accessing the underlying data store
59 | */
60 | Iterable findAll(QuerySelect query);
61 |
62 | /**
63 | * Find one record that satisfies the provided query.
64 | *
65 | * @param
66 | * class type
67 | * @param return param type
68 | * @param query
69 | * Query
70 | * @return an object of entity type T
71 | *
72 | * @throws DataStoreException
73 | * if an error occurs accessing the underlying data store
74 | */
75 | R findOne(QuerySelect query);
76 |
77 | /**
78 | * Updates an existing entity, but only for the selected fields.
79 | * @param
80 | * class type
81 | * @param entity existing entity whose fields need to be updated.
82 | * @param selectedFields list of property names that need to be udpated.
83 | * @return updated entity.
84 | */
85 | T save(T entity, List selectedFields);
86 |
87 | }
88 |
--------------------------------------------------------------------------------
/src/main/java/com/eharmony/pho/api/DataStoreException.java:
--------------------------------------------------------------------------------
1 |
2 | package com.eharmony.pho.api;
3 |
4 | /**
5 | * An exception that indicates a problem loading from or storing to a data
6 | * store. It presents a uniform abstraction across things like
7 | * {@link java.sql.SQLException}.
8 | */
9 | public class DataStoreException extends RuntimeException {
10 |
11 | private static final long serialVersionUID = -1363433871972493184L;
12 |
13 | public DataStoreException() {
14 | super();
15 | }
16 |
17 | public DataStoreException(String message) {
18 | super(message);
19 | }
20 |
21 | public DataStoreException(Throwable cause) {
22 | super(cause);
23 | }
24 |
25 | public DataStoreException(String message, Throwable cause) {
26 | super(message, cause);
27 | }
28 |
29 | }
30 |
--------------------------------------------------------------------------------
/src/main/java/com/eharmony/pho/hbase/PhoenixHBaseDataStoreApiImpl.java:
--------------------------------------------------------------------------------
1 | package com.eharmony.pho.hbase;
2 |
3 | import java.sql.Connection;
4 | import java.util.List;
5 |
6 | import org.slf4j.Logger;
7 | import org.slf4j.LoggerFactory;
8 |
9 | import com.eharmony.pho.api.DataStoreApi;
10 | import com.eharmony.pho.hbase.query.PhoenixHBaseQueryExecutor;
11 | import com.eharmony.pho.hbase.util.PhoenixConnectionManager;
12 | import com.eharmony.pho.query.QuerySelect;
13 | import com.eharmony.pho.query.builder.QueryBuilder;
14 | import com.eharmony.pho.query.builder.QueryUpdateBuilder;
15 | import com.google.common.base.Preconditions;
16 |
17 | /**
18 | * Datastore api implementation for HBase store. Using apache phoenix (http://phoenix.apache.org/) as sql layer to hbase
19 | *
20 | * @author vvangapandu
21 | *
22 | */
23 | public class PhoenixHBaseDataStoreApiImpl implements DataStoreApi {
24 |
25 | private final PhoenixHBaseQueryExecutor queryExecutor;
26 | private final String connectionUrl;
27 | private static final Logger logger = LoggerFactory.getLogger(PhoenixHBaseDataStoreApiImpl.class);
28 |
29 | public PhoenixHBaseDataStoreApiImpl(final String connectionUrl, final PhoenixHBaseQueryExecutor queryExecutor)
30 | throws Exception {
31 | this(connectionUrl, queryExecutor, false);
32 | }
33 |
34 | public PhoenixHBaseDataStoreApiImpl(final String connectionUrl, final PhoenixHBaseQueryExecutor queryExecutor, final boolean testConnection)
35 | throws Exception {
36 | this.connectionUrl = connectionUrl;
37 | this.queryExecutor = Preconditions.checkNotNull(queryExecutor);
38 |
39 | // Below code will ensure that connection string is valid, if not will stop the context loading
40 | if(testConnection) {
41 | Connection conn = PhoenixConnectionManager.getConnection(connectionUrl);
42 | if (conn == null) {
43 | throw new IllegalStateException("unable to create phoenix connection with given url :" + connectionUrl);
44 | } else {
45 | closeConnectionSafe(conn);
46 | }
47 | }
48 | }
49 |
50 | @Override
51 | public T save(T entity) {
52 | Connection conn = null;
53 | try {
54 | conn = PhoenixConnectionManager.getConnection(connectionUrl);
55 | T returnEntity = queryExecutor.save(entity, conn);
56 | conn.commit();
57 | return returnEntity;
58 | } catch (Exception ex) {
59 | throw new RuntimeException(ex);
60 | } finally {
61 | closeConnectionSafe(conn);
62 | }
63 | }
64 |
65 | private void closeConnectionSafe(Connection conn) {
66 | try {
67 | if (conn != null) {
68 | conn.close();
69 | }
70 | } catch (Exception ex) {
71 | logger.warn("Exception while closing the connection...", ex.getMessage());
72 | }
73 | }
74 |
75 | @Override
76 | public Iterable save(Iterable entities) {
77 | Connection conn = null;
78 | try {
79 | conn = PhoenixConnectionManager.getConnection(connectionUrl);
80 | Iterable results = queryExecutor.save(entities, conn);
81 | conn.commit();
82 | return results;
83 | } catch (Exception ex) {
84 | throw new RuntimeException(ex);
85 | } finally {
86 | closeConnectionSafe(conn);
87 | }
88 | }
89 |
90 | @Override
91 | public int[] saveBatch(Iterable entities) {
92 | Connection conn = null;
93 | try {
94 | conn = PhoenixConnectionManager.getConnection(connectionUrl);
95 | int[] results = queryExecutor.saveBatch(entities, conn);
96 | conn.commit();
97 | return results;
98 | } catch (Exception ex) {
99 | throw new RuntimeException(ex);
100 | } finally {
101 | closeConnectionSafe(conn);
102 | }
103 | }
104 |
105 | @Override
106 | public Iterable findAll(QuerySelect query) {
107 | Connection conn = null;
108 | try {
109 | conn = PhoenixConnectionManager.getConnection(connectionUrl);
110 | return queryExecutor.find(query, conn);
111 | } catch (Exception ex) {
112 | throw new RuntimeException(ex);
113 | } finally {
114 | closeConnectionSafe(conn);
115 | }
116 | }
117 |
118 | @Override
119 | public R findOne(QuerySelect query) {
120 | Connection conn = null;
121 | try {
122 | conn = PhoenixConnectionManager.getConnection(connectionUrl);
123 | return queryExecutor.findOne(query, conn);
124 | } catch (Exception ex) {
125 | throw new RuntimeException(ex);
126 | } finally {
127 | closeConnectionSafe(conn);
128 | }
129 | }
130 |
131 | public Iterable findAllEntities(String key, Class clz, String[] projection) throws Exception {
132 | Connection conn = null;
133 | try {
134 | conn = PhoenixConnectionManager.getConnection(connectionUrl);
135 | QueryBuilder builder = new QueryBuilder(clz, clz);
136 | builder.setReturnFields(projection);
137 | QuerySelect query = builder.build();
138 | return queryExecutor.find(query, conn);
139 | } catch (Exception ex) {
140 | throw new RuntimeException(ex);
141 | } finally {
142 | closeConnectionSafe(conn);
143 | }
144 | }
145 |
146 | @Override
147 | public T save(T entity, List selectedFields) {
148 | Connection conn = null;
149 | try {
150 | conn = PhoenixConnectionManager.getConnection(connectionUrl);
151 | QueryUpdateBuilder updateBuilder = QueryUpdateBuilder.builderFor(entity).update(selectedFields);
152 | T returnEntity = (T) queryExecutor.save(updateBuilder.build(), conn);
153 | conn.commit();
154 | return returnEntity;
155 | } catch (Exception ex) {
156 | throw new RuntimeException(ex);
157 | } finally {
158 | closeConnectionSafe(conn);
159 | }
160 | }
161 |
162 | }
163 |
--------------------------------------------------------------------------------
/src/main/java/com/eharmony/pho/hbase/mapper/PhoenixProjectedResultMapper.java:
--------------------------------------------------------------------------------
1 |
2 | package com.eharmony.pho.hbase.mapper;
3 |
4 | import java.lang.reflect.InvocationTargetException;
5 | import java.sql.ResultSet;
6 | import java.sql.ResultSetMetaData;
7 | import java.sql.SQLException;
8 | import java.util.ArrayList;
9 | import java.util.HashSet;
10 | import java.util.List;
11 | import java.util.Set;
12 |
13 | import org.apache.commons.beanutils.BeanUtils;
14 | import org.slf4j.Logger;
15 | import org.slf4j.LoggerFactory;
16 |
17 | import com.eharmony.pho.mapper.EntityPropertiesResolver;
18 | import com.eharmony.pho.mapper.EntityPropertyBinding;
19 | import com.eharmony.pho.mapper.ProjectedResultMapper;
20 | import com.eharmony.pho.query.QuerySelect;
21 |
22 | /**
23 | * Maps the results from hbase to entity object based on entity annotations.
24 | *
25 | * @author vvangapandu
26 | *
27 | */
28 | public class PhoenixProjectedResultMapper {
29 |
30 | private final ProjectedResultMapper mapper;
31 | private final EntityPropertiesResolver entityPropertiesResolver;
32 |
33 | private static final Logger log = LoggerFactory.getLogger(PhoenixProjectedResultMapper.class);
34 |
35 | public PhoenixProjectedResultMapper(final EntityPropertiesResolver entityPropertiesResolver) {
36 | this.mapper = new ProjectedResultMapper();
37 | this.entityPropertiesResolver = entityPropertiesResolver;
38 | }
39 |
40 | protected String[] returnFields(QuerySelect query) {
41 | List list = query.getReturnFields();
42 | String[] array = new String[list.size()];
43 | return list.toArray(array);
44 | }
45 |
46 | public R mapResult(Object o, QuerySelect query, String[] returnFields) {
47 | return query.getEntityClass().equals(query.getReturnType())
48 | ? query.getReturnType().cast(o)
49 | : mapper.mapTo(query.getReturnType(), o, returnFields);
50 | }
51 |
52 | public R mapResult(Object o, QuerySelect query) {
53 | return mapResult(o, query, returnFields(query));
54 | }
55 |
56 | public List mapResults(List extends Object> objects, final QuerySelect query) {
57 | final String[] returnFields = returnFields(query);
58 | List returnList = new ArrayList();
59 | for(Object o: objects) {
60 | returnList.add(mapResult(o, query, returnFields));
61 | }
62 | return returnList;
63 | }
64 |
65 | public Iterable mapResults(ResultSet resultSet, final QuerySelect query) throws SQLException,
66 | InstantiationException, IllegalAccessException, InvocationTargetException {
67 | return mapResults(resultSet, query.getReturnType());
68 | }
69 |
70 | @SuppressWarnings("unchecked")
71 | public Iterable mapResults(ResultSet resultSet, final Class clz) throws SQLException,
72 | InstantiationException, IllegalAccessException, InvocationTargetException {
73 | Set metadataColumns = extractColumnNames(resultSet);
74 | List resultsList = new ArrayList();
75 | boolean resultIsNumber = Number.class.isAssignableFrom(clz);
76 | while (resultSet.next()) {
77 | R instance = null;
78 | if (!resultIsNumber) {
79 | instance = clz.newInstance();
80 | }
81 | for (String columnName : metadataColumns) {
82 | Object value = resultSet.getObject(columnName);
83 | if (value != null) {
84 | log.debug(value.toString());
85 | if (resultIsNumber) {
86 | instance = (R) value;
87 | break;
88 | }
89 |
90 | EntityPropertyBinding entityProperty = entityPropertiesResolver.resolveEntityPropertyBindingByStoreMappingName(columnName, clz);
91 | if (entityProperty != null) {
92 | BeanUtils.copyProperty(instance, entityProperty.getNameFullPath(), value);
93 | }
94 |
95 | }
96 | }
97 | resultsList.add(instance);
98 | }
99 |
100 | return resultsList;
101 | }
102 |
103 | private Set extractColumnNames(ResultSet resultSet) throws SQLException {
104 | ResultSetMetaData metedata = resultSet.getMetaData();
105 | int columnCount = metedata.getColumnCount();
106 | Set metadataColumns = new HashSet();
107 | for(int i=0;i< columnCount;i++) {
108 | try {
109 | metadataColumns.add(metedata.getColumnName(i + 1));
110 | } catch(Exception ex) {
111 | log.warn("Exception while reading the metadata for class...");
112 | }
113 | }
114 | return metadataColumns;
115 | }
116 |
117 |
118 | }
119 |
--------------------------------------------------------------------------------
/src/main/java/com/eharmony/pho/hbase/query/PhoenixHBaseQueryExecutor.java:
--------------------------------------------------------------------------------
1 | package com.eharmony.pho.hbase.query;
2 |
3 | import java.sql.Connection;
4 | import java.sql.PreparedStatement;
5 | import java.sql.ResultSet;
6 | import java.sql.SQLException;
7 | import java.sql.Statement;
8 | import java.util.ArrayList;
9 | import java.util.HashMap;
10 | import java.util.List;
11 | import java.util.Map;
12 |
13 | import org.slf4j.Logger;
14 | import org.slf4j.LoggerFactory;
15 |
16 | import com.eharmony.pho.api.DataStoreException;
17 | import com.eharmony.pho.hbase.mapper.PhoenixProjectedResultMapper;
18 | import com.eharmony.pho.hbase.translator.PhoenixHBaseQueryTranslator;
19 | import com.eharmony.pho.query.QuerySelect;
20 | import com.eharmony.pho.query.QueryUpdate;
21 | import com.eharmony.pho.query.builder.QueryUpdateBuilder;
22 | import com.google.common.base.Preconditions;
23 |
24 | /**
25 | * Executes the query on hbase through phoenix query server after translation using query translator. Select query
26 | * results will be mapped back to result object using result mapper.
27 | *
28 | * @author vvangapandu
29 | *
30 | */
31 | public class PhoenixHBaseQueryExecutor {
32 |
33 | private static final Logger log = LoggerFactory.getLogger(PhoenixHBaseQueryExecutor.class);
34 |
35 | private final PhoenixHBaseQueryTranslator queryTranslator;
36 | private final PhoenixProjectedResultMapper resultMapper;
37 | private boolean showSQL = true;
38 | //Holder for statement properties like queryTimeOut.
39 | private final Map statementProperties;
40 | private static final String QUERY_TIMEOUT_SEC = "queryTimeoutSec";
41 |
42 | public PhoenixHBaseQueryExecutor(final PhoenixHBaseQueryTranslator queryTranslator,
43 | final PhoenixProjectedResultMapper resultMapper) {
44 | this(queryTranslator, resultMapper, new HashMap());
45 | }
46 |
47 | public PhoenixHBaseQueryExecutor(final PhoenixHBaseQueryTranslator queryTranslator,
48 | final PhoenixProjectedResultMapper resultMapper, final Map statementProperties) {
49 | this.queryTranslator = Preconditions.checkNotNull(queryTranslator);
50 | this.resultMapper = Preconditions.checkNotNull(resultMapper);
51 | this.statementProperties = Preconditions.checkNotNull(statementProperties);
52 | }
53 |
54 | public Iterable find(QuerySelect query, Connection conn) throws SQLException {
55 | ResultSet resultSet = null;
56 | Statement statement = null;
57 | try {
58 | String queryStr = queryTranslator.translate(query);
59 | if (showSQL) {
60 | log.info("Query String: {}", queryStr);
61 | }
62 | statement = createStatement(conn);
63 | resultSet = statement.executeQuery(queryStr);
64 | return resultMapper.mapResults(resultSet, query.getReturnType());
65 | } catch (final Exception hx) {
66 | throw new DataStoreException(hx.getMessage(), hx);
67 | } finally {
68 | if (resultSet != null) {
69 | resultSet.close();
70 | }
71 | if (statement != null) {
72 | statement.close();
73 | }
74 | }
75 | }
76 |
77 | private void closeStatementSafe(PreparedStatement ps) {
78 | if (ps != null) {
79 | try {
80 | ps.close();
81 | } catch (Exception ex) {
82 | log.warn("Exception while closing the PreparedStatement...", ex);
83 | }
84 | }
85 | }
86 |
87 | public R findOne(QuerySelect query, Connection conn) {
88 | try {
89 | Iterable results = find(query, conn);
90 | if (results != null && results.iterator() != null && results.iterator().hasNext()) {
91 | return results.iterator().next();
92 | }
93 | } catch (final Exception hx) {
94 | throw new DataStoreException(hx.getMessage(), hx);
95 | }
96 | return null;
97 | }
98 |
99 | public T save(QueryUpdate query, Connection conn) {
100 | PreparedStatement ps = null;
101 | try {
102 | String queryStr = queryTranslator.translate(query);
103 | if (showSQL) {
104 | log.info("Query String {}", queryStr);
105 | }
106 | ps = createPreparedStatement(conn, queryStr);
107 |
108 | int result = ps.executeUpdate();
109 | if (result == 0) {
110 | throw new DataStoreException("Save Failed for query...");
111 | }
112 | return null;
113 | } catch (final Exception hx) {
114 | throw new DataStoreException(hx.getMessage(), hx);
115 | } finally {
116 | closeStatementSafe(ps);
117 | }
118 | }
119 |
120 | public T save(T entity, Connection conn) {
121 | PreparedStatement ps = null;
122 | try {
123 | QueryUpdate query = QueryUpdateBuilder.builderFor(entity).build();
124 | String queryStr = queryTranslator.translate(query);
125 | if (showSQL) {
126 | log.info("Query String {}", queryStr);
127 | }
128 | ps = createPreparedStatement(conn, queryStr);
129 | int result = ps.executeUpdate();
130 | if (result == 0) {
131 | throw new DataStoreException("Save Failed for query...");
132 | }
133 | return entity;
134 | } catch (final Exception hx) {
135 | throw new DataStoreException(hx.getMessage(), hx);
136 | } finally {
137 | closeStatementSafe(ps);
138 | }
139 | }
140 |
141 | public Iterable save(Iterable entities, Connection conn) {
142 | try {
143 | final List saved = new ArrayList();
144 | for (final T entity : entities) {
145 | saved.add(this.save(entity, conn));
146 | }
147 | return saved;
148 | } catch (final Exception hx) {
149 | throw new DataStoreException(hx.getMessage(), hx);
150 | }
151 | }
152 |
153 | public int[] saveBatch(Iterable entities, Connection conn) {
154 | PreparedStatement ps = null;
155 | try {
156 | ps = buildStatementWithBatch(entities, conn);
157 | return ps.executeBatch();
158 | } catch (final Exception hx) {
159 | throw new DataStoreException(hx.getMessage(), hx);
160 | } finally {
161 | closeStatementSafe(ps);
162 | }
163 | }
164 |
165 | public PreparedStatement buildStatementWithBatch(Iterable entities, Connection conn) throws SQLException {
166 | PreparedStatement preparedStatement = null;
167 | for (final T entity : entities) {
168 | QueryUpdate query = QueryUpdateBuilder.builderFor(entity).build();
169 | String queryStr = queryTranslator.translate(query);
170 | if (showSQL) {
171 | log.info("Query String {}", queryStr);
172 | }
173 | if (preparedStatement == null) {
174 | preparedStatement = createPreparedStatement(conn, queryStr);
175 | }
176 | preparedStatement.addBatch(queryStr);
177 | }
178 | return preparedStatement;
179 | }
180 |
181 | private Statement createStatement(final Connection conn) throws SQLException {
182 | Statement statement = conn.createStatement();
183 | if(statementProperties.containsKey(QUERY_TIMEOUT_SEC)) {
184 | String queryTimeOutValue = statementProperties.get(QUERY_TIMEOUT_SEC);
185 | try {
186 | statement.setQueryTimeout(Integer.valueOf(queryTimeOutValue));
187 | } catch(Exception ig) {
188 | log.warn("Ignoring invalid queryTimeout {}", queryTimeOutValue, ig);
189 | }
190 | }
191 | return statement;
192 |
193 | }
194 |
195 | private PreparedStatement createPreparedStatement(final Connection conn, final String queryStr) throws SQLException {
196 | PreparedStatement statement = conn.prepareStatement(queryStr);
197 | if(statementProperties.containsKey(QUERY_TIMEOUT_SEC)) {
198 | String queryTimeOutValue = statementProperties.get(QUERY_TIMEOUT_SEC);
199 | try {
200 | statement.setQueryTimeout(Integer.valueOf(queryTimeOutValue));
201 | } catch(Exception ig) {
202 | log.warn("Ignoring invalid queryTimeout {}", queryTimeOutValue, ig);
203 | }
204 | }
205 | return statement;
206 |
207 | }
208 |
209 | protected PhoenixProjectedResultMapper getMapper() {
210 | return resultMapper;
211 | }
212 |
213 | public boolean isShowSQL() {
214 | return showSQL;
215 | }
216 |
217 | public void setShowSQL(boolean showSQL) {
218 | this.showSQL = showSQL;
219 | }
220 |
221 | }
222 |
--------------------------------------------------------------------------------
/src/main/java/com/eharmony/pho/hbase/translator/MorphiaEntityResolver.java:
--------------------------------------------------------------------------------
1 | package com.eharmony.pho.hbase.translator;
2 |
3 | import org.apache.commons.lang.StringUtils;
4 |
5 | import com.eharmony.pho.translator.EntityResolver;
6 | import com.google.code.morphia.annotations.Entity;
7 |
8 | /**
9 | * Resolve the collection name of an entity class using Morphia's mapper.
10 | */
11 | public class MorphiaEntityResolver implements EntityResolver {
12 |
13 | @Override
14 | public String resolve(Class> entityClass) {
15 | Entity entity = entityClass.getAnnotation(Entity.class);
16 | String mappedName = entityClass.getSimpleName();
17 | if (entity != null && StringUtils.isNotBlank(entity.value())) {
18 | mappedName = entity.value();
19 | }
20 | return mappedName;
21 | }
22 |
23 | }
24 |
--------------------------------------------------------------------------------
/src/main/java/com/eharmony/pho/hbase/translator/PhoenixHBaseAggregate.java:
--------------------------------------------------------------------------------
1 | package com.eharmony.pho.hbase.translator;
2 |
3 | import com.eharmony.pho.query.criterion.Symbolic;
4 |
5 | public enum PhoenixHBaseAggregate implements Symbolic {
6 |
7 | GROUP_BY("GROUP BY"),
8 | COUNT("COUNT"),
9 | AVG("AVG"),
10 | SUM("SUM"),
11 | MAX("MAX"),
12 | MIN("MIN");
13 |
14 | private final String symbol;
15 |
16 | PhoenixHBaseAggregate(String symbol) {
17 | this.symbol = symbol;
18 | }
19 |
20 | @Override
21 | public String symbol() {
22 | return symbol;
23 | }
24 |
25 |
26 | @Override
27 | public String toString() {
28 | return symbol();
29 | }
30 | }
31 |
--------------------------------------------------------------------------------
/src/main/java/com/eharmony/pho/hbase/translator/PhoenixHBaseClauses.java:
--------------------------------------------------------------------------------
1 | package com.eharmony.pho.hbase.translator;
2 |
3 | import com.eharmony.pho.query.criterion.Symbolic;
4 |
5 | /**
6 | * Mappings for Apache Phoenix HBase Clauses
7 | */
8 | public enum PhoenixHBaseClauses implements Symbolic {
9 | FROM("FROM"),
10 | WHERE("WHERE"),
11 | HAVING("HAVING"),
12 | ORDER_BY("ORDER BY"),
13 | LIMIT("LIMIT");
14 |
15 | private final String symbol;
16 |
17 | private PhoenixHBaseClauses(String symbol) {
18 | this.symbol = symbol;
19 | }
20 |
21 | @Override
22 | public String symbol() {
23 | return symbol;
24 | }
25 |
26 | @Override
27 | public String toString() {
28 | return symbol();
29 | }
30 |
31 | }
32 |
--------------------------------------------------------------------------------
/src/main/java/com/eharmony/pho/hbase/translator/PhoenixHBaseOperator.java:
--------------------------------------------------------------------------------
1 | package com.eharmony.pho.hbase.translator;
2 |
3 | import com.eharmony.pho.query.criterion.Symbolic;
4 |
5 | /**
6 | * Mappings for Apache Phoenix HBase query operators
7 | */
8 | public enum PhoenixHBaseOperator implements Symbolic {
9 | EQUAL("="),
10 | NOT_EQUAL("!="),
11 | GREATER_THAN(">"),
12 | GREATER_THAN_OR_EQUAL(">="),
13 | LESS_THAN("<"),
14 | LESS_THAN_OR_EQUAL("<="),
15 |
16 | OR("OR"),
17 | AND("AND"),
18 |
19 | LIKE("LIKE"),
20 | LIKE_CASE_INSENSITIVE("ILIKE"),
21 |
22 | IS_NULL("IS NULL"),
23 | IS_NOT_NULL("IS NOT NULL");
24 |
25 | private final String symbol;
26 |
27 | private PhoenixHBaseOperator(String symbol) {
28 | this.symbol = symbol;
29 | }
30 |
31 | @Override
32 | public String symbol() {
33 | return symbol;
34 | }
35 |
36 | @Override
37 | public String toString() {
38 | return symbol();
39 | }
40 |
41 | }
42 |
--------------------------------------------------------------------------------
/src/main/java/com/eharmony/pho/hbase/translator/PhoenixHBaseQueryTranslator.java:
--------------------------------------------------------------------------------
1 | package com.eharmony.pho.hbase.translator;
2 |
3 | import java.lang.reflect.InvocationTargetException;
4 | import java.util.ArrayList;
5 | import java.util.Arrays;
6 | import java.util.Date;
7 | import java.util.LinkedList;
8 | import java.util.List;
9 | import java.util.Map;
10 | import java.util.Set;
11 |
12 | import com.eharmony.pho.query.criterion.expression.Expression;
13 | import com.eharmony.pho.query.criterion.projection.AggregateProjection;
14 | import com.eharmony.pho.query.criterion.projection.GroupProjection;
15 | import com.eharmony.pho.query.criterion.projection.Projection;
16 | import com.google.common.base.Strings;
17 | import org.apache.commons.beanutils.PropertyUtils;
18 | import org.apache.commons.collections.CollectionUtils;
19 | import org.apache.commons.collections.MapUtils;
20 | import org.apache.commons.lang.StringUtils;
21 | import org.slf4j.Logger;
22 | import org.slf4j.LoggerFactory;
23 |
24 | import com.eharmony.pho.api.DataStoreException;
25 | import com.eharmony.pho.hbase.util.PhoenixDateFormatUtil;
26 | import com.eharmony.pho.mapper.EntityPropertiesResolver;
27 | import com.eharmony.pho.mapper.EntityPropertyBinding;
28 | import com.eharmony.pho.mapper.EntityPropertyValueBinding;
29 | import com.eharmony.pho.query.QuerySelect;
30 | import com.eharmony.pho.query.QueryUpdate;
31 | import com.eharmony.pho.query.criterion.Criterion;
32 | import com.eharmony.pho.query.criterion.Ordering;
33 | import com.eharmony.pho.query.criterion.Orderings;
34 | import com.eharmony.pho.query.criterion.Ordering.NullOrdering;
35 | import com.eharmony.pho.query.criterion.Ordering.Order;
36 | import com.eharmony.pho.query.criterion.expression.NativeExpression;
37 | import com.eharmony.pho.translator.AbstractQueryTranslator;
38 | import com.eharmony.pho.translator.QueryTranslator;
39 | import com.google.common.base.Function;
40 | import com.google.common.base.Joiner;
41 | import com.google.common.collect.Lists;
42 |
43 | import static com.eharmony.pho.hbase.translator.PhoenixHBaseAggregate.*;
44 |
45 | /**
46 | * Translates the entity to Phoenix query to execute on HBase.
47 | *