Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion ibis/backends/polars/compiler.py
Original file line number Diff line number Diff line change
Expand Up @@ -1395,7 +1395,7 @@ def execute_sql_string_view(op, *, ctx: pl.SQLContext, **kw):

@translate.register(ops.View)
def execute_view(op, *, ctx: pl.SQLContext, **kw):
child = translate(op.child, ctx=ctx, **kw)
child = translate(op.parent, ctx=ctx, **kw)
ctx.register(op.name, child)
return child

Expand Down
16 changes: 8 additions & 8 deletions ibis/backends/sql/compilers/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -1545,19 +1545,19 @@ def visit_Limit(self, op, *, parent, n, offset):
def visit_CTE(self, op, *, parent):
return sg.table(parent.alias_or_name, quoted=self.quoted)

def visit_View(self, op, *, child, name: str):
if isinstance(child, sge.Table):
child = sg.select(STAR, copy=False).from_(child, copy=False)
def visit_View(self, op, *, parent, name: str):
if isinstance(parent, sge.Table):
parent = sg.select(STAR, copy=False).from_(parent, copy=False)
else:
child = child.copy()
parent = parent.copy()

if isinstance(child, sge.Subquery):
return child.as_(name, quoted=self.quoted)
if isinstance(parent, sge.Subquery):
return parent.as_(name, quoted=self.quoted)
else:
try:
return child.subquery(name, copy=False)
return parent.subquery(name, copy=False)
except AttributeError:
return child.as_(name, quoted=self.quoted)
return parent.as_(name, quoted=self.quoted)

def visit_SQLStringView(self, op, *, query: str, child, schema):
return sg.parse_one(query, read=self.dialect)
Expand Down
5 changes: 2 additions & 3 deletions ibis/expr/operations/relations.py
Original file line number Diff line number Diff line change
Expand Up @@ -438,12 +438,11 @@ class SQLQueryResult(Relation):
class View(PhysicalTable):
"""A view created from an expression."""

# TODO(kszucs): rename it to parent
child: Relation
parent: Relation

@attribute
def schema(self):
return self.child.schema
return self.parent.schema


@public
Expand Down
4 changes: 2 additions & 2 deletions ibis/expr/types/relations.py
Original file line number Diff line number Diff line change
Expand Up @@ -3930,7 +3930,7 @@ def alias(self, alias: str, /) -> ir.Table:
│ Adelie │ Torgersen │ 36.7 │ 19.3 │ 193 │ … │
└─────────┴───────────┴────────────────┴───────────────┴───────────────────┴───┘
"""
return ops.View(child=self, name=alias).to_expr()
return ops.View(parent=self, name=alias).to_expr()

def sql(self, query: str, /, *, dialect: str | None = None) -> ir.Table:
'''Run a SQL query against a table expression.
Expand Down Expand Up @@ -4026,7 +4026,7 @@ def sql(self, query: str, /, *, dialect: str | None = None) -> ir.Table:

if isinstance(op, ops.View):
name = op.name
expr = op.child.to_expr()
expr = op.parent.to_expr()
else:
name = util.gen_name("sql_query")
expr = self
Expand Down
Loading