Explore Data Products from SAP® BDC Connect for Snowflake

This topic describes how to use a Zero-Copy connector to list available SAP® data products, create catalog-linked databases, and query the shared data in Snowflake.

The connector must be in the CONNECTED state before you perform any of the steps in this topic. See Set up the SAP® BDC Connect for Snowflake Zero-Copy connector.

In SAP® BDC, choose data products to share with Snowflake

To search for and share data products with Snowflake, users must use the central SAP Business Data Cloud catalog and have a global role that grants them the following privileges:

  • BDC Data Packages (read) - To access SAP Business Data Cloud.
  • Catalog Asset (read) - To access the catalog and view objects in the Assets and Data Products collections.
  • Cloud Data Product (share) - To share data products to target systems.

Users with these privileges can share data products from the SAP Business Data Cloud catalog with the desired SAP Snowflake account to make them available for consumption to specific roles in that account.

To share data products with Snowflake:

  1. In the central SAP Business Data Cloud catalog, select data products to share with an SAP Snowflake account
  2. From Catalog & Marketplace, search for (or use filters) to find the data products to be shared
  3. From the search results, select Share in the data product to be shared (for example, customer) to open the Manage Share Access dialog
  4. In the Overview section, learn more about the data product by reviewing its details and available objects.
  5. Under Target System:
    1. Choose the Snowflake account with the enrolled Zero-Copy connector to share with (if there is more than one).
    2. Select Update.

A message confirms the share process has started. After it finishes, a notification shows the result.

In Snowflake, list shared data products

To list the data products that SAP® BDC has shared with your Snowflake account, call SYSTEM$ZEROCOPY_CONNECTOR_LIST_SHARES:

SELECT SYSTEM$ZEROCOPY_CONNECTOR_LIST_SHARES('my_db.my_schema.my_sap_connector');

The function returns a JSON array. Each element represents one shared data product. Pass the name value as SHARE_NAME when you create a catalog-linked database, and copy that value exactly:

[
  {
    "name": "usid:b077d21c-b7a2-479a-a20e-bba1dbe91034:ns:sap.s4pce:r:SalesOrder:v:1",
    "id": "25c0de58-6e61-4bcc-ba68-c2c15b7a2d4b",
    "display_name": "Sales Order (BDF730, sap.s4pce:apiResource:SalesOrder:v1)",
    "comment": "An agreement between a vendor and a customer to provide products on a specific date.",
    "status": "MOUNTED",
    "catalog_linked_databases": [ { "name": "SALES_ORDER_CLD" } ],
    "properties": {
      "sap.ord.apiResource.ordId": "sap.s4pce:apiResource:SalesOrder:v1",
      "sap.ord.systemInstance.name": "BDF730",
      "sap.ord.systemInstance.id": "30f962e7-791c-41d7-9e72-1534823e8b21"
    }
  }
]

For a description of the output, see SYSTEM$ZEROCOPY_CONNECTOR_LIST_SHARES. The function reads the list from SAP® BDC each time you call it, so the names and descriptions are the ones that SAP® BDC currently returns. If a data product that you expect is missing, check in SAP® BDC that it’s shared with the Snowflake account and connector that you’re using.

To filter and search more easily, parse the JSON output into a tabular format using PARSE_JSON and LATERAL FLATTEN:

WITH raw AS (
  SELECT PARSE_JSON(
    SYSTEM$ZEROCOPY_CONNECTOR_LIST_SHARES('my_db.my_schema.my_sap_connector')
  ) AS json_data
)
SELECT
  f.value:name::STRING                                         AS name,
  f.value:id::STRING                                           AS id,
  f.value:display_name::STRING                                 AS display_name,
  f.value:comment::STRING                                      AS comment,
  f.value:properties['sap.ord.apiResource.ordId']::STRING      AS api_resource_ord_id,
  f.value:properties['sap.ord.systemInstance.name']::STRING    AS system_instance_name,
  f.value:properties['sap.ord.systemInstance.id']::STRING      AS system_instance_id
FROM raw,
LATERAL FLATTEN(INPUT => json_data) f;

Create a catalog-linked database

To mount a shared SAP® data product in Snowflake, create a catalog-linked database with CREATE DATABASE … LINKED_ZEROCOPY_CONNECTOR. The role requires the CREATE DATABASE privilege on the account and the USAGE privilege on the connector. The owner of the catalog-linked database can be different from the owner of the connector.

