当前位置: 首页 > wzjs >正文

全屏网站设计尺寸网站正在建设代码

全屏网站设计尺寸,网站正在建设代码,长治建设工程交易网,做相同性质的网站算侵权吗需求背景: 有一些xls大文件数据。使用spark-excel(spark-excel)来读取时,文件太大会oom;工具提供的流式读取参数:maxRowsInMemory 也只支持xlsx类型文件。搜索了poi流式读取xls的方案,HSSFEvent…

需求背景: 有一些xls大文件数据。使用spark-excel(spark-excel)来读取时,文件太大会oom;工具提供的流式读取参数:maxRowsInMemory 也只支持xlsx类型文件。搜索了poi流式读取xls的方案,HSSFEventFactory提供了HSSFListener进行逐条处理数据。所以编写了spark读取xls的简易source。代码如下:

spark.read.format(“xls”).option(“path”, logPath).load()能够跑通。但是对应xls大文件还是会oom。具体了解后得到原因:SSTRecord存储了整个excel中所有字符串去重后结果,LabelSSTRecord只是存储了该字符串值在SSTRecord中的索引位置。所以在逐条处理xls文件数据的时候遇到SSTRecord还是会oom。

结论:没实现成功,失败;找不到其它实习方案,只能python脚本提前将xls文件转为csv。

package cn.keytop.source.xlsimport org.apache.hadoop.fs.{FileSystem, Path}
import org.apache.poi.hssf.eventusermodel._
import org.apache.poi.hssf.eventusermodel.dummyrecord.LastCellOfRowDummyRecord
import org.apache.poi.hssf.record._
import org.apache.poi.hssf.usermodel.HSSFDataFormatter
import org.apache.poi.poifs.filesystem.POIFSFileSystem
import org.apache.spark.sql.types._
import org.apache.spark.sql.{DataFrame, Row, SQLContext}import scala.collection.mutable.ArrayBuffer/*** @author: 王建成* @since: 2025/4/18 13:46* @description: coding需求和地址 编写一个spark source plugin来读取xls大文件数据*/              
class XLSReader {def read(pathStr: String, sqlContext: SQLContext): org.apache.spark.sql.DataFrame = {val hadoopConf = sqlContext.sparkContext.hadoopConfigurationval fsPath = new Path(pathStr)val fs = fsPath.getFileSystem(hadoopConf)// 获取所有 .xls 文件val allFiles: Array[Path] = {if (fs.isDirectory(fsPath)) {fs.listStatus(fsPath).filter(f => f.isFile && f.getPath.getName.toLowerCase.endsWith(".xls")).map(_.getPath)} else {Array(fsPath)}}// 每个文件读取出一个 DataFrame,然后合并val dfs = allFiles.map { filePath =>println(s"Reading XLS file: $filePath")readSingleXLS(filePath, fs, sqlContext)}dfs.reduceOption(_.union(_)).getOrElse {// 如果目录下没有任何 xls 文件sqlContext.createDataFrame(sqlContext.sparkContext.emptyRDD[Row], StructType(Nil))}}private def readSingleXLS(path: Path, fs: FileSystem, sqlContext: SQLContext): DataFrame = {val inputStream = fs.open(path)val fsPOI = new POIFSFileSystem(inputStream)val rowsBuffer = ArrayBuffer[ArrayBuffer[String]]()var sstRecord: SSTRecord = nullvar headers: ArrayBuffer[String] = ArrayBuffer()var currentRow = ArrayBuffer[String]()var currentRowNum = -1val listener = new HSSFListener {val formatter = new HSSFDataFormatter()override def processRecord(record: Record): Unit = {record match {case sst: SSTRecord =>sstRecord = sstcase label: LabelSSTRecord =>val value = sstRecord.getString(label.getSSTIndex).toStringensureSize(currentRow, label.getColumn + 1, "")currentRow(label.getColumn) = valuecurrentRowNum = label.getRowcase number: NumberRecord =>val value = number.getValue.toStringensureSize(currentRow, number.getColumn + 1, "")currentRow(number.getColumn) = valuecurrentRowNum = number.getRowcase _: LastCellOfRowDummyRecord =>if (currentRow.nonEmpty) {if (currentRowNum == 0 && headers.isEmpty) {headers = currentRow.clone()} else {rowsBuffer += currentRow.clone()}}currentRow.clear()currentRowNum = -1case _ =>}}def ensureSize(buffer: ArrayBuffer[String], size: Int, default: String): Unit = {while (buffer.size < size) {buffer += default}}}val factory = new HSSFEventFactory()val request = new HSSFRequest()val listener1 = new MissingRecordAwareHSSFListener(listener)val listener2 = new FormatTrackingHSSFListener(listener1)request.addListenerForAllRecords(listener2)factory.processWorkbookEvents(request, fsPOI)val schema = StructType(headers.map(name => StructField(name, StringType, nullable = true)))val rows = rowsBuffer.map(Row.fromSeq)sqlContext.createDataFrame(sqlContext.sparkContext.parallelize(rows), schema)}}
package cn.keytop.source.xlsimport org.apache.spark.rdd.RDD
import org.apache.spark.sql.sources.{BaseRelation, DataSourceRegister, RelationProvider, TableScan}
import org.apache.spark.sql.types.StructType
import org.apache.spark.sql.{Row, SQLContext}import java.io.Serializable
/*** @author: 王建成* @since: 2025/4/18 13:46* @description: coding需求和地址 编写一个spark source plugin来读取xls大文件数据*/
class DefaultSource extends RelationProvider with DataSourceRegister with Serializable{override def shortName(): String = "xls"override def createRelation(sqlContext: SQLContext, parameters: Map[String, String]): BaseRelation = {val path = parameters.getOrElse("path", throw new IllegalArgumentException("Missing path"))val reader = new XLSReader()val df = reader.read(path, sqlContext)new BaseRelation with TableScan {override def sqlContext: SQLContext = sqlContextoverride def schema: StructType = df.schemaoverride def buildScan(): RDD[Row] = df.rdd}}
}

文章转载自:

http://MpQSGBEO.pwdgy.cn
http://4OLv4CgK.pwdgy.cn
http://neDdfUwj.pwdgy.cn
http://hXEqhYS2.pwdgy.cn
http://RO0nLDiD.pwdgy.cn
http://GioSWY85.pwdgy.cn
http://pU5B7HSW.pwdgy.cn
http://MBRnxvh5.pwdgy.cn
http://mDumiOmg.pwdgy.cn
http://XRDKwnjc.pwdgy.cn
http://bcEMlq3u.pwdgy.cn
http://tQ291GTI.pwdgy.cn
http://GOPNChFu.pwdgy.cn
http://f3ErmUhn.pwdgy.cn
http://MeA7HYIW.pwdgy.cn
http://aCUXTH6u.pwdgy.cn
http://53s0EAMX.pwdgy.cn
http://MtmpZmxb.pwdgy.cn
http://Hi9tQmcg.pwdgy.cn
http://K0sbpmuS.pwdgy.cn
http://xugZ1OPk.pwdgy.cn
http://NBA4RIGe.pwdgy.cn
http://pZ4s8J35.pwdgy.cn
http://TjDNArzp.pwdgy.cn
http://w2bpLQZE.pwdgy.cn
http://copFHFX8.pwdgy.cn
http://NFxeLiyD.pwdgy.cn
http://3as6lz7r.pwdgy.cn
http://uA42to93.pwdgy.cn
http://i6DH8YsY.pwdgy.cn
http://www.dtcms.com/wzjs/680886.html

相关文章:

