Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Document the fast SQL method of creating all UDFs required by BigQuery Migration Service for SQL Translation #467

Open
danieldeleo opened this issue Oct 21, 2024 · 0 comments · May be fixed by #479
Assignees
Labels
documentation Improvements or additions to documentation

Comments

@danieldeleo
Copy link
Collaborator

danieldeleo commented Oct 21, 2024

-- SET YOUR DESIRED BQ REGION BELOW
SET @@location="us-east4";
/**********************************
 * DO NOT EDIT SQL BELOW THIS LINE
 **********************************/
DECLARE YOUR_PROJECT_ID STRING DEFAULT(@@project_id);
DECLARE YOUR_REGION STRING DEFAULT(@@location);
DECLARE region_suffix STRING DEFAULT(
  IF(YOUR_REGION="US", "", "_" || REPLACE(YOUR_REGION, "-", "_"))
);
-- Get regional UDFs
DECLARE cw_udf_ddls ARRAY<STRING>;
EXECUTE IMMEDIATE 
FORMAT("""
  SELECT ARRAY_AGG(ddl ORDER BY created) AS cw_udf_ddls
  FROM bqutil.fn%s.INFORMATION_SCHEMA.ROUTINES
  WHERE specific_name LIKE "cw_%%"
  """,
  region_suffix
)
INTO cw_udf_ddls;
-- Creates the fn dataset within your project
EXECUTE IMMEDIATE "CREATE SCHEMA IF NOT EXISTS " || YOUR_PROJECT_ID || ".fn" || region_suffix;
-- Creates all cw_* UDFs within your new fn dataset
FOR cw_udf_ddl IN (SELECT * FROM UNNEST(cw_udf_ddls) ddl)
DO EXECUTE IMMEDIATE REPLACE(REPLACE(cw_udf_ddl.ddl, "bqutil", YOUR_PROJECT_ID), "CREATE ", "CREATE OR REPLACE ");
END FOR;
@afleisc afleisc added the documentation Improvements or additions to documentation label Nov 21, 2024
@danieldeleo danieldeleo self-assigned this Feb 26, 2025
@danieldeleo danieldeleo linked a pull request Feb 26, 2025 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
documentation Improvements or additions to documentation
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants