Snowflake implementation reference
This page describes how the Snowflake wire is built: the HTTP listener, the login flow and session tokens, every routed endpoint, how a statement is dispatched, SHOW and stage support, type mapping, error codes, transactions, limits and tests. For the port, the proof scores and how to connect, see the operator page Snowflake. Authentication policy across all wires is in Security.
Code lives in src/protocol/snowflake/:
| File | Role |
|---|---|
mod.rs |
SnowflakeHandler: listener, HTTP parsing, routing, login, v1 and v2 statement endpoints, SHOW, type mapping. |
session.rs |
SfSession and run_statement: per-token sessions, Snowflake statement handling, error mapping. |
dialect.rs |
Snowflake SQL to engine SQL translation. |
stage.rs |
Internal stages, file formats, PUT/GET/LIST/REMOVE, COPY INTO. |
(source: src/protocol/snowflake/, module doc comments)
Listener and HTTP layer
- The default port is 8443 (
snowflake_portinServerConfig::default); a config file that omits the key turns the wire off. (source:src/config.rs,ServerConfig::default) -
SnowflakeHandler::startspawns one task per connection withTCP_NODELAY, insideaudit::in_connection("snowflake"). With a[tls]section every connection goes throughacceptor.acceptfirst: TLS is implicit and there is no plaintext fallback on the same port. (source:src/protocol/snowflake/mod.rs,start,handle_connection) Not verified: no Rust test covers this wire over TLS. - The HTTP/1.1 parser is hand-written (
parse_request). Header names are lowercased. OnlyContent-Lengthbodies are read; chunked transfer encoding is not handled. A newBufReaderis made for each request, so bytes of a pipelined second request read into the old buffer would be lost. (source:src/protocol/snowflake/mod.rs,parse_request) Not verified: no test sends pipelined or chunked requests. - Bodies are limited to 256 MB (
MAX_HTTP_BODY). A body overPREAUTH_BODY_LIMIT(1 MB) is read only after the request's credentials pass.Content-Encoding: gzipbodies are inflated with the same cap. (source:src/protocol/snowflake/mod.rs,MAX_HTTP_BODY,parse_request;src/protocol/buffer_limits.rs,PREAUTH_BODY_LIMIT) - File uploads under
/__sdb_stage/are streamed to storage (stage::http_put) instead of being buffered, and downloads are streamed in 4 MB chunks. (source:src/protocol/snowflake/mod.rs,handle_connection;src/protocol/snowflake/stage.rs,http_put,CHUNK)
Endpoints
route_request handles these; anything else is 404 NOT_FOUND (source: src/protocol/snowflake/mod.rs, route_request):
| Method and path | Auth | Handler |
|---|---|---|
POST /session/v1/login-request |
none | login_request |
GET /healthcheck |
none | health reply |
POST /queries/v1/query-request |
token | v1_query_request |
GET /queries/<id>/result |
token | v1_query_result |
GET /monitoring/queries/<id> |
token | query status |
GET /queries/v1/query-result?requestId= |
token | v1_query_result |
POST /queries/v1/abort-request |
token | v1_abort_request |
POST /telemetry/send |
token | accepted and ignored |
POST /session/heartbeat |
token | keep-alive |
POST /session (?delete=true) |
token | logout (closes the session) |
POST /api/v2/statements |
token | execute_statement |
GET /api/v2/statements/<id> |
token | get_statement |
POST /api/v2/statements/<id>/cancel |
token | cancel_statement |
GET /api/v2/databases |
token | list_databases |
GET /api/v2/databases/<name>/schemas |
token | list_schemas |
The module doc comment lists further endpoints (warehouses, stages over REST, tasks, streams, /session/token-request) that route_request does not route. (source: src/protocol/snowflake/mod.rs, module doc, route_request)
Authentication
Login
login_request reads data.LOGIN_NAME and data.PASSWORD and checks them with verify_credential (catalog password with the failed-login delay). A failure is 401 UNAUTHORIZED unless SYNERGYDB_DEV_INSECURE_AUTH is set. On success it returns a session token snowflake-token-<uuid>, a master token snowflake-master-<uuid>, validityInSeconds 3600, masterValidityInSeconds 14400, an integer sessionId and serverVersion "9.38.2". It takes databaseName, schemaName, warehouse and roleName from the query string, and reads CLIENT_ENVIRONMENT and SESSION_PARAMETERS (including AUTOCOMMIT). (source: src/protocol/snowflake/mod.rs, login_request)
The check is verify_credential, not verify_wire_credential, so synergy_wire_snowflake membership is not required. (source: src/protocol/snowflake/mod.rs, login_request; src/auth/wire_auth.rs)
Later requests
check_auth accepts (source: src/protocol/snowflake/mod.rs, check_auth, request_token, token_was_issued):
| Header | Accepted when |
|---|---|
Authorization: Snowflake Token="<token>" |
the token was issued by login_request
|
Authorization: Bearer <token> |
the token was issued by login_request
|
X-Snowflake-Authorization-Token-Type present, with Authorization holding the token |
the token was issued by login_request
|
Authorization: Basic ... |
the user and an Argon2 hash are in SNOWFLAKE_AUTH_HASHES
|
any snowflake-token-* or snowflake-master-* token |
only with SYNERGYDB_DEV_INSECURE_AUTH
|
Test: test_auth_fails_closed_without_dev_flag.
-
SNOWFLAKE_AUTH_HASHESis aOnceLockthat nothing sets, so it is always empty and Basic authentication never succeeds. (source:src/protocol/snowflake/mod.rs,SNOWFLAKE_AUTH_HASHES,get_snowflake_auth_hashes) - Issued tokens never expire and are never removed, whatever
validityInSecondssays. Logout closes the session but the token still authenticates, and the next request opens a new session for it (session_for). (source:src/protocol/snowflake/mod.rs,token_was_issued;src/protocol/snowflake/session.rs,session_for) Not verified: no test covers token lifetime or logout.
Sessions
SfSession holds one engine per token, running as the login user with decimal division switched on. Defaults: database SYNERGYDB, schema PUBLIC, warehouse COMPUTE_WH, role PUBLIC. A login database that does not exist leaves the session with no database. (source: src/protocol/snowflake/session.rs, SfSession, session_for, default_sf_db)
Statement execution (v1)
-
v1_query_requestrequiressqlText, supports bindings andasyncExec, and keeps statement results in a map; when it passes 20,000 entries it is cut to the 10,000 most recent completed ones. Fetching a result by id does not check which session ran it.queryResultFormatis alwaysjson; Arrow result sets are not produced. (source:src/protocol/snowflake/mod.rs,v1_query_request,v1_query_result,build_v1_data) - Inside a transaction, every statement except
BEGIN,START,COMMIT,ROLLBACK,END,CREATE,DROP,ALTER,TRUNCATE,COMMENT,GRANT,REVOKEandUSEruns underSAVEPOINT __sdb_stmt, so a failing statement undoes only its own changes. (source:src/protocol/snowflake/session.rs,run_statement)
run_statement_inner tries these in order (source: src/protocol/snowflake/session.rs, run_statement_inner):
-
stage_dispatch:PUT,GET,LIST/LS,REMOVE/RM,COPY INTO;CREATE/DROP/DESC/SHOW/ALTERofSTAGEandFILE FORMAT;SELECTfrom@stage;INFER_SCHEMA;IDENTIFIER(). -
ALTER TABLE/ALTER VIEWcomments (alter_comment_sql) andCREATE TABLE ... LIKE(create_like_sql). -
SAVEPOINT,RELEASEandROLLBACK TOare refused with code 1003 (syntax error). -
USE,BEGIN/START TRANSACTION,COMMIT,ROLLBACK,ALTER SESSION,ALTER WAREHOUSE. -
CREATE,DROPandUNDROPofDATABASE,SCHEMAandWAREHOUSE. Warehouses are only names, saved under__catalog__:snowflake_warehouses. These commit an open transaction. -
MERGE(run_merge),SELECT GET_DDL(...)(get_ddl),DESCRIBE/DESC TABLE. - A statement whose three-part names all point at one other database runs in that database (
with_database). -
run_generic:translate_snowflake_sql, thendialect::translate, then the engine. DDL commits an open transaction. WithAUTOCOMMIToff, DML opens a transaction.CREATE TABLE ... AS SELECTreportsrows_inserted.
SHOW
ShowCommand::parse understands TERSE, LIKE, STARTS WITH, LIMIT ... FROM and IN ACCOUNT | DATABASE | SCHEMA | TABLE | VIEW. execute_show_as answers DATABASES, SCHEMAS, OBJECTS, TABLES, VIEWS, FUNCTIONS, USER FUNCTIONS, COLUMNS, PRIMARY KEYS, UNIQUE KEYS, IMPORTED KEYS and EXPORTED KEYS. Any other SHOW returns an empty result with columns created_on and name. Stage and file-format SHOW go through stage.rs. (source: src/protocol/snowflake/mod.rs, ShowCommand::parse, execute_show_as) Tests: test_show_command_parse, test_show_objects_lists_catalog, test_show_databases.
SQL API (v2)
POST /api/v2/statements sends the statement text straight to the engine with execute_via_query_engine: no Snowflake dialect translation and no bind parameters. SHOW goes to execute_show_as. Engine errors are 400 SQL_EXECUTION_ERROR. (source: src/protocol/snowflake/mod.rs, execute_statement, execute_via_query_engine) Test: test_execute_statement.
Stages
- Named stages (
@s), the user stage (@~) and table stages (@%t) are stored in the key-value store in 4 MB chunks, with a 5 GB limit per file.COPY INTOloads in batches of 1000 rows. (source:src/protocol/snowflake/stage.rs,CHUNK,MAX_FILE,BATCH_ROWS) - Storage keys:
__sfstage_meta__:,__sfstage_data__:,__sfstage_loaded__:; catalogs__catalog__:sfstage:and__catalog__:sffileformat:. (source:src/protocol/snowflake/stage.rs) -
PUTandGETreturn a stage grant token: a bearer token scoped to one stage prefix, read-only or read-write, valid for 4 hours (issue_grant). The client uses it on/__sdb_stage/URLs, which are handled beforeroute_request. (source:src/protocol/snowflake/stage.rs,issue_grant,http_put,http_other,HTTP_PREFIX;src/protocol/snowflake/mod.rs,handle_connection,parse_request) -
Not verified:
stage.rshas no unit tests. The operator page reports 79/85 stage probes.
Type mapping
Result column types come from pg_oid_to_snowflake_type, and the wire type sent in rowtype from snowflake_type_to_wire (source: src/protocol/snowflake/mod.rs, pg_oid_to_snowflake_type, snowflake_type_to_wire):
| Engine type | Snowflake type | Wire type
|
|---|---|---|
| bool | BOOLEAN | boolean |
| int2, int4, int8, numeric | NUMBER | fixed (NUMBER(p,s) keeps p and s; bare NUMBER is 38,0) |
| float4, float8 | FLOAT | real |
| varchar, char | VARCHAR | text |
| text | TEXT | text |
| bytea | BINARY | binary |
| date | DATE | date |
| time | TIME | time (scale 9) |
| timestamp | TIMESTAMP | timestamp_ntz |
| timestamptz | TIMESTAMP_TZ | timestamp_tz |
| uuid | VARCHAR | text |
| json, jsonb | VARIANT | variant |
| text[] | ARRAY | array |
| anything else | TEXT | text |
TIMESTAMP_LTZ and OBJECT are also recognised by snowflake_type_to_wire. Cells in v1 results are strings; encode_v1_temporal encodes dates as days since the epoch and times and timestamps in Snowflake's numeric forms, and fixed_at_scale pads NUMBER values to their scale. (source: src/protocol/snowflake/mod.rs, encode_v1_temporal, fixed_at_scale, rowset_to_v1_strings)
Error mapping
map_engine_error gives a Snowflake error code and SQLSTATE (source: src/protocol/snowflake/session.rs, map_engine_error, SfError):
| Engine condition | Code | SQLSTATE | Message form |
|---|---|---|---|
| missing object | 2003 | 42S02 | Object '...' does not exist or not authorized. |
| invalid column | 904 | 42000 | |
| bad date | 100040 | 22007 | |
| bad timestamp | 100035 | 22007 | |
| bad boolean | 100037 | 22018 | |
| bad number | 100038 | 22018 | |
| parse error | 1003 | 42000 | |
| already exists | 2002 | 42710 | |
| division by zero | 100051 | 22012 | |
| unknown function | 2140 | 42601 | |
| NOT NULL violation | 100072 | 22000 | |
| anything else | 100040 | 42000 | |
| empty SQL text | 900 | 42000 | |
USE of a missing object (does_not_exist) |
2003 | 02000 | |
no current database for the statement (cannot_use) |
2043 | 02000 |
Statement errors are returned with HTTP 200 and a JSON body with success: false, code, message, data.sqlState and data.errorCode (error_response). (source: src/protocol/snowflake/session.rs, error_response)
The statement diff lists two places where SynergyDB returns NULL and Snowflake returns an error: SELECT no_such_col FROM (SELECT 1 a) (Snowflake 904) and SELECT 1 + 'abc' (Snowflake 100038). (source: docs/proof/2026-11-30/proof-pack-a3232c9/snowflake-statement-diff.txt)
Transactions
-
BEGINorSTART TRANSACTIONopens a transaction;COMMITandROLLBACKend it. DDL and database, schema and warehouse statements commit an open transaction first. With sessionAUTOCOMMIToff (from login orALTER SESSION), DML opens a transaction implicitly. (source:src/protocol/snowflake/session.rs,run_statement_inner,run_generic,alter_session) - Savepoints are not available to clients (code 1003); the wire uses
__sdb_stmtinternally for statement atomicity. (source:src/protocol/snowflake/session.rs,run_statement,run_statement_inner)
Limits and configuration
| Setting | Default | Effect |
|---|---|---|
[server] snowflake_port |
8443 | Listener port; omitted in a config file means off. |
MAX_HTTP_BODY |
256 MB | Largest request body (also after gzip). |
PREAUTH_BODY_LIMIT |
1 MB | Larger bodies need valid credentials first. |
| Statement results kept | 20,000, cut to 10,000 | v1 result map. |
| Stage file | 5 GB |
MAX_FILE. |
| Stage grant token | 4 h |
issue_grant. |
| Session token | no expiry |
validityInSeconds 3600 is advertised but not enforced. |
SYNERGYDB_DEV_INSECURE_AUTH |
unset | Any login and any snowflake-token-* accepted (test harnesses only). |
(source: src/config.rs; src/protocol/snowflake/mod.rs; src/protocol/snowflake/stage.rs; src/protocol/buffer_limits.rs)
Not wired and not implemented
-
Not wired: Basic authentication (
SNOWFLAKE_AUTH_HASHESis never filled). (source:src/protocol/snowflake/mod.rs,get_snowflake_auth_hashes) - Not implemented: Arrow result format, token renewal (
/session/token-request), the REST endpoints for warehouses, stages, tasks and streams listed in the module doc, chunked request bodies, client savepoints, external stage URLs inCOPY INTO. (source:src/protocol/snowflake/mod.rs,route_request,parse_request;src/protocol/snowflake/session.rs,run_statement_inner;../../wires/snowflake.md)
Tests and proof
| Where | What |
|---|---|
src/protocol/snowflake/mod.rs |
8 tests, including test_auth_fails_closed_without_dev_flag, test_show_command_parse, test_show_objects_lists_catalog, test_execute_statement, test_create_database. |
src/protocol/snowflake/dialect.rs |
17 unit tests. |
session.rs, stage.rs
|
No unit tests. |
tests/protocol_snowflake.rs |
Drives QueryEngine directly, not the HTTP wire. |
docs/proof/2026-11-30/proof-pack-a3232c9/snowflake-statement-diff.txt |
174/177 statements identical to cached answers from a real Snowflake account; 175/177 ignoring NUMBER precision. The three misses: ZEROIFNULL precision, the missing-column case and the 1 + 'abc' case above. |
(source: the files named)
The stages (79/85), snowflake-sqlalchemy (193/205) and dbt (116/116) results on the operator page come from status entries that this page did not re-check.