Skip to content

SQL Export

This section covers how to export FeatureByte features as SQL code. SQL export requires a deployment that contains the features you want to export.

Prerequisites

Before exporting SQL, you need:

  1. Features created through Feature Ideation or defined manually
  2. A deployment containing your features

Export from UI

Step 1: Navigate to Your Deployment

Go to the Deployments catalog and select the deployment containing the features you want to export.

Deployment with Features

Step 2: Generate SQL

  1. Click the SQL tab in the deployment view
  2. Click Generate SQL (if the SQL hasn't been generated yet)
  3. FeatureByte will generate SQL containing all features in the deployment

Generated SQL

Step 3: Copy the SQL

Once generated, you can:

  • Copy the SQL directly from the UI
  • Use the Regenerate SQL button to refresh the SQL if needed

Using the SQL Template

The exported SQL is a SELECT statement with placeholders like {{ CURRENT_TIMESTAMP }}. As shown in the screenshot above, the SQL includes all features from your deployment and uses these placeholders for dynamic timestamp values.

To use this SQL in your environment, you need to fill in the placeholders and then wrap it for your specific use case:

Filling Placeholders

Replace {{ CURRENT_TIMESTAMP }} with your desired timestamp. For date strings, ensure proper casting to TIMESTAMP:

# For historical computation
sql_for_date = sql_template.replace("{{ CURRENT_TIMESTAMP }}", "CAST('2024-01-15' AS TIMESTAMP)")

# For current computation
sql_current = sql_template.replace("{{ CURRENT_TIMESTAMP }}", "CURRENT_TIMESTAMP()")

Wrapping the SQL

Create a new table when you want to store the computed features:

CREATE TABLE customer_features
USING DELTA
PARTITIONED BY (POINT_IN_TIME)
AS
SELECT ...  -- your exported SQL here

Insert into an existing table for regular batch updates:

INSERT INTO daily_features
SELECT ...  -- your exported SQL here

Create a view for on-demand feature computation:

CREATE VIEW current_features AS
SELECT ...  -- your exported SQL here

Next Steps

See Scheduling Examples for how to operationalize this SQL.