This is an automated email from the ASF dual-hosted git repository.

djwang pushed a commit to branch merge-with-upstream
in repository https://gitbox.apache.org/repos/asf/cloudberry-pxf.git

commit 2b70d309e6d7174fe04ace05069981f510f26ef6
Author: liuxiaoyu <[email protected]>
AuthorDate: Tue Oct 7 18:49:55 2025 +0800

    fix: refactor projection header logic for PostgreSQL compatibility
    
    - Restore original projection counting logic in pxfheaders.c
    - Remove premature number calculation and header setting
    - Fix attribute collection flow for different PG versions
    - Clean up code formatting and comments
    - Update Makefile configuration
    - Minor formatting fix in pxfdelimited_formatter.c
---
 Makefile                                    |  8 ++++----
 external-table/src/pxfdelimited_formatter.c |  2 +-
 external-table/src/pxfheaders.c             | 30 ++++++++++++++---------------
 3 files changed, 20 insertions(+), 20 deletions(-)

diff --git a/Makefile b/Makefile
index 30b9d3f7..1014689f 100644
--- a/Makefile
+++ b/Makefile
@@ -34,7 +34,7 @@ ifneq ($(FDW_SUPPORT),)
 endif
 
 cli:
-       make -C cli/go/src/pxf-cli
+       make -C cli
 
 server:
        make -C server
@@ -42,7 +42,7 @@ server:
 clean:
        rm -rf build
        make -C $(SOURCE_EXTENSION_DIR) clean-all
-       make -C cli/go/src/pxf-cli clean
+       make -C cli clean
        make -C server clean
 ifneq ($(FDW_SUPPORT),)
        make -C fdw clean
@@ -62,7 +62,7 @@ it:
 
 install:
        make -C $(SOURCE_EXTENSION_DIR) install
-       make -C cli/go/src/pxf-cli install
+       make -C cli install
        make -C server install
 ifneq ($(FDW_SUPPORT),)
        make -C fdw install
@@ -105,7 +105,7 @@ gppkg-rpm: rpm
 
 rpm:
        make -C $(SOURCE_EXTENSION_DIR) stage
-       make -C cli/go/src/pxf-cli stage
+       make -C cli stage
        make -C server stage
        set -e ;\
        PXF_MAIN_VERSION=$${PXF_VERSION//-SNAPSHOT/} ;\
diff --git a/external-table/src/pxfdelimited_formatter.c 
b/external-table/src/pxfdelimited_formatter.c
index ecf9f52b..6617c547 100644
--- a/external-table/src/pxfdelimited_formatter.c
+++ b/external-table/src/pxfdelimited_formatter.c
@@ -234,7 +234,7 @@ new_pxfdelimited_state(FunctionCallInfo fcinfo)
        fmt_state->nColumns = nColumns;
 
        fmt_state->external_encoding = FORMATTER_GET_EXTENCODING(fcinfo);
-       fmt_state->enc_conversion_proc = ((FormatterData*) 
fcinfo->context)->fmt_conversion_proc;
+       fmt_state->enc_conversion_proc = ((FormatterData*) 
fcinfo->context)->fmt_conv_funcs;
 
        fmt_state->saw_delim = false;
        fmt_state->saw_eol = false;
diff --git a/external-table/src/pxfheaders.c b/external-table/src/pxfheaders.c
index 0c991eb7..583384a3 100644
--- a/external-table/src/pxfheaders.c
+++ b/external-table/src/pxfheaders.c
@@ -522,10 +522,8 @@ add_projection_desc_httpheader_pg94(CHURL_HEADERS headers,
        int                             *varNumbers = projInfo->pi_varNumbers;
        Bitmapset               *attrs_used;
        StringInfoData  formatter;
-       List               *targetList;   // targetList from the query plan
-       TupleDesc          tupdesc;
+       TupleDesc               tupdesc;
 
-       // STEP 0: initialize variables
        initStringInfo(&formatter);
        attrs_used = NULL;
        number = 0;
@@ -544,9 +542,10 @@ add_projection_desc_httpheader_pg94(CHURL_HEADERS headers,
        if (!varNumbers)
        {
                /*
-                * we use expression_tree_walker to access attrno information
-                * we do it through a helper function 
add_attnums_from_targetList
+                * When there are not just simple Vars we need to
+                * walk the tree to get attnums
                 */
+#endif
                List     *l = lappend_int(NIL, 0);
                ListCell *lc1;
 
@@ -563,7 +562,7 @@ add_projection_desc_httpheader_pg94(CHURL_HEADERS headers,
                        {
                                attrs_used =
                                        bms_add_member(attrs_used,
-                                                                attno - 
FirstLowInvalidHeapAttributeNumber);
+                                                                       attno - 
FirstLowInvalidHeapAttributeNumber);
                        }
                }
 
@@ -588,8 +587,11 @@ add_projection_desc_httpheader_pg94(CHURL_HEADERS headers,
                                                 varNumbers[i] - 
FirstLowInvalidHeapAttributeNumber);
        }
 
-       // STEP 3: collect attribute numbers from qualifiers (WHERE conditions)
        ListCell *attribute = NULL;
+
+       /*
+        * AttrNumbers coming from quals
+        */
        foreach(attribute, qualsAttributes)
        {
                AttrNumber attrNumber = (AttrNumber) lfirst_int(attribute);
@@ -598,10 +600,8 @@ add_projection_desc_httpheader_pg94(CHURL_HEADERS headers,
                                                 attrNumber + 1 - 
FirstLowInvalidHeapAttributeNumber);
        }
 
-       // STEP 4: for attributes in the relation that are not dropped, add 
projection headers for those selected in steps 0 - 3 above
        tupdesc = RelationGetDescr(rel);
-       droppedCount = 0;
-       headerCount = 0;
+       dropped_count = 0;
 
        for (i = 1; i <= tupdesc->natts; i++)
        {
@@ -609,7 +609,7 @@ add_projection_desc_httpheader_pg94(CHURL_HEADERS headers,
                if (tupdesc->attrs[i - 1]->attisdropped)
                {
                        /* keep a counter of the number of dropped attributes */
-                       droppedCount++;
+                       dropped_count++;
                        continue;
                }
 
@@ -617,15 +617,15 @@ add_projection_desc_httpheader_pg94(CHURL_HEADERS headers,
                {
                        /* Shift the column index by the running dropped_count 
*/
                        add_projection_index_header(headers, formatter,
-                                                                               
i - 1 - droppedCount, long_number);
-                       headerCount++;
+                                                                               
i - 1 - dropped_count, long_number);
+                       number++;
                }
        }
 
-       if (headerCount != 0)
+       if (number != 0)
        {
                /* Convert the number of projection columns to a string */
-               pg_ltoa(headerCount, long_number);
+               pg_ltoa(number, long_number);
                churl_headers_append(headers, "X-GP-ATTRS-PROJ", long_number);
        }
 


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to