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. 毕设着急了吧?Python股票数据分析,制作动态柱状图

    写在前面的一些屁话: 雪球成立于 2010 年,是北京雪球信息科技有限公司旗下推出的投资者社区.雪球一直致力于为中国投资者提供跨市场(沪深.香港.美国),跨品种(股票.基金.债券等)的数据查询.资讯获 ...

  2. vim插件的社区活跃度怎么样

    www.vim.org -> Scripts -> Browse all可以看到有5051个插件.搜索Nerd可以看到NerdTree插件,它的评分是Rating 7882/2514, D ...

  3. JavaScript基本知识点——带你逐步解开JS的神秘面纱

    JavaScript基本知识点--带你逐步解开JS的神秘面纱 在我们前面的文章中已经深入学了HTML和CSS,在网页设计中我们已经有能力完成一个美观的网页框架 但仅仅是网页框架不足以展现出网页的魅力, ...

  4. C#/VB.NET 添加多行文本水印到Word文档

    一般情况下,在Word中添加文字水印仅支持添加一个文本字样的水印,但在复杂的办公环境中,由于对不同文档的设计要求,需要在Word文档中添加平铺水印效果,即文档中的水印文字以多行多列分布的形式存在.本文 ...

  5. 推荐系统-协同过滤在Spark中的实现

    作者:vivo 互联网服务器团队-Tang Shutao 现如今推荐无处不在,例如抖音.淘宝.京东App均能见到推荐系统的身影,其背后涉及许多的技术.本文以经典的协同过滤为切入点,重点介绍了被工业界广 ...

  6. 丽泽普及2022交流赛day19 半社论

    目录 No Problem Str Not TSP 题面 题解 代码 Game 题面 题解 代码 No Problem 暴力 Str 存在循环节,大力找出来即可,长度显然不超过 \(10^3\) . ...

  7. s905l3a系列刷armbian 教你从0搭建自己的博客

    最近服务器又更换了,原来的有一点点小意外(一个电阻给我焊接时搞掉了). 哎~~今天,我淘到了一个好东西----CM311-3a,配置很诱人,价格也不贵,60绰绰有余 比较 CM311-3a N1(炒到 ...

  8. 技术分享 | 将GreatSQL添加到系统systemd服务

    欢迎来到 GreatSQL社区分享的MySQL技术文章,如有疑问或想学习的内容,可以在下方评论区留言,看到后会进行解答 GreatSQL社区原创内容未经授权不得随意使用,转载请联系小编并注明来源. 1 ...

  9. 一键到位「GitHub 热点速览 v.22.32」

    作者:HelloGitHub-小鱼干 上上周在 B 站观看了智能键盘--瀚文的制作过程,本周 GitHub 热榜上出现了它的软硬件开源项目 HelloWord-Keyboard,如果你的动手能力强不妨 ...

  10. NetCore路由的Endpoint模式

    IdentityServer里有各种Endpoint,如TokenEndpoint,UserInfoEndpoint,Authorize Endpoint,Discovery Endpoint等等.E ...