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
Labels
documentation Improvements or additions to documentation

Comments

@danieldeleo
Copy link
Collaborator

-- REPLACE VARIABLE BELOW WITH YOUR OWN PROJECT 
DECLARE YOUR_PROJECT_ID STRING DEFAULT("YOUR_OWN_PROJECT_ID_HERE");
-- REPLACE VARIABLE BELOW WITH YOUR BQ REGION 
DECLARE YOUR_REGION STRING DEFAULT("us-east4");
/**********************************
 * DO NOT EDIT SQL BELOW THIS LINE
 **********************************/
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;
-- Create the fn dataset with your project
EXECUTE IMMEDIATE "CREATE SCHEMA IF NOT EXISTS " || YOUR_PROJECT_ID || ".fn" || region_suffix;
-- Create all cw_* UDFs within your new fn dataset
FOR cw_udf_ddl IN (SELECT * FROM UNNEST(cw_udf_ddls) ddl)
DO EXECUTE IMMEDIATE REPLACE(cw_udf_ddl.ddl, "bqutil", YOUR_PROJECT_ID);
END FOR;
@afleisc afleisc added the documentation Improvements or additions to documentation label Nov 21, 2024
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

No branches or pull requests

2 participants