栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 面试经验 > 面试问答

将文字值设置为set的新列添加到DataFrame中

面试问答 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

将文字值设置为set的新列添加到DataFrame中

我自己找到了解决方案(在一些帮助下):

Map<File, Dataset<Row> allWords = ...StructField[] structFields = new StructField[] {        new StructField("word", DataTypes.StringType, false, metadata.empty()),        new StructField("count", DataTypes.IntegerType, false, metadata.empty()),        new StructField("files", DataTypes.createArrayType(DataTypes.IntegerType), true, metadata.empty())};StructType structType = new StructType(structFields);Dataset<Row> allFilesWords = spark.createDataframe(new ArrayList<>(), structType);for (Map.Entry<File, Dataset<Row>> entry : allWords.entrySet()) {    Integer fileIndex = files.indexOf(entry.getKey());    allFilesWords.unionAll( allWords.get(entry.getKey())         .withColumn("files", functions.typedLit(seq, MyTypeTags.SeqInteger()))    );}

问题在于这TypeTag是Scala的编译时工件,根据我在另一个问题中得到的内容,它需要由Scala编译器生成,并且无法用Java生成。因此,我不得不TypeTag在Scala文件中编写我的自定义数据结构,并将其添加到我的Maven Java项目中。为此,我关注了本文。

这是我的MyTypeTags.scala文件:

import scala.reflect.runtime.universe._object MyTypeTags {  val SeqInteger = typeTag[Seq[Integer]]}


转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/469914.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号