spark写orc格式文件

  1. 在hive中建表格式存储格式为orc

    创新互联坚持“要么做到,要么别承诺”的工作理念,服务领域包括:网站设计、做网站、企业官网、英文网站、手机端网站、网站推广等服务,满足客户于互联网时代的舞钢网站设计、移动媒体设计的需求,帮助企业找到有效的互联网解决方案。努力成为您成熟可靠的网络建设合作伙伴!

      create table user(id int,name string) stored as orc;  

  2. spark写文件        

    val jsons = "hdfs://localhost:9000/test/artist_orc.json"
    val people = sc.textFile(jsons)
    val schemaString = "id name"
    val schema = StructType(schemaString.split(" ").map(fieldName => {if(fieldName == "name")
      StructField(fieldName, StringType, true) else StructField(fieldName, IntegerType, true)}))

    val rowRDD = people.map(line=>{
      JSONObject.fromObject(line)
    }).map(p => Row(new Integer(p.get("id").toString), p.get("name")))

    val hiveContext = new org.apache.spark.sql.hive.HiveContext(sc)
    val peopleSchemaRDD = hiveContext.createDataFrame(rowRDD, schema)
    peopleSchemaRDD.write.format("orc").save("hdfs://localhost:9000/user/xb/warehouse/artist_orc/adf")

网页题目:spark写orc格式文件
分享URL:https://www.cdcxhl.com/article30/pdcspo.html

成都网站建设公司_创新互联,为您提供搜索引擎优化网站改版网站导航网站收录网站设计公司定制网站

广告

声明:本网站发布的内容(图片、视频和文字)以用户投稿、用户转载内容为主,如果涉及侵权请尽快告知,我们将会在第一时间删除。文章观点不代表本网站立场,如需处理请联系客服。电话:028-86922220;邮箱:631063699@qq.com。内容未经允许不得转载,或转载时需注明来源: 创新互联

手机网站建设