package com.grady.sedona

import org.apache.sedona.sql.utils.SedonaSQLRegistrator
import org.apache.sedona.viz.core.Serde.SedonaVizKryoRegistrator
import org.apache.spark.serializer.KryoSerializer
import org.apache.spark.sql.SparkSession object SedonaReadCsv { // hdfs 文件位置
val csvPointInputLocation = "/tmp/jiang/" + "testpoint.csv" def main(args: Array[String]): Unit = {
val ss:SparkSession = SparkSession.builder()
.config("spark.serializer",classOf[KryoSerializer].getName)
.config("spark.kryo.registrator", classOf[SedonaVizKryoRegistrator].getName)
.appName("SedonaAnalysisScv").getOrCreate() SedonaSQLRegistrator.registerAll(ss) readCsv(ss) ss.stop()
} def readCsv(ss: SparkSession): Unit = {
val pointCsvDF = ss.read
.format("csv")
.option("delimiter",",")
.option("header","false")
.load(csvPointInputLocation) pointCsvDF.createOrReplaceTempView("test_point_csv")
pointCsvDF.show(10) val pointDF = ss.sql("select ST_Point(cast(test_point_csv._c0 as Decimal(24,20)),cast(test_point_csv._c1 as Decimal(24,20))) as pointshape from test_point_csv")
pointCsvDF.createOrReplaceTempView("test_point")
pointDF.show()
} }

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 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<parent>
<artifactId>spark-practise</artifactId>
<groupId>org.example</groupId>
<version>1.0-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion> <artifactId>sedona</artifactId> <properties>
<maven.compiler.source>8</maven.compiler.source>
<maven.compiler.target>8</maven.compiler.target>
</properties> <dependencies>
<dependency>
<groupId>org.apache.spark</groupId>
<artifactId>spark-core_${scala.binary.version}</artifactId>
<version>${spark.version}</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.apache.spark</groupId>
<artifactId>spark-sql_${scala.binary.version}</artifactId>
<version>${spark.version}</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.apache.spark</groupId>
<artifactId>spark-yarn_${scala.binary.version}</artifactId>
<version>${spark.version}</version>
<scope>provided</scope>
</dependency> <!-- sedona -->
<dependency>
<groupId>org.apache.sedona</groupId>
<artifactId>sedona-core-3.0_2.12</artifactId>
<version>1.1.1-incubating</version>
</dependency>
<dependency>
<groupId>org.apache.sedona</groupId>
<artifactId>sedona-sql-3.0_2.12</artifactId>
<version>1.1.1-incubating</version>
</dependency>
<dependency>
<groupId>org.apache.sedona</groupId>
<artifactId>sedona-viz-3.0_2.12</artifactId>
<version>1.1.1-incubating</version>
</dependency>
<dependency>
<groupId>org.locationtech.jts</groupId>
<artifactId>jts-core</artifactId>
<version>1.18.0</version>
</dependency>
</dependencies> <build>
<resources>
<resource>
<directory>src/main/resources</directory>
<filtering>true</filtering>
</resource>
</resources> <plugins>
<plugin>
<groupId>net.alchim31.maven</groupId>
<artifactId>scala-maven-plugin</artifactId>
<version>3.2.1</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
<scalaVersion>${scala.version}</scalaVersion>
</configuration>
<executions>
<execution>
<id>scala-compile-first</id>
<phase>process-resources</phase>
<goals>
<goal>add-source</goal>
<goal>compile</goal>
</goals>
</execution>
<execution>
<id>scala-test-compile</id>
<phase>process-test-resources</phase>
<goals>
<goal>testCompile</goal>
</goals>
</execution>
</executions>
</plugin> <plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>3.2.1</version>
<configuration>
<artifactSet>
<excludes>
<exclude>org.slf4j:*</exclude>
</excludes>
</artifactSet>
</configuration>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
<configuration>
<createDependencyReducedPom>false</createDependencyReducedPom>
<filters>
<filter>
<artifact>*:*</artifact>
<excludes>
<exclude>META-INF/*.SF</exclude>
<exclude>META-INF/*.DSA</exclude>
<exclude>META-INF/*.RSA</exclude>
</excludes>
</filter>
</filters>
<transformers>
<transformer implementation="org.apache.maven.plugins.shade.resource.ServicesResourceTransformer" />
</transformers>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>

执行spark-submit --master yarn --driver-memory=2G --class com.grady.sedona.SedonaReadCsv /app/data/appdeploy/sedona-1.0-SNAPSHOT.jar

日志:

+----+-----+
| _c0| _c1|
+----+-----+
| 1.1|101.1|
| 2.1|102.1|
| 3.1|103.1|
| 4.1|104.1|
| 5.1|105.1|
| 6.1|106.1|
| 7.1|107.1|
| 8.1|108.1|
| 9.1|109.1|
|10.1|110.1|
+----+-----+ +------------------+
| pointshape|
+------------------+
| POINT (1.1 101.1)|
| POINT (2.1 102.1)|
| POINT (3.1 103.1)|
| POINT (4.1 104.1)|
| POINT (5.1 105.1)|
| POINT (6.1 106.1)|
| POINT (7.1 107.1)|
| POINT (8.1 108.1)|
| POINT (9.1 109.1)|
|POINT (10.1 110.1)|
|POINT (11.1 111.1)|
|POINT (12.1 112.1)|
|POINT (13.1 113.1)|
|POINT (14.1 114.1)|
|POINT (15.1 115.1)|
|POINT (16.1 116.1)|
|POINT (17.1 117.1)|
|POINT (18.1 118.1)|
|POINT (19.1 119.1)|
|POINT (20.1 120.1)|
+------------------+
only showing top 20 rows

sedona(Geospark)读取csv的更多相关文章

  1. sparkR读取csv文件

    sparkR读取csv文件 The general method for creating SparkDataFrames from data sources is read.df. This met ...

  2. C# 读取 CSV 文件

    最近做一个C#项目要导入CSV文件中的数据到Oracle中,使用Aspose.Cells读取中文字段标题却乱码,表的最后多出几行null记录,而且不是免费的,后来找到了NPOI,顾名思义,就是POI的 ...

  3. PHP读取CSV数据写入数据库

    /*读取csv文件*/ public function testCsv(){ $fileName = "tel.csv"; $fp=fopen($fileName,"r& ...

  4. VB6.0 读取CSV文件

    最近做了一个Upload文件的需求,文件的格式为CSV,读取文件的方法整理了一下,如下: 1.先写了一个读取CSV文件的Function: '读取CSV文件 '假设传入的参数strFile=C:\Do ...

  5. php读取csv文件,在linux上出现中文读取不到的情况 解决方法

    今,php读取csv文件,在linux上出现中文读取不到的情况,google,后找到解决办法<?phpsetlocale(LC_ALL, 'zh_CN');$row = 1;$handle = ...

  6. 内容写到 csv 格式的文件中 及 读取 csv 格式的文件内容

    <?php/*把内容写到 csv 格式的文件中 基本思路是:1.用 $fp = fopen("filename", 'mode')打开一个csv文件,可以是打开时才建立的2. ...

  7. Unity 读取CSV与Excel

    前几天看到我们在游戏中需要动态加载某些角色的游戏策划值,关于这个问题怎么解决呢?其实办法很多种,归根到底,就是数据的读取.我们可以想到的存储数据的载体有很多.例如:txt,xml,csv,excel. ...

  8. 使用univocity-parsers创建和读取csv文件

    import com.univocity.parsers.csv.CsvFormat;import com.univocity.parsers.csv.CsvParser;import com.uni ...

  9. PHP读取CSV大文件导入数据库的示例

    对于数百万条数据量的CSV文件,文件大小可能达到数百M,如果简单读取的话很可能出现超时或者卡死的现象. 为了成功将CSV文件里的数据导入数据库,分批处理是非常必要的. 下面这个函数是读取CSV文件中指 ...

随机推荐

  1. SAP Smartforms 参数配置

    DATA : sf_name TYPE rs38l_fnam. DATA : sf_output_options TYPE ssfcompop. DATA : sf_control_parameter ...

  2. go-zero微服务实战系列(九、极致优化秒杀性能)

    上一篇文章中引入了消息队列对秒杀流量做削峰的处理,我们使用的是Kafka,看起来似乎工作的不错,但其实还是有很多隐患存在,如果这些隐患不优化处理掉,那么秒杀抢购活动开始后可能会出现消息堆积.消费延迟. ...

  3. 题解 P2278 【[HNOI2003]操作系统】

    一道大模拟 题面想必大家都很清楚了,一堆进程在抢占资源,除了先来后到的顺序以外,优先级大的还可以插队,空闲的时候未结束的进程会插进来占用空闲的时间. 那么,我们可以容易地想到,我们寻找这个最大的优先级 ...

  4. NLM5系列中继采集仪的常见问题

    NLM5系列中继采集采发仪常见问题 1.UART 通讯问题使用 UART 接口时一定要确认收发双方的通讯参数完全一致,包括通讯速率.数据位.校验位.停止位参数.NLM 在上电时会主动输出设备基本信息, ...

  5. ooday07 Java_接口

    笔记: 接口: 是一种引用数据类型 由interface定义 只能包含常量和抽象方法------默认权限是public 接口不能被实例化 接口是需要被实现/继承,实现/派生类:必须重写所有抽象方法 一 ...

  6. input函数的高级使用

    经典的a+b问题终于重出江湖了 a=input('a = ') b=input('b = ') print(a+b)//error,因为此时ab是字符串类型,其加号起到的是连接的作用 所以这就是类型转 ...

  7. 常用的函数式接口_Supplier和常用的函数式接口Supplier接口练习_求数组中元素最大值

    Supplier接口 package com.yang.Test.SupplierStudy; import java.util.function.Supplier; /** * 常用的函数式接口 * ...

  8. python 部分内置函数详解

    简介 eval与exec eval和exec都是python内置的可以执行python代码的函数,但它们之间有所区别. eval(expression[, globals[, locals]]) ex ...

  9. 企业级数据治理工作怎么开展?Datahub这样做

    大数据发展到今天,扮演了越来越重要的作用.数据可以为各种组织和企业提供关键决策的支持,也可以通过数据分析帮助发现更多的有价值的东西,如商机.风险等等. 在数据治理工作开展的时候,往往会有一个专门负责数 ...

  10. Frida使用文档(一)安装、启动、运行、关闭

    本文所有教程及源码.软件仅为技术研究.不涉及计算机信息系统功能的删除.修改.增加.干扰,更不会影响计算机信息系统的正常运行.不得将代码用于非法用途,如侵立删!企鹅:1033383881 Frida使用 ...