-
-
Notifications
You must be signed in to change notification settings - Fork 20
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
Narrow types via join / join-condition #531
Conversation
@gharlan could you do me a favour and verify the expected types? |
assertType('PDOStatement<array{adaid: int<-32768, 32767>, 0: int<-32768, 32767>, akid: int<-2147483648, 2147483647>, 1: int<-2147483648, 2147483647>}>', $stmt); | ||
|
||
$stmt = $pdo->query('SELECT adaid, akid from ada left join ak on (adaid = eladaid)'); | ||
assertType('PDOStatement<array{adaid: int<-32768, 32767>, 0: int<-32768, 32767>, akid: int<-2147483648, 2147483647>|null, 1: int<-2147483648, 2147483647>|null}>', $stmt); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
rows not matched in the main result, will be filled up with null, therefore even a non-nullable column can get null on outer joins
$stmt = $pdo->query('SELECT adaid, eladaid from ada join ak on (adaid = eladaid)'); | ||
assertType('PDOStatement<array{adaid: int<-32768, 32767>, 0: int<-32768, 32767>, eladaid: int<-2147483648, 2147483647>, 1: int<-2147483648, 2147483647>}>', $stmt); | ||
|
||
$stmt = $pdo->query('SELECT adaid, eladaid from ada inner join ak on (adaid = eladaid)'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
on inner join, nullable columns get non nullable
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think these expectations are correct 👍
b15c06c
to
2cab3d4
Compare
/** | ||
* @api | ||
*/ | ||
final class Join |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
not sure it makes sense to model joins here. maybe we should instead use SqlFtw\Sql\Dml\TableReference\Join
instead, as we need the low level information
src/SqlAst/QueryScope.php
Outdated
if ($join->getType() === Join::TYPE_OUTER) { | ||
return TypeCombinator::addNull($column->getType()); | ||
} | ||
return TypeCombinator::removeNull($column->getType()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we should only add/remove NULLs for columns which are part of the join condition, but not regular columns selected from joined tables - without beeing part of the join condition.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
closes #527