首页 \ 问答 \ Spark - 为udf提供额外参数(Spark - provide extra parameter to udf)

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
更新时间:2023-05-23 15:05

最满意答案

虽然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 ...
  • 我看到你有一个循环,所以我会调整我的代码。 您可以放置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 ...

相关文章

更多

最新问答

更多
  • 您如何使用git diff文件,并将其应用于同一存储库的副本的本地分支?(How do you take a git diff file, and apply it to a local branch that is a copy of the same repository?)
  • 将长浮点值剪切为2个小数点并复制到字符数组(Cut Long Float Value to 2 decimal points and copy to Character Array)
  • OctoberCMS侧边栏不呈现(OctoberCMS Sidebar not rendering)
  • 页面加载后对象是否有资格进行垃圾回收?(Are objects eligible for garbage collection after the page loads?)
  • codeigniter中的语言不能按预期工作(language in codeigniter doesn' t work as expected)
  • 在计算机拍照在哪里进入
  • 使用cin.get()从c ++中的输入流中丢弃不需要的字符(Using cin.get() to discard unwanted characters from the input stream in c++)
  • No for循环将在for循环中运行。(No for loop will run inside for loop. Testing for primes)
  • 单页应用程序:页面重新加载(Single Page Application: page reload)
  • 在循环中选择具有相似模式的列名称(Selecting Column Name With Similar Pattern in a Loop)
  • System.StackOverflow错误(System.StackOverflow error)
  • KnockoutJS未在嵌套模板上应用beforeRemove和afterAdd(KnockoutJS not applying beforeRemove and afterAdd on nested templates)
  • 散列包括方法和/或嵌套属性(Hash include methods and/or nested attributes)
  • android - 如何避免使用Samsung RFS文件系统延迟/冻结?(android - how to avoid lag/freezes with Samsung RFS filesystem?)
  • TensorFlow:基于索引列表创建新张量(TensorFlow: Create a new tensor based on list of indices)
  • 企业安全培训的各项内容
  • 错误:RPC失败;(error: RPC failed; curl transfer closed with outstanding read data remaining)
  • C#类名中允许哪些字符?(What characters are allowed in C# class name?)
  • NumPy:将int64值存储在np.array中并使用dtype float64并将其转换回整数是否安全?(NumPy: Is it safe to store an int64 value in an np.array with dtype float64 and later convert it back to integer?)
  • 注销后如何隐藏导航portlet?(How to hide navigation portlet after logout?)
  • 将多个行和可变行移动到列(moving multiple and variable rows to columns)
  • 提交表单时忽略基础href,而不使用Javascript(ignore base href when submitting form, without using Javascript)
  • 对setOnInfoWindowClickListener的意图(Intent on setOnInfoWindowClickListener)
  • Angular $资源不会改变方法(Angular $resource doesn't change method)
  • 在Angular 5中不是一个函数(is not a function in Angular 5)
  • 如何配置Composite C1以将.m和桌面作为同一站点提供服务(How to configure Composite C1 to serve .m and desktop as the same site)
  • 不适用:悬停在悬停时:在元素之前[复制](Don't apply :hover when hovering on :before element [duplicate])
  • 常见的python rpc和cli接口(Common python rpc and cli interface)
  • Mysql DB单个字段匹配多个其他字段(Mysql DB single field matching to multiple other fields)
  • 产品页面上的Magento Up出售对齐问题(Magento Up sell alignment issue on the products page)