user-defined-functions

data transferred in calling a user defined function

此生再无相见时 提交于 2019-12-13 04:34:08
问题 I need to analyze a big source code.Code contains several function calls. Depending upon the computation and communication between function calls, i will need to figure out the best configuration scheme for the overall execution of the source code. According to me , Data communicated in calling a function(if it is on different machine,server etc)=Input Data Size+Output Data Size for getting the input data size and output data size ,i think i should rewrite all functions to have variable

Unique Count (Excel VBA vs Formulas) Faster Approach

♀尐吖头ヾ 提交于 2019-12-13 03:56:56
问题 32 Bit Excel 365 on 64 Bit Win7 Worksheet 300600 Rows x 105 Columns Goal: Calculate the Number of Unique Entries in each Column Attempted Solution 1: Formula {=SUM(1/COUNTIF(A8:A300600,A8:A300600))} Issue: Long Runtime, Freezes Excel, Must Stop Calculation Attempted Solution 2: VBA UDF Function UniqueCount(Selection As Range) As Integer Dim UniqueArray() ReDim UniqueArray(0 To Selection.Count) Dim Rng As Range Dim CUniqueCount As Integer CUniqueCount = 0 For Each Rng In Selection For i = 0 To

Enter User Defined Function into Column Using VBA

久未见 提交于 2019-12-13 02:58:21
问题 I currently am using a formula in Column J of Sheet 2 of my workbook that will look up values from 5 columns on Sheet 1 and return the corresponding text. For example if the value from column M on Sheet 2 matches any of the values from column J on Sheet 1 it would return "N", if not it would look in column K and if matched anything there it would return D, and so on. I am doing this in VBA so the formula used is ActiveSheet.Range("J2:J" & intLastRow).FormulaR1C1 = _ "=IFERROR(IF(ISNUMBER

How to rename an existing Spark SQL function

和自甴很熟 提交于 2019-12-13 02:47:35
问题 I am using Spark to call functions on the data which is submitted by the user. How can I rename an already existing function to a different name like like REGEXP_REPLACE to REPLACE ? I tried the following code : ss.udf.register("REPLACE", REGEXP_REPLACE) // This doesn't work ss.udf.register("sum_in_all", sumInAll) ss.udf.register("mod", mod) ss.udf.register("average_in_all", averageInAll) 回答1: Import it with an alias : import org.apache.spark.sql.functions.{regexp_replace => replace } df.show

Scalar-Valued Function in NHibernate

流过昼夜 提交于 2019-12-13 02:15:21
问题 I have the following scalar function in MS SQL 2005: CREATE FUNCTION [dbo].[Distance] ( @lat1 float, @long1 float,@lat2 float, @long2 float ) RETURNS float AS BEGIN RETURN (3958*3.1415926*sqrt((@lat2-@lat1)*(@lat2-@lat1) + cos(@lat2/57.29578)*cos(@lat1/57.29578)*(@long2-@long1)*(@long2-@long1))/180); END I need to be able to call this function from my NHibernate queries. I read over this article, but I got bogged down in some details that I didn't understand right away. If you've used scalar

SQL Server change font in html string

心已入冬 提交于 2019-12-13 01:53:36
问题 I have a strings stored in my database formatted as html, and users can change the font size. That's fine, but I need to make a report and the font sizes all need to be the same. So, if I have the following html, I want to modify it to have a font size of 10: <HTML><BODY><DIV STYLE="text-align:Left;font-family:Tahoma;font-style:normal;font-weight:normal;font-size:11;color:#000000;"><DIV><DIV><P><SPAN>This is my text to display.</SPAN></P></DIV></DIV></DIV></BODY></HTML> I have a user defined

Join 2 tables in Hive using a phone number and a prefix (variable length)

♀尐吖头ヾ 提交于 2019-12-13 01:34:36
问题 I'm trying to match phone numbers to an area using Hive. I've got a table (prefmap) that maps a number prefix (prefix) to an area (area) and another table (users) with a list of phone numbers (nb). There is only 1 match per phone number (no sub-area) The problem is that the length of the prefixes is not fixed so I cannot use the UDF function substr(nb,"prefix's length") in the JOIN's ON() condition to match the substring of a number to a prefix. And when I try to use instr() to find if a

UDF in Spark SQL DSL

淺唱寂寞╮ 提交于 2019-12-13 00:49:24
问题 I am trying to use DSL over pure SQL in Spark SQL jobs but I cannot get my UDF works. sqlContext.udf.register("subdate",(dateTime: Long)=>dateTime.toString.dropRight(6)) This doesn't work rdd1.toDF.join(rdd2.toDF).where("subdate(rdd1(date_time)) === subdate(rdd2(dateTime))") I also would like to add another join condition like in this working pure SQL val results=sqlContext.sql("select * from rdd1 join rdd2 on rdd1.id=rdd2.idand subdate(rdd1.date_time)=subdate(rdd2.dateTime)") Thanks for your

A GenericUDF Function to Extract a Field From an Array of Structs‏

孤街浪徒 提交于 2019-12-13 00:45:24
问题 I am trying to write a GenericUDF function to collect all of a specific struct field(s) within an array for each record, and return them in an array as well. I wrote the GenericUDF (as below), and it seems to work but: 1) It does not work when I am performing this on an external table, it works fine on a managed table, any idea? 2) I am having a tough time writing a test on this. I have attached the test I have so far, and it does not work, always getting 'java.util.ArrayList cannot be cast

Assigning default value for type

不问归期 提交于 2019-12-13 00:25:27
问题 How to assign default value to following type of Oracle statement into PostgreSQL 9.3? CREATE OR REPLACE FUNCTION(.... ... DECLARE v_var Table01.column01%TYPE := 'SLOW'; BEGIN ... ... END; 回答1: Postgres allows to provide parameter defaults , which kick in for missing parameters in the function call. Only allowed for parameters at the end of the list . Example: CREATE OR REPLACE FUNCTION foo ( param1 int , v_char tbl01.col01%TYPE DEFAULT 'foo' ) ... -- no need to DECLARE anything else. BEGIN .