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

Spark - 输出parqute文件

pom.xml

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
  <modelVersion>4.0.0</modelVersion>
  <parent>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-parent</artifactId>
    <version>2.2.5.RELEASE</version>
    <relativePath/> <!-- lookup parent from repository -->
  </parent>
  <groupId>com.sp</groupId>
  <artifactId>spark</artifactId>
  <version>0.0.1-SNAPSHOT</version>
  <name>spark</name>
  <description>spark</description>
  <properties>
    <java.version>1.8</java.version>
  </properties>
  <dependencies>
    <dependency>
      <groupId>org.apache.spark</groupId>
      <artifactId>spark-core_2.12</artifactId>
      <version>3.1.1</version>
    </dependency>
    <dependency>
      <groupId>org.apache.spark</groupId>
      <artifactId>spark-sql_2.12</artifactId>
      <version>3.1.1</version>
    </dependency>
    <dependency>
      <groupId>org.codehaus.janino</groupId>
      <artifactId>janino</artifactId>
      <version>3.0.8</version>
    </dependency>
    <dependency>
      <groupId>org.springframework.boot</groupId>
      <artifactId>spring-boot-starter</artifactId>
    </dependency>

    <dependency>
      <groupId>org.springframework.boot</groupId>
      <artifactId>spring-boot-devtools</artifactId>
      <scope>runtime</scope>
      <optional>true</optional>
    </dependency>
    <dependency>
      <groupId>org.projectlombok</groupId>
      <artifactId>lombok</artifactId>
      <optional>true</optional>
    </dependency>
    <dependency>
      <groupId>org.springframework.boot</groupId>
      <artifactId>spring-boot-starter-test</artifactId>
      <scope>test</scope>
    </dependency>
  </dependencies>

  <build>
    <plugins>
      <plugin>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-maven-plugin</artifactId>
        <configuration>
          <excludes>
            <exclude>
              <groupId>org.projectlombok</groupId>
              <artifactId>lombok</artifactId>
            </exclude>
          </excludes>
        </configuration>
      </plugin>
    </plugins>
  </build>

</project>

Application

package com.sp.spark;

import org.apache.spark.SparkConf;
import org.apache.spark.sql.Dataset;
import org.apache.spark.sql.Row;
import org.apache.spark.sql.SQLContext;
import org.apache.spark.sql.SaveMode;
import org.apache.spark.sql.SparkSession;
import org.springframework.boot.autoconfigure.SpringBootApplication;

@SpringBootApplication
public class SparkApplication {

  public static void main(String[] args) {
    SparkConf sparkConf = new SparkConf()
        .setAppName("PTableCol1k")
        .setMaster("local[*]");

    SparkSession sparkSession = SparkSession.builder().config(sparkConf).getOrCreate();

    //  part-00000-27cf239b-44f7-4c2f-8dbf-eea035af6c40-c000.gz.parquet
    // 	part-03538-08d91713-5f2a-4606-bb22-c84adec00bc5.c000.gz.parquet

    // 测试默认命名方式  part-00000-d950cbeb-c8c4-4c1a-a20a-f679afc0260f-c000.gz.parquet
    SQLContext sqlContext = sparkSession.sqlContext();
    sqlContext.setConf("spark.sql.parquet.compression.codec","gzip");

    Dataset<Row> writer = sparkSession.read().csv("D://test.csv");
    writer.write().mode(SaveMode.Overwrite);
    writer.write().parquet("D://parquet");
  }
}

http://www.kler.cn/a/161282.html

相关文章:

  • 【Compose multiplatform教程12】【组件】Box组件
  • Dots 常用操作
  • 使用开源在线聊天工具Fiora轻松搭建个性化聊天平台在线交流
  • 网络安全加密
  • JZ31 栈的压入、弹出序列
  • 复习打卡大数据篇——Hadoop HDFS 03
  • 漫谈Uniapp App热更新包-Jenkins CI/CD打包工具链的搭建
  • 【刷题日志】牛客 HJ73 计算日期到天数转换
  • Canvas鼠标画线
  • java字符串String类的常用方法
  • Swift 中 User Defaults 的读取和写入
  • 商家门店小程序怎么做?门店小程序的优势和好处
  • Docker 一些设置
  • zabbix配置snmp trap--使用snmptrapd和Bash接收器--图文教程
  • Android启动界面之isTaskRoot的妙用及Deeplink的处理
  • 从文字到使用,一文读懂Kafka服务使用
  • macOS 13.6上Sublime无法使用Package Control问题
  • Vue3 Element-Plus 一站式生成动态表单:简化前端开发流程
  • 浅谈https
  • jQuery的入口函数
  • Java毕业设计源码—vue+SpringBoot图书借阅管理图书馆管理系统
  • 10_企业架构NOSQL数据库之MongoDB
  • [ffmpeg] find 编码器
  • 最新GM/T 0126-2023《HTML密码应用置标语法》等25项密码行业标准
  • QML优化,当列表数据过多时,切换tab可能会导致卡顿的情况。
  • StarRocks 存算分离最佳实践,让降本增效更简单