Skip to content

Added type handler for jsonpath - #3177

Merged
YohDeadfall merged 5 commits into
npgsql:mainfrom
YohDeadfall:json-path
Sep 24, 2020
Merged

YohDeadfall merged 5 commits into
npgsql:mainfrom
YohDeadfall:json-path

Conversation

@YohDeadfall

Copy link
Copy Markdown
Contributor

Fixes #2504

@YohDeadfall
YohDeadfall requested a review from roji as a code owner September 22, 2020 12:11
@YohDeadfall YohDeadfall mentioned this pull request Sep 22, 2020

@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.

Am a bit confused in the tests but other LGTM.

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.

Is there a need for us to test different cases here? After all Npgsql is just reading and writing strings here and doesn't interact with the content in any way... If that's the case, I'd consider just embedding any same query (one of the below) in the tests themselves for simplification

@YohDeadfall YohDeadfall Sep 22, 2020 •

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

An experiment, looking for unification of our type handlers tests, so in the final they should just accept cases and have test methods in the base class like in benchmarks. No boilerplate code, just cases.

Take a look at the numeric test class or money, for an example.

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.

The difference is that in numeric there really are different cases for us to test, because they trigger different code paths inside the handler. With jsonpath we are just passing a string..

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Yes, but the idea is to have a common base for all type tests. Doesn't matter what is going to be tested, it tested the same way.

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.

I'm not sure I see the point of that. Am OK for merging as-is, but maybe better to do test cases when we actually apply the common base?

If you want to keep this, is anything additional being tested by having two test cases? Why not just keep one? I'm asking because the test gives the impression that we actually care what's in those strings.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

The next step is to start test unification, so the answer to your question is no (:

To see why I added the second case, just remove double quotes from the query string and see what happens. While jsonpath is transferred as a C string prefixed by a version number, the internal representation isn't a string and casting it back could give a different result.

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.

nit: can also write Assert.True which I find slightly more clear, but really not important.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

This test verifies that the server correctly parsed the parameter and it has the same values the unlined into the query. Otherwise, reading the passed parameter may hide a possible bug because of a symmetric in Write.

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.

I agree it's a good idea to split reading and writing tests (and we don't do that with many types).

But specifically here, isn't it enough to just do SELECT @p::text and assert on the returned text representation? That would be a 100% reliable test of the sending, no?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

In that case we will rely on the behavior of TextHandler which could have a bug too.

@roji roji Sep 23, 2020 •

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.

I think it's ok to assume that TextHandler works in this test, no? After all you're relying on BoolHandler not having bugs in the exact same way

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Fixed, it doesn't rely on other handlers any more.

@YohDeadfall
YohDeadfall requested a review from roji September 23, 2020 09:11

@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.

OK for merging but see my remaining test comments.

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.

I'm not sure I see the point of that. Am OK for merging as-is, but maybe better to do test cases when we actually apply the common base?

If you want to keep this, is anything additional being tested by having two test cases? Why not just keep one? I'm asking because the test gives the impression that we actually care what's in those strings.

using var conn = await OpenConnectionAsync();
MinimumPgVersion(conn, "12.0", "The jsonpath type was introduced in PostgreSQL 12");

using var cmd = new NpgsqlCommand($"SELECT 'Passed' WHERE @p::text = {query}::text", conn) { Parameters = { new NpgsqlParameter("p", NpgsqlDbType.JsonPath) { Value = expected } } };

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.

Am OK for merging, but I still don't understand the point of this compared to just SELECT @p::text and asserting on the returned string - it's needlessly complicated.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

We don't use other handlers and we should have more reliable tests. Plus keep in mind that I told you in other thread, I want to unify tests, so it won't work well for floating point numbers and you know why.

@YohDeadfall
YohDeadfall merged commit 048c460 into npgsql:main Sep 24, 2020
@YohDeadfall
YohDeadfall deleted the json-path branch September 24, 2020 07:31
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.

Implement new jsonpath datatype

2 participants