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 cb5995454a509ee88feead17c291544cf1ea66ff Author: Himanshu Pandey <[email protected]> AuthorDate: Thu Sep 15 15:28:40 2022 -0700 Code Refactor --- external-table/src/gpdbwritableformatter.c | 81 ++++++++++-------------------- 1 file changed, 26 insertions(+), 55 deletions(-) diff --git a/external-table/src/gpdbwritableformatter.c b/external-table/src/gpdbwritableformatter.c index a76a836d..79dd35eb 100644 --- a/external-table/src/gpdbwritableformatter.c +++ b/external-table/src/gpdbwritableformatter.c @@ -54,6 +54,7 @@ PG_FUNCTION_INFO_V1(gpdbwritableformatter_export); PG_FUNCTION_INFO_V1(gpdbwritableformatter_import); Datum gpdbwritableformatter_import(PG_FUNCTION_ARGS); Datum gpdbwritableformatter_export(PG_FUNCTION_ARGS); +static Form_pg_attribute getAttributeFromTupleDesc(TupleDesc, int); static const int ERR_COL_OFFSET = 9; static const int FIRST_LINE_NUM = 1; @@ -347,11 +348,7 @@ boolArrayToByteArray(bool *data, int len, int validlen, int *outlen, TupleDesc t for (i = 0, j = 0, k = 7; i < len; i++) { /* Ignore dropped attributes. */ - #if PG_VERSION_NUM >= 120000 - Form_pg_attribute attr = &tupdesc->attrs[i]; - #else - Form_pg_attribute attr = tupdesc->attrs[i]; - #endif + Form_pg_attribute attr = getAttributeFromTupleDesc(tupdesc,i); if (attr->attisdropped) continue; @@ -396,11 +393,7 @@ byteArrayToBoolArray(bits8 *data, int data_len, int len, bool **booldata, int bo for (i = 0, j = 0, k = 7; i < boollen; i++) { /* Ignore dropped attributes. */ - #if PG_VERSION_NUM >= 120000 - Form_pg_attribute attr = &tupdesc->attrs[i]; - #else - Form_pg_attribute attr = tupdesc->attrs[i]; - #endif + Form_pg_attribute attr = getAttributeFromTupleDesc(tupdesc,i); if (attr->attisdropped) { @@ -440,11 +433,7 @@ verifyExternalTableDefinition(int16 ncolumns_remote, AttrNumber nvalidcolumns, A /* Extract Column Type and check against External Table definition */ for (i = 0; i < ncolumns; i++) { - #if PG_VERSION_NUM >= 120000 - Form_pg_attribute attr = &tupdesc->attrs[i]; - #else - Form_pg_attribute attr = tupdesc->attrs[i]; - #endif + Form_pg_attribute attr = getAttributeFromTupleDesc(tupdesc,i); /* Ignore dropped attributes. */ if (attr->attisdropped) continue; @@ -512,11 +501,7 @@ gpdbwritableformatter_export(PG_FUNCTION_ARGS) nvalidcolumns = 0; for (i = 0; i < ncolumns; i++) { - #if PG_VERSION_NUM >= 120000 - Form_pg_attribute attr = &tupdesc->attrs[i]; - #else - Form_pg_attribute attr = tupdesc->attrs[i]; - #endif + Form_pg_attribute attr = getAttributeFromTupleDesc(tupdesc,i); if (!attr->attisdropped) nvalidcolumns++; @@ -545,11 +530,7 @@ gpdbwritableformatter_export(PG_FUNCTION_ARGS) /* setup the text/binary input function */ for (i = 0; i < ncolumns; i++) { - #if PG_VERSION_NUM >= 120000 - Form_pg_attribute attr = &tupdesc->attrs[i]; - #else - Form_pg_attribute attr = tupdesc->attrs[i]; - #endif + Form_pg_attribute attr = getAttributeFromTupleDesc(tupdesc,i); Oid type = attr->atttypid; bool isvarlena; @@ -607,11 +588,7 @@ gpdbwritableformatter_export(PG_FUNCTION_ARGS) */ for (i = 0; i < ncolumns; i++) { - #if PG_VERSION_NUM >= 120000 - Form_pg_attribute attr = &tupdesc->attrs[i]; - #else - Form_pg_attribute attr = tupdesc->attrs[i]; - #endif + Form_pg_attribute attr = getAttributeFromTupleDesc(tupdesc,i); /* Ignore dropped attributes. */ if (attr->attisdropped) continue; @@ -697,11 +674,7 @@ gpdbwritableformatter_export(PG_FUNCTION_ARGS) /* Write col type for columns that have not been dropped */ for (i = 0; i < ncolumns; i++) { - #if PG_VERSION_NUM >= 120000 - Form_pg_attribute attr = &tupdesc->attrs[i]; - #else - Form_pg_attribute attr = tupdesc->attrs[i]; - #endif + Form_pg_attribute attr = getAttributeFromTupleDesc(tupdesc,i); /* Ignore dropped attributes. */ if (!attr->attisdropped) @@ -718,11 +691,7 @@ gpdbwritableformatter_export(PG_FUNCTION_ARGS) /* Column Value */ for (i = 0; i < ncolumns; i++) { - #if PG_VERSION_NUM >= 120000 - Form_pg_attribute attr = &tupdesc->attrs[i]; - #else - Form_pg_attribute attr = tupdesc->attrs[i]; - #endif + Form_pg_attribute attr = getAttributeFromTupleDesc(tupdesc,i); /* Ignore dropped attributes and null values. */ if (!attr->attisdropped && !myData->nulls[i]) @@ -789,11 +758,7 @@ gpdbwritableformatter_import(PG_FUNCTION_ARGS) /* Get the number of valid columns, excluding dropped columns */ for (i = 0; i < ncolumns; i++) { - #if PG_VERSION_NUM >= 120000 - Form_pg_attribute attr = &tupdesc->attrs[i]; - #else - Form_pg_attribute attr = tupdesc->attrs[i]; - #endif + Form_pg_attribute attr = getAttributeFromTupleDesc(tupdesc,i); if (!attr->attisdropped) nvalidcolumns++; @@ -820,11 +785,7 @@ gpdbwritableformatter_import(PG_FUNCTION_ARGS) for (i = 0; i < ncolumns; i++) { - #if PG_VERSION_NUM >= 120000 - Form_pg_attribute attr = &tupdesc->attrs[i]; - #else - Form_pg_attribute attr = tupdesc->attrs[i]; - #endif + Form_pg_attribute attr = getAttributeFromTupleDesc(tupdesc,i); Oid type = attr->atttypid; @@ -942,11 +903,7 @@ gpdbwritableformatter_import(PG_FUNCTION_ARGS) /* extract column value */ for (i = 0; i < ncolumns; i++) { - #if PG_VERSION_NUM >= 120000 - Form_pg_attribute attr = &tupdesc->attrs[i]; - #else - Form_pg_attribute attr = tupdesc->attrs[i]; - #endif + Form_pg_attribute attr = getAttributeFromTupleDesc(tupdesc, i); /* Ignore dropped attributes. */ if (attr->attisdropped) @@ -1051,3 +1008,17 @@ gpdbwritableformatter_import(PG_FUNCTION_ARGS) FORMATTER_SET_TUPLE(fcinfo, tuple); FORMATTER_RETURN_TUPLE(tuple); } + +static inline Form_pg_attribute +getAttributeFromTupleDesc(TupleDesc tupdesc, int index) +{ + Form_pg_attribute attr; + #if PG_VERSION_NUM >= 120000 + attr = &tupdesc->attrs[index]; + #else + attr = tupdesc->attrs[index]; + #endif + + return attr; + +} --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
