haridsv commented on code in PR #2070:
URL: https://github.com/apache/phoenix/pull/2070#discussion_r1944134609


##########
phoenix-core-client/src/main/java/org/apache/phoenix/util/CDCUtil.java:
##########
@@ -155,6 +162,73 @@ public static boolean isBinaryType(PDataType dataType) {
                 || dataType.getSqlType() == PDataType.VARBINARY_ENCODED_TYPE);
     }
 
+    /**
+     * Return true if the parseNode or any of its children contains 
PARTITION_ID() function.
+     *
+     * @param parseNode The parseNode from Where clause.
+     * @return True if the parseNode or any of its children contains 
PARTITION_ID()
+     * function. False otherwise.
+     */
+    public static boolean isPartitionIdIncludedInTree(ParseNode parseNode) {
+        if (parseNode instanceof PartitionIdParseNode) {
+            return true;
+        }
+        if (parseNode == null || 
CollectionUtils.isEmpty(parseNode.getChildren())) {
+            return false;
+        }
+        return parseNode.getChildren().stream()
+                .anyMatch(CDCUtil::isPartitionIdIncludedInTree);
+    }
+
+    /**
+     * Add IN Operator for PARTITION_ID() so that the full table scan CDC 
query can be
+     * optimized to be range scan.
+     *
+     * @param conn The Connection.
+     * @param cdcName CDC Object name.
+     * @param query SQL Query Statement.
+     * @return Updated query including PartitionId with IN operator.
+     * @throws SQLException If the distinct partition ids retrieval fails.
+     */
+    public static String addPartitionInList(final Connection conn, final 
String cdcName,
+                                            final String query) throws 
SQLException {
+        ResultSet rs = conn.createStatement().executeQuery("SELECT DISTINCT 
PARTITION_ID() FROM "
+                + cdcName);
+        List<String> partitionIds = new ArrayList<>();
+        while (rs.next()) {
+            partitionIds.add(rs.getString(1));
+        }
+        if (partitionIds.isEmpty()) {
+            return query;
+        }
+        StringBuilder builder;
+        boolean queryHasWhere = query.contains(" WHERE ");

Review Comment:
   Basically, before calling into the second compilePlan, this new statement 
object of custom class will be constructed which is basically a clone of the 
original, except for this extra list of partition IDs and that is what goes 
into the second call.



-- 
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.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to