Skip to content

Commit

Permalink
feat(flink): add from_connection API for backend
Browse files Browse the repository at this point in the history
  • Loading branch information
deepyaman committed Jul 18, 2024
1 parent ec11cf4 commit 1733177
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
11 changes: 11 additions & 0 deletions ibis/backends/flink/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,17 @@ def do_connect(self, table_env: TableEnvironment) -> None:
"""
self._table_env = table_env

@classmethod
def from_connection(cls, table_env: TableEnvironment) -> None:
"""Create a Flink `Backend` from an existing table environment.
Parameters
----------
table_env
A table environment.
"""
return ibis.flink.connect(table_env)

def disconnect(self) -> None:
pass

Expand Down
6 changes: 5 additions & 1 deletion ibis/backends/tests/test_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -1616,6 +1616,10 @@ def test_insert_using_col_name_not_position(con, first_row, second_row, monkeypa
con.drop_table(table_name)


CON_ATTR = {"flink": "_table_env"}
DEFAULT_CON_ATTR = "con"


def test_from_connection(con):
new_con = type(con).from_connection(con.con)
new_con = type(con).from_connection(getattr(con, CON_ATTR.get(con.name, "con")))
assert {"astronauts", "batting", "diamonds"} <= set(new_con.list_tables())

0 comments on commit 1733177

Please sign in to comment.