Skip to content

Commit 8bf03f6

Browse files
committed
feat(server): support duckb's CREATE SECRET
1 parent 08412e3 commit 8bf03f6

File tree

2 files changed

+23
-0
lines changed

2 files changed

+23
-0
lines changed

fakesnow/cursor.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@
4343
SQL_SUCCESS = "SELECT 'Statement executed successfully.' as 'status'"
4444
SQL_CREATED_DATABASE = Template("SELECT 'Database ${name} successfully created.' as 'status'")
4545
SQL_CREATED_SCHEMA = Template("SELECT 'Schema ${name} successfully created.' as 'status'")
46+
SQL_CREATED_SECRET = Template("SELECT 'Secret ${name} successfully created.' as 'status'")
4647
SQL_CREATED_TABLE = Template("SELECT 'Table ${name} successfully created.' as 'status'")
4748
SQL_CREATED_VIEW = Template("SELECT 'View ${name} successfully created.' as 'status'")
4849
SQL_CREATED_STAGE = Template("SELECT 'Stage area ${name} successfully created.' as status")
@@ -410,6 +411,15 @@ def _execute(self, transformed: exp.Expression, params: MutableParams | None = N
410411

411412
elif cmd == "DROP SCHEMA" and ident == self._conn.schema:
412413
self._conn._schema = None # noqa: SLF001
414+
elif (
415+
cmd == "CREATE"
416+
and isinstance(transformed, exp.Command)
417+
and isinstance(transformed.expression, str)
418+
and transformed.expression.upper().startswith(" SECRET")
419+
):
420+
match = re.search(r"SECRET\s+(\w+)\s*\(", transformed.expression, re.IGNORECASE)
421+
secret_name = match[1].upper() if match else "UNKNOWN"
422+
result_sql = SQL_CREATED_SECRET.substitute(name=secret_name)
413423

414424
if table_comment := cast(tuple[exp.Table, str], transformed.args.get("table_comment")):
415425
# record table comment

tests/test_copy_into.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -304,6 +304,19 @@ def test_copy_no_files(dcur: snowflake.connector.cursor.DictCursor, s3_client: S
304304
assert dcur.fetchall() == [{"status": "Copy executed with 0 files processed."}]
305305

306306

307+
def test_description_create_secret(dcur: snowflake.connector.cursor.DictCursor):
308+
# NB: this is NOT a Snowflake object, it's a DuckDB secret, and will fail on Snowflake
309+
# but we want to ensure that the description works so that CREATE SECRET works from the server
310+
dcur.execute("""
311+
CREATE SECRET my_secret (
312+
TYPE s3,
313+
KEY_ID 'my_secret_key',
314+
SECRET 'my_secret_value'
315+
)""")
316+
assert dcur.fetchall() == [{"status": "Secret MY_SECRET successfully created."}]
317+
assert dcur.description
318+
319+
307320
def test_errors(dcur: snowflake.connector.cursor.DictCursor, s3_client: S3Client) -> None:
308321
create_table(dcur)
309322

0 commit comments

Comments
 (0)