Skip to content

Commit

Permalink
refactor(ops): use catalog and database kwargs for Namespace op
Browse files Browse the repository at this point in the history
This is an internals only change, but changes `database` to `catalog`
and changes `schema` to `database` for our internal `Namespace` op.
  • Loading branch information
gforsyth committed Mar 25, 2024
1 parent dfb8734 commit 21f57d4
Show file tree
Hide file tree
Showing 9 changed files with 11 additions and 11 deletions.
2 changes: 1 addition & 1 deletion ibis/backends/bigquery/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -558,7 +558,7 @@ def table(
table.name,
schema=schema_from_bigquery_table(bq_table),
source=self,
namespace=ops.Namespace(schema=dataset, database=project),
namespace=ops.Namespace(database=dataset, catalog=project),
)
table_expr = node.to_expr()
return rename_partitioned_column(table_expr, bq_table, self.partition_column)
Expand Down
2 changes: 1 addition & 1 deletion ibis/backends/duckdb/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -289,7 +289,7 @@ def table(
name,
schema=table_schema,
source=self,
namespace=ops.Namespace(database=catalog, schema=database),
namespace=ops.Namespace(catalog=catalog, database=database),
).to_expr()

def get_schema(
Expand Down
2 changes: 1 addition & 1 deletion ibis/backends/flink/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -254,7 +254,7 @@ def table(
name,
schema=schema,
source=self,
namespace=ops.Namespace(schema=catalog, database=database),
namespace=ops.Namespace(catalog=catalog, database=database),
)
return node.to_expr()

Expand Down
2 changes: 1 addition & 1 deletion ibis/backends/sql/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ def table(
name,
schema=table_schema,
source=self,
namespace=ops.Namespace(database=database, schema=schema),
namespace=ops.Namespace(catalog=catalog, database=database),
).to_expr()

def _to_sqlglot(
Expand Down
6 changes: 3 additions & 3 deletions ibis/backends/sql/compiler.py
Original file line number Diff line number Diff line change
Expand Up @@ -1061,7 +1061,7 @@ def __sql_name__(self, op: ops.ScalarUDF | ops.AggUDF) -> str:
# not actually a table, but easier to quote individual namespace
# components this way
namespace = op.__udf_namespace__
return sg.table(funcname, db=namespace.schema, catalog=namespace.database).sql(
return sg.table(funcname, db=namespace.database, catalog=namespace.catalog).sql(
self.dialect
)

Expand Down Expand Up @@ -1140,7 +1140,7 @@ def visit_UnboundTable(
self, op, *, name: str, schema: sch.Schema, namespace: ops.Namespace
) -> sg.Table:
return sg.table(
name, db=namespace.schema, catalog=namespace.database, quoted=self.quoted
name, db=namespace.database, catalog=namespace.catalog, quoted=self.quoted
)

def visit_InMemoryTable(
Expand All @@ -1158,7 +1158,7 @@ def visit_DatabaseTable(
namespace: ops.Namespace,
) -> sg.Table:
return sg.table(
name, db=namespace.schema, catalog=namespace.database, quoted=self.quoted
name, db=namespace.database, catalog=namespace.catalog, quoted=self.quoted
)

def visit_SelfReference(self, op, *, parent, identifier):
Expand Down
2 changes: 1 addition & 1 deletion ibis/expr/operations/relations.py
Original file line number Diff line number Diff line change
Expand Up @@ -314,7 +314,7 @@ class PhysicalTable(Relation):
@public
class Namespace(Concrete):
database: Optional[str] = None
schema: Optional[str] = None
catalog: Optional[str] = None


@public
Expand Down
2 changes: 1 addition & 1 deletion ibis/expr/operations/udf.py
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ def _make_node(
# method
"__func__": property(fget=lambda _, fn=fn: fn),
"__config__": FrozenDict(kwargs),
"__udf_namespace__": ops.Namespace(schema=schema, database=database),
"__udf_namespace__": ops.Namespace(database=schema, catalog=database),
"__module__": fn.__module__,
"__func_name__": func_name,
}
Expand Down
2 changes: 1 addition & 1 deletion ibis/expr/types/relations.py
Original file line number Diff line number Diff line change
Expand Up @@ -256,7 +256,7 @@ def get_name(self) -> str:
"""Return the fully qualified name of the table."""
arg = self._arg
namespace = getattr(arg, "namespace", ops.Namespace())
pieces = namespace.database, namespace.schema, arg.name
pieces = namespace.catalog, namespace.database, arg.name
return ".".join(filter(None, pieces))

def __array__(self, dtype=None):
Expand Down
2 changes: 1 addition & 1 deletion ibis/tests/expr/test_table.py
Original file line number Diff line number Diff line change
Expand Up @@ -2065,7 +2065,7 @@ def test_invalid_distinct_empty_key():

def test_unbind_with_namespace():
schema = ibis.schema({"a": "int"})
ns = ops.Namespace(database="db", schema="sch")
ns = ops.Namespace(catalog="catalog", database="database")

t_op = ops.DatabaseTable(name="t", schema=schema, source=None, namespace=ns)
t = t_op.to_expr()
Expand Down

0 comments on commit 21f57d4

Please sign in to comment.