CREATE DATABASE my_sales_order
  LINKED_ZEROCOPY_CONNECTOR = (
    CONNECTOR_NAME = 'my_db.my_schema.my_sap_connector',
    SHARE_NAME = 'usid:b077d21c-b7a2-479a-a20e-bba1dbe91034:ns:sap.s4pce:r:SalesOrder:v:1'
  );

Each catalog-linked database mounts exactly one data product, so specify one SHARE_NAME, copied exactly (the match is case-sensitive). You can create multiple catalog-linked databases from the same connector, one for each data product shared from SAP® BDC.

Snowflake populates the database in the background, so schemas and tables can take a few minutes to appear. Shortly after you create the database, Snowflake also creates a read-only schema named SNOWFLAKE$ in it, with a semantic view generated from the data product. For details, see The semantic view and primary keys.

SYNC_INTERVAL_SECONDS is the only property that you can change after you create the database. The Salesforce-only properties don’t apply to SAP® BDC catalog-linked databases. For the discovery interval, see Data freshness and refresh.

To confirm the database was created, use SHOW DATABASES:

SHOW DATABASES LIKE 'MY_SALES_ORDER%';

The semantic view and primary keys

Each catalog-linked database has one semantic view, in its SNOWFLAKE$ schema. Snowflake generates it from the SAP® Core Schema Notation (CSN) of the data product. The semantic view adds business meaning to the shared data and supports AI capabilities such as Cortex Analyst directly on top of the SAP® data in Snowflake.

Snowflake builds the view in the background after the database is created, so it can appear a few minutes after the database. The view is owned by the role that owns the database. To find it:

SHOW SEMANTIC VIEWS IN SCHEMA my_sales_order."SNOWFLAKE$";

The semantic view is built only from the CSN, not from the tables. A column that is in a table but not in the CSN doesn’t appear in the view. Snowflake doesn’t rebuild the view automatically when the CSN changes on the SAP® side. To pick up a CSN change, call SYSTEM$ZEROCOPY_REFRESH_SEMANTIC_VIEW. The refresh runs in the background and keeps the grants on the view:

SELECT SYSTEM$ZEROCOPY_REFRESH_SEMANTIC_VIEW('my_sales_order');

Creating your own views or semantic views inside a catalog-linked database isn’t supported. To build your own semantic view on SAP® data, create it in a different database and reference the tables of the catalog-linked database.

Snowflake also creates primary keys from the CSN. For each table whose CSN entity marks key elements, Snowflake adds an informational PRIMARY KEY ... RELY constraint to the table. The constraint isn’t enforced. If a table already has a different primary key, Snowflake keeps the existing key. To see the constraints, use SHOW PRIMARY KEYS:

SHOW PRIMARY KEYS IN DATABASE my_sales_order;

PII tagging and masking

Snowflake tags columns as personally identifiable information (PII) based on annotations in the SAP® Core Schema Notation (CSN) shared with the data product:

  • Columns that the CSN marks as potentially personal or sensitive data are tagged with the PII tag in the SNOWFLAKE$ schema, shortly after the catalog-linked database is created.
  • A masking policy is attached to the PII tag, so query results are masked by default for every role, including ACCOUNTADMIN and the database owner role.

Important

Only grant unmasking access to roles that are authorized to view PII.

To unmask PII, the database owner role can set the UNMASK_PII tag in the catalog-linked database’s automatically created SNOWFLAKE$ schema on the role that needs to see unmasked data:

ALTER ROLE my_role SET TAG my_sales_order."SNOWFLAKE$".UNMASK_PII = 'true';

Only the session’s primary role is checked. To see unmasked values, use the tagged role as the primary role, for example with USE ROLE my_role.

Data freshness and refresh

Snowflake doesn’t copy data from SAP® Business Data Cloud; queries read the data product where SAP® stores it. Three separate settings determine how current a catalog-linked database is:

  • Discovery of schemas and tables: New and removed tables are picked up at the interval set by SYNC_INTERVAL_SECONDS on the catalog-linked database. The default for SAP® BDC is 86400 seconds (24 hours).
  • Table metadata refresh: Existing tables pick up the latest table metadata from SAP® BDC at an interval set on the connector, which applies to every catalog-linked database of that connector. The default is 30 seconds for new connectors; existing connectors might have a different interval.
  • Semantic view: Not rebuilt automatically. See The semantic view and primary keys.

Discovery of schemas and tables

SYNC_INTERVAL_SECONDS can range from 30 to 86400 seconds (1 day). To see the current value, call SYSTEM$GET_CATALOG_LINKED_DATABASE_CONFIG and check sync_interval_seconds. To change it, use ALTER DATABASE … UPDATE LINKED_ZEROCOPY_CONNECTOR:

