# Cloud connections

Precise reads campaign data where it already sits: AWS, Google Cloud, Snowflake or Databricks. You grant named columns to one reader, Precise runs one fixed statement, and the export lands in storage you own.

| Capability | Runtime | Status |
|---|---|---|
| Grant a named reader, export a fixed projection and check the connection | Tenant Cloud | Preview |
| Read a pinned Apache Iceberg snapshot | Tenant Cloud | Preview |
| Run sketch functions on the tenant Gateway | Tenant Cloud | Preview |
| Inspect the sample cloud projection with `/api/v1/clouds/{cloud}/probe` | Sandbox | Preview |
| Run governed sample queries and check the rows in DuckDB | Sandbox | Live |

> [!NOTE]
> The connectors are tested against local stand-ins for each cloud's APIs. A live connection is set up with you during onboarding, and each statement is confirmed against your account. [Known limits](../../reference/known-limits.md) lists what each Preview item is waiting for.

## Hosted public sandbox vs. tenant cloud deployment

Precise separates the hosted public sandbox from customer cloud deployments at the runtime boundary:

| Deployment | Where `precise-gateway` runs | Data read | Provenance and failure behavior |
|---|---|---|---|
| Hosted public sandbox (`https://sandbox.precise.ai`) | Precise's hosted Cloud Run service (`public` mode) | Synthetic Sample Book (84 orders, $19.85M media spend, public Parquet files) | Reports `is_sample: true` and `tenant_source: "synthetic_public_book"`. Also hosts this documentation site at `/docs` on the same origin. |
| Customer cloud (`tenant-read` or `spend-capable`) | Inside the customer's authorized cloud (AWS, Google Cloud, Snowflake or Databricks) | Only the granted views, columns and pinned table snapshots you authorize | Reports `is_sample: false`, `tenant_source: "tenant_warehouse"`, and real `snapshot_age_seconds`. Raw logs stay in your cloud; only governed aggregates, run digests and summary metadata cross to Precise Access. |

In `tenant-read` and `spend-capable` modes, synthetic sample-book fallback is disabled completely. The same server build switches modes via deployment configuration without changing application code, and fails closed if tenant bindings are missing or unpinned: unconfigured warehouse bindings return HTTP 503 (`TENANT_BOOK_UNCONFIGURED`), mutable tokens such as `latest` return HTTP 409 (`SNAPSHOT_PIN_REQUIRED`), sample-only routes return HTTP 409 (`SYNTHETIC_FALLBACK_DISABLED`), and cross-tenant credentials return HTTP 403 (`TENANT_MISMATCH`). Live customer cloud warehouse IAM grants and credentials are provisioned with your data and security teams during onboarding.

## What you grant

