Skip to content

Conversation

ozdemircs
Copy link

@ozdemircs ozdemircs commented Apr 6, 2023

This PR adds the Error debug function similar to the BigQuery as discussed in the #6775 and here.

Copy link
Collaborator

@Mytherin Mytherin left a comment

Choose a reason for hiding this comment

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

Thanks for the PR! After reading the discussion on #6775 I prefer the ERROR option for three reasons, (1) the ability for the user to specify an error message, (2) compatibility with BigQuery, (3) simplicity and clarity in what the function accomplishes. It is rather unusual for assert to return its input value, and it took me a while to parse what was actually happening here. I think the ERROR function is a cleaner solution that would be more understandable to users.

Apologies for not realizing the discussion happening there earlier.

@Tishj
Copy link
Contributor

Tishj commented Apr 7, 2023

Ah my bad for suggesting it then.

Though I think the reasoning was that if the result is unused, it could get optimized out.

That is what inspired the value.assert(x -> x != 0) idea

Assertions don't normally return anything, and since they throw, I also wouldn't expect the return value to be a boolean.
Returning its input when succesful sounded somewhat logical to me

@Mytherin
Copy link
Collaborator

Mytherin commented Apr 7, 2023

In the BigQuery example they avoid the optimizer by either using the function in the WHERE clause with an IF condition, or by using it in a CASE statement. I think that is fine as a work-around - it just seems more readable to me.

value.assert(x -> x != 0)

The issue with this syntax is that it is very geared towards this one case (checking for 0 on a single variable) - it would not work in general if you have more complex conditions you want to check. I also think the ERROR function has potential other purposes as a debug function because it can be used to e.g. test correct error handling in clients.

@ozdemircs ozdemircs changed the title Fixes #6775 Invariants scalar function Fixes #6775 Error scalar function Apr 7, 2023
@ozdemircs
Copy link
Author

Thanks for the review @Mytherin, I updated the description of the current PR and code in the same branch, if you need me, to close this PR and send a new one please let me know.

I overall agree with the concerns. I think, we made the problem a bit complicated.

@Tishj thanks for the help and thinking together in the discussion, no worries, the purpose was to get familiar with the code, and the assert was a good start.

@Mytherin Mytherin merged commit 810d2d8 into duckdb:master Apr 9, 2023
@Mytherin
Copy link
Collaborator

Mytherin commented Apr 9, 2023

Thanks for the fixes! LGTM

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.

3 participants