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
0 answers

Refresh MYSQL UDF

I am trying to use my own UDF (written in c++) as a mysql extension. I was able to install the function via CREATE FUNCTION decrypt RETURNS STRING SONAME "libudf_func.so"; and use it. I could also drop the function via DROP FUNCTION…
Carlotta
  • 11
  • 3
1
vote
2 answers

Matching vocabulary elements to indices from LDA Model using PySpark

I'd like to take a Spark LDA Model's term indices from the .describeTopics() output and match them to the appropriate term in the count vectorizer's vocabulary. Here is the point of friction: terms = ['fuzzy', 'wuzzy', 'bear', 'seashells', 'chuck',…
1
vote
0 answers

Speeding up a User Defined Function in Python

I have defined this function: def RCP(row): ### This function is what we use to predict the total number of purchases our customers will make over the ### remainder of their lifetime as a customer. For each row in the dataframe, we iterate…
1
vote
1 answer

VBA Array repetition

I am trying to make a function that takes in 3 values, and outputs that many of three different numbers in array format (in this case 1,2,4). For example: EntryArray(1,2,1) would output vertically: 1,1,2,2,2,4,4. However, it should repeat this array…
Gabriel
  • 13
  • 3
1
vote
0 answers

df.show() fails with java.lang.IllegalStateException on pyspark

I am working on approx 9mn rows - applying a pyspark UDF on each of them which blows up the data to 2bn rows. I am then grouping the resultant dataframe which results in 64mn rows (fc_ss below grouped to fc_agg). When I do fc_agg.show() I get an…
1
vote
2 answers

'Undefined function' when using DAO QueryDef in VBA

I'm assigning an Access 2007 query to a QueryDef in Excel VBA. My query calls a user-defined function, because it performs a calculation on the results of evaluating a field with a regular expression. I'm using a QueryDef because I'm collecting…
sigil
  • 9,370
  • 40
  • 119
  • 199
1
vote
2 answers

PySpark UDF issues when referencing outside of function

I facing the issue that I get the error TypeError: cannot pickle '_thread.RLock' object when I try to apply the following code: from pyspark.sql.types import * from pyspark.sql.functions import * data_1 =…
1
vote
2 answers

Executing sql from a javascipt UDF

I have a snowflake table being used to store records of sql being executed by a stored procedure and any error messages. The records in this table are being saved as a string with special chars escaped with javascripts escape('log') function. I then…
1
vote
1 answer

While compiling Snowflake UDF getting error SQL Error [1003] [42000]: SQL compilation error: syntax error line 7 at position 31 unexpected '{'

I want the table names in a string variable Object_List as below Object_List=('Table1,Table2,Table3) and want the output as a Table of Values RowNo TableName 1 Table1 2 Table2 3 Table3. The code giving error is as below: CREATE OR…
1
vote
1 answer

Cannot create UDFs returning "Table" in Snowflake - compilation error

USE AGDWHDEV.EDW_WEATHER; -- My database and schema CREATE OR REPLACE function EDW_WEATHER.find_nearest_radar() returns table (LATITUDE number, LONGITUDE number) as 'SELECT 1 LATITUDE, 1 LONGITUDE'; -- The function compiled successfully but…
1
vote
1 answer

r function: multiple linear regression prediction estimate and interval (user-defined function)

I am working on a user-defined function in r to calculate prediction estimate and intervals from a linear regression at 95%. I have a function which replicates the predict.lm() function fit and interval. However when applied to multiple linear…
1
vote
2 answers

Snowflake UDF execution time limit

I've got an error when calling a UDF when the amount of data get increased: Database Error in model test_model (models/prep/test_model.sql) 100132 (P0000): JavaScript execution error: UDF execution time limit exceeded by function IMAGE_URL …
1
vote
1 answer

Is it a good practice to create a stored procedure that creates a user-defined function...?

I'm analyzing a fellow developer's SQL code and I could be totally wrong, but something they've done doesn't seem good to me. The design is for a dynamic expression builder. The expressions are stored using a few tables and the system works. The…
1
vote
1 answer

Call nls from within a function in R, passing a user-specified function with any number of arguments

I have a function that uses stats::nls() internally to get parameter estimates for a non-linear model. However, the number of parameters I need the function to estimate is variable and determined by the users. How can I do this? This function is…
1
vote
1 answer

How to return 0 if null from UDF in Snowflake

I am writing user defined functions in Snowflake and doing some SELECT in the functions. I need to return 0 if select returns NULL. In the below example if there is no rid available from tableA, function is returning NULL, but i need my function to…