Spark - 为udf提供额外参数(Spark - provide extra parameter to udf)
我正在尝试创建一个spark scala udf,以便转换以下形状的MongoDB对象:
Object: "1": 50.3 "8": 2.4 "117": 1.0
进入Spark ml SparseVector。 问题是,为了创建一个SparseVector,我还需要一个输入参数 - 它的大小。 在我的应用程序中,我将Vector大小保存在单独的MongoDB集合中。 所以,我定义了以下UDF函数:
val mapToSparseVectorUdf = udf { (myMap: Map[String, Double], size: Int) => { val vb: VectorBuilder[Double] = new VectorBuilder(length = -1) vb.use(myMap.keys.map(key => key.toInt).toArray, myMap.values.toArray, size) vb.toSparseVector } }
而我试图这样称呼它:
df.withColumn("VecColumn", mapToSparseVectorUdf(col("MapColumn"), vecSize)).drop("MapColumn")
但是,我的IDE对该udf调用说“不适用”。 有没有办法使这种UDF可以采取额外的参数?
I'm trying to create a spark scala udf in order to transform MongoDB objects of the following shape:
Object: "1": 50.3 "8": 2.4 "117": 1.0
Into Spark ml SparseVector. The problem is that in order to create a SparseVector, I need one more input parameter - its size. And in my app I keep the Vector sizes in a separate MongoDB collection. So, I defined the following UDF function:
val mapToSparseVectorUdf = udf { (myMap: Map[String, Double], size: Int) => { val vb: VectorBuilder[Double] = new VectorBuilder(length = -1) vb.use(myMap.keys.map(key => key.toInt).toArray, myMap.values.toArray, size) vb.toSparseVector } }
And I was trying to call it like this:
df.withColumn("VecColumn", mapToSparseVectorUdf(col("MapColumn"), vecSize)).drop("MapColumn")
However, my IDE says "Not applicable" to that udf call. Is there a way to make this kind of UDF that can take an extra parameter?
原文:https://stackoverflow.com/questions/49388781
最满意答案
虽然TABLE,COL,COLGROUP,TBODY,TD,TFOOT,TH,THEAD和TR元素不能直接设置为内容可编辑,但内容可编辑的SPAN或DIV元素可以放在单个表格单元格内(TD和TH元素) )。
资料来源: http : //msdn.microsoft.com/en-us/library/ms537837(v = vs。85).aspx
所以我建议你在内容周围放置div或span并将属性设置为this。
Though the TABLE, COL, COLGROUP, TBODY, TD, TFOOT, TH, THEAD, and TR elements cannot be set as content editable directly, a content editable SPAN, or DIV element can be placed inside the individual table cells (TD and TH elements).
Source: http://msdn.microsoft.com/en-us/library/ms537837(v=vs.85).aspx
So i suggesst you place a div or span around the content and set the attribute to this.
相关问答
更多-
使用最大宽度设置最大宽度 td { white-space: pre-wrap; word-break: break-all; width: 200px; max-width: 200px; } 溢出的内容现在将溢出高度而不是宽度。 文档: http : //www.w3schools.com/cssref/pr_dim_max-width.asp Use max-width to set a maximum width td { white-space: pre-wrap; wo ...
-
在某些浏览器中,您需要在粘贴事件触发之前关注textarea,这意味着您只能实际使用此技术来处理由键盘快捷键(如Ctrl - V)触发的粘贴。 这是一个类似的问题,有更多信息: https://stackoverflow.com/a/2177059/96100 You need to focus the textarea before the paste event fires in some browsers, which means you can only realistically use this ...
-
无需使用库或条件编译即可实现: if (document.addEventListener) { alert("IE9 or greater"); } if (window.requestAnimationFrame) { alert("IE10 or greater"); } Can be achieved without using libraries or conditional compilation: if (document.addEventListener) { a ...
-
如果您创建可排序元素的处理程序可能会更好,因为它超过了单击事件。 我使用.draggable-area创建了一个元素,并将它用于可排序的句柄选项 $(function(){ $("#textTemplate").draggable({ helper: "clone", zIndex: 2500, }); $( "#editorDesignView" ).droppable({ accept: '#textTemplate', drop: funct ...
-
我建议拦截删除和退格键并手动执行删除操作。 步骤是: 获取所选范围 如果范围的末端位于可编辑的
- 元素内,则调整范围的末尾 在范围上调用deleteContents() 。 请注意,以下内容对IE <= 8不起作用。如果需要支持这些浏览器,可以使用我的Rangy库,它也可以用来简化deleteSelectedContent() 。 演示: http : //jsfiddle.net/timdown/STcXa/3/ 码: var editor = document.getElementById("edi ...
-
嗨,这个问题似乎已经解决了自己更新我们的JQuery版本到最新版本。 我不确定是什么导致它或为什么会发生但现在已经解决了。 Hi this issue seems to have solved itself after updating our version of JQuery to the latest version. I'm not sure what caused it or why it was happening but is is fixed now.
-
虽然TABLE,COL,COLGROUP,TBODY,TD,TFOOT,TH,THEAD和TR元素不能直接设置为内容可编辑,但内容可编辑的SPAN或DIV元素可以放在单个表格单元格内(TD和TH元素) )。 资料来源: http : //msdn.microsoft.com/en-us/library/ms537837(v = vs。85).aspx 所以我建议你在内容周围放置div或span并将属性设置为this。 Though the TABLE, COL, COLGROUP, TBODY, TD, T ...
-
使用Javascript在一列中更改属性contenteditable(Change property contenteditable in one column with Javascript)[2023-07-26]
我看到你有一个循环,所以我会调整我的代码。 您可以放置if语句,如下所述: $.each(currentTD, function () { if (!$(this).attr("contenteditable")) ;// item doesn't have this attribute 此外,如果您取消设置值如下: $(this).prop('contenteditable', ""); 您还可以检查该值是否为空 var contenteditable = $(this).attr ... -
使用phpjs.org的nl2br函数是最简单的: http ://phpjs.org/functions/nl2br:480 编辑(完全工作 - 测试) 我在你的小提琴上测试了这个并且它有效: $('div').keyup(function(){ $('textarea').val( $(this).html().replace( /
/g, '\n' ) ); //$('textarea').val($(this).html()) // also not working as exp ... -
为了避免这种问题并最大限度地提高兼容性,最好只在div等有限数量的标签上使用contentEditable,如果你在td等其他元素中使用它,那么你可能会发现像这样的问题。 所以解决方案是在每个单元格中包含一个div,并使这些div成为contentEditable元素 In order to avoid that kind of problems and maximize compatibility, it's better to use contentEditable only on a restrict ...