【发布时间】:2017-09-20 04:13:56
【问题描述】:
我有一个名为 Body(String) 的数据框列。正文列数据是这样的
<p>I want to use a track-bar to change a form's opacity.</p>
<p>This is my code:</p>
<pre><code>decimal trans = trackBar1.Value / 5000;
this.Opacity = trans;
</code></pre>
<p>When I build the application, it gives the following error:</p>
<blockquote>
<p>Cannot implicitly convert type 'decimal' to 'double'.</p>
</blockquote>
<p>I tried using <code>trans</code> and <code>double</code> but then the
control doesn't work. This code worked fine in a past VB.NET project. </p>
,While applying opacity to a form should we use a decimal or double value?
使用正文我想准备两个单独的列代码和文本。代码位于名为代码的元素之间,而文本则是其他一切。
我创建了一个如下所示的 UDF
case class bodyresults(text:String,code:String)
val Body:String=>bodyresults=(body:String)=>{ val xmlbody=scala.xml.XML.loadString(body)
val code = (xmlbody \\ "code").toString;
val text = "I want every thing else as text. what should I do"
(text,code)
}
val bodyudf=udf(Body)
val posts5=posts4.withColumn("codetext",bodyudf(col("Body")))
这不起作用。我的问题是 1.如您所见,数据中没有根节点。我还能使用 scala XML 解析吗? 2. 如何将除代码之外的所有内容解析为文本。
如果我的代码有问题请告诉我
预期输出:
(code,text)
code = decimal trans = trackBar1.Value / 5000;this.Opacity = trans;trans double
text = everything else
【问题讨论】:
-
有什么错误,如果有的话?您的预期输出是什么?
-
在 spark-shell 中没有显示任何错误消息。 UDF 正文中有问题。 spark-shell 没有创建函数。
-
好的。代码标签位于多个位置。你想要全部还是只想要里面的
pre,即decimal trans = ...? -
所有这些都在一起。我添加了预期的输出
-
在这种情况下,是否会从最后一段中删除 trans 和 double ?
标签: scala apache-spark xml-parsing spark-dataframe user-defined-functions