Re: general purpose array_sort - Mailing list pgsql-hackers

From jian he
Subject Re: general purpose array_sort
Date
Msg-id CACJufxF6TNuv=b33sh+Kb7q5ZME9HfeMPwbGtbuMd5mgJe_ECw@mail.gmail.com
Whole thread Raw
In response to Re: general purpose array_sort  (Junwang Zhao <zhjwpku@gmail.com>)
Responses Re: general purpose array_sort
List pgsql-hackers
On Wed, Oct 23, 2024 at 10:28 PM Junwang Zhao <zhjwpku@gmail.com> wrote:
> PFA v7 with multi-array support.
>

if (ARR_NDIM(array) == 1)
{
}
else
{
}
can be simplified.
i think beginning part of array_sort can be like the following:
(newline emitted)

---------------------------------------------------------------------
    if (ARR_NDIM(array) < 1)
        PG_RETURN_ARRAYTYPE_P(array);
    if (dirstr != NULL)
    {
        if (!parse_sort_order(text_to_cstring(dirstr), &sort_asc, &nulls_first))
            ereport(ERROR,
                    (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
                     errmsg("second parameter must be a valid sort
direction")));
    }
    elmtyp = ARR_ELEMTYPE(array);
    if (ARR_NDIM(array) > 1)
        elmtyp = get_array_type(elmtyp);
    typentry = (TypeCacheEntry *) fcinfo->flinfo->fn_extra;
    if (typentry == NULL || typentry->type_id != elmtyp)
    {
        typentry = lookup_type_cache(elmtyp, sort_asc ?
TYPECACHE_LT_OPR : TYPECACHE_GT_OPR);
        if ((sort_asc && !OidIsValid(typentry->lt_opr)) ||
            (!sort_asc && !OidIsValid(typentry->gt_opr)))
            ereport(ERROR,
                    (errcode(ERRCODE_UNDEFINED_FUNCTION),
                    errmsg("could not identify an ordering operator
for type %s",
                            format_type_be(elmtyp))));
        fcinfo->flinfo->fn_extra = (void *) typentry;
    }
---------------------------------------------------------------------
/*
 * array_sort
 *
 * Sorts the array in either ascending or descending order.
 * The array must be empty or one-dimensional.
 */
comments need to be updated.


typedef enum
    PARSE_SORT_ORDER_DONE
} ParseSortOrderState;

last one, should have comma, like
"PARSE_SORT_ORDER_DONE, "



pgsql-hackers by date:

Previous
From: Amit Kapila
Date:
Subject: Re: Pgoutput not capturing the generated columns
Next
From: hugo
Date:
Subject: Useless field ispartitioned in CreateStmtContext