enum agtype_value_type get_ith_agtype_value_type()

in src/backend/utils/adt/agtype_util.c [596:673]


enum agtype_value_type get_ith_agtype_value_type(agtype_container *container,
                                                 uint32 i)
{
    enum agtype_value_type type;
    uint32 nelements;
    agtentry entry;

    if (!AGTYPE_CONTAINER_IS_ARRAY(container))
    {
        ereport(ERROR, (errmsg("container is not an agtype array")));
    }

    nelements = AGTYPE_CONTAINER_SIZE(container);
    if (i >= nelements)
    {
        ereport(ERROR, (errmsg("index out of bounds")));
    }

    entry = container->children[i];
    switch ((entry)&AGTENTRY_TYPEMASK)
    {
    case AGTENTRY_IS_STRING:
        type = AGTV_STRING;
        break;
    case AGTENTRY_IS_NUMERIC:
        type = AGTV_NUMERIC;
        break;
    case AGTENTRY_IS_AGTYPE:
    {
        char *base_addr;
        uint32 agt_header;
        char *base;

        base_addr = (char *)&container->children[nelements];
        base = base_addr + INTALIGN(get_agtype_offset(container, i));
        agt_header = *((uint32 *)base);

        switch (agt_header)
        {
        case AGT_HEADER_INTEGER:
            type = AGTV_INTEGER;
            break;
        case AGT_HEADER_FLOAT:
            type = AGTV_FLOAT;
            break;
        case AGT_HEADER_VERTEX:
            type = AGTV_VERTEX;
            break;
        case AGT_HEADER_EDGE:
            type = AGTV_EDGE;
            break;
        case AGT_HEADER_PATH:
            type = AGTV_PATH;
            break;
        default:
            ereport(ERROR, (errmsg("unexpected agt_header type")));
            break;
        }
        break;
    }
    case AGTENTRY_IS_BOOL_TRUE:
        type = AGTV_BOOL;
        break;
    case AGTENTRY_IS_BOOL_FALSE:
        type = AGTV_BOOL;
        break;
    case AGTENTRY_IS_NULL:
        type = AGTV_NULL;
        break;
    case AGTENTRY_IS_CONTAINER:
        type = AGTV_BINARY;
        break;
    default:
        ereport(ERROR, (errmsg("unexpected agtentry type")));
        break;
    }
    return type;
}