-
Notifications
You must be signed in to change notification settings - Fork 216
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
feat: Allow join side to take an ident that resolves to a literal #4499
Conversation
Thanks! Added one quick question, fine to merge now though. A code comment saying what's the intent of the new code + a changelog is great but not strictly necessary. |
🤔
|
Ah yeah, that's like the Python trick of defining FWIW, this PR would interpret that code snippet as a left join rather than a right join. It first tries to use the I'll push a changelog entry and some code comments soon. |
I too think this is odd. Wouldn't we have to make a breaking change to accept text as an argument? |
The original behavior (treating the provided ident as a bare string) would still be the default, so I don't think this would be a breaking change... this only adds functionality in the fallback case where the ident provided to There are probably a few other options to consider in order to make the join side parametrizable, but I went this route because the implementation was the simplest and had the least overall impact. |
Yes, I understand your intention (Great work!). However, given that we are currently rethinking our type system (includes table and column name resolution), I am wondering if this change makes sense. |
Thanks -- yeah, I really appreciate the work around the type system, I've already found it useful for certain things and am looking forward to future improvements. I'm hoping this change is mostly outside those bounds, though, because it's really just about finding a way to pass a parameter to the Since idents can reference just about anything in the PRQL context, I tried to double-check that you wouldn't get strange behavior if a user passes an ident that resolves to something odd. For example, if you try to pass a table column name to the |
Agree with @vanillajonathan & @eitsupi on reflection; it is less simple to allow both strings and bare words here. Should we switch to a string param for normal uses too; so it's That seems a bit less aesthetic. But it's unclear what type it is now. Possibly it's enum type, like If we go with the enum type, we could allow (If getting there is really hard, I would be +0.1 on merging this with an experimental label to unblock @kgutwin and then resolving later) |
I agree that moving towards an enum strategy makes a lot of sense. That said, I really like the ergonomics of Are you thinking we should use something like the named unions that are defined in #4038? That would be a good starting point, but it seems like there's a lot of implementation left to do, for example to handle dereferencing individual elements of the union. I can't tell yet whether getting that done would be "really hard" but I suspect it'll be outside my scope in the near term... If we can agree on what the UX and structure for this feature ought to be long-term, could we consider merging this PR for the time being, so that I can close out the feature request on my project? I'm happy to help out with the proper implementation once it's clear. |
Yes it would still be written as I think that's fine for merging this version (unless others really disagree?). Could we add a short note to the code referencing this discussion and saying it's experimental / subject to change? |
That sounds good to me, I'll put in a quick comment shortly. I'll also open an issue to continue the discussion on how function could take (and validate) named unions as parameters. As an aside, for transparency, I found a workaround in my project that means this feature is no longer necessary for me in the short term. We have some other tasks to do later that would be helped by this, so a merge would still be good, but I understand if it's best to set this aside for a more complete implementation. |
Great — I can't seem to edit the PR (I think this might be a setting on your end?), but if we can accept that change and run |
Co-authored-by: Maximilian Roos <5635139+max-sixty@users.noreply.github.com>
This PR makes a small addition to the
join
transform, allowing theside:
parameter to take an Ident that resolves immediately to a string literal.Example:
compiles as you would expect to
Why this change? I am working on a set of "library" functions for my project, and one of them is a simple "map" transform that takes in a relation as a lookup table and outputs a new column. The basic code for this function is:
Which works great -- but it isn't configurable as to the join type, which means users of this library function only get one hard-coded option. What I want is to expose the join side as a function parameter... with this PR, it now looks like this:
Note the use of
join side:_param.side
to pass the side value in via parameter.Feedback is welcome - thanks!