Skip to content

Support network_supeq and network_subeq by default #541

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

Merged
merged 4 commits into from
Jul 23, 2024

Conversation

soupi
Copy link
Contributor

@soupi soupi commented Jul 19, 2024

What

This PR lists network_supeq and network_subeq in the default allowed prefix functions, to complete support for types such as CIDR.

How

Add them to the default list, add tests, and regenerate configs.

@soupi soupi marked this pull request as draft July 19, 2024 14:19
Copy link
Contributor Author

@soupi soupi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@plcplc I know this is quite hacky. If you have ideas on how to make this awesome, do let me know :)

Comment on lines 1331 to 1343
SELECT DISTINCT ON (oprname)
o.oprname AS operator_name,
o.oprcode::text AS exposed_name,
'custom' AS operator_kind,
o.oprleft as operator_type,
(SELECT typname FROM pg_catalog.pg_type WHERE oid = o.oprleft LIMIT 1) as operator_type_name
FROM
pg_operator as o
WHERE
o.oprname IS NOT NULL
AND o.oprcode::text IS NOT NULL
AND o.oprleft = o.oprright
AND o.oprresult = (SELECT oid FROM pg_catalog.pg_type WHERE typname = 'bool' LIMIT 1)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This code generates a result that looks like this:

Screenshot from 2024-07-19 16-54-44

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Considering that this gets the exposedName from pg_operator.oprcode, which is a reference to pg_proc.oid (which when cast to text via ::text yields the value pg_proc.proname) I should think that simply adding network_supeq to the list of known prefix-functions in the introspection options should make it appear (and text_pattern_ge and friends too)

AND (
map.operator_type is null
OR map.operator_type = op.argument1_type
OR op.argument1_cast_chain LIKE ('% -> ' || map.operator_type_name)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

so using the operator name and the type, i can know that >>= on inet should be called network_supeq and should be an operator for the type cidr which has a valid cast from cidr to inet.

Base automatically changed from gil/add-neq to main July 23, 2024 09:39
@soupi soupi force-pushed the gil/even-more-operators branch from 6e46a0a to fb1b0c6 Compare July 23, 2024 10:54
@soupi soupi changed the title introspect for more operator names Support network_supeq and network_subeq by default Jul 23, 2024
@soupi soupi marked this pull request as ready for review July 23, 2024 11:02
@soupi
Copy link
Contributor Author

soupi commented Jul 23, 2024

@plcplc changed the implementation to only add the functions to the list, as we discussed.

Comment on lines 157 to 161
"network_sub".to_string(),
"network_subeq".to_string(),
"network_sup".to_string(),
"network_supeq".to_string(),
"on_pb".to_string(),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

@@ -883,6 +883,31 @@ expression: default_configuration
"foreignRelations": {},
"description": null
},
"custom_test_cidr": {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's a bit weird that we also update v3 and v4 test snapshots for this change, but I suppose it follows from each version using sharing the same test database definition.

@soupi soupi added this pull request to the merge queue Jul 23, 2024
Merged via the queue into main with commit 50cf427 Jul 23, 2024
30 checks passed
@soupi soupi deleted the gil/even-more-operators branch July 23, 2024 11:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants