Für unser neues Programm "Apache Spark for Data Engineers" und das Webinar zum Kurs am 2. Dezember haben wir eine Übersetzung eines Übersichtsartikels über Spark 3.0 vorbereitet.
Spark 3.0 brachte eine ganze Reihe wichtiger Verbesserungen heraus, darunter: verbesserte Leistung mit ADQ, Lesen von Binärdateien, verbesserte SQL- und Python-Unterstützung, Python 3.0, Hadoop 3-Integration, ACID-Unterstützung.
In diesem Artikel hat der Autor versucht, Beispiele für die Verwendung dieser neuen Funktionen zu geben. Dies ist der erste erste Artikel über die Funktionalität von Spark 3.0. Diese Artikelserie soll fortgesetzt werden.
Dieser Artikel hebt die folgenden Funktionen in Spark 3.0 hervor:
AQE-Framework (Adaptive Query Execution)
Unterstützung für neue Sprachen
Neue Schnittstelle für strukturiertes Streaming
Binärdateien lesen
Rekursives Durchsuchen von Ordnern
Unterstützung für mehrere Datenbegrenzer (||)
Neue integrierte Spark-Funktionen
Wechseln Sie zum proleptischen Gregorianischen Kalender
Data Frame Tail
Repartitionsfunktion in SQL-Abfragen
Verbesserte ANSI SQL-Kompatibilität
(AQE) – , , Spark 3.0. , , .
3.0 Spark , , Spark , . AQE , , , .
, (AQE) . spark.sql.adaptive.enabled true. AQE, Spark TPC-DS Spark 2.4
AQE Spark 3.0 3 :
,
join sort-merge broadcast
Spark 3.0 , :
Python3 (Python 2.x)
Scala 2.12
JDK 11
Hadoop 3 , Kafka 2.4.1 .
Spark Structured Streaming
web- Spark . , , , -, . , .
2 :
: Databricks
«Active Streaming Queries» , «Completed Streaming Queries» – .
Run ID : , , , , , . , Databricks.
Spark 3.0 “binaryFile”, .
binaryFile, DataFrameReader image, pdf, zip, gzip, tar . , .
val df = spark.read.format("binaryFile").load("/tmp/binary/spark.png")
df.printSchema()
df.show()
root
|-- path: string (nullable = true)
|-- modificationTime: timestamp (nullable = true)
|-- length: long (nullable = true)
|-- content: binary (nullable = true)
+--------------------+--------------------+------+--------------------+
| path| modificationTime|length| content|
+--------------------+--------------------+------+--------------------+
|file:/C:/tmp/bina…|2020-07-25 10:11:…| 74675|[89 50 4E 47 0D 0...|
+--------------------+--------------------+------+--------------------+
Spark 3.0 recursiveFileLookup, . true , DataFrameReader , .
spark.read.option("recursiveFileLookup", "true").csv("/path/to/folder")
Spark 3.0 (||) CSV . , CSV :
col1||col2||col3||col4
val1||val2||val3||val4
val1||val2||val3||val4
:
val df = spark.read
.option("delimiter","||")
.option("header","true")
.csv("/tmp/data/douplepipedata.csv")
Spark 2.x , . :
throws java.lang.IllegalArgumentException: Delimiter cannot be more than one character: ||
Spark
Spark SQL, Spark .
sinh,cosh,tanh,asinh,acosh,atanh,any,bitand,bitor,bitcount,bitxor,
booland,boolor,countif,datepart,extract,forall,fromcsv,
makedate,makeinterval,maketimestamp,mapentries
mapfilter,mapzipwith,maxby,minby,schemaofcsv,tocsv
transformkeys,transform_values,typeof,version
xxhash64
Spark : 1582 , – .
JDK 7 java.sql.Date API. JDK 8 java.time.LocalDate API .
Spark 3.0 , Pandas, R Apache Arrow. 15 1582 ., Date&Timestamp, Spark 3.0, . , 15 1582 .
Spark 3.0 Date & Timestamp :
makedate(), maketimestamp(), makeinterval().
makedate(year, month, day) – <>, <> <>.
makedate(2014, 8, 13)
//returns 2014-08-13.
maketimestamp(year, month, day, hour, min, sec[, timezone]) – Timestamp <>, <>, <>, <>, <>, < >.
maketimestamp(2014, 8, 13, 1,10,40.147)
//returns Timestamp 2014-08-13 1:10:40.147
maketimestamp(2014, 8, 13, 1,10,40.147,CET)
makeinterval(years, months, weeks, days, hours, mins, secs) –
makedate() make_timestam() 0.
DataFrame.tail()
Spark head(), , tail(), Pandas Python. Spark 3.0 tail() . tail() scala.Array[T] Scala.
val data=spark.range(1,100).toDF("num").tail(5)
data.foreach(print)
//Returns
//[95][96][97][98][99]
repartition SQL
SQL Spark actions, Dataset/DataFrame, , Spark SQL repartition() . SQL-. .
val df=spark.range(1,10000).toDF("num")
println("Before re-partition :"+df.rdd.getNumPartitions)
df.createOrReplaceTempView("RANGE¨C17CTABLE")
println("After re-partition :"+df2.rdd.getNumPartitions)
//Returns
//Before re-partition :1
//After re-partition :20
ANSI SQL
Spark data-, ANSI SQL, Spark 3.0 . , true spark.sql.parser.ansi.enabled Spark .
Newprolab Apache Spark:
Apache Spark - (Scala). 11 , 5 .
Apache Spark (Python). " ". 6 , 5 .