Skip to content

Label tree support - #2991

Closed
NinoFloris wants to merge 2 commits into
npgsql:mainfrom
NinoFloris:label-tree-support
Closed

NinoFloris wants to merge 2 commits into
npgsql:mainfrom
NinoFloris:label-tree-support

Conversation

@NinoFloris

Copy link
Copy Markdown
Member

https://www.postgresql.org/docs/13/release-13.html

Add support for binary I/O of ltree, lquery, and ltxtquery types (Nino Floris)

As ltree now supports binary protocol in beta 1 of pg 13 I thought it time to dig up this branch :)
It implements the wire format (one byte for version, binary string afterwards) and maps this to a string. We may want to parse it into segments for IEnumerable/string[] support.

I'm not sure what's with all the regions so I just followed the trend here.

@NinoFloris
NinoFloris requested a review from roji May 31, 2020 14:02
@NinoFloris
NinoFloris requested a review from YohDeadfall as a code owner May 31, 2020 14:02
@YohDeadfall YohDeadfall added this to the 5.0 milestone May 31, 2020

@YohDeadfall YohDeadfall left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Looks good, but would you mind to add some tests? (: While it uses the text handler, there should be some tests to ensure that no change will break label trees.

You can use inheritdoc elements on public members to avoid warnings.

await buf.Ensure(1, async);
var version = buf.ReadByte();
if (version != LqueryProtocolVersion)
throw new NotSupportedException($"Don't know how to decode lquery with wire format {version}, your connection is now broken");

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Now it isn't. The driver properly handles invalid data in columns without breaking connections. By the way, we have ThrowHelper where you can put this code and avoid duplication in six places.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

As this handler is almost a one to one copy the wording should be fixed in these other places as well.
https://github.com/npgsql/npgsql/blob/main/src/Npgsql/TypeHandlers/JsonHandler.cs#L266

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Sure, will address this too (:

Ltxtquery = 63, // Extension type

#endregion

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

nit: Empty line.

@YohDeadfall YohDeadfall removed this from the 5.0 milestone May 31, 2020
@YohDeadfall YohDeadfall linked an issue May 31, 2020 that may be closed by this pull request

@roji roji left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

  • Should we call this LTree rather than Ltree (and so LTxtQuery instead of Ltxtquery, etc.)? That seems like the right C# naming thing to do.
  • It would definitely be good to see some tests. I'm looking into having the PG13 beta on our CI.
  • Does it make sense to provide a non-string, model representation, i.e. an actual tree? As it is we're passing the burden of parsing etc. to the user.


namespace Npgsql.TypeHandlers
{
#pragma warning disable CS1591 // Missing XML comment for publicly visible type or member

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Yeah, ideally this wouldn't be here. Definitely no need to document private/internal stuff though.

@NinoFloris

Copy link
Copy Markdown
Member Author

@roji ltree works on paths, which as a set form a tree. some form of string list might help.

I'll get to the feedback in a few days I expect, I already had this laying around, good to hear no major things :)

@roji

roji commented Jun 18, 2020

Copy link
Copy Markdown
Member

@NinoFloris FYI we now run tests on PG13 so that should help here.

@roji

roji commented Sep 6, 2020

Copy link
Copy Markdown
Member

@NinoFloris ping, would be nice to get this in soon.

@roji
roji changed the base branch from dev to main September 17, 2020 14:34
/// The PostgreSQL ltree type, each value is a label path "a.label.tree.value", forming a tree in a set.
/// </summary>
/// <remarks>See http://www.postgresql.org/docs/current/static/ltree.html</remarks>
Ltree = 61, // Extension type

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Should start from the maximum existing type number plus one. Since #3177 gets merged soon, makes sense to use 58 as the first.

@YohDeadfall

Copy link
Copy Markdown
Contributor

Finished by #3312. Thanks, @NinoFloris!

@NinoFloris

Copy link
Copy Markdown
Member Author

@YohDeadfall no thank you - seriously - for bringing it over the finish line.

@NinoFloris
NinoFloris deleted the label-tree-support branch August 28, 2023 12:58
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.

Support for the ltree contrib type

3 participants