Fokko commented on code in PR #6590: URL: https://github.com/apache/iceberg/pull/6590#discussion_r1085250404
########## python/pyiceberg/cli/console.py: ########## @@ -365,3 +366,37 @@ def table(ctx: Context, identifier: str, property_name: str) -> None: # noqa: F ctx.exit(1) else: raise NoSuchPropertyException(f"Property {property_name} does not exist on {identifier}") + + +@run.command() +@click.option("--table", "-t", multiple=True) +@click.argument("sql") +@click.pass_context +@catch_exception() +def sql(ctx: Context, table: List[str], sql: str) -> None: + """Lists all the files of the table""" + import duckdb + + from pyiceberg.expressions import parser + + catalog, output = _catalog_and_output(ctx) + + con = duckdb.connect(database=":memory:") + for arg in table: + if "=" in arg: + ident, filter = arg.split("=", maxsplit=1) + else: + ident = arg + filter = None + + t = catalog.load_table(ident) + alias = t.name()[-1] + + scan = t.scan() + if filter: + scan = scan.filter(parser.parse(filter)) + + # register the table with duckdb + scan.to_duckdb(alias, con) Review Comment: Are you able to connect to the session? I believe the session is closed after the parent process exits. A trick I found is opening a database to a specific location, and then taking a copy of the in-memory reference of the table. As an example: ```python scan.to_duckdb(alias + "_tmp", con) con.execute(f"CREATE TABLE {alias} AS SELECT * FROM {alias}_tmp") ``` The view is only on the session level, by taking a copy it gets written to the database file, and it can be read by other processes as well. -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: issues-unsubscr...@iceberg.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org --------------------------------------------------------------------- To unsubscribe, e-mail: issues-unsubscr...@iceberg.apache.org For additional commands, e-mail: issues-h...@iceberg.apache.org