An **AccessGrant** describes the warehouse reader, allowed projection and destination. An **ExportRequest** selects one partition and format. A **ConnectGrant** describes an Iceberg catalog, readable relations, storage and positive and negative permission checks. Download the first two files here and the separate ConnectGrants in [Check the connection](#check-the-connection).

| Cloud | Owner or administrator | Query principal | Export and storage principal |
|-|-|-|-|
| Athena | Create the workgroup, result bucket, Glue catalog grants and Lake Formation column grants. | Needs query execution and result retrieval in that workgroup, catalog access and Lake Formation permission for the named columns. | Scope output-bucket access, multipart operations and any KMS permissions to this grant. Iceberg CTAS also creates a catalog table. |
| BigQuery | Authorize a projected view on the source dataset. Set the job project, dataset region and export bucket location. | Needs view reads and `bigquery.jobs.create` in the job project. The Jobs request takes `jobReference.projectId` from `compute`. | Check ordinary export create/delete rights on the destination. Managed Iceberg uses a separate connection service account with bucket get and object read/list/create/delete rights. The administrator configures table creation and connection delegation. |
| Snowflake | Grant usage on the database, schema and warehouse and SELECT on the projected view. Set the session's database and schema. | Quoted identifiers are case-sensitive. Use the catalog's exact case in the grant. Snowflake resolves ordinary unquoted identifiers to upper case. | Internal stages require the appropriate stage read/write grants. An external stage needs USAGE and its storage integration's destination rights. Managed Iceberg also needs its external volume. |
| Databricks | Register a non-overlapping cloud external location. Grant USE CATALOG, USE SCHEMA and CREATE TABLE on the export schema as applicable. | Needs SELECT on the view, CAN USE on the SQL warehouse, and required parent privileges. | Grant CREATE EXTERNAL TABLE and the applicable file rights on the external location. A volume used for Arrow staging has its own volume privileges. |

These are distinct runtime identities and provisioning steps. Check each role against the chosen operation. [Athena CTAS](https://docs.aws.amazon.com/athena/latest/ug/create-table-as.html), [BigQuery export permissions](https://docs.cloud.google.com/bigquery/docs/exporting-data#required_permissions), [managed Iceberg permissions](https://docs.cloud.google.com/bigquery/docs/biglake-iceberg-tables-in-bigquery#required_roles), [Snowflake identifiers](https://docs.snowflake.com/en/sql-reference/identifiers-syntax), [Databricks volumes](https://docs.databricks.com/aws/en/volumes/).

### Render an export locally

Save the [Athena AccessGrant](../../downloads/cloud/access-grant.json) and [ExportRequest](../../downloads/cloud/export-request.json). Build the two command-line tools from the Precise source tree. From its root:

```sh
cargo build --locked --manifest-path rust/Cargo.toml -p precise-gateway --bin precise-snapshot-export --bin precise-connect-verify
export GATEWAY_BIN="$PWD/rust/target/debug"
```

In the same shell, change to the download directory. The first command emits the grant plan. The second emits literal SQL, the provider request, destination, grant digest and the source version it reads.

```sh
"$GATEWAY_BIN/precise-snapshot-export" access-grant.json
"$GATEWAY_BIN/precise-snapshot-export" access-grant.json export-request.json
```

## The one statement Precise runs

A request names a tenant, a run tag, columns, one equality filter on a granted column with its type (`string`, `integer` or `date`), one fixed version of the source table, and an output format (`parquet`, `iceberg` or `arrow_stream`). The source version is a UTC time on every cloud, or a snapshot ID on Athena and Databricks. These four statements were rendered from the sample grants on 24 Nov 2026, reading the table as it stood at 00:00 UTC on 1 October.

```sql
-- AWS, Athena
/* precise.run=run-2026-09-30-delivery */ UNLOAD (SELECT "order_id", "seller_id", "impressions", "media_spend_usd" FROM "ads"."delivery_daily" FOR TIMESTAMP AS OF TIMESTAMP '2026-10-01 00:00:00 UTC' WHERE "day" = DATE '2026-09-30') TO 's3://acme-precise-exports/snapshots/460ff52e32ff771db3596f29/' WITH (format = 'PARQUET')

-- Google Cloud, BigQuery
/* precise.run=run-2026-09-30-delivery */ EXPORT DATA OPTIONS(uri='gs://acme-precise-exports/snapshots/063a3e47299bdcd6e770f8ee/*.parquet', format='PARQUET', overwrite=false) AS SELECT `order_id`, `seller_id`, `impressions`, `media_spend_usd` FROM `precise_out.precise_abc366168757eec26a3cf417aacf8a9b` WHERE `day` = DATE '2026-09-30'

-- Snowflake
/* precise.run=run-2026-09-30-delivery */ COPY INTO @ads.precise_stage/snapshots/0a103e8fee74b0b7dc7c2be0/ FROM (SELECT "ORDER_ID" AS "order_id", "SELLER_ID" AS "seller_id", "IMPRESSIONS" AS "impressions", "MEDIA_SPEND_USD" AS "media_spend_usd" FROM "PRECISE_OUT"."PRECISE_206CB73CD69C3D3D36711416D0500B1E" WHERE "DAY" = DATE '2026-09-30') FILE_FORMAT=(TYPE=PARQUET) HEADER=TRUE

-- Databricks
/* precise.run=run-2026-09-30-delivery */ CREATE TABLE `precise_out`.`pin_a8b1f35928db78476e0c84f2` USING PARQUET LOCATION 's3://acme-precise-exports/databricks/snapshots/a8b1f35928db78476e0c84f2' AS SELECT `order_id`, `seller_id`, `impressions`, `media_spend_usd` FROM `precise_out`.`precise_6a7bbb018e904102730c95fdbf33c414` WHERE `day` = DATE '2026-09-30'
```

On BigQuery, Snowflake and Databricks the statement reads a view pinned to that source time. Your provisioning principal creates the view and grants the reader `SELECT` on it, once per source version. The rendered request carries both statements. For Snowflake:

```sql
CREATE VIEW "PRECISE_OUT"."PRECISE_206CB73CD69C3D3D36711416D0500B1E" AS SELECT "DAY", "IMPRESSIONS", "MEDIA_SPEND_USD", "ORDER_ID", "SELLER_ID" FROM "ADS"."DELIVERY_DAILY" AT (TIMESTAMP => '2026-10-01T00:00:00Z'::TIMESTAMP_TZ)
GRANT SELECT ON VIEW "PRECISE_OUT"."PRECISE_206CB73CD69C3D3D36711416D0500B1E" TO ROLE "PRECISE-READER"
```

The target directory is named by a digest of the request, under your prefix. On Databricks the Parquet location is an `s3://`, `gs://` or `abfss://` prefix covered by a registered external location. A `/Volumes/` path for Parquet returns `Databricks external table LOCATION cannot be inside /Volumes/. Set export_sink to a non-overlapping s3://, gs:// or abfss:// prefix covered by a registered Unity Catalog external location.` A volume can stage Arrow results. Managed Iceberg CTAS leaves LOCATION to Unity Catalog. The location is confirmed against your workspace during setup.

Download the [four product grants and ten golden provider requests](../../downloads/cloud/warehouse-examples.json) and the [comparison script](../../downloads/cloud/verify-warehouse.py). Each case includes its complete input, literal SQL, provider JSON, target and digest. Athena and BigQuery each support Parquet and Iceberg. Snowflake and Databricks support those two and Arrow. For BigQuery Iceberg, use `DEFAULT` or a qualified connection such as `billing-project.us-central1.bigconn`. The sample GCP grant for **Parquet** still carries a short legacy connection name. The Iceberg golden uses the qualified name.

```sh
python3 verify-warehouse.py "$GATEWAY_BIN/precise-snapshot-export" warehouse-examples.json
```

The complete BigQuery managed-Iceberg Jobs request in this fixture is:

```json
{
  "jobReference": {
    "projectId": "tenant-compute",
    "jobId": "precise_6fd845af9ed9c419f4fdb2cdc887468e95c018fdc7baceff60a538eea309985c"
  },
  "configuration": {
    "query": {
      "query": "/* precise.run=r01 */ CREATE TABLE `out.pin_6fd845af9ed9c419f4fdb2cd` WITH CONNECTION `billing-project.us-central1.bigconn` OPTIONS(file_format='PARQUET', table_format='ICEBERG', storage_uri='gs://private/export/6fd845af9ed9c419f4fdb2cd/') AS SELECT `amount` FROM `out.precise_cd3871a13775bc0517caaa050cea027f` WHERE `day` = DATE '2026-11-23'",
      "useLegacySql": false
    },
    "labels": {
      "precise_run": "6fd845af9ed9c419f4fdb2cd"
    }
  }
}
```

The filter value is written as its declared type, so a date filter compares dates. Every statement reads one fixed source version, and the request digest names the export destination. Keep the provider job ID, row count and exported-object digests with the run to show a reproducible warehouse snapshot. Running the statement needs the warehouse access you granted.

## Twelve requests, put to each grant

Each request below was put to the current renderer with the sample grant, once per cloud, on 24 Nov 2026. Anything outside the grant is turned away before a statement exists.

| Request | Answer |
|-|-|
| The granted columns for one day. One granted column. Every granted column. Another day. The same day under a new run tag | All five render |
| The same rows as an Arrow stream | Renders on Snowflake and Databricks. AWS and Google Cloud answer `unsupported warehouse output format` |
| A column the grant does not name (`hashed_email`). A filter on such a column. A day value that carries a quote. A run tag that closes the comment it sits in | Each answers `invalid export projection, partition or run tag` |
| A table the grant does not name (`ads.user_profiles`) | `relation outside grant` |
| The same statement for another tenant | `export tenant mismatch` |

The sample app shows the four grants under Connections. Its Databricks Parquet destination is `s3://acme-precise-exports/databricks/snapshots`. Answer trimmed to the grant's summary, recorded from sample data.

```sh preview
curl -s "$PRECISE_URL/api/v1/clouds/aws/probe"
```

```json answer
{
  "cloud": "aws",
  "warehouse": "Athena",
  "can_read": [{"table": "ads.delivery_daily", "columns": ["order_id", "seller_id", "day", "impressions", "media_spend_usd"]}],
  "runs_as": "precise-reader",
  "compute": "precise-workgroup",
  "writes_to": "s3://acme-precise-exports/snapshots",
  "rows_leave_your_cloud": false
}
```

## Check the connection

Download the [four complete ConnectGrants](../../downloads/cloud/connect-grants.json) and the [loopback connection demo](../../downloads/cloud/connection-demo.py). With Python 3, OpenSSL and the CLI on your machine, run this in a fresh download directory. The second command checks one fresh card: `--tenant` names the tenant you expect (defaulting to `PRECISE_TOPOLOGY_TENANT` when omitted), and `--max-age` the oldest card you accept in seconds (defaulting to `3600`).

```sh
python3 connection-demo.py "$GATEWAY_BIN/precise-connect-verify" connect-grants.json new-connection-results
"$GATEWAY_BIN/precise-connect-verify" --verify new-connection-results/public-test-key.pem new-connection-results/aws-card.json --tenant agency-demo --max-age 3600
```

On 24 Nov 2026 the demo printed `4 signed cards, 24 allowed observations, 24 denied observations, 4 expected scopes`, and the check above exited 0. The same check with `--tenant other-tenant` exits 1 with `topology freshness or tenant mismatch`.

The demo starts a local synthetic Iceberg REST catalog on an unused loopback port. Four cloud profiles use the same local bearer reader and plain native read. Add `--use-grant-port` to use the exact published grants and their recorded loopback port. The default changes the origin and checks its new scope. It generates a disposable PKCS#8 RSA signing key, probes the catalog with the actual CLI, verifies all four cards, and compares the signed scope with the independently computed expected grant scope. Each run writes a public key, per-provider grant and card, and deletes the private signing key. For the provider-specific authentication, planning, vended-credential and restricted-read paths, the source tree has a separate four-provider protocol test:

```sh
cargo test --locked --manifest-path rust/Cargo.toml -p precise-gateway --test connect_verify signed_topology_observes_both_permission_columns_on_all_four_clouds
```

The card schema is `precise.topology-card/v1`. Its RS256 signature covers canonical content, and the CLI recomputes its topology digest. A card is valid for one hour after it is issued. The CLI checks the signed issue and expiry times, the expected tenant, the card's age against `--max-age`, and the one-time nonce. It does not check the expected scope: compare the card's `scope` with the grant you issued, as the demo does. Each card has six successful observations (config, namespaces, tables, allowed HEAD, allowed load and a storage canary matching its configured SHA-256) and six denials (HEAD and load on three forbidden tables). A denial counts only for a table the catalog lists, because a blanket 403 says nothing about whether the table exists. A 404 fails the check. A card contains tenant, principal, scope, observed routes and permission results. Real deployments choose a scoped workload identity, SigV4, OAuth2 client credentials, key-pair JWT or bearer configuration appropriate to their provider.

The [signed sample cards](../../downloads/cloud/signed-cards.json) are historical examples, issued before cards carried issue and expiry times; the current CLI rejects them with `signed issuance required`.

## Native Apache Iceberg reads

The Gateway reads Iceberg tables through the `/v1` routes in Apache Iceberg release 1.12.0. The tagged contract declares OpenAPI 3.1.1 and `info.version` 0.0.1. It pins one snapshot, then picks a read path for each table.

| Door | When it is used |
|-|-|
| `scan_plan` | The catalog plans the scan on its server and returns the file tasks |
| `read_restrictions` | The catalog returns `read-restrictions`: required column projections, a required row filter, or both. The Gateway applies them, and the reader must present attestation evidence |
| `plain_iceberg` | A pinned snapshot read for a table that needs no server governance |
| `export` | Warehouse fallback for a table the native reader cannot serve: an unsupported format or schema, or no usable scan plan. It refuses any table that carries catalog read restrictions or requires server-side planning. |
| `arrow_stream` | Snowflake and Databricks return the projection as an Arrow stream |

- **Pin.** The pin holds the table UUID, snapshot id, schema id, metadata location, manifest list, projection and restrictions. A reopened run reads the retained snapshot, or replans the scan and compares the plan with the pin.
- **Renames.** Top-level fields are mapped by field ID, so a renamed column keeps its meaning.
- **Restrictions.** Supported column actions are `replace-with-null`, `mask-alphanum`, `show-first-4`, `show-last-4`, `truncate-to-year` and `truncate-to-month`. Row filters are applied to original values before projection.
- **Restricted reads.** For example, a required predicate `region = US` filters original rows before projection; selecting a raw masked column stops the read. A restricted table is read on its native door or not at all: when the native reader cannot serve it, the read is refused, and the warehouse fallback never runs without the catalog's restrictions. This is the refusal the REST spec requires when a restriction cannot be honored. [Apache catalog specification](https://github.com/apache/iceberg/blob/apache-iceberg-1.12.0/open-api/rest-catalog-open-api.yaml#L1056-L1058)
- **Budget.** An import reads at most 256 MiB per file and 4 GiB per pin.

The seven principal operations are GET config, GET namespaces, GET tables, HEAD table, GET table metadata, POST scan plan and GET credentials. Table routes are under `/v1/{prefix}/namespaces/{namespace}/tables/{table}`. Planning adds `/plan`, credential vending adds `/credentials`. Optional asynchronous planning polls `/plan/{plan-id}` and POSTs to `/tasks`. Capabilities select the needed calls per table. A vended read chooses the narrowest matching prefix. For example, when a short-lived credential expires, the reader refreshes it for the same pin. A storage 401 triggers a single renewal attempt. A 403 denies the catalog read. A planning route the catalog advertises but does not serve selects the warehouse fallback, under the same restriction rule.

## Sketch functions

Gateway SQL carries Apache DataSketches for distinct counts, overlaps and quantiles on large tables.

| Build a sketch | Read it | Parameters |
|-|-|-|
| `hll_sketch` | `hll_estimate`, `hll_union` | HLL_8, lgK 12 |
| `theta_sketch` | `theta_estimate`, `theta_intersect`, `theta_union` | lgK 12, default seed |
| `kll_sketch` | `kll_quantile` | Doubles, k 200 |

Sketch estimates are approximate by design. Null inputs are skipped. Strings are hashed as raw UTF-8 bytes with the Apache default seed, the same input the Java and C++ libraries use. The Gateway evaluates sketches itself. The connection card records a `sketch_pushdown` flag when the warehouse's four probe images match the Gateway's byte for byte on a fresh challenge series; the query planner does not use that flag yet. These functions run in a cloud deployment's Gateway. The public sandbox serves exact counts, and a sketch query there answers `422 query_failed` with `Invalid function 'hll_estimate'`.

Two audiences' overlap comes from one query: build a Theta sketch per audience, then read `theta_estimate` on each and on their `theta_intersect`, or merge a column of Theta sketches with `theta_union` before reading `theta_estimate`. The Jaccard overlap is the intersection over the union, where the union is the two estimates added less the intersection.

## Check a number yourself

Run the governed query, then run the same SQL in DuckDB over the public Parquet files.

```sql try
SELECT d.deal_type,
       SUM(c.impressions) AS impressions,
       ROUND(SUM(c.media_spend_usd), 2) AS media_spend_usd,
       ROUND(1000.0 * SUM(c.media_spend_usd) / SUM(c.impressions), 2) AS cpm_usd
FROM gold_daily_cube c
JOIN deals d ON d.deal_id = c.deal_id
GROUP BY d.deal_type
ORDER BY media_spend_usd DESC
```

Measured on the sample book, the Gateway returns three rows: open auction at $8.56 per thousand, private marketplace at $12.27, programmatic guaranteed at $15.41. The DuckDB tab on the panel builds this script for you.

```sql
CREATE VIEW gold_daily_cube AS SELECT * FROM read_parquet('https://sandbox.precise.ai/data/parquet/gold_daily_cube.parquet');
CREATE VIEW deals AS SELECT * FROM read_parquet('https://sandbox.precise.ai/data/parquet/deals.parquet');
-- then the SELECT above, unchanged
```

On 2026-11-24, DuckDB 1.5.5 returned the same three rows as the Gateway, to the cent. Every table is public at `https://sandbox.precise.ai/data/parquet/<table>.parquet`. The manifest lists each file with its byte size, row count and SHA-256, so you can confirm the file you read. For what crosses each boundary, see [Data boundaries](../security-and-infosec/data-boundaries.md).

```sh try
curl -s https://sandbox.precise.ai/data/manifest.json
```

Next: [Methodology and holdouts](methodology-and-holdouts.md).
