Questions tagged [user-defined-functions]

A function provided by the user of a program or an environment most often for spreadsheet type applications or database applications. Use [custom-functions-excel] for Excel and [custom-function] for Google sheets. Specify a programming language tag as well: [google-apps-script], [javascript], [sql], [tsql], etc. as well as a tag for the application: [excel], [google-spreadsheet], [sql-server] etc.

In the context of a programming language or an environment, a User Defined Function (UDF) is a function that is created by a user to perform a specific task (as opposed to a function that is intrinsic to the environment, built into the programming language or environment).

Spreadsheet applications like Excel and Google Sheets calls these "custom functions".

Microsoft also uses the term User Defined Functions with . The tag may also be applicable. See What is the need for user-defined functions in SQL Server?

Use:

4875 questions
1
vote
1 answer

pyspark job with udf posting data at rest api

I am facing some performance issue with one of pyspark udf function that post data to REST API(uses cosmos db to store the data). # The spark dataframe(df) contains near about 30-40k data. # I am using python udf function to post it over rest api: …
1
vote
1 answer

How to create a BigQuery UDF function to UNNEST multiple REPEATED levels?

Background: I have a BigQuery schema with several REPEATED levels and trying create UDF functions to facilitate querying. Able to handle 1 level: when I'm dealing with only 1 REPEATED level I'm able to write the below UDF function which…
Max
  • 12,794
  • 30
  • 90
  • 142
1
vote
3 answers

VBA how to check if three values are the same, excluding cells that are blank?

I have been racking my brain around the best way to check if the cell value in three cells are exactly the same. However, the tricky part is that any one of these three cells can be blank. I have not found a simple solution that does not require a…
1
vote
0 answers

Correct way of using sys._xoptions to get the import directory in Snowflake Python UDTF?

I'm working on creating a Snowflake User-defined table function (UDTF) in Python. I want my UDTF to read an ML model from a file. I'm following this very helpful blog…
stys
  • 707
  • 7
  • 23
1
vote
7 answers

How can I optimize this horrendously inefficient User Defined Function in SQL Server 08

Is there anyway to optimize this horrible inefficient UDF in SQL Server 08. I am fairly new to UDF's and especially looking at them for optimizations. UPDATE: Should I be sending a column to a function like this if I wanted to perform it on each…
kevin bailey
1
vote
1 answer

How to use JS function in UDF BigQuery when checking file exists in Google Cloud Storage

I'd like to use JS function in BigQuery when checking if file exists in Google Cloud Storage. But BigQuery kept showing error when **select UDF_FUNCTION_NAME() ** ReferenceError: require is not defined at My JS code is like this. BUCKET PATH is…
1
vote
3 answers

sql function to return table of names and values given a querystring

Anyone have a t-sql function that takes a querystring from a url and returns a table of name/value pairs? eg I have a value like this stored in my database: foo=bar&baz=qux&x=y and I want to produce a 2-column (key and val) table (with 3 rows in…
Rory
  • 40,559
  • 52
  • 175
  • 261
1
vote
1 answer

PySpark custom UDF ModuleNotFoundError

Running into the following error when use custom UDF Traceback (most recent call last): File "/usr/local/lib/python3.8/dist-packages/pyspark/worker.py", line 603, in main func, profiler, deserializer, serializer = read_udfs(pickleSer, infile,…
1
vote
1 answer

UDF's in Excel add-in

I have an add-in which defines a User Defined Formula (checks regular expression matching) in Excel in which it will be used to in cells custom validation. Assume user A has the add-in installed and user B doesn't have the add-in. Thus, if user A…
FAF
  • 113
  • 4
1
vote
0 answers

Iterating over Column object of a dataframe in a UDF function and store data during iteration in a dictionary

I'm new to PySpark and UDF. I have a dataframe and I want to iterate over multiple columns (Each column in original DF is Column object) and use a UDF to store data in a dictionary. I have written the below code, but nothing gets stored in the…
1
vote
1 answer

How to take data from nested JSON data in bigquery

I have table with column field as follow : { "Quantity":{ "id_1":1, "id_2":4, }, "Discount" : { "id_1":2, "id_2":1, }, "sales":{ "id_1":{ "price":50, "quantity":1 }, "id_2":{ "quantity":1, …
1
vote
0 answers

How best to determine JSON null Variant in a Java UDF?

In a Java UDF I want to determine whether a Variant value is a JSON null but it seems the only way to do it is to convert it to a Json String and compare it to the string "null". Since I am working with values that may be very large, converting the…
Felipe Hoffa
  • 54,922
  • 16
  • 151
  • 325
1
vote
1 answer

Executing UDF ( User Defined function ) containing a Node module in Cosmos Db

I have created a UDF function to process some content based on dates in Azure cosmos database. The function looks like below function userDefinedFunction(array,dateString){ var moment = require('moment'); const startDate =…
1
vote
1 answer

running sql queries inside a Snowpark UDF (cannot pickle '_thread.lock')

I want to create a Snowflake Snowpark UDF which returns a single value. However, to converge to this value, I want to run a SQL query inside the function and iterate over the resultant rows. My code looks something like this: @udf(.....) def…
1
vote
1 answer

Azure Databrickd:- PythonException: 'RuntimeError: The length of output in Scalar iterator pandas UDF should be the same with the input's;

Env : Azure Databricks Cluster : 11.3 LTS (includes Apache Spark 3.3.0, Scala 2.12) I have pandas_udf, its working for 4 rows, but I tried with more than 4 rows getting below error. PythonException: 'RuntimeError: The length of output in Scalar…