@@ -617,6 +617,52 @@ def to_json(
617
617
)
618
618
619
619
620
+ class HasCurrentCatalog (abc .ABC ):
621
+ @property
622
+ @abc .abstractmethod
623
+ def current_catalog (self ) -> str :
624
+ """The name of the current catalog in the backend.
625
+
626
+ A collection of `table` is referred to as a `database`.
627
+ A collection of `database` is referred to as a `catalog`.
628
+
629
+ These terms are mapped onto the corresponding features in each
630
+ backend (where available), regardless of the terminology the backend uses.
631
+
632
+ See the
633
+ [Table Hierarchy Concepts Guide](/concepts/backend-table-hierarchy.qmd)
634
+ for more info.
635
+
636
+ Returns
637
+ -------
638
+ str
639
+ The name of the current catalog.
640
+ """
641
+
642
+
643
+ class HasCurrentDatabase (abc .ABC ):
644
+ @property
645
+ @abc .abstractmethod
646
+ def current_database (self ) -> str :
647
+ """The name of the current database in the backend.
648
+
649
+ A collection of `table` is referred to as a `database`.
650
+ A collection of `database` is referred to as a `catalog`.
651
+
652
+ These terms are mapped onto the corresponding features in each
653
+ backend (where available), regardless of the terminology the backend uses.
654
+
655
+ See the
656
+ [Table Hierarchy Concepts Guide](/concepts/backend-table-hierarchy.qmd)
657
+ for more info.
658
+
659
+ Returns
660
+ -------
661
+ str
662
+ The name of the current database.
663
+ """
664
+
665
+
620
666
class CanListCatalog (abc .ABC ):
621
667
@abc .abstractmethod
622
668
def list_catalogs (self , * , like : str | None = None ) -> list [str ]:
@@ -629,15 +675,17 @@ def list_catalogs(self, *, like: str | None = None) -> list[str]:
629
675
A collection of `database` is referred to as a `catalog`.
630
676
631
677
These terms are mapped onto the corresponding features in each
632
- backend (where available), regardless of whether the backend itself
633
- uses the same terminology.
678
+ backend (where available), regardless of the terminology the backend uses.
679
+
680
+ See the
681
+ [Table Hierarchy Concepts Guide](/concepts/backend-table-hierarchy.qmd)
682
+ for more info.
634
683
:::
635
684
636
685
Parameters
637
686
----------
638
687
like
639
- A pattern in Python's regex format to filter returned database
640
- names.
688
+ A pattern in Python's regex format to filter returned catalog names.
641
689
642
690
Returns
643
691
-------
@@ -659,8 +707,11 @@ def create_catalog(self, name: str, /, *, force: bool = False) -> None:
659
707
A collection of `database` is referred to as a `catalog`.
660
708
661
709
These terms are mapped onto the corresponding features in each
662
- backend (where available), regardless of whether the backend itself
663
- uses the same terminology.
710
+ backend (where available), regardless of the terminology the backend uses.
711
+
712
+ See the
713
+ [Table Hierarchy Concepts Guide](/concepts/backend-table-hierarchy.qmd)
714
+ for more info.
664
715
:::
665
716
666
717
Parameters
@@ -682,8 +733,11 @@ def drop_catalog(self, name: str, /, *, force: bool = False) -> None:
682
733
A collection of `database` is referred to as a `catalog`.
683
734
684
735
These terms are mapped onto the corresponding features in each
685
- backend (where available), regardless of whether the backend itself
686
- uses the same terminology.
736
+ backend (where available), regardless of the terminology the backend uses.
737
+
738
+ See the
739
+ [Table Hierarchy Concepts Guide](/concepts/backend-table-hierarchy.qmd)
740
+ for more info.
687
741
:::
688
742
689
743
Parameters
@@ -709,8 +763,11 @@ def list_databases(
709
763
A collection of `database` is referred to as a `catalog`.
710
764
711
765
These terms are mapped onto the corresponding features in each
712
- backend (where available), regardless of whether the backend itself
713
- uses the same terminology.
766
+ backend (where available), regardless of the terminology the backend uses.
767
+
768
+ See the
769
+ [Table Hierarchy Concepts Guide](/concepts/backend-table-hierarchy.qmd)
770
+ for more info.
714
771
:::
715
772
716
773
Parameters
@@ -737,6 +794,20 @@ def create_database(
737
794
) -> None :
738
795
"""Create a database named `name` in `catalog`.
739
796
797
+ ::: {.callout-note}
798
+ ## Ibis does not use the word `schema` to refer to database hierarchy.
799
+
800
+ A collection of `table` is referred to as a `database`.
801
+ A collection of `database` is referred to as a `catalog`.
802
+
803
+ These terms are mapped onto the corresponding features in each
804
+ backend (where available), regardless of the terminology the backend uses.
805
+
806
+ See the
807
+ [Table Hierarchy Concepts Guide](/concepts/backend-table-hierarchy.qmd)
808
+ for more info.
809
+ :::
810
+
740
811
Parameters
741
812
----------
742
813
name
@@ -755,13 +826,27 @@ def drop_database(
755
826
) -> None :
756
827
"""Drop the database with `name` in `catalog`.
757
828
829
+ ::: {.callout-note}
830
+ ## Ibis does not use the word `schema` to refer to database hierarchy.
831
+
832
+ A collection of `table` is referred to as a `database`.
833
+ A collection of `database` is referred to as a `catalog`.
834
+
835
+ These terms are mapped onto the corresponding features in each
836
+ backend (where available), regardless of the terminology the backend uses.
837
+
838
+ See the
839
+ [Table Hierarchy Concepts Guide](/concepts/backend-table-hierarchy.qmd)
840
+ for more info.
841
+ :::
842
+
758
843
Parameters
759
844
----------
760
845
name
761
846
Name of the schema to drop.
762
847
catalog
763
- Name of the catalog to drop the database from. If `None`, the
764
- current catalog is used.
848
+ Name of the catalog to drop the database from.
849
+ If `None`, the current catalog is used.
765
850
force
766
851
If `False`, an exception is raised if the database does not exist.
767
852
@@ -981,73 +1066,105 @@ def _filter_with_like(values: Iterable[str], like: str | None = None) -> list[st
981
1066
def list_tables (
982
1067
self , * , like : str | None = None , database : tuple [str , str ] | str | None = None
983
1068
) -> list [str ]:
984
- """Return the list of table names in the current database.
1069
+ """The table names that match `like` in the given ` database` .
985
1070
986
1071
For some backends, the tables may be files in a directory,
987
1072
or other equivalent entities in a SQL database.
988
1073
989
- ::: {.callout-note}
990
- ## Ibis does not use the word `schema` to refer to database hierarchy.
991
-
992
- A collection of tables is referred to as a `database`.
993
- A collection of `database` is referred to as a `catalog`.
994
-
995
- These terms are mapped onto the corresponding features in each
996
- backend (where available), regardless of whether the backend itself
997
- uses the same terminology.
998
- :::
999
-
1000
1074
Parameters
1001
1075
----------
1002
1076
like
1003
1077
A pattern in Python's regex format.
1004
1078
database
1005
- The database from which to list tables.
1006
- If not provided, the current database is used.
1079
+ The database, or (catalog, database) from which to list tables.
1080
+
1081
+ For backends that support a single-level table hierarchy,
1082
+ you can pass in a string like `"bar"`.
1007
1083
For backends that support multi-level table hierarchies, you can
1008
1084
pass in a dotted string path like `"catalog.database"` or a tuple of
1009
1085
strings like `("catalog", "database")`.
1086
+ If not provided, the current database
1087
+ (and catalog, if applicable for this backend) is used.
1088
+
1089
+ See the
1090
+ [Table Hierarchy Concepts Guide](/concepts/backend-table-hierarchy.qmd)
1091
+ for more info.
1010
1092
1011
1093
Returns
1012
1094
-------
1013
1095
list[str]
1014
1096
The list of the table names that match the pattern `like`.
1015
1097
1098
+ Examples
1099
+ --------
1100
+ >>> import ibis
1101
+ >>> con = ibis.duckdb.connect()
1102
+ >>> foo = con.create_table("foo", schema=ibis.schema(dict(a="int")))
1103
+ >>> con.list_tables()
1104
+ ['foo']
1105
+ >>> bar = con.create_view("bar", foo)
1106
+ >>> con.list_tables()
1107
+ ['bar', 'foo']
1108
+ >>> con.create_database("my_database")
1109
+ >>> con.list_tables(database="my_database")
1110
+ []
1111
+ >>> con.raw_sql("CREATE TABLE my_database.baz (a INTEGER)") # doctest: +ELLIPSIS
1112
+ <duckdb.duckdb.DuckDBPyConnection object at 0x...>
1113
+ >>> con.list_tables(database="my_database")
1114
+ ['baz']
1016
1115
"""
1017
1116
1018
1117
@abc .abstractmethod
1019
1118
def table (
1020
1119
self , name : str , / , * , database : tuple [str , str ] | str | None = None
1021
1120
) -> ir .Table :
1022
- """Construct a table expression.
1023
-
1024
- ::: {.callout-note}
1025
- ## Ibis does not use the word `schema` to refer to database hierarchy.
1026
-
1027
- A collection of tables is referred to as a `database`.
1028
- A collection of `database` is referred to as a `catalog`.
1029
-
1030
- These terms are mapped onto the corresponding features in each
1031
- backend (where available), regardless of whether the backend itself
1032
- uses the same terminology.
1033
- :::
1121
+ """Construct a table expression from the corresponding table in the backend.
1034
1122
1035
1123
Parameters
1036
1124
----------
1037
1125
name
1038
1126
Table name
1039
1127
database
1040
- Database name
1041
- If not provided, the current database is used.
1128
+ The database, or (catalog, database) from which to get the table.
1129
+
1130
+ For backends that support a single-level table hierarchy,
1131
+ you can pass in a string like `"bar"`.
1042
1132
For backends that support multi-level table hierarchies, you can
1043
1133
pass in a dotted string path like `"catalog.database"` or a tuple of
1044
1134
strings like `("catalog", "database")`.
1135
+ If not provided, the current database
1136
+ (and catalog, if applicable for this backend) is used.
1137
+
1138
+ See the
1139
+ [Table Hierarchy Concepts Guide](/concepts/backend-table-hierarchy.qmd)
1140
+ for more info.
1045
1141
1046
1142
Returns
1047
1143
-------
1048
1144
Table
1049
1145
Table expression
1050
1146
1147
+ Examples
1148
+ --------
1149
+ >>> import ibis
1150
+ >>> backend = ibis.duckdb.connect()
1151
+
1152
+ Get the "foo" table from the current database
1153
+ (and catalog, if applicable for this backend):
1154
+
1155
+ >>> backend.table("foo") # doctest: +SKIP
1156
+
1157
+ Get the "foo" table from the "bar" database
1158
+ (in DuckDB's language they would say the "bar" schema,
1159
+ in SQL this would be `"bar"."foo"`)
1160
+
1161
+ >>> backend.table("foo", database="bar") # doctest: +SKIP
1162
+
1163
+ Get the "foo" table from the "bar" database, within the "baz" catalog
1164
+ (in DuckDB's language they would say the "bar" schema, and "baz" database,
1165
+ in SQL this would be `"baz"."bar"."foo"`)
1166
+
1167
+ >>> backend.table("foo", database=("baz", "bar")) # doctest: +SKIP
1051
1168
"""
1052
1169
1053
1170
@property
0 commit comments