JingsongLi commented on a change in pull request #10381: [FLINK-14513][hive] 
Implement listPartitionsByFilter to HiveCatalog
URL: https://github.com/apache/flink/pull/10381#discussion_r355107686
 
 

 ##########
 File path: 
flink-connectors/flink-connector-hive/src/main/java/org/apache/flink/table/catalog/hive/util/HiveTableUtil.java
 ##########
 @@ -175,4 +186,93 @@ public static boolean requireRelyConstraint(byte trait) {
                return (trait & HIVE_CONSTRAINT_RELY) != 0;
        }
 
+       /**
+        * Generates a filter string for partition columns from the given 
filter expressions.
+        *
+        * @param numNonPartCol The number of non-partition columns -- used to 
shift field reference index
+        * @param partColNames The names of all partition columns
+        * @param expressions  The filter expressions in CNF form
+        * @return an Optional filter string equivalent to the expressions, 
which is empty if the expressions can't be handled
+        */
+       public static Optional<String> makePartitionFilter(int numNonPartCol, 
List<String> partColNames, List<Expression> expressions) {
+               List<String> filters = new ArrayList<>(expressions.size());
+               ExpressionExtractor extractor = new 
ExpressionExtractor(numNonPartCol, partColNames);
+               for (Expression expression : expressions) {
+                       String str = expression.accept(extractor);
+                       if (str == null) {
+                               return Optional.empty();
+                       }
+                       filters.add(str);
+               }
+               return Optional.of(String.join(" and ", filters));
+       }
+
+       private static class ExpressionExtractor implements 
ExpressionVisitor<String> {
+
+               private static final Map<FunctionDefinition, String> funcToStr 
= new HashMap<>();
 
 Review comment:
   checkstyle

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
[email protected]


With regards,
Apache Git Services

Reply via email to