Use remote app operations

About remote app operations

Remote app operations let a provider perform different types of operations on the consumer Snowflake Native App, such as running on-demand SQL statements for troubleshooting or disabling the application.

Currently, the supported operation types are run_sql, disable, enable, and retry_upgrade:

Operation TypeDescriptionConsent Required?
run_sqlRun a SQL statement on the application.Yes
disableDisable the application.No
enableEnable a disabled application.No
retry_upgradeRetry upgrading the application.No

Prerequisites

Before you can use remote app operations, you need the following:

Operation type: run_sql

Consumer consent required? Yes.

To run a SQL statement on a Snowflake Native App, call the SYSTEM$REMOTE_APP_OPERATION function with the run_sql operation type. For example:

SELECT SYSTEM$REMOTE_APP_OPERATION(
  'run_sql',
  'package_name',
  'application_hash',
  '{"sql": "SELECT * FROM app_schema.app_table"}'
);

This function call executes SELECT * FROM app_schema.app_table as the application.

The system function returns a JSON string {"request_id": "<uuid>"}. This request_id can be used to query the result of the operation in the event table. See Querying operation results section below for more details.

Reading the result of the SQL statement

The execution of the SQL statement is logged in the event table, with information on the status, query result, and execution time. See the Querying operation results section below for more details.

Operation type: disable

Consumer consent required? No.

To disable a Snowflake Native App, call the SYSTEM$REMOTE_APP_OPERATION function with the disable operation type. For example:

SELECT SYSTEM$REMOTE_APP_OPERATION(
  'disable',
  'package_name',
  'application_hash',
  '{"reason": "Application needs to be disabled for maintenance"}'
);

The reason specified will be visible to the consumer as the application’s disablement reason, for instance in DESCRIBE APPLICATION.

The system function returns a JSON string {"request_id": "<uuid>"}. This request_id can be used to query the result of the operation in the event table. See Querying operation results section below for more details.

Operation type: enable

Consumer consent required? No.

To re-enable a Snowflake Native App that you previously disabled, call the SYSTEM$REMOTE_APP_OPERATION function with the enable operation type. For example:

SELECT SYSTEM$REMOTE_APP_OPERATION(
  'enable',
  'package_name',
  'application_hash'
);

Note

This operation can only enable applications that have been disabled by the provider. If an application was disabled by Snowflake, see What to do if an app is unavailable.

The system function returns a JSON string {"request_id": "<uuid>"}. This request_id can be used to query the result of the operation in the event table. See Querying operation results section below for more details.

Operation type: retry_upgrade

Consumer consent required? No.

To retry a failed upgrade on a Snowflake Native App, call the SYSTEM$REMOTE_APP_OPERATION function with the retry_upgrade operation type. This operation is non-blocking. For example:

SELECT SYSTEM$REMOTE_APP_OPERATION(
  'retry_upgrade',
  'package_name',
  'application_hash'
);

The system function returns a JSON string {"request_id": "<uuid>"}. This request_id can be used to query the result of the operation in the event table. See Querying operation results section below for more details.

Querying operation results

Whenever SYSTEM$REMOTE_APP_OPERATION is called and modifies the consumer Snowflake Native App, the operation is logged in the event table for the consumer to view.

If event sharing is enabled, the provider can also query the operation results from the event table. Each successful SYSTEM$REMOTE_APP_OPERATION call returns a JSON string {"request_id": "<uuid>"}. Use this request_id to query the status and result of the operation in the event table.

Note

If SYSTEM$REMOTE_APP_OPERATION fails due to a syntax error or incorrect arguments (for example, the enable operation is called on an enabled application), the function call is not logged to the event table.

Here are example queries to get started:

-- Get the latest ten invocations
SELECT timestamp,
       RECORD_ATTRIBUTES['snow.application.remote_app_operation.operation_type']::STRING AS operation_type,
       RECORD_ATTRIBUTES['snow.application.remote_app_operation.request_id']::STRING AS request_id,
       VALUE['status']::STRING     AS status,
       value
FROM   snowflake.telemetry.events
WHERE  SCOPE['name'] = 'snow.application.remote_app_operation'
AND    RECORD_ATTRIBUTES['snow.application.hash'] = '<application_hash>'
LIMIT  10;
-- Query a specific invocation
SELECT PARSE_JSON(VALUE['result'])
FROM   snowflake.telemetry.events
WHERE  SCOPE['name'] = 'snow.application.remote_app_operation'
AND    RECORD_ATTRIBUTES['snow.application.remote_app_operation.request_id'] = '<request_id>';