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


##########
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:
   I wanted to have subquery but PARTITION_ID() function does not work with 
subquery, resolving it turns out to be more complicated without significant 
changes.



-- 
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: issues-unsubscr...@phoenix.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org

Reply via email to