[ Web Proxy ]
URL:
Viewing: https://docs.cloud.google.com/bigquery/docs/reference/standard-sql/bigqueryml-syntax-hash-bucketize [Back]  [Original]

The ML.HASH_BUCKETIZE function  |  BigQuery  |  Google Cloud Documentation Skip to main content
Google Cloud Documentation [Google Cloud Documentation]
Send feedback Stay organized with collections Save and categorize content based on your preferences.

The ML.HASH_BUCKETIZE function

This document describes the ML.HASH_BUCKETIZE function, which lets you convert a string expression to a deterministic hash and then bucketize it by the modulo value of that hash.

You can use this function with models that support manual feature preprocessing. For more information, see the following documents:

Syntax

ML.HASH_BUCKETIZE(string_expression, hash_bucket_size)

Arguments

ML.HASH_BUCKETIZE takes the following arguments:

Output

ML.HASH_BUCKETIZE returns an INT64 value that identifies the bucket.

Example

The following example bucketizes string expressions into three buckets:

SELECT
  f, ML.HASH_BUCKETIZE(f, 3) AS bucket
FROM UNNEST(['a', 'b', 'c', 'd']) AS f;

The output looks similar to the following:

+---+--------+
| f | bucket |
+---+--------+
| a |   0    |
+---+--------+
| b |   1    |
+---+--------+
| c |   1    |
+---+--------+
| d |   2    |
+------------+

What's next

Send feedback

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 2026-08-11 UTC.

Need to tell us more? [[["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 2026-08-11 UTC."],[],[]]

Web Proxy Viewer  |  New URL  |  Original Page