user-defined-functions

Use a UDF as the default value in a table column in SQL Server

独自空忆成欢 提交于 2019-12-31 01:47:54
问题 I created a scaler UDF (called sCurrentAppUser()) in SQL Server 2012 Express and I would like to use this UDF as a default value when defining a table. But every time I try, I get an error of "'sCurrentAppUser' is not a recognized built-in function name." Since I can't post more than two links yet (reputation), I'll link to my research and references in a comment. Here's my UDF: ALTER FUNCTION [dbo].[sCurrentAppUser] () RETURNS nVarChar(128) AS BEGIN DECLARE @CurrentAppUser nVarChar(128) IF

How to send each group at a time to the spark executors?

六月ゝ 毕业季﹏ 提交于 2019-12-30 13:37:09
问题 I'm unable to send each group of dataframe at a time to the executor. I have a data as below in company_model_vals_df dataframe . ---------------------------------------------------------------------------------------- | model_id | fiscal_year | fiscal_quarter | col1 | col2 | col3 | col4 | col5 | col6 | ---------------------------------------------------------------------------------------- | 1 | 2018 | 1 | r1 | r2 | r3 | r4 | r5 | r6 | | 1 | 2018 | 2 | r1 | r2 | r3 | r4 | r5 | r6 | | 1 |

CLR Table-valued function with array argument

坚强是说给别人听的谎言 提交于 2019-12-30 06:11:09
问题 I have a SQL CLR function like this one: public partial class UserDefinedFunctions { [Microsoft.SqlServer.Server.SqlFunction(TableDefinition = "number int", FillRowMethodName = "FillRow")] public static IEnumerable MyClrFunction(object obj) { // read obj array input and then var result = new ArrayList(); result.Add((SqlInt32)1); result.Add((SqlInt32)2); result.Add((SqlInt32)3); return result; } public static void FillRow(object obj, out SqlInt32 number) { number = (SqlInt32)obj; } } I would

Returning Multiple Arrays from User-Defined Aggregate Function (UDAF) in Apache Spark SQL

点点圈 提交于 2019-12-30 03:13:10
问题 I am trying to create a user-defined aggregate function (UDAF) in Java using Apache Spark SQL that returns multiple arrays on completion. I have searched online and cannot find any examples or suggestions on how to do this. I am able to return a single array, but cannot figure out how to get the data in the correct format in the evaluate() method for returning multiple arrays. The UDAF does work as I can print out the arrays in the evaluate() method, I just can't figure out how to return

scala spark dataframe explode is slow - so, alternate method - create columns and rows from arrays in a column

a 夏天 提交于 2019-12-29 09:32:38
问题 Scala 2.11.8, spark 2.0.1 The explode function is very slow - so, looking for an alternate method. I think it is possible with RDD's with flatmap - and, help is greatly appreciated. I have an udf that returns List(String, String, String, Int) of varying lengths. For each row in the dataframe, I want to create multiple rows, and make multiple columns. def Udf = udf ( (s: String ) => { if (s=="1") Seq(("a", "b", "c", 0), ("a1", "b1", "c1", 1), ("a2", "b2", "c2", 2)).toList else Seq(("a", "b",

scala spark dataframe explode is slow - so, alternate method - create columns and rows from arrays in a column

让人想犯罪 __ 提交于 2019-12-29 09:32:17
问题 Scala 2.11.8, spark 2.0.1 The explode function is very slow - so, looking for an alternate method. I think it is possible with RDD's with flatmap - and, help is greatly appreciated. I have an udf that returns List(String, String, String, Int) of varying lengths. For each row in the dataframe, I want to create multiple rows, and make multiple columns. def Udf = udf ( (s: String ) => { if (s=="1") Seq(("a", "b", "c", 0), ("a1", "b1", "c1", 1), ("a2", "b2", "c2", 2)).toList else Seq(("a", "b",

Is it possible to write a UDF in VBA that contains a period in the name?

限于喜欢 提交于 2019-12-29 08:51:51
问题 Excel 2010 ships with some functions that contain a period in their name. For example STDEV.S and PERCENTILE.EXC Is it possible to assign a name to my own function with a name such as PERCENTILE.CUSTOM using VBA? For example, I would like to reference the following function using the formula =NAME.SUFFIX() Option Explicit Function NAMEdotSUFFIX() As Variant NAMEdotSUFFIX = 42 End Function 回答1: It is not possible from VBA. This MSDN article shows how to define a function in VBA, and

Why does my spreadsheet function behave differently than when called from code?

北战南征 提交于 2019-12-29 08:40:15
问题 When I call the function from Excel (in a cell): =allVlookup(O24,A:D,3,"") vs via vba MsgBox allVlookup(Range("O24"), Range("A:D"), 3, "") I get different results. When called from Excel, I only get the first match, but when calling from a vba test sub with identical parameters (except adding Range to the arguments to allow the sub to run), I get the full results (which is more than one). The function I am using is: Public Function allVlookup(lookupRange As Range, tableRange As Range,

When called from an Excel VBA UDF, Range.Precedents returns the range and not its precedents. Is there a workaround?

与世无争的帅哥 提交于 2019-12-29 08:32:35
问题 I have this VBA function: Public Function testPrec(target As Range) As String testPrec = target.Precedents.Address(External:=False) End Function In cell C11, I have this formula: =C6+C8 If I call testPrec from the immediate window, it works just fine: ?testPrec([c11]) $C$6,$C$8 EDIT: It also works fine if called from a non-UDF macro Sub. The anomaly is the UDF case. If I call it from the worksheet as a UDF: =testPrec(C11) I just get back "$C$11". Does anyone know what's going on, or even

Return a User Defined Data Type in an Excel Cell

China☆狼群 提交于 2019-12-28 07:00:46
问题 I've searched the web and I've searched the questions here on stackoverflow, but I haven't been able to find a solution. Here is what I'd like to do: Suppose I have the following code in a class module named "MyClass" Option Explicit Dim var1 as integer Sub Initialize(v as integer) var1 = v End Sub Function GetVar1() GetVar1 = var1 End Function Then I have a UDF in a separate module with the code Function InitializeMyClass(v as integer) as MyClass Dim myvar as MyClass Set myvar = new MyClass