user-defined-functions

Using UDF in SELECT statement

寵の児 提交于 2019-12-12 20:55:58
问题 I made a user-define function for business hours calculation. This is my UDF. CREATE FUNCTION fn_GetBusinessHour (@date datetime, @addHours int) RETURNS datetime AS BEGIN DECLARE @CalcuatedDate datetime; DECLARE @addDayCount int, @addHourCount int, @addMinCount int; SET @addDayCount = @addHours / 8.5; SET @addHourCount = @addHours - (@addDayCount * 8.5); SET @addMinCount = @addHours - (@addDayCount * 8.5) - @addHourCount; IF(@addDayCount != 0) SET @CalcuatedDate = DATEADD(DD, @addDayCount,

How to debug mysql user-defined function?

﹥>﹥吖頭↗ 提交于 2019-12-12 19:11:32
问题 I have a mysql function, i want to debug it, set breakboints, see variables values on that time period etc. How to do it ? 回答1: You cannot debug UDF function when it is called by MySQL. But I think you can try these variants: debug your functions without MySQL, just pass test parameter values into function. try to output values into the file when UDF is called, this will help you to view internal variables and understand what is happen. 回答2: From my current search so far (though I might have

Creating a User Defined function in Stored Procedure in SQL 2005

邮差的信 提交于 2019-12-12 18:36:17
问题 I have a stored procedure in which i want to create a user defined function - Split (splits a string separated with delimiters and returns the strings in a table), make use of the function and finally drop the function. My question is that whether i can create a user defined function inside a stored procedure and drop it finally? Thank you. Regards NLV 回答1: Technically...yes you could but that does not mean you should. You would have to be careful about avoiding GO statements (just use Exec

SQL Server 2008 Updating VarChar Column with a UDF?

馋奶兔 提交于 2019-12-12 17:25:50
问题 I have a scalar function that takes a two variables @input1 @input2 and it returns the value of @input1 and @input2 (actual thing is more complex but this distills the idea). I want to update all rows in a table column using this function, passing the value 'abc ' for @input1 and using the column name in @input2, so my update statement would look something like: update mytable set mycolumn = (select dbo.myfunc( 'abc ' , mycolumn ) ) -- prepend the literal 'abc ' to every row for column

Why SQL functions are faster than UDF

☆樱花仙子☆ 提交于 2019-12-12 16:13:38
问题 Though it's a quite subjective question but I feel it necessary to share on this forum. I have personally experienced that when I create a UDF (even if that is not complex) and use it into my SQL it drastically decrease the performance. But when I use SQL inbuild function they happen to work pretty faster. Conversion , logical & string functions are clear example of that. So, my question is "Why SQL in build functions are faster than UDF"? and it would be an advantage if someone can guide me

How to access custom UDFs through Spark Thrift Server?

依然范特西╮ 提交于 2019-12-12 16:10:02
问题 I am running Spark Thrift Server on EMR. I start up the Spark Thrift Server by: sudo -u spark /usr/lib/spark/sbin/start-thriftserver.sh --queue interactive.thrift --jars /opt/lib/custom-udfs.jar Notice that I have a customer UDF jar and I want to add it to the Thrift Server classpath, so I added --jars /opt/lib/custom-udfs.jar in the above command. Once I am in my EMR, I issued the following to connect to the Spark Thrift Server. beeline -u jdbc:hive2://localhost:10000/default Then I was able

Create a User defined function like SQL server 2017 STRING_AGG on earlier versions

假装没事ソ 提交于 2019-12-12 15:39:46
问题 I try to create a generic function that can be used like this example of using the new string_agg built-in function on SQL Server 2017 the inside implementation can be something like the follow with tbl as( select a.Id, c.Desc from TableA a join TableB b on b.aId = a.Id join TableC c on c.Code = b.bCode ) select distinct ID , STUFF(( select ', ' + Desc from tbl t where t.ID = tbl.ID for xml path(''),TYPE).value('.','VARCHAR(MAX)'),1,2,'') Desc from tbl But how to receives the field key, the

“Catching” Errors from within a user defined function in SQL Server 2005

纵饮孤独 提交于 2019-12-12 15:07:36
问题 I have a function that takes a number as an input and converts it to a date. This number isn't any standard form of date number, so I have to manually subdivide portions of the number to various date parts, cast the date parts to varchar strings and then, concatenate and cast the strings to a new datetime object. My question is how can I catch a casting failure and return a null or low-range value from my function? I would prefer for my function to "passively" fail, returning a default value,

Is there a way to call a function defined using `val` in Scala with the whole curly brace block as an argument and not the final result of that block? [duplicate]

大城市里の小女人 提交于 2019-12-12 11:30:25
问题 This question already has an answer here : scala By-name parameter on a anonymous function (1 answer) Closed 5 months ago . I know that if we want to pass a block of code in curly braces as an argument to functions defined using def , we can write: def run(func: => Unit) { func } run { print(1) println(2) } // prints 12 But is there a way to achieve the same style with an anonymous function? I have tried the following: val v: (()=>Unit) => Unit = ( w: ()=> Unit) => { w() } v( () => { println

Apache Spark UDF that returns dynamic data types

孤街浪徒 提交于 2019-12-12 11:16:36
问题 I have UDF that processes JSON and returns dynamic data results per row. In my case I need this to validate data and return validated data. The schema is flexible for each row. This means I cannot create case class for every case (some of my data can be nested). I've tried to return tuple from my UDF function, but I had no luck in this either (because I needed to convert from list to tuple), and I didn't find an elegant solution for that. The data types that I'm returning are String , Integer