-
Notifications
You must be signed in to change notification settings - Fork 488
Propagate null through agtype arithmetic operators #2405
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -165,6 +165,12 @@ Datum agtype_add(PG_FUNCTION_ARGS) | |
| agtv_lhs = get_ith_agtype_value_from_container(&lhs->root, 0); | ||
| agtv_rhs = get_ith_agtype_value_from_container(&rhs->root, 0); | ||
|
|
||
| /* openCypher: arithmetic over null yields null. */ | ||
| if (agtv_lhs->type == AGTV_NULL || agtv_rhs->type == AGTV_NULL) | ||
| { | ||
| PG_RETURN_NULL(); | ||
| } | ||
|
Comment on lines
+168
to
+172
|
||
|
|
||
| /* | ||
| * One or both values is a string OR one is a string and the other is | ||
| * either an integer, float, or numeric. If so, concatenate them. | ||
|
|
@@ -525,6 +531,12 @@ Datum agtype_sub(PG_FUNCTION_ARGS) | |
| agtv_lhs = get_ith_agtype_value_from_container(&lhs->root, 0); | ||
| agtv_rhs = get_ith_agtype_value_from_container(&rhs->root, 0); | ||
|
|
||
| /* openCypher: arithmetic over null yields null. */ | ||
| if (agtv_lhs->type == AGTV_NULL || agtv_rhs->type == AGTV_NULL) | ||
| { | ||
| PG_RETURN_NULL(); | ||
| } | ||
|
|
||
| if (agtv_lhs->type == AGTV_INTEGER && agtv_rhs->type == AGTV_INTEGER) | ||
| { | ||
| agtv_result.type = AGTV_INTEGER; | ||
|
|
@@ -615,6 +627,12 @@ Datum agtype_neg(PG_FUNCTION_ARGS) | |
|
|
||
| agtv_value = get_ith_agtype_value_from_container(&v->root, 0); | ||
|
|
||
| /* openCypher: arithmetic over null yields null. */ | ||
| if (agtv_value->type == AGTV_NULL) | ||
| { | ||
| PG_RETURN_NULL(); | ||
| } | ||
|
|
||
| if (agtv_value->type == AGTV_INTEGER) | ||
| { | ||
| agtv_result.type = AGTV_INTEGER; | ||
|
|
@@ -666,6 +684,12 @@ Datum agtype_mul(PG_FUNCTION_ARGS) | |
| agtv_lhs = get_ith_agtype_value_from_container(&lhs->root, 0); | ||
| agtv_rhs = get_ith_agtype_value_from_container(&rhs->root, 0); | ||
|
|
||
| /* openCypher: arithmetic over null yields null. */ | ||
| if (agtv_lhs->type == AGTV_NULL || agtv_rhs->type == AGTV_NULL) | ||
| { | ||
| PG_RETURN_NULL(); | ||
| } | ||
|
|
||
| if (agtv_lhs->type == AGTV_INTEGER && agtv_rhs->type == AGTV_INTEGER) | ||
| { | ||
| agtv_result.type = AGTV_INTEGER; | ||
|
|
@@ -756,6 +780,12 @@ Datum agtype_div(PG_FUNCTION_ARGS) | |
| agtv_lhs = get_ith_agtype_value_from_container(&lhs->root, 0); | ||
| agtv_rhs = get_ith_agtype_value_from_container(&rhs->root, 0); | ||
|
|
||
| /* openCypher: arithmetic over null yields null. */ | ||
| if (agtv_lhs->type == AGTV_NULL || agtv_rhs->type == AGTV_NULL) | ||
| { | ||
| PG_RETURN_NULL(); | ||
| } | ||
|
|
||
| if (agtv_lhs->type == AGTV_INTEGER && agtv_rhs->type == AGTV_INTEGER) | ||
| { | ||
| if (agtv_rhs->val.int_value == 0) | ||
|
|
@@ -874,6 +904,12 @@ Datum agtype_mod(PG_FUNCTION_ARGS) | |
| agtv_lhs = get_ith_agtype_value_from_container(&lhs->root, 0); | ||
| agtv_rhs = get_ith_agtype_value_from_container(&rhs->root, 0); | ||
|
|
||
| /* openCypher: arithmetic over null yields null. */ | ||
| if (agtv_lhs->type == AGTV_NULL || agtv_rhs->type == AGTV_NULL) | ||
| { | ||
| PG_RETURN_NULL(); | ||
| } | ||
|
|
||
| if (agtv_lhs->type == AGTV_INTEGER && agtv_rhs->type == AGTV_INTEGER) | ||
| { | ||
| agtv_result.type = AGTV_INTEGER; | ||
|
|
@@ -964,6 +1000,12 @@ Datum agtype_pow(PG_FUNCTION_ARGS) | |
| agtv_lhs = get_ith_agtype_value_from_container(&lhs->root, 0); | ||
| agtv_rhs = get_ith_agtype_value_from_container(&rhs->root, 0); | ||
|
|
||
| /* openCypher: arithmetic over null yields null. */ | ||
| if (agtv_lhs->type == AGTV_NULL || agtv_rhs->type == AGTV_NULL) | ||
| { | ||
| PG_RETURN_NULL(); | ||
| } | ||
|
|
||
| if (agtv_lhs->type == AGTV_INTEGER && agtv_rhs->type == AGTV_INTEGER) | ||
| { | ||
| agtv_result.type = AGTV_FLOAT; | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These tests pass a bare string literal as the RHS (type
unknown), which relies on implicit coercion/operator resolution and can make the intent of testing the scalar agtype operator path less explicit. Consider casting the RHS toagtype(e.g.,'1'::agtype) so the tests more directly exercise agtype-vs-agtype arithmetic and are less sensitive to changes in implicit casts.