Skip to content
Permalink
Browse files
Refactor agtype_access_operator
Refactored the agtype_access_operator and support functions to
eliminate the constant conversions back-and-forth.

Also corrected the response to AGTV_NULL

Moved get_agtype_key from age_vle.c to agtype.c for usage by
others.

Adjusted 2 regression tests.
  • Loading branch information
jrgemignani committed Feb 28, 2022
1 parent 0406d61 commit 466f09408a3fb5489b882bb380db3e6fe2229c4a
Showing 5 changed files with 364 additions and 94 deletions.
@@ -5404,7 +5404,7 @@ SELECT * FROM cypher('case_statement', $$
$$ ) AS (i agtype, j agtype, case_statement agtype);
i | j | case_statement
------+-----------+----------------
1 | null | "i is 1"
1 | | "i is 1"
"a" | "b" | "j is b"
0 | 1 | "0 AND 1"
true | false | "i or j true"
@@ -5427,7 +5427,7 @@ SELECT * FROM cypher('case_statement', $$
$$ ) AS (j agtype, case_statement agtype);
j | case_statement
-----------+----------------
null | "not a or b"
| "not a or b"
"b" | "b"
1 | 1
false | false
@@ -101,8 +101,6 @@ typedef struct VLE_path_container

/* declarations */
/* agtype functions */
static agtype_value *get_agtype_key(agtype_value *agtv, char *search_key,
int search_key_len);
static agtype_iterator *get_next_object_pair(agtype_iterator *it,
agtype_container *agtc,
agtype_value *key,
@@ -387,42 +385,6 @@ static bool is_an_edge_match(VLE_local_context *vlelctx, edge_entry *ee)
return true;
}

/*
* Helper function to iterate through all object pairs, looking for a specific
* key. It will return the key or NULL if not found.
*/
static agtype_value *get_agtype_key(agtype_value *agtv, char *search_key,
int search_key_len)
{
int i = 0;

if (agtv == NULL || search_key == NULL || search_key_len <= 0)
{
return NULL;
}

/* iterate through all pairs */
for (i = 0; i < agtv->val.object.num_pairs; i++)
{
agtype_value *agtv_key = &agtv->val.object.pairs[i].key;
agtype_value *agtv_value = &agtv->val.object.pairs[i].value;

char *current_key = agtv_key->val.string.val;
int current_key_len = agtv_key->val.string.len;

Assert(agtv_key->type == AGTV_STRING);

/* check for an id of type integer */
if (current_key_len == search_key_len &&
pg_strcasecmp(current_key, search_key) == 0)
{
return agtv_value;
}
}

return NULL;
}

/*
* Helper function to free up the memory used by the VLE_local_context.
*

0 comments on commit 466f094

Please sign in to comment.