user-defined-functions

How to use a recursive function to update a table?

喜欢而已 提交于 2020-01-17 03:01:07
问题 This is a follow-up from this question. Functions are not allowed to write to the database, but what if I wanted to update a record every time a function was called, specifically a recursive function? Currently, I have a function that takes an ID and returns a float. I'd like to update a table using the given ID and the returned float. Ordinarily, a simple stored procedure could be used to call the function and then make the update. My function is recursive, and so the solution isn't that

Store Python function in JSON

半城伤御伤魂 提交于 2020-01-16 06:57:28
问题 Say I have a JSON file as such: { "x":5, "y":4, "func" : def multiplier(a,b): return a*d } This over-simplifies what I want to try and do, but basically I am attempting to story a python UDF into a JSON file. Is there a way to do this so that when I do: with open('config.json') as f: data = json.load(f) I can access those values and do something like: v1, v2 = data['x'], data['y'] mult = data['func'] print(mult(v1,v2)) To get expected output: 20 NOTE : To my understanding JSON doesn't store

Error 1121 importing external library in Pig UDF in Jython

六月ゝ 毕业季﹏ 提交于 2020-01-15 19:17:03
问题 I'm having a problem using the python library simplejson in jython to write a Pig UDF. I need because jython-standalone-2.5.2.jar doesn't come with a JSON library. I'm using Apache Pig version 0.11.0-cdh4.4.0 (rexported) compiled Sep 03 2013, 20:25:46, and according to the documentation http://pig.apache.org/docs/r0.11.1/udf.html#python-advanced "You can import Python modules in your Python script. Pig resolves Python dependencies recursively, which means Pig will automatically ship all

Error 1121 importing external library in Pig UDF in Jython

ⅰ亾dé卋堺 提交于 2020-01-15 19:16:51
问题 I'm having a problem using the python library simplejson in jython to write a Pig UDF. I need because jython-standalone-2.5.2.jar doesn't come with a JSON library. I'm using Apache Pig version 0.11.0-cdh4.4.0 (rexported) compiled Sep 03 2013, 20:25:46, and according to the documentation http://pig.apache.org/docs/r0.11.1/udf.html#python-advanced "You can import Python modules in your Python script. Pig resolves Python dependencies recursively, which means Pig will automatically ship all

Pandas: create a new column in a dataframe that is a function of a rolling window

不想你离开。 提交于 2020-01-15 18:51:30
问题 I have a data frame and can compute a new column of rolling 10 period means using pandas.stats.moments.rolling_mean(ExistingColumn, 10, min_periods=10) . If there are fewer than 10 periods available, I get a NaN. I can do the same for rolling medians. Perfect. I'd now like to compute other rolling functions of N periods, but can't for the life of me figure out how to do use a user defined function with Pandas. In particular, I want to compute a rolling 10 point Hodges Lehman Mean, which is

Passing empty list to user defined table type parameter on a scalar function

為{幸葍}努か 提交于 2020-01-15 07:23:07
问题 So I have this user-defined table type parameter, which is used in my scalar function and might be empty. I've read this topic about passing empty list to table-valued parameter on a stored procedure: Binding empty list or null value to table valued parameter on a stored procedure (.net) And basically, as one of the repliers said: "The trick is: don’t pass in the parameter at all . The default value for a table-valued parameter is an empty table" However, when I try this on scalar function, I

Check constraint does not work on bulk insert for more than 250 records

此生再无相见时 提交于 2020-01-13 08:16:44
问题 My query : INSERT into PriceListRows (PriceListChapterId,[No]) SELECT TOP 250 100943 ,N'2' FROM #AnyTable This query works fine and the following exception raises as desired: The INSERT statement conflicted with the CHECK constraint "CK_PriceListRows_RowNo_Is_Not_Unqiue_In_PriceList". The conflict occurred in database "TadkarWeb", table "dbo.PriceListRows". but with changing SELECT TOP 250 to SELECT TOP 251 (yes! just changing 250 to 251!) the query runs successfully without any check

Custom sort in SQL Server

久未见 提交于 2020-01-13 07:18:51
问题 I have a table where the results are sorted using an "ORDER" column, eg: Doc_Id Doc_Value Doc_Order 1 aaa 1 12 xxx 5 2 bbb 12 3 ccc 24 My issue is to initially set up this order column as efficiently and reusably as possible. My initial take was to set up a scalar function that could be used as a default value when a new entry is added to the table: ALTER FUNCTION [dbo].[Documents_Initial_Order] ( ) RETURNS int AS BEGIN RETURN (SELECT ISNULL(MAX(DOC_ORDER),0) + 1 FROM dbo.Documents) When a

Invoke Pig Latin script from other Pig script

五迷三道 提交于 2020-01-11 09:34:33
问题 I have a question about PIG Latin. Is there any way how to invoke some pig script from the other pig script? I know it is possible to run user defined functions (UDFs) like: REGISTER myudfs.jar; A = LOAD 'student_data' AS (name: chararray, age: int, gpa: float); B = FOREACH A GENERATE myudfs.UPPER(name); DUMP B; But it is not working for pig script. We are counting some different customer parameters and for readibility and reuse it would be great to load some pig snippets, something like:

Deterministic scalar function to get day of week for a date

故事扮演 提交于 2020-01-11 05:40:53
问题 SQL Server, trying to get day of week via a deterministic UDF. Im sure this must be possible, but cant figure it out. UPDATE: SAMPLE CODE.. CREATE VIEW V_Stuff WITH SCHEMABINDING AS SELECT MD.ID, MD.[DateTime] ... dbo.FN_DayNumeric_DateTime(MD.DateTime) AS [Day], dbo.FN_TimeNumeric_DateTime(MD.DateTime) AS [Time], ... FROM {SOMEWHERE} GO CREATE UNIQUE CLUSTERED INDEX V_Stuff_Index ON V_Stuff (ID, [DateTime]) GO 回答1: Ok, i figured it.. CREATE FUNCTION [dbo].[FN_DayNumeric_DateTime] (@DT