Many organizations store important business information in Google Drive. Reports, product documents, customer feedback, spreadsheets, presentations, invoices, and technical documentation are often maintained as separate files rather than stored in a database.
When developers need to analyze this information, they traditionally download the files, extract their contents, convert them into a suitable format, and then load the extracted data into BigQuery or another analytical platform.
This process works, but it introduces additional steps. It also creates another copy of the original information that must be maintained and updated.
Google BigQuery provides another approach through ObjectRef. It allows developers to represent files stored in Google Drive as references that can be used directly in BigQuery queries and supported AI functions.
Instead of manually downloading every document, developers can use ObjectRef with functions such as OBJ.LIST, OBJ.MAKE_REF, and AI.GENERATE to discover files and analyze their contents.
In this article, we will explore how ObjectRef works with Google Drive, how to configure the required environment, how to list files from a Drive folder, and how to analyze documents directly through BigQuery SQL.
What Is ObjectRef in BigQuery?
ObjectRef is a specialized STRUCT type in BigQuery that represents a reference to an unstructured object stored outside BigQuery.
The object can be an image, document, audio file, or another supported file type.
Instead of storing the complete file inside a BigQuery table, ObjectRef stores information that identifies the original object and allows supported BigQuery functions to access its contents.
An ObjectRef value can contain the following fields:
Field | Data Type | Description |
|---|
uri | STRING | Identifies the location of the file |
version | STRING | Stores the object version when supported |
authorizer | STRING | Identifies the Cloud resource connection used for delegated access when supported |
details | JSON | Contains metadata or processing information |
For Google Drive, the ObjectRef structure has some important differences.
The uri field contains the Google Drive file URL. The version and authorizer fields are always NULL because Google Drive ObjectRef currently does not support versioning or delegated access.
The details field can contain metadata such as the file name, content type, file size, and last updated information.
For example, a Google Drive file can be represented using the following reference:
SELECT
OBJ.MAKE_REF(
'https://drive.google.com/file/d/FILE_ID'
) AS document_ref;
Here, OBJ.MAKE_REF creates an ObjectRef value from the supplied Google Drive URL.
The actual file remains in Google Drive. BigQuery uses the reference when a supported function needs to access the file.
How ObjectRef Works With Google Drive
ObjectRef connects external files with BigQuery's SQL and AI capabilities.
The general processing flow looks like this:
Google Drive
|
v
Stored Documents
|
v
OBJ.LIST
|
v
ObjectRef Values
|
v
BigQuery SQL
|
v
AI Functions
|
v
Extracted Insights
|
v
Structured Results
The process begins by identifying the files stored in Google Drive.
BigQuery can then create ObjectRef values for those files. These references can be passed to supported AI functions to extract information, summarize documents, or generate structured results.
For example, an organization might store hundreds of PDF reports in a Google Drive folder. Instead of downloading each report, developers can list the files, select the required documents, and use AI.GENERATE to extract specific information.
It is important to understand that ObjectRef does not automatically import every file into BigQuery. It provides a reference through which supported functions can access the original content.
Prerequisites for Using Google Drive ObjectRef
Before implementing the solution, configure the Google Cloud environment.
The following requirements should be considered:
Requirement | Purpose |
|---|
Google Cloud project | Hosts BigQuery resources |
BigQuery | Executes SQL queries |
Google Drive | Stores the source documents |
BigQuery access | Allows users to execute queries |
Google Drive permissions | Allows access to the target files |
ObjectRef preview access | Enables Google Drive ObjectRef functionality |
Supported Gemini model | Processes document content through AI functions |
Requesting Google Drive ObjectRef Access
Google Drive ObjectRef support is currently a preview feature and requires allowlist access.
To request access, contact the Google Cloud team using the address provided in the BigQuery ObjectRef documentation:
[email protected]
Include your Google Cloud project ID in the request.
Do not assume that having an active BigQuery project automatically enables Google Drive ObjectRef functionality.
Understanding Google Drive Permissions
Google Drive ObjectRef uses direct access.
This means the user executing the query must have permission to access the referenced files.
If you are using a service account, the required Google Drive files or folders must be shared with that service account.
Unlike Cloud Storage ObjectRef, Google Drive does not support delegated access through a Cloud resource connection.
This distinction is important when designing applications that run scheduled queries or automated processing jobs.
Creating an ObjectRef From a Google Drive File
The first step is to create an ObjectRef value from a Google Drive file URL.
Suppose an organization stores a PDF report in Google Drive.
The file URL looks like this:
https://drive.google.com/file/d/FILE_ID
You can create its ObjectRef value using OBJ.MAKE_REF.
SELECT
OBJ.MAKE_REF(
'https://drive.google.com/file/d/FILE_ID'
) AS document_ref;
Replace FILE_ID with the actual ID of the Google Drive file.
The function returns a reference containing the file URI and associated reference information.
You can also use Google Workspace document URLs.
Supported URL formats include:
Google Drive file:
https://drive.google.com/file/d/FILE_ID
Google Drive open URL:
https://drive.google.com/open?id=FILE_ID
Google Docs:
https://docs.google.com/document/d/FILE_ID
Google Sheets:
https://docs.google.com/spreadsheets/d/FILE_ID
Google Slides:
https://docs.google.com/presentation/d/FILE_ID
The important point is that you should use a valid file URL rather than a personal Drive homepage or a Drive search URL.
Listing Google Drive Files With OBJ.LIST
Creating references manually is useful when you already know which files you want to process.
However, organizations often store hundreds or thousands of documents inside a shared folder.
In this situation, OBJ.LIST provides a more convenient approach.
It returns file metadata and ObjectRef values for files stored in a specified Google Drive folder.
Consider the following query:
SELECT
uri,
content_type,
size,
ref
FROM
OBJ.LIST(
'https://drive.google.com/drive/folders/FOLDER_ID'
);
Replace FOLDER_ID with the actual Google Drive folder ID.
The query returns information about the files found in the folder.
The main output columns include:
Column | Description |
|---|
uri | Google Drive URL of the file |
content_type | MIME type of the file |
size | File size |
ref | ObjectRef value representing the file |
The ref column is particularly important because it can be passed directly to supported AI functions.
Filtering Files by Type
A Google Drive folder may contain PDFs, images, spreadsheets, presentations, and other documents.
In many situations, processing every file is unnecessary.
You can filter the results using the content_type column.
For example, the following query returns PDF files only:
SELECT
uri,
content_type,
size,
ref
FROM
OBJ.LIST(
'https://drive.google.com/drive/folders/FOLDER_ID'
)
WHERE
content_type = 'application/pdf';
This is useful when building document-processing pipelines that work only with PDF reports.
You can also filter files using their names.
SELECT
uri,
JSON_VALUE(
ref.details,
'$.gdrive_metadata.file_name'
) AS file_name,
content_type,
size,
ref
FROM
OBJ.LIST(
'https://drive.google.com/drive/folders/FOLDER_ID'
)
WHERE
JSON_VALUE(
ref.details,
'$.gdrive_metadata.file_name'
) LIKE '%.pdf';
Here, JSON_VALUE extracts the file name from the metadata stored inside the ObjectRef details field.
This approach makes it easier to select files based on naming conventions.
Analyzing Google Drive Documents With AI.GENERATE
Listing files is only the first step.
The real advantage of ObjectRef becomes clear when it is combined with BigQuery AI functions.
AI.GENERATE allows developers to send instructions along with supported input data and receive generated results.
For example, suppose a company stores business reports in a Google Drive folder.
The requirement is to summarize each report and extract important information.
You can combine OBJ.LIST with AI.GENERATE.
SELECT
uri,
result.summary,
result.action_items
FROM (
SELECT
uri,
AI.GENERATE(
(
'Summarize this document and extract its key action items.',
ref
),
output_schema =>
'summary STRING,
action_items ARRAY<STRING>'
) AS result
FROM
OBJ.LIST(
'https://drive.google.com/drive/folders/FOLDER_ID'
)
WHERE
content_type NOT IN (
'application/vnd.google-apps.folder',
'application/vnd.google-apps.shortcut'
)
);
This query performs several operations.
First, OBJ.LIST discovers the files stored in the Google Drive folder.
Next, the WHERE condition removes folders and shortcuts. These entries are not ordinary document files and should not be passed to the AI function.
AI.GENERATE then receives two inputs:
The output schema requests two fields:
The result is a structured SQL output rather than one large text response.
This is useful when the extracted information needs to be stored in another table or consumed by a reporting application.
Extracting Specific Information From Google Drive Files
Document summarization is useful, but business applications often need specific fields rather than a general summary.
For example, an organization may want to extract information from invoices stored in Google Drive.
The required fields might include:
Invoice number
Customer name
Invoice date
Total amount
Payment status
AI.GENERATE can be used with an output schema to request these fields.
SELECT
uri,
invoice_details.invoice_number,
invoice_details.customer_name,
invoice_details.invoice_date,
invoice_details.total_amount
FROM (
SELECT
uri,
AI.GENERATE(
(
'Extract the invoice number, customer name,
invoice date, and total amount from this document.
Do not guess missing values.',
ref
),
output_schema =>
'invoice_number STRING,
customer_name STRING,
invoice_date STRING,
total_amount STRING'
) AS invoice_details
FROM
OBJ.LIST(
'https://drive.google.com/drive/folders/FOLDER_ID'
)
WHERE
content_type = 'application/pdf'
);
The query asks the model to identify specific invoice fields.
The extracted values can then be used for reporting, invoice tracking, and further SQL processing.
However, AI-generated extraction should not be treated as a replacement for financial validation. Important values such as invoice totals and payment information should be checked against the original document or validated through business rules.
For example, an application can verify whether the extracted invoice total matches the sum of its line items before accepting the record.
Working With Google Docs, Sheets, and Slides
One useful capability of Google Drive ObjectRef is that BigQuery can process supported Google Workspace documents without requiring developers to manually export each document first.
BigQuery automatically exports supported Workspace file types into formats suitable for AI processing.
Google Workspace File | Processing Format |
|---|
Google Docs | Markdown |
Google Slides | Plain text |
Google Sheets | CSV |
This makes it possible to analyze different types of business information using a common SQL workflow.
Analyzing Google Docs
Google Docs can contain project documentation, meeting notes, business requirements, and technical specifications.
You can create an ObjectRef for a Google Docs file and pass it to AI.GENERATE.
SELECT
result.summary,
result.key_points
FROM (
SELECT
AI.GENERATE(
(
'Summarize this document and identify its
most important technical points.',
OBJ.MAKE_REF(
'https://docs.google.com/document/d/FILE_ID'
)
),
output_schema =>
'summary STRING,
key_points ARRAY<STRING>'
) AS result
);
The query extracts a summary and a list of important technical points.
Analyzing Google Sheets
Google Sheets can contain sales information, product records, operational data, and customer feedback.
BigQuery exports the first tab of a Google Sheets document as CSV for AI processing.
For example:
SELECT
AI.GENERATE(
(
'Analyze this spreadsheet and summarize
the major business trends.',
OBJ.MAKE_REF(
'https://docs.google.com/spreadsheets/d/FILE_ID'
)
)
) AS spreadsheet_analysis;
This query asks the model to analyze the spreadsheet and return a summary.
One important limitation is that only the first tab is exported. If the required information is stored in another tab, prepare a separate source or use another suitable data-loading approach.
Analyzing Google Slides
Google Slides presentations are exported as plain text for AI processing.
This can be useful for extracting presentation summaries, project objectives, and key discussion points.
SELECT
AI.GENERATE(
(
'Summarize this presentation and identify
the main business objectives.',
OBJ.MAKE_REF(
'https://docs.google.com/presentation/d/FILE_ID'
)
)
) AS presentation_summary;
The model receives the exported textual content rather than an editable presentation object.
Understanding Google Drive ObjectRef Limitations
Before using this approach in production, developers should understand its current limitations.
Preview Availability
Google Drive ObjectRef is a preview feature and requires allowlist access.
Projects that are not enabled for the feature cannot assume that OBJ.LIST and OBJ.MAKE_REF will work with Google Drive URLs.
File Size Limit
When Google Drive files are passed to AI functions, the exported content must not exceed 7 MiB.
This applies to the exported representation of Google Workspace files, not necessarily their original stored size.
For binary files such as PDFs and images, the limit applies to the raw file size.
Folder Listing Limit
OBJ.LIST supports up to 10,000 files per Google Drive folder.
Folder listing is non-recursive, which means it does not automatically explore nested folders.
If documents are distributed across multiple folders, process each folder separately.
Shortcuts Are Not Automatically Resolved
Google Drive shortcuts appear with the MIME type application/vnd.google-apps.shortcut.
BigQuery does not automatically follow these shortcuts to their target files.
Filter them out before calling AI functions.
No Versioning Support
Google Drive ObjectRef does not support file versioning.
The latest available file content is used during processing.
If your application requires reproducible document analysis, maintain your own processing records and document snapshots.
Unsupported Workspace Files
Some Google Workspace file types cannot be exported for AI processing.
Examples include Google Drawings, Forms, Sites, Jamboard, and Apps Script files.
These files can produce row-level processing errors.
No Delegated Access
Unlike Cloud Storage ObjectRef, Google Drive ObjectRef does not support delegated access through a BigQuery Cloud resource connection.
The query user must have direct access to the Google Drive files.
These limitations should be considered before designing a large document-processing architecture.
ObjectRef vs. Traditional BigQuery External Tables
Developers may wonder why ObjectRef is useful when BigQuery already supports Google Drive external tables.
Both approaches provide access to external data, but they solve different problems.
Feature | Google Drive External Tables | Google Drive ObjectRef |
|---|
Main purpose | Query structured tabular data | Reference unstructured files |
Supported examples | CSV, JSON, Avro, Google Sheets | Documents, images, PDFs, audio, and other supported files |
SQL querying | Queries exposed table columns | Uses references with supported functions |
AI integration | Requires an appropriate AI-processing approach | Can pass references directly to supported AI functions |
File discovery | External table configuration | OBJ.LIST |
File reference | External table metadata | ObjectRef STRUCT |
Typical use case | Analyze spreadsheet records | Extract insights from documents and media |
If you want to query rows and columns from a CSV file or spreadsheet, an external table may be the better option.
If you want to analyze document content, images, or other unstructured files through AI functions, ObjectRef provides a more suitable approach.
Best Practices for Production Applications
Using ObjectRef can simplify document-processing pipelines, but production implementations still need proper data management and access controls.
Filter Files Before AI Processing
Do not pass every file returned by OBJ.LIST to an AI function.
Filter by MIME type, file name, and other available metadata.
This prevents unsupported files, folders, and shortcuts from entering the processing pipeline.
Maintain Processing Metadata
Store information such as the original file URI, file name, processing timestamp, query status, and extracted results.
This makes it easier to investigate failed processing jobs and understand which documents have already been analyzed.
Because Google Drive ObjectRef does not provide versioning, maintain an application-level strategy for tracking document changes.
Validate Extracted Information
AI-generated values should be validated before they are used in financial, legal, or operational systems.
For example, an extracted invoice amount should be checked against the source document and business validation rules.
Use Least-Privilege Access
Give users and service accounts access only to the Drive folders and documents they actually need.
Avoid sharing sensitive folders with broad groups simply to make a BigQuery query work.
Handle Row-Level Errors
A query may return successfully even when individual file-processing operations fail.
Inspect the status information returned by the AI function and record failed documents for investigation.
Do not assume that a successful query means every file was processed successfully.
Control Processing Costs
AI processing can become expensive when a folder contains thousands of large documents.
Start with a small set of files, filter unnecessary documents, and evaluate model usage before running large-scale queries.
For recurring workloads, consider processing only new or changed documents and maintaining the results in a standard BigQuery table.
Protect Sensitive Information
Google Drive documents may contain customer details, financial information, employee records, or confidential business data.
Review data access policies and organizational requirements before sending document content for AI processing.
Common Mistakes to Avoid
Assuming Google Drive ObjectRef Is Generally Available
Google Drive support requires preview allowlist access.
Verify that your project is enabled before building an application around it.
Using Incorrect Drive URLs
OBJ.LIST expects a folder URL in the following format:
https://drive.google.com/drive/folders/FOLDER_ID
Using a file URL for a folder can cause BigQuery to treat the folder as an individual object instead of listing its contents.
Expecting Recursive Folder Discovery
OBJ.LIST does not automatically explore nested folders.
If your documents are stored in multiple directory levels, process the required folders separately.
Forgetting to Filter Shortcuts
Shortcuts are returned as separate entries and are not resolved automatically.
Remove them before passing references to AI functions.
Assuming All Google Sheets Tabs Are Processed
BigQuery exports only the first tab of a Google Sheets document for AI processing.
Applications that depend on multiple tabs should account for this limitation.
Treating AI Output as Verified Business Data
AI-generated information may contain incorrect or incomplete values.
Always apply validation before using extracted results in business-critical workflows.
Troubleshooting Common Issues
Problem | Possible Cause | Solution |
|---|
Google Drive URL is rejected | Incorrect URL format | Use a supported Google Drive file or folder URL |
Access denied | Query user lacks Drive permissions | Grant the required viewer access |
ObjectRef feature is unavailable | Project is not allowlisted | Request preview access |
Folder listing returns unexpected results | File URL used instead of folder URL | Use the correct Drive folder URL |
AI processing fails for some files | Unsupported file type or file size | Check MIME type and the 7 MiB limit |
Shortcuts cause processing errors | Shortcuts are not resolved | Filter shortcut MIME types |
Nested documents are missing | Folder listing is non-recursive | Query nested folders separately |
Google Sheets data is incomplete | Required information is on another tab | Prepare a separate export or use another data-loading method |
Document extraction returns errors | Insufficient file permissions or unsupported Workspace format | Verify access and file compatibility |
When troubleshooting, check both the BigQuery query execution status and the individual AI function results.
Summary
Google BigQuery ObjectRef provides a way to work with unstructured files stored outside BigQuery, including documents, images, and other supported content.
By combining OBJ.MAKE_REF and OBJ.LIST with AI.GENERATE, developers can discover Google Drive files, reference their contents, and extract useful information directly through SQL.
In this article, we explored how to create ObjectRef values, list files from Google Drive folders, filter documents, summarize reports, extract invoice information, and process Google Docs, Sheets, and Slides.
We also covered important limitations, including preview availability, direct access permissions, file size restrictions, non-recursive folder listing, and the absence of delegated access and versioning for Google Drive.
For organizations that maintain large collections of business documents, ObjectRef can simplify the process of connecting unstructured information with analytical workflows.
The most practical approach is to use traditional BigQuery tables for structured information and ObjectRef for external documents and media. This allows developers to combine SQL, external file references, and AI-powered extraction without building a separate download and document-processing pipeline for every use case.
Join the conversation! Your thoughts help the community grow.