  • 网站建设后期服务收费标准怀化建设企业网站
  • wordpress 移动建站海淀中小企业网站开发
  • 建设网站写需求分析建设通网站怎么注销
  • 展示型网站搭建深圳市国家高新技术企业认定
  • 深圳的网站设计派多格宠物网站建设
  • 百度站长平台工具东莞做网站seo
  • 一流的邯郸网站建设医院网站加快建设方案
  • 网站文字公告代码湖南专业竞价优化服务
  • 厦门做网站 厦门专业做网站的公司 我想做网站太原做网站公司哪家好
  • 深圳网站建设 推荐xtdseo运行时间 wordpress
  • 姜堰网站定制对红色网站建设的建议
  • 怎么做加密网站北京住房和城乡建设官方网站
  • 行政审批网站建设规范盐亭网站建设
  • 上海网站建设网页制作你却网页版梦幻西游红色伙伴搭配
  • 聚美优品网站建设导向域名绑定wordpress
  • 岫岩做网站户型图在哪个网站找
  • 领导高度重视门户网站建设网页的风格有哪些方面
  • 事业单位备案网站wordpress 去掉版权
  • 信息网站 微站成都网站开发费用
  • 企业网站买卖建设流程商会联盟网站建设方案
  • 乐平市建设局网站flash网页制作教程
  • 惠州网站外包做网站常用的英文字体
  • 网站首页缩略图 seo湖南工业大学网址
  • 找人做网站 源码被盗用宠物网站设计案例
  • 郑州官网网站推广优化自己做网站自己做推广教程视频教程
  • 四川建设厅网上查询网站首页建网站的公司有哪些
  • 代刷推广网站苏州的互联网企业
  • 用友公司能不能做网站建设合肥昱天建设有限公司网站
  • wordpress 做大型网站林业公司网站模版
  • 微信网站 教程上海搬家公司哪家好