A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://developers.google.com/bigquery/docs/reference/standard-sql/bigqueryml-syntax-translate below:

The ML.TRANSLATE function | BigQuery

Stay organized with collections Save and categorize content based on your preferences.

The ML.TRANSLATE function

This document describes the ML.TRANSLATE function, which lets you translate text stored in BigQuery tables by using the Cloud Translation API.

Syntax
ML.TRANSLATE(
  MODEL `PROJECT_ID.DATASET.MODEL`,
  { TABLE `PROJECT_ID.DATASET.TABLE` | (QUERY_STATEMENT) },
  STRUCT('MODE_NAME' AS translate_mode [, 'TARGET_LANGUAGE_CODE' AS target_language_code ])
)
Arguments

ML.TRANSLATE takes the following arguments:

Output

ML.TRANSLATE returns the input table plus the following columns:

Quotas

See Cloud AI service functions quotas and limits.

Known issues

Sometimes after a query job that uses this function finishes successfully, some returned rows contain the following error message:

A retryable error occurred: RESOURCE EXHAUSTED error from <remote endpoint>

This issue occurs because BigQuery query jobs finish successfully even if the function fails for some of the rows. The function fails when the volume of API calls to the remote endpoint exceeds the quota limits for that service. This issue occurs most often when you are running multiple parallel batch queries. BigQuery retries these calls, but if the retries fail, the resource exhausted error message is returned.

To iterate through inference calls until all rows are successfully processed, you can use the BigQuery remote inference SQL scripts or the BigQuery remote inference pipeline Dataform package.

Locations

ML.TRANSLATE must run in the same region as the remote model that the function references. For more information about supported locations for models based on the Cloud Translation API, see Locations for remote models.

Example

Example 1

The following example applies text translation on the column name text_content on the bq table mybqtable in mydataset to Chinese.

# Create model
CREATE OR REPLACE MODEL
`myproject.mydataset.mytranslatemodel`
REMOTE WITH CONNECTION `myproject.myregion.myconnection`
OPTIONS (remote_service_type = 'cloud_ai_translate_v3')
# Translate text
SELECT * FROM ML.TRANSLATE(
  MODEL `mydataset.mytranslatemodel`,
  TABLE `mydataset.mybqtable`,
  STRUCT('translate_text' AS translate_mode, 'zh-CN' AS target_language_code));

The output is similar to the following:

ml_translate_result  | ml_translate_status | text_content |
------- | -------- | --------
{"glossary_translations":[],"translation_memory_translations":[],"translations":[{"detected_language_code":"en","translated_text":"苹果"}]} | | apple

Example 2

The following example translates the text in the column text_content in the table mybqtable to Chinese, and parses the JSON results into separate columns.

# Translate text and parse the json
CREATE TABLE
  `mydataset.translate_result` AS (
  SELECT
    STRING(ml_translate_result.translations[0].detected_language_code) AS `Original Language`,
    text_content AS `Original Text`,
    "zh-CN" AS `Destination Language`,
    STRING(ml_translate_result.translations[0].translated_text) AS Translation,
    ml_translate_status as `Status`
  FROM ML.TRANSLATE(
    MODEL `mydataset.mytranslatemodel`,
    TABLE `mydataset.mybqtable`,
    STRUCT('translate_text' AS translate_mode, 'zh-CN' AS target_language_code)));

SELECT * FROM `mydataset.translate_result`;

The output is similar to the following:

Original Language  | Original Text | Destination Language | Translation  |  Status  |
------- | -------- | -------- | -------- | --------
en  |  apple  |  zh-cn. |  苹果   | |

If you get an error like query limit exceeded, you might have exceeded the quota for this function, which can leave you with unprocessed rows. Use the following query to complete processing the unprocessed rows:

CREATE TABLE
  `mydataset.translate_result_next` AS (
  SELECT
    STRING(ml_translate_result.translations[0].detected_language_code) AS `Original Language`,
    text_content AS `Original Text`,
    'zh-CN' AS `Destination Language`,
    STRING(ml_translate_result.translations[0].translated_text) AS Translation,
    ml_translate_status as `Status`
  FROM ML.TRANSLATE(
    MODEL `mydataset.mytranslatemodel`,
    (SELECT `Original Text` AS text_content
     FROM `mydataset.translate_result`
     WHERE Status != ''),
    STRUCT('translate_text' AS translate_mode, 'zh-CN' AS target_language_code)));

SELECT * FROM `mydataset.translate_result_next`;
What's next

Except as otherwise noted, the content of this page is licensed under the Creative Commons Attribution 4.0 License, and code samples are licensed under the Apache 2.0 License. For details, see the Google Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.

Last updated 2025-08-07 UTC.

[[["Easy to understand","easyToUnderstand","thumb-up"],["Solved my problem","solvedMyProblem","thumb-up"],["Other","otherUp","thumb-up"]],[["Hard to understand","hardToUnderstand","thumb-down"],["Incorrect information or sample code","incorrectInformationOrSampleCode","thumb-down"],["Missing the information/samples I need","missingTheInformationSamplesINeed","thumb-down"],["Other","otherDown","thumb-down"]],["Last updated 2025-08-07 UTC."],[[["The `ML.TRANSLATE` function enables the translation of text within BigQuery tables using the Cloud Translation API."],["This function requires a remote model with a `REMOTE_SERVICE_TYPE` of `CLOUD_AI_TRANSLATE_V3`, and a specified BigQuery table or query containing a `text_content` column for analysis."],["Users can select from translation modes like `TRANSLATE_TEXT` or `DETECT_LANGUAGE`, with `TRANSLATE_TEXT` needing a target language code."],["The function returns a `JSON` value in `ml_translate_result`, containing the translation, and a status in `ml_translate_status`."],["Exceeding quotas can lead to `resource exhausted` errors for some rows, which may require the use of BigQuery remote inference SQL scripts or Dataform packages for full processing."]]],[]]


RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4