Skip to content

Remove the associated type from SelectableExpression #774

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 1 commit into from
Mar 5, 2017

Conversation

sgrif
Copy link
Member

@sgrif sgrif commented Mar 4, 2017

This removes the flawed "SQL type varies based on the query source"
design in favor of "things become nullable if they're on the wrong side
of an outer join". This means that columns from the right side of a left
join can no longer directly be selected. .nullable must be manually
called. This sounds like a huge deal, but that's already the case today
with tuples (which is a more common case), and it hasn't caused a huge
ergonomics issue. Ultimately most queries just use the default select
clause.

This also causes the nullability to bubble up. If you're building a
compound expression that involves a column from the right side of a left
join, you don't have to worry about that in the compound expression. You
just have to make the whole thing nullable at the top level. This
mirrors SQL's semantics quite nicely.

One downside of this is that .nullable can no longer be used in
arbitrary select clauses. Doing so is questionably useful at best, but
I'd still like to bring back that support in the future. Ultimately
doing so more requires rust-lang/rust#40097 or
similar.

@sgrif sgrif requested a review from killercup March 4, 2017 12:05
sgrif added a commit that referenced this pull request Mar 4, 2017
I spotted this while working on #774. This method is not part of the
public API, and is useless now that `sql` exists. I've skipped adding a
changelog entry since this doesn't affect public API.
@sgrif sgrif mentioned this pull request Mar 4, 2017
This removes the flawed "SQL type varies based on the query source"
design in favor of "things become nullable if they're on the wrong side
of an outer join". This means that columns from the right side of a left
join can no longer directly be selected. `.nullable` must be manually
called. This sounds like a huge deal, but that's already the case today
with tuples (which is a more common case), and it hasn't caused a huge
ergonomics issue. Ultimately most queries just use the default select
clause.

This also causes the nullability to bubble up. If you're building a
compound expression that involves a column from the right side of a left
join, you don't have to worry about that in the compound expression. You
just have to make the whole thing nullable at the top level. This
mirrors SQL's semantics quite nicely.

One downside of this is that `.nullable` can no longer be used in
arbitrary select clauses. Doing so is questionably useful at best, but
I'd still like to bring back that support in the future. Ultimately
doing so more requires rust-lang/rust#40097 or
similar.
@sgrif sgrif force-pushed the sg-rm-selectable-expression-type branch from fdefafa to 6a8deb2 Compare March 4, 2017 13:26
Copy link
Member

@killercup killercup left a comment

Choose a reason for hiding this comment

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

Looks good to me.

Not sure about the possible errors user see, though. How would they discover they need to call .nullable on (some item in the) select param? I'd probably add a note to left_outer_join, as this is a place I'd look for an explanation.

/// type is usually the same as `Expression::SqlType`, but is used to indicate
/// that a column is always nullable when it appears on the right side of a left
/// outer join, even if it wasn't nullable to begin with.
/// Indicates that an expression can be selected from a source. Columns will
Copy link
Member

Choose a reason for hiding this comment

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

Would begin a new paragraph after the first sentence

/// outer join, even if it wasn't nullable to begin with.
/// Indicates that an expression can be selected from a source. Columns will
/// implement this for their table. Certain special types, like `CountStar` and
/// `Bound` will implement this for all sources. Most compound expressions will
Copy link
Member

Choose a reason for hiding this comment

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

comma after Bound

@sgrif sgrif merged commit 86b0664 into master Mar 5, 2017
@sgrif sgrif deleted the sg-rm-selectable-expression-type branch March 5, 2017 18:22
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