ALTER DATABASE my_sales_order UPDATE LINKED_ZEROCOPY_CONNECTOR
  SET SYNC_INTERVAL_SECONDS = 3600;

To run discovery once without waiting for the next scheduled run, call SYSTEM$SYNC_ZEROCOPY_OBJECTS. The function starts discovery in the background and doesn’t refresh table metadata:

SELECT SYSTEM$SYNC_ZEROCOPY_OBJECTS('my_sales_order');

Both operations require the MODIFY or OWNERSHIP privilege on the catalog-linked database. To pause and resume scheduled discovery, use ALTER DATABASE … SUSPEND DISCOVERY and RESUME DISCOVERY, which require the OWNERSHIP privilege on the database.

Table metadata refresh

To see the table metadata refresh interval of a connector, call SYSTEM$GET_ZEROCOPY_METADATA_AUTO_REFRESH_INTERVAL. To change it, call SYSTEM$SET_ZEROCOPY_METADATA_AUTO_REFRESH_INTERVAL, which requires the MODIFY privilege on the connector. The value must be between 30 seconds and 1 day:

SELECT SYSTEM$GET_ZEROCOPY_METADATA_AUTO_REFRESH_INTERVAL('my_db.my_schema.my_sap_connector');

SELECT SYSTEM$SET_ZEROCOPY_METADATA_AUTO_REFRESH_INTERVAL('my_db.my_schema.my_sap_connector', '5m');

A table can’t be more current in Snowflake than the data that SAP® last committed to the data product. SYNC_INTERVAL_SECONDS and the refresh options of individual tables don’t change the table metadata refresh interval.

Check status

The functions that work on any catalog-linked database also work on catalog-linked databases created from a Zero-Copy connector:

SELECT SYSTEM$CATALOG_LINK_STATUS('my_sales_order');
SELECT SYSTEM$AUTO_REFRESH_STATUS('my_sales_order.my_schema.my_table');

Explore the data

List the schemas and tables available in the catalog-linked database:

SHOW SCHEMAS IN DATABASE my_sales_order;

SHOW TABLES IN DATABASE my_sales_order;

Query the data. Schema, table, and column names come from the data product, so replace the names in these examples with the names returned by SHOW SCHEMAS, SHOW TABLES, and DESC TABLE:

SELECT * FROM my_sales_order.salesorder.salesorder LIMIT 100;

Catalog-linked databases created from a Zero-Copy connector are case-insensitive. The names that SHOW commands return are in SAP® mixed case, but you can use them without double quotes, as in the preceding example.

The catalog-linked database is read-only. To transform or combine the data, create your objects in a different database, as shown in Create table as select (CTAS).

You can join tables across multiple catalog-linked databases. For example, to find the top customers by revenue using data from two shared data products:

SELECT
  s.salesorder,
  s.soldtoparty,
  c.customername,
  c.country,
  s.totalnetamount
FROM my_sales_order.salesorder.salesorder s
JOIN my_customers.customer.customer c
  ON s.soldtoparty = c.customer
WHERE s.overallsdprocessstatus != 'C'
ORDER BY s.totalnetamount DESC
LIMIT 10;

Create table as select (CTAS)

To persist query results as a native Snowflake table, use CREATE TABLE AS SELECT (CTAS). Create a new database to hold the results, and replace the source table and column names with the names from your data products:

CREATE DATABASE IF NOT EXISTS my_ctas_db;
USE DATABASE my_ctas_db;

CREATE OR REPLACE TABLE top_customers_by_revenue AS
SELECT
  c.customer,
  c.customername,
  c.country,
  c.region,
  c.businesstype,
  COUNT(DISTINCT s.salesorder)           AS num_orders,
  SUM(s.totalnetamount)                  AS total_revenue,
  AVG(s.totalnetamount)                  AS avg_order_amount
FROM my_customers.customer.customer c
JOIN my_sales_order.salesorder.salesorder s
  ON c.customer = s.soldtoparty
WHERE c.deletionindicator = FALSE
GROUP BY 1, 2, 3, 4, 5;

-- Query the result table
SELECT * FROM top_customers_by_revenue LIMIT 10;

Drop a catalog-linked database

All catalog-linked databases must be dropped before you can disconnect or drop the connector. Catalog-linked databases do not support UNDROP.

DROP DATABASE my_sales_order;

Dropping and re-creating a catalog-linked database doesn’t change the data that it shows, and it removes the grants on the database and the objects in it. If data looks missing or out of date, see Troubleshoot the SAP® BDC Connect for Snowflake Zero-Copy connector.