You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
frompathlibimportPathimportpytestfromtypingimportGenerator, List, Optionalfromchdbimportdbapifromchdb.dbapi.cursorsimportCursordefchdb_dbapi(dump_paths: List[Path], path: Optional[Path] =None) ->Generator[Cursor, None, None]:
""" Create a clickhouse dbapi cursor in memory using chdb. Note that this method can take multiple paths depending on what is planned to be tested. Args: dump_paths (List[Path]): The list of path for the dumps to load at each fixture Yields: Generator[Cursor, None, None]: The cursor """string_path=str(path) ifpathelseNoneifpathandpath.exists(): # A path is given and a session existswithdbapi.connect(path=string_path) ascursor:
yieldcursorelse: # Fallbackwithdbapi.connect(path=string_path) ascursor:
fordump_pathindump_paths:
sql_content=dump_path.read_text()
cursor.execute(sql_content)
yieldcursor@pytest.fixture(scope="session")defalembic_dump_path() ->Path:
path=Path.cwd() /"../../dumps/clickhouse_alembic_dump.sql"returnpath.resolve()
@pytest.fixture(scope="session")defclickhouse_chdb_dbapi(alembic_dump_path: Path) ->Generator[Cursor, None, None]:
yieldfromchdb_dbapi([alembic_dump_path])
deftest_clickhouse_session_dbapi(clickhouse_chdb_dbapi):
clickhouse_chdb_dbapi.execute("SHOW tables IN default;")
result=list(clickhouse_chdb_dbapi.fetchall()[0])
# This should never changeassert"alembic_version"inresult
Here is the content of "../../dumps/clickhouse_alembic_dump.sql" :
When I try to check the structure of the "default" database before loading my .sql file :
defchdb_dbapi(dump_paths: List[Path], path: Optional[Path] =None) ->Generator[Cursor, None, None]:
""" Create a clickhouse dbapi cursor in memory using chdb. Note that this method can take multiple paths depending on what is planned to be tested. Args: dump_paths (List[Path]): The list of path for the dumps to load at each fixture Yields: Generator[Cursor, None, None]: The cursor """string_path=str(path) ifpathelseNoneifpathandpath.exists(): # A path is given and a session existswithdbapi.connect(path=string_path) ascursor:
yieldcursorelse: # Fallbackwithdbapi.connect(path=string_path) ascursor:
fordump_pathindump_paths:
cursor.execute("select database, name from system.tables;")
fordatabase, nameincursor.fetchall():
print(f"{database}.{name}")
sql_content=dump_path.read_text()
cursor.execute(sql_content)
yieldcursor
It gives me this, without a single "default" database existing :
ClickHouse has changed the default database name from local to default. But still the default database is not persistent.
So, the easiest way to fix is just use another db name for your database otherthan default
I'm using :
I'm trying to execute this python :
Here is the content of "../../dumps/clickhouse_alembic_dump.sql" :
When executing my test, it comes with this error :
When I try to check the structure of the "default" database before loading my .sql file :
It gives me this, without a single "default" database existing :
NB: This code worked in chdb 1.4.1, and when upgrading it, it explodes. Is it a regression ? Is it a bug ?
The text was updated successfully, but these errors were encountered: