Spark 3.0: novos recursos e exemplos de seu uso - parte 1

Para nosso novo programa "Apache Spark para Engenheiros de Dados" e o webinar sobre o curso , que acontecerá em 2 de dezembro, preparamos uma tradução de um artigo de visão geral sobre o Spark 3.0.

Spark 3.0 saiu com um monte de melhorias importantes, incluindo: desempenho aprimorado com ADQ, leitura de binários, suporte aprimorado de SQL e Python, Python 3.0, integração de Hadoop 3, suporte ACID. 

Neste artigo, o autor tentou dar exemplos do uso dessas novas funções. Este é o primeiro artigo sobre a funcionalidade do Spark 3.0 e esta série de artigos deve continuar.

Este artigo destaca os seguintes recursos no Spark 3.0:

  • Estrutura Adaptive Query Execution (AQE)

  • Suporte para novos idiomas

  • Nova interface para streaming estruturado

  • Lendo arquivos binários

  • Navegação recursiva de pasta

  • Suporte a múltiplos delimitadores de dados (||)

  • Novos recursos integrados do Spark

  • Mudar para o calendário gregoriano proléptico

  • Data Frame Tail

  • Função de repartição em consultas SQL

  • Compatibilidade ANSI SQL aprimorada

(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 .




All Articles