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 240a95c25c2f87aa3c1fe65e4132a02b64c15813
Author: Himanshu Pandey <[email protected]>
AuthorDate: Fri Sep 30 14:45:15 2022 -0700

    Fixing Table/DB encoding comparison for GP7
---
 external-table/src/gpdbwritableformatter.c | 57 ++++++++++++++++++++++++------
 1 file changed, 47 insertions(+), 10 deletions(-)

diff --git a/external-table/src/gpdbwritableformatter.c 
b/external-table/src/gpdbwritableformatter.c
index 79dd35eb..fc08cd24 100644
--- a/external-table/src/gpdbwritableformatter.c
+++ b/external-table/src/gpdbwritableformatter.c
@@ -512,11 +512,30 @@ gpdbwritableformatter_export(PG_FUNCTION_ARGS)
         */
        if (myData == NULL)
        {
-               if (FORMATTER_GET_EXTENCODING(fcinfo) != PG_UTF8)
-               {
-                    ereport(ERROR, 
(errcode(ERRCODE_EXTERNAL_ROUTINE_EXCEPTION),
-                           errmsg(FORMATTER_ENCODING_ERR_MSG, "export")));
-               }
+        // In GP7 FORMATTER_GET_EXTENCODING(fcinfo) gets the database encoding 
which may not match the table encoding
+        // and thus results in exception here. So getting the table encoding 
from the ExtTableEntry
+#if PG_VERSION_NUM < 120000
+        if (FORMATTER_GET_EXTENCODING(fcinfo) != PG_UTF8)
+        {
+                 ereport(ERROR, (errcode(ERRCODE_EXTERNAL_ROUTINE_EXCEPTION),
+                            errmsg("gpdbwritable formatter can only export 
UTF8 formatted data. Define the external table with ENCODING UTF8")));
+        }
+#else
+        Relation rel = FORMATTER_GET_RELATION(fcinfo);
+        if(rel != NULL)
+        {
+            ExtTableEntry *exttbl = GetExtTableEntry(rel->rd_id);
+            if (exttbl->encoding != PG_UTF8) {
+                ereport(ERROR, (errcode(ERRCODE_EXTERNAL_ROUTINE_EXCEPTION),
+                        errmsg("gpdbwritable formatter can only export UTF8 
formatted data. Define the external table with ENCODING UTF8")));
+            }
+        }
+        // TODO: If for some reason the Relation is null here, then shall we 
throw an error anyways ??
+        else{
+            ereport(ERROR, (errcode(ERRCODE_EXTERNAL_ROUTINE_EXCEPTION),
+                    errmsg("gpdbwritable formatter can only export UTF8 
formatted data. Define the external table with ENCODING UTF8")));
+        }
+#endif
 
                myData = palloc(sizeof(format_t));
                myData->values = palloc(sizeof(Datum) * ncolumns);
@@ -769,11 +788,29 @@ gpdbwritableformatter_import(PG_FUNCTION_ARGS)
         */
        if (myData == NULL)
        {
-               if (FORMATTER_GET_EXTENCODING(fcinfo) != PG_UTF8)
-               {
-                       ereport(ERROR, 
(errcode(ERRCODE_EXTERNAL_ROUTINE_EXCEPTION),
-                                                       
errmsg(FORMATTER_ENCODING_ERR_MSG, "import")));
-               }
+        // In GP7 FORMATTER_GET_EXTENCODING(fcinfo) gets the database encoding 
which may not match the table encoding
+        // and thus results in exception here. So getting the table encoding 
from the ExtTableEntry
+#if PG_VERSION_NUM < 120000
+            if (FORMATTER_GET_EXTENCODING(fcinfo) != PG_UTF8)
+            {
+                     ereport(ERROR, 
(errcode(ERRCODE_EXTERNAL_ROUTINE_EXCEPTION),
+                                errmsg("gpdbwritable formatter can only import 
UTF8 formatted data. Define the external table with ENCODING UTF8")));
+            }
+#else
+        Relation rel = FORMATTER_GET_RELATION(fcinfo);
+        if(rel != NULL) {
+            ExtTableEntry *exttbl = GetExtTableEntry(rel->rd_id);
+            if (exttbl->encoding != PG_UTF8) {
+                ereport(ERROR, (errcode(ERRCODE_EXTERNAL_ROUTINE_EXCEPTION),
+                        errmsg("gpdbwritable formatter can only import UTF8 
formatted data. Define the external table with ENCODING UTF8")));
+            }
+        }
+        // TODO: If for some reason the Relation is null here, then shall we 
throw an error anyways ??
+        else{
+            ereport(ERROR, (errcode(ERRCODE_EXTERNAL_ROUTINE_EXCEPTION),
+                    errmsg("gpdbwritable formatter can only import UTF8 
formatted data. Define the external table with ENCODING UTF8")));
+        }
+#endif
 
                myData = palloc(sizeof(format_t));
                myData->values = palloc(sizeof(Datum) * ncolumns);


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

Reply via email to