Github user jihoonson commented on a diff in the pull request:
https://github.com/apache/tajo/pull/772#discussion_r39943564
--- Diff:
tajo-catalog/tajo-catalog-drivers/tajo-hive/src/main/java/org/apache/tajo/catalog/store/HiveCatalogStore.java
---
@@ -845,11 +856,155 @@ public boolean existPartitionMethod(String
databaseName, String tableName) throw
}
@Override
- public List<CatalogProtos.PartitionDescProto> getPartitions(String
databaseName,
- String tableName)
{
- throw new UnsupportedOperationException();
+ public List<CatalogProtos.PartitionDescProto> getAllPartitions(String
databaseName, String tableName)
+ throws UndefinedDatabaseException, UndefinedTableException,
UndefinedPartitionMethodException,
+ PartitionNotFoundException {
+ PartitionsByFilterProto.Builder request =
PartitionsByFilterProto.newBuilder();
+ request.setDatabaseName(databaseName);
+ request.setTableName(tableName);
+ request.setFilter("");
+
+ List<PartitionDescProto> partitions =
getPartitionsByFilter(request.build());
+ if (partitions.size() == 0) {
+ throw new PartitionNotFoundException(tableName);
+ } else {
+ return partitions;
+ }
+ }
+
+ @Override
+ public List<PartitionDescProto>
getPartitionsByAlgebra(PartitionsByAlgebraProto request) throws
+ UndefinedDatabaseException, UndefinedTableException,
UndefinedPartitionMethodException,
+ PartitionNotFoundException, UnsupportedException {
+
+ List<PartitionDescProto> list = null;
+
+ try {
+ String databaseName = request.getDatabaseName();
+ String tableName = request.getTableName();
+
+ TableDescProto tableDesc = getTable(databaseName, tableName);
+ String filter = getFilter(databaseName, tableName,
tableDesc.getPartition().getExpressionSchema().getFieldsList()
+ , request.getAlgebra());
+ list = getPartitionsByFilterFromHiveMetaStore(databaseName,
tableName, filter);
+ } catch (UnsupportedException ue) {
+ throw ue;
+ } catch (Exception se) {
+ throw new TajoInternalError(se);
+ }
+
+ return list;
+ }
+
+ private String getFilter(String databaseName, String tableName,
List<ColumnProto> partitionColumns
+ , String json) throws TajoException {
+
+ Expr[] exprs = null;
+
+ if (json != null && !json.isEmpty()) {
+ Expr algebra = JsonHelper.fromJson(json, Expr.class);
+ exprs = AlgebraicUtil.toConjunctiveNormalFormArray(algebra);
+ }
+
+ PartitionFilterAlgebraVisitor visitor = new
PartitionFilterAlgebraVisitor();
+ visitor.setIsHiveCatalog(true);
+
+ Expr[] filters =
AlgebraicUtil.getAccumulatedFiltersByExpr(databaseName + "." + tableName,
partitionColumns, exprs);
+
+ StringBuffer sb = new StringBuffer();
+
+ // Write join clause from second column to last column.
+ Column target;
+
+ int addedFilter = 0;
+ String result;
+ for (int i = 0; i < partitionColumns.size(); i++) {
+ target = new Column(partitionColumns.get(i));
+
+ if (!(filters[i] instanceof IsNullPredicate)) {
+ visitor.setColumn(target);
+ visitor.visit(null, new Stack<Expr>(), filters[i]);
+ result = visitor.getResult();
+
+ // If visitor build filter successfully, add filter to be used for
executing hive api.
+ if (result.length() > 0) {
--- End diff --
When does the result have zero-length?
We should handle this situation.
---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at [email protected] or file a JIRA ticket
with INFRA.
---