Skip to content

Instantly share code, notes, and snippets.

@ducnh1022
Created March 28, 2026 05:04
Show Gist options
  • Select an option

  • Save ducnh1022/3ebf826936daf031c1d9ac034311ae62 to your computer and use it in GitHub Desktop.

Select an option

Save ducnh1022/3ebf826936daf031c1d9ac034311ae62 to your computer and use it in GitHub Desktop.
-- handle string float, numeric, integer
SAFE_CAST(
REGEXP_REPLACE(col, r"[^0-9eE+\\-\\.]", "")
AS FLOAT64)
-- handle string boolean
CASE
WHEN col IS NULL THEN NULL
WHEN LOWER(TRIM(col)) IN ("true", "1", "yes", "y", "t") THEN TRUE
WHEN LOWER(TRIM(col)) IN ("false", "0", "no", "n", "f") THEN FALSE
ELSE NULL
END
-- data profiling string pattern report
REGEXP_REPLACE(
REGEXP_REPLACE(your_column, r'\d+', '0'),
r'[A-Za-z]+', 'a'
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment