diff --git a/ibis/backends/polars/compiler.py b/ibis/backends/polars/compiler.py index 8734c86674e4..a67b7df34773 100644 --- a/ibis/backends/polars/compiler.py +++ b/ibis/backends/polars/compiler.py @@ -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 diff --git a/ibis/backends/sql/compilers/base.py b/ibis/backends/sql/compilers/base.py index 521c22a7b6de..e3894c7f1e63 100644 --- a/ibis/backends/sql/compilers/base.py +++ b/ibis/backends/sql/compilers/base.py @@ -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) diff --git a/ibis/expr/operations/relations.py b/ibis/expr/operations/relations.py index 90dc400a8ded..b8d5ff8a5973 100644 --- a/ibis/expr/operations/relations.py +++ b/ibis/expr/operations/relations.py @@ -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 diff --git a/ibis/expr/types/relations.py b/ibis/expr/types/relations.py index c1164e672fee..1c69325cdaa6 100644 --- a/ibis/expr/types/relations.py +++ b/ibis/expr/types/relations.py @@ -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. @@ -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