-
Notifications
You must be signed in to change notification settings - Fork 609
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor(ir): accept any relation in
ops.ExistsSubquery
(#8264)
- Loading branch information
Showing
20 changed files
with
98 additions
and
74 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,7 +6,7 @@ FROM "foo_t" AS "t0" | |
WHERE | ||
EXISTS( | ||
SELECT | ||
CAST(1 AS TINYINT) AS "1" | ||
1 | ||
FROM "bar_t" AS "t1" | ||
WHERE | ||
( | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -20,7 +20,7 @@ FROM ( | |
WHERE | ||
EXISTS( | ||
SELECT | ||
CAST(1 AS TINYINT) AS "1" | ||
1 | ||
FROM "lineitem" AS "t1" | ||
WHERE | ||
( | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -32,7 +32,7 @@ FROM ( | |
WHERE | ||
EXISTS( | ||
SELECT | ||
1 AS "1" | ||
1 | ||
FROM "hive"."ibis_sf1"."lineitem" AS "t1" | ||
WHERE | ||
( | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
from __future__ import annotations | ||
|
||
from public import public | ||
|
||
import ibis.expr.datashape as ds | ||
import ibis.expr.datatypes as dt | ||
import ibis.expr.rules as rlz | ||
from ibis.common.annotations import attribute | ||
from ibis.common.exceptions import IntegrityError | ||
from ibis.expr.operations.core import Value | ||
from ibis.expr.operations.relations import Relation # noqa: TCH001 | ||
|
||
|
||
@public | ||
class Subquery(Value): | ||
rel: Relation | ||
|
||
@attribute | ||
def relations(self): | ||
return frozenset() | ||
|
||
|
||
@public | ||
class ExistsSubquery(Subquery): | ||
dtype = dt.boolean | ||
shape = ds.columnar | ||
|
||
|
||
@public | ||
class ScalarSubquery(Subquery): | ||
shape = ds.scalar | ||
|
||
def __init__(self, rel): | ||
if len(rel.schema) != 1: | ||
raise IntegrityError( | ||
"Relation passed to ScalarSubquery() must have exactly one " | ||
f"column, got {len(rel.schema)}" | ||
) | ||
super().__init__(rel=rel) | ||
|
||
@attribute | ||
def value(self): | ||
(value,) = self.rel.values.values() | ||
return value | ||
|
||
@attribute | ||
def dtype(self): | ||
return self.value.dtype | ||
|
||
|
||
@public | ||
class InSubquery(Subquery): | ||
needle: Value | ||
|
||
dtype = dt.boolean | ||
shape = ds.columnar | ||
|
||
def __init__(self, rel, needle): | ||
if len(rel.schema) != 1: | ||
raise IntegrityError( | ||
"Relation passed to InSubquery() must have exactly one " | ||
f"column, got {len(rel.schema)}" | ||
) | ||
(value,) = rel.values.values() | ||
if not rlz.comparable(value, needle): | ||
raise IntegrityError(f"{needle!r} is not comparable to {value!r}") | ||
super().__init__(rel=rel, needle=needle) | ||
|
||
@attribute | ||
def value(self): | ||
(value,) = self.rel.values.values() | ||
return value | ||
|
||
@attribute | ||
def relations(self): | ||
return self.needle.relations |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters