UDF not found despite declaration as Resources :(

72 views
Skip to first unread message

Jerome Massot

unread,
Sep 4, 2019, 12:05:28 PM9/4/19
to Google Cloud Developers
Dear all,

I have the following issue : I have created a UDF, added it in a list of UDF resources and declared a custom job config including this new udf resources.

from google.cloud.bigquery.query import UDFResource
from google.cloud.bigquery.job import QueryJobConfig

edit_distance = """
CREATE TEMP FUNCTION HammingDistance(a STRING, b STRING) AS (
...
);
"""

# add the user defined function as resources and create a query job config
udf_function_resources = UDFResource('inlineCode', edit_distance)
custom_job_config = QueryJobConfig()
custom_job_config.udf_resources = [udf_function_resources]

I create the following SQL query string :
unitary_query = "SELECT CHUNK_ID, LABEL, TEXT, START_OFFSET, END_OFFSET from " + entities_table + " WHERE LABEL='" + label + "' AND HammingDistance(LOWER(TEXT), '" + attribute +"') < 2"

And try it in BigQuery client:
unitary_query = bq_client.query(unitary_query, job_config=custom_job_config)
    bq_results = unitary_query.result()

But, I have the following error:
BadRequest: 400 Function not found: HammingDistance at [1:143]

Thanks for help

Best regards

Jerome

Ismail (Cloud Platform Support)

unread,
Sep 19, 2019, 1:55:54 PM9/19/19
to Google Cloud Developers

The 400 error could be due to resourceExceeded. It is always recommended to follow the best practices for JavaScript UDFs


I further recommend that you submit a BigQuery Public Issue report with the BigQuery engineering team to investigate this issue with the exact reproduction steps.

Reply all
Reply to author
Forward
0 new messages