Prepare data with Gemini
This document describes how to generate and manage SQL code suggestions for your data preparations in BigQuery.
For more information, see Introduction to BigQuery data preparation.
Before you begin
Open the data preparation editor in BigQuery
You can open the data preparation editor in BigQuery by creating a new data preparation, creating one from an existing table, or opening an existing data preparation. For more information about what happens when you create a data preparation, see Data preparation entry points.
On the BigQuery page, you can go to the data preparation editor in the following ways:
Create new
To create a new data preparation in BigQuery, follow these steps:
- In the Google Cloud console, go to the BigQuery
page.
Go to BigQuery - Go to the Create new list and click Data preparation. The data preparation editor is displayed in a new untitled data preparation tab.
- In the editor's search bar, enter your table name or keywords and
select a table. The data preparation editor for the table opens,
showing a preview of your data on the Data tab, and an initial
set of data preparation suggestions from Gemini.
A Data preparation resource appears in the Explorer pane, where you can access this preparation in the future. - Optional: To simplify your view, turn on full screen mode by clicking fullscreen Full screen.
Create new from table
To create a new data preparation from an existing table, follow these steps:
- In the Google Cloud console, go to the BigQuery
page.
Go to BigQuery - In the Explorer pane, hold the pointer over a table.
- Click more_vert
Menu > Query in > Data preparation. The
data preparation editor for the table opens, showing a preview of your
data on the Data tab, and an initial set of data preparation
suggestions from Gemini.
A Data preparation resource appears in the Explorer pane, where you can access this preparation in the future. - Optional: To simplify your view, turn on full screen mode by clicking fullscreen Full screen.
Open existing
To open the editor for an existing data preparation, follow these steps:
- In the Google Cloud console, go to the BigQuery
page.
Go to BigQuery - In the Explorer pane, click your project name and data preparations.
- Select the existing data preparation. The graph view of the data preparation pipeline is displayed.
- Select one of the nodes in the graph. The data preparation editor for the table opens, showing a preview of your data on the Data tab, and an initial set of data preparation suggestions from Gemini.
- Optional: To simplify your view, turn on full screen mode by clicking fullscreen Full screen.
Add data preparation steps
You prepare data in steps. You can preview or apply steps suggested by Gemini. You can also improve the suggestions, or apply your own steps.
Apply and improve suggestions by Gemini
When you open the data preparation editor for your table, Gemini inspects the data and schema from the table you loaded and generates filter and transformation suggestions. The suggestions appear on cards in the Steps list.
The following image shows where you can apply and improve steps suggested by Gemini:
To apply a suggestion by Gemini as a data preparation step, do the following:
- In the data view, click a column name or a particular cell. Gemini generates suggestions for filtering and transforming the data.
Optional: To improve the suggestions, edit the values of one to three cells in the table to demonstrate what the values in a column should look like. For example, enter a date the way you want to format all dates. Gemini generates new suggestions based on your changes.
The following image shows how you can edit values to improve the steps suggested by Gemini:
Select a suggestion card.
- Optional: To preview the result of the suggestion card, click Preview.
- Optional: To modify the suggestion card using natural language, click Edit.
Click Apply.
Add steps with natural language or SQL expressions
If no suggestions meet your needs, add your own by clicking Add step, selecting a step type, and entering a prompt in natural language describing your intent.
Add a transformation
- In the data view, click Add step and choose the Transformation option.
- In the Description field, enter a prompt, such as
Convert the state column to uppercase
. Click send Send.
Gemini generates a SQL expression and a new description based on your prompt.
In the Target column list, select or enter a column name.
Optional: To update the SQL expression, revise the prompt and click send Send, or manually enter a SQL expression.
Optional: Click Preview and review the step.
Click Apply.
Filter rows
To add a filter that removes rows, follow these steps:
- In the data view, click Add step > Filter.
- In the Description field, enter a prompt, such as
Column ID should not be NULL
. - Click Generate. Gemini generates a SQL expression and a new description based on your prompt.
- Optional: To update the SQL expression, revise the prompt and click send Send, or enter a SQL expression manually.
- Optional: Click Preview and review the step.
- Click Apply.
Filter expression format
SQL expressions for filters retain rows that match the specified condition. This
is equivalent to a SELECT … WHERE SQL_EXPRESSION
statement.
For example, to retain records where the column year
is greater than or equal
to 2000
, the condition is year >= 2000
.
Expressions must follow the BigQuery SQL syntax for the
WHERE
clause.
Configure the error table and add a validation rule
You can add a filter that creates a validation rule, which sends errors to an error table or fails the data preparation run.
Configure the error table
To configure your error table, follow these steps:
- In the data view, go to the toolbar and click More > Error table.
- Click Enable error table.
- Define the table location.
- Optional: Define a maximum duration for keeping errors.
- Click Save.
Add a validation rule
To add a validation rule, follow these steps:
- In the data view, click Add step > Filter.
- Enter a description for the step.
- Enter a SQL expression, in the form of a
WHERE
clause. - Optional: If you want the SQL expression to act as a validation rule, select the Failed validation rows go to error table checkbox. You can also change a filter to a validation in the data preparation toolbar by clicking More > Error table.
- Optional: Click Preview and review the step.
- Click Apply.
Delete a column
To delete a column from a data preparation, follow these steps:
- In the schema view, click more_vert Menu next to the column to be deleted.
- Click Delete. A new applied step is added for the deleted column.
Add a join operation with Gemini
To add a join operation step between two sources in your data preparation, follow these steps:
- In the data view for a node in your data preparation, go to the Steps list, and click Add step > Join.
- In the Add join dialog, click Browse, and then select the other table involved in the join operation (referred to as the right side of the join).
- Optional: Select the type of join operation that you want to perform, such as Inner join.
Review the Gemini-generated join key information in the following fields:
- Join description: The natural language description of the SQL expression for the join operation. When you edit this description and click send Send, Gemini suggests new SQL join conditions.
Join conditions: The SQL expressions within the
ON
clause for the join operation. You can use theL
andR
qualifiers to refer to the left and right source tables, respectively. For example, to join thecustomer_id
column from the left table to thecustomer_id
column from the right table, enterL.customerId = R.customerId
. These qualifiers aren't case-sensitive.
Optional: To refine the suggestions from Gemini, edit the Join description field, and then click send Send.
Optional: To preview the join operation settings of your data preparation, click Preview.
Click Apply.
The join operation step is created. The source table that you selected (the right side of the join) and the join operation are reflected in the list of applied steps and in the nodes in the graph view of your data preparation.
Add or change a destination table
To add or change a destination table for the output of your data preparation, follow these steps:
- In the data view, click Add > Destination.
- Select the project where the destination table is stored.
- Select one of the datasets, or load a new dataset.
- Enter a destination table. If the table doesn't exist, the data preparation creates a new table on the first run. For more information, see Write mode.
- Select your dataset as the destination dataset.
- Click Save.
View the data sample and schema for an applied step
To view sample and schema details at a particular step in the data preparation, do the following:
- In the data view, go to the Steps list and click Applied steps.
- Select a step. The Data and Schema tabs appear, displaying the data sample and schema as of this particular step.
Edit an applied step
To edit an applied step, do the following:
- In the data view, go to the Steps list and click Applied steps.
- Select a step.
- Next to the step, click more_vert Menu > Edit.
- In the Edit Applied Step dialog, you can do the following:
- Edit the description of the step.
- Get suggestions from Gemini by editing the description and clicking send Send.
- Edit the SQL expression.
- In the Target column field, select a column.
- Optional: Click Preview and review the step.
- Click Apply.
Delete an applied step
To delete an applied step, do the following:
- In the data view, go to the Steps list and click Applied steps.
- Select a step.
- Click more_vert Menu > Delete.
Run the data preparation
After you've added your data preparation steps, configured the destination, and fixed any validation errors, you can perform test runs on a sample of the data, or deploy the steps and schedule data preparation runs. For more information, see Schedule data preparations.
Refresh data preparation samples
Data in the sample isn't automatically refreshed. If data in the source tables for the data preparation has changed, but the changes aren't reflected in the data sample of the preparation, click More > Refresh sample.
What's next
- Learn how to schedule data preparations.
- Learn about managing data preparations.
- Learn about quotas and limits for Gemini in BigQuery.
- Review Gemini in BigQuery pricing.