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

How do I change the default value of a dropdown field based on a button in Power Apps?

On my home screen in Powerapps, I have 8 buttons. Each button states a category. What I want is that by selecting a certain button it makes the value automatically be filled in on the dropdown field of categories on the next page. I have already…
1
vote
2 answers

Table-Valued User-Defined Function parameter used for IN clause

How can I create a Table-Valued User-Defined Function in SQL Server that takes an input parameter for an IN clause? I'm trying to write this very simple function: CREATE FUNCTION dbo.MyTableValuedFunction (@myList VARCHAR(MAX)) RETURNS @myTable…
1
vote
1 answer

Snowflake UDF with Array Input Parameter

I am creating a new SQL UDF in Snowflake and UDF is created successfully. But when I am passing value while calling the UDF, I am getting below error. 001044 (42P13): SQL compilation error: error line 1 at position 20. Invalid argument types for…
1
vote
0 answers

Hanging Task in Databricks

I am applying a pandas UDF to a grouped dataframe in databricks. When I do this, a couple tasks hang forever, while the rest complete quickly. I start by repartitioning my dataset so that each group is in one partition: group_factors = ['a','b','c']…
1
vote
1 answer

PySpark execute SQL from within a UDF

I have a PySpark DF like below (all in Databricks Notebook): +-------+--------------------------+------+----------+ |city |brand |weight|date | +-------+--------------------------+------+----------+ |Dallas |['BMW',…
user1717931
  • 2,419
  • 5
  • 29
  • 40
1
vote
0 answers

How tu mock EF.Functions.ILike during Unit Tests by EF's user defined function mapping

I have changed current code _context.TABLE.Where(x => x.COLUMN1.Contains("xxx") || x.COLUMN2.Contains("xxx")) into _context.TABLE.Where(x => EF.Functions.ILike(x.COLUMN1, "%xxx%") || EF.Functions.ILike(x.COLUMN2, "%xxx%"))) This get me what I…
1
vote
1 answer

Dynamic Data Validation

I was wondering if anyone has a better idea of how to return a tag's properties, than the UDF method shown below. Tags are listed in Column B and the properties in Column C. The code below works but is a bit slow. After being called from a cell…
Martin
  • 69
  • 6
1
vote
0 answers

Apache Iceberg bug MERGE INTO PySpark with UDF causes: `Cannot generate code for expression`

I have encountered a major bug with MERGE INTO in Spark when writing into Apache Iceberg format using a python UDF. The problem is that when the column that is used in the ON clause of MERGE INTO has been affected by a UDF, the merge throws an…
thijsvdp
  • 404
  • 3
  • 16
1
vote
1 answer

Is SQL Server able to reuse execution plans for functions when types differ in a meaningless way? Or is that only true of stored procedures?

Consider the following queries on a user-defined inline-table-valued function, foo, which has one parameter, @bar varchar(MAX): DECLARE @Long nvarchar(500) SELECT * FROM foo(@long) DECLARE @Short varchar(5) SELECT * FROM foo(@Short) Suppose that…
1
vote
1 answer

MySQL 8.0 STR_TO_DATE behaves differently when wrapped into user defined function

I am preparing a dataload from a temporary table containing pretty many columns. I decided to wrap some calls to system functions into UDF functions to be able to trim some behaviors in one shot and avoid nasty copy-pasting. Now I got stuck on a…
Kuba D
  • 93
  • 1
  • 7
1
vote
0 answers

Call python image function in pyspark

Trying to navigate the waters between python and pyspark, I have a function for rotating images written in python: from PIL import Image def rotate_image(image, rotation_angle): im = Image.open(image) out = im.rotate(rotation_angle, expand =…
1
vote
1 answer

using column names as a function argument in user-defined function in R

id <- 1:30 math<-rnorm(30,1,10) history<-rnorm(30,1,10) data<-data.frame(id,math,history) For example I want to make a function that generate one column without using {{}} or tidy evaluation. I want to use standard…
Tube
  • 177
  • 5
1
vote
1 answer

how to not use require() in my user-defined function in R

This is reproducible minimal dataset and function because it is not the point. my real function is very complicated but that's not the point in here. id <- 1:30 x<-rnorm(30,1,10) y<-rnorm(30,1,10) data<-data.frame(id,x,y) try<-function(data, …
Tube
  • 177
  • 5
1
vote
2 answers

How do I write a Pyspark UDF to generate all possible combinations of column totals?

I have the following code which creates a new column based on combinations of columns in my dataframe, minus duplicates: import itertools as it import pandas as pd df = pd.DataFrame({ 'a': [3,4,5,6,3], 'b': [5,7,1,0,5], 'c': [3,4,2,1,3], …
jack homareau
  • 319
  • 1
  • 8
1
vote
1 answer

user defined R function that use column names as an argument

set.seed(2023) pid <- 1:30 y1 <- rnorm(30, 10, 10) y2 <- rnorm(30, 10, 10) x1 <- rnorm(30, 5, 2) x2 <- rnorm(30, 5, 2) x3 <- rnorm(30, 300, 3) This is minimal reproducible data. I want to make a function as below. try <- function(data, a, b) { …
Tube
  • 177
  • 5