{"id":342289,"date":"2022-12-07T15:02:52","date_gmt":"2022-12-07T15:02:52","guid":{"rendered":"http:\/\/savepearlharbor.com\/?p=342289"},"modified":"-0001-11-30T00:00:00","modified_gmt":"-0001-11-29T21:00:00","slug":"","status":"publish","type":"post","link":"https:\/\/savepearlharbor.com\/?p=342289","title":{"rendered":"<span>\u041a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u043f\u0430\u0440\u0442\u0438\u0446\u0438\u0439 \u0432 Spark DataFrame, DataSet \u043d\u0430 \u043e\u0441\u043d\u043e\u0432\u0435 Relational Data Base table<\/span>"},"content":{"rendered":"<div><\/div>\n<div id=\"post-content-body\">\n<div>\n<div class=\"article-formatted-body article-formatted-body article-formatted-body_version-2\">\n<div xmlns=\"http:\/\/www.w3.org\/1999\/xhtml\">\n<figure class=\"full-width\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/6cd\/441\/7bf\/6cd4417bfd3e8083633ef0f8cbe41589.png\" width=\"780\" height=\"439\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/6cd\/441\/7bf\/6cd4417bfd3e8083633ef0f8cbe41589.png\"\/><figcaption><\/figcaption><\/figure>\n<div class=\"persona\" persona=\"true\"><img decoding=\"async\" persona=\"true\" class=\"image persona__image\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/e80\/e29\/431\/e80e294311e2403007ef5cd13757a7f2.png\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/e80\/e29\/431\/e80e294311e2403007ef5cd13757a7f2.png\"\/><\/p>\n<h5 class=\"persona__heading\" persona=\"true\">\u0410\u0432\u0442\u043e\u0440 \u0441\u0442\u0430\u0442\u044c\u0438: \u0412\u0430\u0434\u0438\u043c \u041e\u043f\u043e\u043b\u044c\u0441\u043a\u0438\u0439<\/h5>\n<p>Luxoft DXC Technology, Scala Big Data \u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a  <\/p>\n<\/div>\n<p><a href=\"https:\/\/habr.com\/ru\/company\/otus\/blog\/686142\/\">\u0412 \u043f\u0440\u043e\u0448\u043b\u043e\u0439 \u0441\u0442\u0430\u0442\u044c\u0435<\/a> \u043c\u044b \u0440\u0430\u0441\u0441\u043c\u043e\u0442\u0440\u0435\u043b\u0438 \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u043f\u0430\u0440\u0442\u0438\u0446\u0438\u0439, \u043a\u043e\u0442\u043e\u0440\u043e\u0435 \u043f\u043e \u0443\u043c\u043e\u043b\u0447\u0430\u043d\u0438\u044e \u0441\u043e\u0437\u0434\u0430\u0435\u0442\u0441\u044f Apache Spark \u043f\u0440\u0438 \u0438\u043d\u0438\u0446\u0438\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438 DataFrame, DataSet:<\/p>\n<ol>\n<li>\n<p>\u0441\u043e\u0437\u0434\u0430\u043d\u043d\u044b\u0445 \u043d\u0430 \u043e\u0441\u043d\u043e\u0432\u0435 Scala \u043a\u043e\u043b\u043b\u0435\u043a\u0446\u0438\u0438;<\/p>\n<\/li>\n<li>\n<p>\u0441\u043e\u0437\u0434\u0430\u043d\u043d\u044b\u0445 \u0438\u0437 \u043f\u0430\u043c\u044f\u0442\u0438;\u00a0<\/p>\n<\/li>\n<li>\n<p>\u0441\u043e\u0437\u0434\u0430\u043d\u043d\u044b\u0445 \u0438\u0437 RDD;<\/p>\n<\/li>\n<li>\n<p>\u0441\u043e\u0437\u0434\u0430\u043d\u043d\u044b\u0445 \u0438\u0437 \u0444\u0430\u0439\u043b\u0430 \u043d\u0430 Hadoop Distributed File System;<\/p>\n<\/li>\n<li>\n<p>\u0441\u043e\u0437\u0434\u0430\u043d\u043d\u044b\u0445 \u0438\u0437 \u0444\u0430\u0439\u043b\u0430 \u043d\u0430 AWS S3;<\/p>\n<\/li>\n<li>\n<p>\u043f\u043e\u043b\u0443\u0447\u0435\u043d\u043d\u043e\u0433\u043e \u0438\u0437 \u0434\u0436\u043e\u0439\u043d\u0430 \u0434\u0432\u0443\u0445 DataFrame \u0438\u043b\u0438 DataSet.<\/p>\n<\/li>\n<\/ol>\n<p>\u0412 \u0442\u0435\u043a\u0443\u0449\u0435\u0439 \u0441\u0442\u0430\u0442\u044c\u0435 \u043f\u0440\u043e\u0434\u043e\u043b\u0436\u0438\u043c \u0440\u0430\u0441\u0441\u043c\u0430\u0442\u0440\u0438\u0432\u0430\u0442\u044c \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u043f\u0430\u0440\u0442\u0438\u0446\u0438\u0439 \u0443 Spark DataFrame \u0438 DataSet, \u0441\u043e\u0437\u0434\u0430\u043d\u043d\u044b\u0445 \u043d\u0430 \u043e\u0441\u043d\u043e\u0432\u0435 \u0442\u0430\u0431\u043b\u0438\u0446\u044b \u0432 Relational Database\u00a0<\/p>\n<p>\u041a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u043f\u0430\u0440\u0442\u0438\u0446\u0438\u0439 \u0432 \u0441\u043e\u0437\u0434\u0430\u043d\u043d\u043e\u043c DataFrame \u043c\u043e\u0436\u0435\u0442 \u0434\u0430\u0442\u044c \u043e\u0442\u0432\u0435\u0442 \u043d\u0430 \u0432\u043e\u043f\u0440\u043e\u0441: \u0441\u043a\u043e\u043b\u044c\u043a\u043e Apache Spark \u0441\u043e\u0437\u0434\u0430\u043b \u0435\u0444\u043b\u043e\u0432 \u0434\u043b\u044f \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u044f \u043f\u0430\u0440\u0430\u043b\u043b\u0435\u043b\u044c\u043d\u043e\u0439 \u0437\u0430\u0433\u0440\u0443\u0437\u043a\u0438 \u0434\u0430\u043d\u043d\u044b\u0445 \u0438\u0437 \u0432\u044b\u0448\u0435\u043f\u0435\u0440\u0435\u0447\u0438\u0441\u043b\u0435\u043d\u043d\u044b\u0445 \u0441\u0442\u043e\u0440\u0430\u0434\u0436\u0435\u0439. \u0418 \u0442\u0430\u043a \u043a\u0430\u043a \u043e\u0441\u043d\u043e\u0432\u043d\u043e\u0435 \u043f\u0440\u0435\u0438\u043c\u0443\u0449\u0435\u0441\u0442\u0432\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u044f Apache Spark \u044d\u0442\u043e \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u044c \u043e\u0440\u0433\u0430\u043d\u0438\u0437\u0430\u0446\u0438\u0438 \u043f\u0430\u0440\u0430\u043b\u043b\u0435\u043b\u044c\u043d\u043e\u0439 \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u043a\u0438 \u0440\u0430\u0441\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u043d\u044b\u0445 \u0434\u0430\u043d\u043d\u044b\u0445 \u043d\u0430 \u043c\u0430\u0448\u0438\u043d\u0430\u0445 \u0441 \u043e\u0433\u0440\u0430\u043d\u0438\u0447\u0435\u043d\u043d\u043e\u0439 \u043c\u043e\u0449\u043d\u043e\u0441\u0442\u044c\u044e, \u0442\u043e \u0434\u043b\u044f Data ENgineer \u0432\u0430\u0436\u043d\u043e \u043a\u0430\u043a \u0440\u0430\u0441\u043f\u0430\u0440\u0430\u043b\u043b\u0435\u043b\u0438\u0442\u044c \u0437\u0430\u0433\u0440\u0443\u0437\u043a\u0443 \u0432 \u0441\u0430\u043c\u043e\u043c \u043d\u0430\u0447\u0430\u043b\u0435.\u00a0\u00a0\u00a0\u00a0<\/p>\n<p>\u0414\u0430\u0432\u0430\u0439\u0442\u0435 \u043d\u0430\u0447\u043d\u0435\u043c \u0441 DataFrame \u0441\u043e\u0437\u0434\u0430\u043d\u043d\u043e\u0433\u043e \u043d\u0430 \u043e\u0441\u043d\u043e\u0432\u0435 \u0442\u0430\u0431\u043b\u0438\u0446\u044b Relational DataBase.\u00a0<\/p>\n<p>\u0414\u043b\u044f \u0442\u0430\u043a\u0438\u0445 Relational DataBase \u043a\u0430\u043a:<\/p>\n<ul>\n<li>\n<p>DB2<\/p>\n<\/li>\n<li>\n<p>MariaDB<\/p>\n<\/li>\n<li>\n<p>MS Sql<\/p>\n<\/li>\n<li>\n<p>Oracle<\/p>\n<\/li>\n<li>\n<p>PostgreSQL<\/p>\n<\/li>\n<\/ul>\n<p>\u0421\u0430\u043c\u044b\u0439 \u043f\u0440\u043e\u0441\u0442\u043e\u0439 \u0432\u0430\u0440\u0438\u0430\u043d\u0442 \u0447\u0442\u0435\u043d\u0438\u044f \u0442\u0430\u0431\u043b\u0438\u0446\u044b Relational Database employee \u0438\u0437 \u0441\u0445\u0435\u043c\u044b HR** \u0441 \u043f\u0440\u0438\u043c\u0435\u0440\u0430\u043c\u0438 \u0432\u044b\u0433\u043b\u044f\u0434\u0438\u0442 \u043a\u0430\u043a:<\/p>\n<pre><code>val parallelism = 3 val spark = SparkSession \u00a0\u00a0.builder() \u00a0\u00a0.appName(\"Integrating Postgres\") \u00a0\u00a0.master(s\"local[$parallelism]\") \u00a0\u00a0.getOrCreate() val jdbcEmployeesDF: DataFrame = spark.read \u00a0\u00a0.format(\"jdbc\") \u00a0\u00a0.option(\"url\", \"jdbc:postgresql:\/\/localhost:5432\/spark\") \u00a0\u00a0.option(\"dbtable\", \"public.employees\") \u00a0\u00a0.option(\"user\", \"docker\") \u00a0\u00a0.option(\"password\", \"docker\") \u00a0\u00a0.load() println(s\"Partitions number is ${jdbcEmployeesDF.rdd.getNumPartitions}\") println(s\"Raw Count of employee is ${jdbcEmployeesDF.count()}\")<\/code><\/pre>\n<p>\u0412 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u0435 \u0442\u0430\u043a\u043e\u0433\u043e \u0447\u0442\u0435\u043d\u0438\u044f \u0431\u0443\u0434\u0435\u0442 \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u043e \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0435\u0435:<\/p>\n<pre><code>\"Partitions number is 1\"  \"Raw Count of employee is 3003\"<\/code><\/pre>\n<p>\u0412\u044b\u0445\u043e\u0434\u0438\u0442, \u0447\u0442\u043e \u043f\u043e \u0434\u0435\u0444\u043e\u043b\u0442\u0443 Apache Spark \u0441\u043e\u0437\u0434\u0430\u0435\u0442 \u043e\u0434\u0438\u043d task \u0438 \u0447\u0438\u0442\u0430\u0435\u0442 \u0434\u0430\u043d\u043d\u044b\u0435 \u0432 \u043e\u0434\u0438\u043d \u043f\u043e\u0442\u043e\u043a. \u0427\u0442\u043e \u0441 \u0442\u043e\u0447\u043a\u0438 \u0437\u0440\u0435\u043d\u0438\u044f \u043d\u0430\u043b\u0438\u0447\u0438\u044f \u043a\u043b\u0430\u0441\u0442\u0435\u0440\u0430 \u0438 \u0434\u0430\u043b\u044c\u043d\u0435\u0439\u0448\u0435\u0439 \u0440\u0430\u0441\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u043d\u043e\u0439 \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u043a\u0438 \u043d\u0435\u0430\u0434\u0435\u043a\u0432\u0430\u0442\u043d\u043e.<\/p>\n<p>\u0422\u0430\u043a\u043e\u0439 \u0436\u0435 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442 \u043c\u044b \u043f\u043e\u043b\u0443\u0447\u0438\u043c, \u0435\u0441\u043b\u0438 \u0431\u0443\u0434\u0435\u043c \u0447\u0438\u0442\u0430\u0442\u044c \u0434\u0430\u043d\u043d\u044b\u0435 \u0438\u0437 <a href=\"https:\/\/www.postgresql.org\/docs\/current\/ddl-partitioning.html#:~:text=2.-,Declarative%20Partitioning,used%20as%20the%20partition%20key\">\u043f\u0430\u0440\u0442\u0438\u0446\u0438\u043e\u043d\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u043e\u0439\u00a0\u0442\u0430\u0431\u043b\u0438\u0446\u044b Postgres<\/a>.\u00a0\u00a0<\/p>\n<p>\u0422.\u0435. Apache Spark, \u0432\u044b\u0447\u0438\u0442\u044b\u0432\u0430\u044f \u0434\u0430\u043d\u043d\u044b\u0435, \u043d\u0435 \u043c\u0430\u043f\u043f\u0438\u0442 \u043f\u0430\u0440\u0442\u0438\u0446\u0438\u0438 Postgres \u043d\u0430 \u043f\u0430\u0440\u0442\u0438\u0446\u0438\u0438 Spark Dataframe.<\/p>\n<h3>\u041a\u0430\u043a \u0436\u0435 \u0443\u043f\u0440\u0430\u0432\u043b\u044f\u0442\u044c \u043f\u0430\u0440\u0430\u043b\u043b\u0435\u043b\u044c\u043d\u044b\u043c \u0447\u0442\u0435\u043d\u0438\u0435\u043c \u0438 \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e\u043c \u043f\u0430\u0440\u0442\u0438\u0446\u0438\u0439?<\/h3>\n<p>\u041c\u0435\u0442\u043e\u0434 <code>.repartition(n)<\/code> \u0438 <code>.repartition(col(colName))<\/code> \u043d\u0435 \u043f\u043e\u0434\u0445\u043e\u0434\u044f\u0442, \u0442\u0430\u043a \u043a\u0430\u043a \u043f\u0430\u0440\u0430\u043b\u0435\u043b\u0438\u0437\u0430\u0446\u0438\u044f \u0431\u0443\u0434\u0435\u0442 \u043f\u0440\u043e\u0438\u0441\u0445\u043e\u0434\u0438\u0442\u044c \u0443\u0436\u0435 \u043f\u043e\u0441\u043b\u0435 \u0442\u043e\u0433\u043e \u043a\u0430\u043a \u0434\u0430\u043d\u043d\u044b\u0435 \u0438\u0437 \u0431\u0430\u0437\u044b \u0431\u0443\u0434\u0443\u0442 \u0432 \u043f\u0430\u043c\u044f\u0442\u0438 Spark.\u00a0<\/p>\n<p>Apache Spark \u043f\u043e\u0434\u0434\u0435\u0440\u0436\u0438\u0432\u0430\u0435\u0442 \u0441\u043f\u0435\u0446\u0438\u0430\u043b\u044c\u043d\u044b\u0435\u00a0\u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u044b \u0434\u043b\u044f DataFrame, DataSet, \u0441\u043e\u0437\u0434\u0430\u043d\u043d\u044b\u0445 \u043d\u0430 \u043e\u0441\u043d\u043e\u0432\u0435 \u0442\u0430\u0431\u043b\u0438\u0446\u0435. \u0412\u0441\u0435 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u044b \u043f\u043e\u0434\u0440\u043e\u0431\u043d\u043e \u043e\u043f\u0438\u0441\u0430\u043d\u044b \u0432 <a href=\"https:\/\/spark.apache.org\/docs\/latest\/sql-data-sources-jdbc.html#data-source-option\">\u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u0430\u0446\u0438\u0438<\/a>.\u00a0<\/p>\n<p>\u0414\u043b\u044f \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438 \u043f\u0430\u0440\u0430\u043b\u043b\u0435\u043b\u0438\u0437\u043c\u0430 \u043d\u0430\u043c \u0438\u043d\u0442\u0435\u0440\u0435\u0441\u043d\u044b \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0435:<\/p>\n<p><code>columnName<\/code> \u0438\u043b\u0438 <code>partitionColumn<\/code> \u2014 \u043a\u043e\u043b\u043e\u043d\u043a\u0430, \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u0431\u0443\u0434\u0435\u0442 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c\u0441\u044f \u0434\u043b\u044f \u0444\u043e\u0440\u043c\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f \u0444\u0438\u043b\u044c\u0442\u0440\u0430 \u0432 SQL \u0437\u0430\u043f\u0440\u043e\u0441\u0430\u0445 \u0441 \u0440\u0430\u0437\u043b\u0438\u0447\u043d\u044b\u0445 \u0431\u0440\u043e\u043a\u0435\u0440\u043e\u0432;<\/p>\n<p><code>lowerBound<\/code>, <code>upperBound<\/code> \u2014 \u043d\u0438\u0436\u043d\u044f\u044f \u0433\u0440\u0430\u043d\u0438\u0446\u0430 \u0438 \u0432\u0435\u0440\u0445\u043d\u044f\u044f \u0433\u0440\u0430\u043d\u0438\u0446\u0430;<\/p>\n<p><code>numPartitions<\/code> \u2014 \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u0447\u0430\u0441\u0442\u0435\u0439 \u043d\u0430 \u043a\u043e\u0442\u043e\u0440\u043e\u0435 \u0431\u0443\u0434\u0435\u0442 \u0440\u0430\u0437\u0431\u0438\u0442\u0430 \u0442\u0430\u0431\u043b\u0438\u0446\u0430 \u0434\u043b\u044f \u043f\u0430\u0440\u0430\u043b\u043b\u0435\u043b\u044c\u043d\u043e\u0433\u043e \u0447\u0442\u0435\u043d\u0438\u044f.<\/p>\n<pre><code>val jdbcEmployeesPartitionedByEmpNoDF: DataSet[Employee] = \u00a0\u00a0spark.read \u00a0\u00a0.jdbc(url = \"jdbc:postgresql:\/\/localhost:5432\/spark\", table = \"public.employees\", columnName = \"emp_no\", lowerBound = 110010, upperBound =\u00a0 499990, numPartitions = 10, connectionProperties \u00a0\u00a0).as[Employee] println(s\"Partitions number is ${jdbcEmployeesPartitionedByEmpNoDF.rdd.getNumPartitions}\") println(s\"Raw Count of employee is ${jdbcEmployeesPartitionedByEmpNoDF.count()}\")<\/code><\/pre>\n<p>\u0412 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u0435 \u0442\u0430\u043a\u043e\u0433\u043e \u0447\u0442\u0435\u043d\u0438\u044f \u0431\u0443\u0434\u0435\u0442 \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u043e \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0435\u0435:<\/p>\n<pre><code>\"Partitions count 0 min emp_no = 10010 and max emp_no = 111400 Partitions count 10003 min emp_no = 200000 and max emp_no = 227000 Partitions count 2701 min emp_no = 227010 and max emp_no = 266000 Partitions count 3900 min emp_no = 266010 and max emp_no = 299990 Partitions count 3399 Partitions count 0 Partitions count 0 min emp_no = 400000 and max emp_no = 421990 Partitions count 2200 min emp_no = 422000 and max emp_no = 460990 Partitions count 3900 min emp_no = 461000 and max emp_no = 499990 Partitions count 3900 Partitions number is 10 Raw Count of employee is 30003\"<\/code><\/pre>\n<p>\u041a\u0430\u043a \u0432\u0438\u0434\u043d\u043e \u043d\u0430 \u043b\u043e\u0433\u0430\u0445 \u0432 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u0435 \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u044f \u043a\u043e\u0434\u0430 \u0437\u0430\u0433\u0440\u0443\u0437\u043a\u0430 \u043f\u0440\u043e\u0438\u0441\u0445\u043e\u0434\u0438\u0442 \u0432 7 \u043f\u043e\u0442\u043e\u043a\u043e\u0432, \u043a\u0430\u0436\u0434\u044b\u0439 \u0438\u0437 \u043a\u043e\u0442\u043e\u0440\u044b\u0445 \u0447\u0438\u0442\u0430\u0435\u0442 \u0441\u0432\u043e\u044e \u0447\u0430\u0441\u0442\u044c \u0434\u0430\u043d\u043d\u044b\u0445 \u0438\u0437 \u0431\u0430\u0437\u044b. \u041d\u0430\u043b\u0438\u0447\u0438\u0435 \u0437\u0430\u043f\u0438\u0441\u0435\u0439 \u0441 \u043d\u043e\u043c\u0435\u0440\u0430\u043c\u0438 \u043c\u0435\u043d\u044c\u0448\u0435 110010 \u0433\u043e\u0432\u043e\u0440\u0438\u0442 \u043e \u0442\u043e\u043c, \u0447\u0442\u043e <code>lowerBound<\/code>\u00a0 \u0438 <code>upperBound<\/code> \u0438\u0437 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u043e\u0432 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044e\u0442\u0441\u044f \u0442\u043e\u043b\u044c\u043a\u043e\u00a0 \u0434\u043b\u044f \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u0438\u044f \u0448\u0430\u0433\u0430 \u0440\u0430\u0437\u0434\u0435\u043b\u0430, \u0430 \u043d\u0435 \u0434\u043b\u044f \u0444\u0438\u043b\u044c\u0442\u0440\u0430\u0446\u0438\u0438 \u0441\u0442\u0440\u043e\u043a \u0432 \u0442\u0430\u0431\u043b\u0438\u0446\u0435. \u0422\u0430\u043a\u0438\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c, \u0432\u0441\u0435 \u0441\u0442\u0440\u043e\u043a\u0438 \u0432 \u0442\u0430\u0431\u043b\u0438\u0446\u0435 \u0431\u0443\u0434\u0443\u0442 \u0440\u0430\u0437\u0434\u0435\u043b\u0435\u043d\u044b \u0438 \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0435\u043d\u044b.<\/p>\n<p>\u041d\u0435 \u043f\u043e\u0441\u043b\u0435\u0434\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u043d\u043e \u0438\u0434\u0443\u0449\u0438\u0435 \u043d\u043e\u043c\u0435\u0440\u0430 <code>emp_no<\/code>\u00a0 \u0432 <code>employees<\/code>\u00a0\u043f\u0440\u0438\u0432\u043e\u0434\u0438\u0442 \u043a \u0442\u043e\u043c, \u0447\u0442\u043e \u0435\u0441\u0442\u044c \u043f\u0435\u0440\u0435\u043a\u043e\u0441 \u0432 \u043f\u0430\u0440\u0442\u0438\u0446\u0438\u044f\u0445.\u00a0<\/p>\n<p>\u0420\u0435\u0448\u0438\u0442\u044c \u044d\u0442\u0443 \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u0443 \u043c\u043e\u0436\u043d\u043e \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u0438\u043c\u0438 \u0441\u043f\u043e\u0441\u043e\u0431\u0430\u043c\u0438:\u00a0<\/p>\n<p>\u041f\u0435\u0440\u0432\u043e\u0435, \u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u043f\u043e\u0434\u043e\u0431\u0440\u0430\u0442\u044c \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u044b <code>lowerBound<\/code>\u00a0 \u0438 <code>upperBound<\/code> \u0434\u043b\u044f \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u0438\u044f \u043e\u043f\u0442\u0438\u043c\u0430\u043b\u044c\u043d\u043e\u0433\u043e \u0448\u0430\u0433\u0430.\u00a0<\/p>\n<p>\u0422\u0430\u043a\u0436\u0435 \u043c\u043e\u0436\u043d\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c DataSource v2 \u0438 \u043d\u0430\u043f\u0438\u0441\u0430\u0442\u044c \u0441\u043e\u0431\u0441\u0442\u0432\u0435\u043d\u043d\u044b\u0439 \u043a\u0430\u0441\u0442\u043e\u043c\u043d\u044b\u0439 \u043a\u043e\u043d\u043d\u0435\u043a\u0442\u043e\u0440. \u041a\u0430\u0441\u0442\u043e\u043c\u043d\u044b\u0439 \u043a\u043e\u043d\u043d\u0435\u043a\u0442\u043e\u0440 \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u0442\u0441\u044f \u0442\u0430\u043a\u0436\u0435 \u0440\u0435\u0430\u043b\u0438\u0437\u043e\u0432\u0430\u0442\u044c \u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440 \u043c\u0430\u043f\u043f\u0438\u043d\u0433 \u043f\u0430\u0440\u0442\u0438\u0446\u0438\u0439 \u0442\u0430\u0431\u043b\u0438\u0446\u044b Postgres \u043d\u0430 \u043f\u0430\u0440\u0442\u0438\u0446\u0438\u0438 DataFrame. \u0427\u0442\u043e\u0431\u044b \u0440\u0435\u0430\u043b\u0438\u0437\u043e\u0432\u0430\u0442\u044c \u043d\u0430\u043f\u0438\u0441\u0430\u0442\u044c \u043a\u0430\u0441\u0442\u043e\u043c\u043d\u044b\u0439 \u043a\u043e\u043d\u043d\u0435\u043a\u0442\u043e\u0440, \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u044b \u0431\u0430\u0437\u043e\u0432\u044b\u0435 \u0437\u043d\u0430\u043d\u0438\u044f Scala (\u0442\u0430\u043a \u043a\u0430\u043a Apache Spark \u043d\u0430\u043f\u0438\u0441\u0430\u043d \u043d\u0430 Scala) \u0438 \u0437\u043d\u0430\u043d\u0438\u044f \u0440\u0430\u0431\u043e\u0442\u044b RDD, DataFrame, DataSet \u043f\u043e\u0434 \u043a\u0430\u043f\u043e\u0442\u043e\u043c. \u041d\u0430 \u043a\u0443\u0440\u0441\u0435 \u041e\u0422\u0423\u0421\u0430 <a href=\"https:\/\/otus.pw\/Zy0t\/\">Spark Developer<\/a> \u043c\u043e\u0436\u043d\u043e \u0431\u044b\u0441\u0442\u0440\u043e \u043e\u0441\u0432\u043e\u0438\u0442\u044c \u0432\u0441\u0435 \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u044b\u0435 \u0437\u043d\u0430\u043d\u0438\u044f \u0438 \u043d\u0430\u043f\u0438\u0441\u0430\u0442\u044c \u043a\u0430\u0441\u0442\u043e\u043c\u043d\u044b\u0439 \u043a\u043e\u043d\u043d\u0435\u043a\u0442\u043e\u0440.<\/p>\n<p>\u041f\u0430\u0440\u0430\u043c\u0435\u0442\u0440 \u0434\u043b\u044f DataFrame \u043c\u0430\u0441\u0441\u0438\u0432 \u043f\u0440\u0435\u0434\u0438\u043a\u0430\u0442\u043e\u0432 \u044d\u0442\u043e \u0435\u0449\u0435 \u043e\u0434\u0438\u043d \u0441\u043f\u043e\u0441\u043e\u0431 \u0440\u0430\u0437\u0431\u0438\u0442\u044c \u0438\u0441\u0445\u043e\u0434\u043d\u0443\u044e \u0442\u0430\u0431\u043b\u0438\u0446\u0443 \u0432 \u0440\u0435\u043b\u044f\u0446\u0438\u043e\u043d\u043d\u043e\u0439 \u0431\u0430\u0437\u0435 \u0434\u0430\u043d\u043d\u044b\u0445, \u043a\u043e\u0433\u0434\u0430, \u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u0443 \u043d\u0430\u0441 \u043d\u0435\u0442 \u043a\u043e\u043b\u043e\u043d\u043a\u0438 \u0441 \u043f\u043e\u0441\u043b\u0435\u0434\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u043d\u043e \u0438\u0434\u0443\u0449\u0438\u043c\u0438 \u043d\u0435\u043f\u043e\u0432\u0442\u043e\u0440\u044f\u044e\u0449\u0438\u043c\u0441\u044f \u0447\u0438\u0441\u043b\u043e\u0432\u044b\u043c\u0438 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f\u043c\u0438, \u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440 id.\u00a0<\/p>\n<p>\u0412 \u043f\u0440\u043e\u0441\u0442\u043e\u043c \u0441\u043b\u0443\u0447\u0430\u0435 \u043c\u044b \u043c\u043e\u0436\u0435\u043c \u0440\u0430\u0437\u0434\u0435\u043b\u0438\u0442\u044c DataFrame \u043d\u0430 \u0434\u0432\u0435 \u0447\u0430\u0441\u0442\u0438, \u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u0432\u0441\u0435 \u0437\u0430\u043f\u0438\u0441\u0438 \u0441 gender male \u0431\u0443\u0434\u0443\u0442 \u0432 \u043e\u0434\u043d\u043e\u043c \u0434\u0430\u0442\u0430 \u0444\u0440\u0435\u0439\u043c\u0435, \u0432\u0441\u0435 \u043e\u0441\u0442\u0430\u043b\u044c\u043d\u044b\u0435 \u0432 \u0434\u0440\u0443\u0433\u043e\u043c.\u00a0\u041a\u043e\u0434, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043f\u043e\u0437\u0432\u043e\u043b\u0438\u0442 \u0437\u0430\u0433\u0440\u0443\u0436\u0430\u0442\u044c \u0434\u0430\u043d\u043d\u044b\u0435 \u043f\u043e \u043f\u043e\u043b\u043e\u0432\u043e\u043c\u0443 \u043f\u0440\u0438\u0437\u043d\u0430\u043a\u0443, \u0431\u0443\u0434\u0435\u0442 \u0432\u044b\u0433\u043b\u044f\u0434\u0435\u0442\u044c \u0442\u0430\u043a:<\/p>\n<pre><code>val jdbcEmployeesPartitionedByGenderDF = \u00a0\u00a0spark.read .jdbc(url = \"jdbc:postgresql:\/\/localhost:5432\/spark\", \u00a0\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 table = \"public.employees\", \u00a0\u00a0\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 predicates = Array(\"gender = 'M'\", \"gender = 'F'\"), \u00a0\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 connectionProperties = connectionProperties) jdbcEmployeesPartitionedByGenderDF.rdd.foreachPartition { it => \u00a0\u00a0\u00a0println(s\"Partitions count = ${it.length}\") }  Partitions count = 12091 Partitions count = 17912 Partitions number is 2 Raw Count of employee is 30003<\/code><\/pre>\n<p>\u0422\u0430\u043a\u043e\u0439 \u0432\u0430\u0440\u0438\u0430\u043d\u0442 \u043d\u0435\u043c\u043d\u043e\u0433\u043e \u043b\u0443\u0447\u0448\u0435, \u0447\u0435\u043c \u0437\u0430\u0433\u0440\u0443\u0437\u043a\u0430 \u0434\u0430\u043d\u043d\u044b\u0445 \u0432 \u043e\u0434\u0438\u043d \u043f\u043e\u0442\u043e\u043a.\u00a0<\/p>\n<p>\u0415\u0441\u043b\u0438 \u0437\u0430\u043f\u0443\u0441\u0442\u0438\u0442\u044c \u043a\u043e\u0434 \u0441 \u0442\u0430\u043a\u0438\u043c \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u043e\u043c:<\/p>\n<pre><code>predicates = Array(\"gender = 'M'\", \"gender = 'F'\", \"gender = 'M'\")<\/code><\/pre>\n<p>\u0420\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u043e\u043c \u0431\u0443\u0434\u0435\u0442\u00a0<\/p>\n<pre><code>Partitions count = 12091 Partitions count = 17912 Partitions count = 17912 Partitions number is 3 Raw Count of employee is 47915<\/code><\/pre>\n<p>\u041a\u0430\u043a \u0432\u0438\u0434\u043d\u043e \u0438\u0437 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u0430, \u0431\u044b\u043b\u0430 \u0441\u043e\u0437\u0434\u0430\u043d\u0430 \u0435\u0449\u0435 \u043e\u0434\u043d\u0430 \u043f\u0430\u0440\u0442\u0438\u0446\u0438\u044f \u0438 \u0434\u0430\u043d\u043d\u044b\u0435 \u0431\u044b\u043b\u0438 \u0434\u0443\u043f\u043b\u0438\u0446\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u044b\u0435. \u0418\u043c\u0435\u043d\u043d\u043e \u043f\u043e\u044d\u0442\u043e\u043c\u0443 \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e \u0430\u043a\u043a\u0443\u0440\u0430\u0442\u043d\u043e \u0432\u044b\u0431\u0438\u0440\u0430\u0442\u044c \u043f\u0440\u0435\u0434\u0438\u043a\u0430\u0442\u044b \u0434\u043b\u044f \u0440\u0430\u0431\u043e\u0442\u044b.<\/p>\n<p>\u0412 \u0441\u0442\u0430\u0442\u044c\u0435 \u043c\u044b \u0440\u0430\u0437\u043e\u0431\u0440\u0430\u043b\u0438, \u043a\u0430\u043a \u0443\u0432\u0435\u043b\u0438\u0447\u0438\u0442\u044c \u0441\u043a\u043e\u0440\u043e\u0441\u0442\u044c \u0437\u0430\u0433\u0440\u0443\u0437\u043a\u0438 \u0434\u0430\u043d\u043d\u044b\u0445 \u0438\u0437 \u0440\u0435\u043b\u044f\u0446\u0438\u043e\u043d\u043d\u043e\u0439 \u0431\u0430\u0437\u044b \u0432 Spark \u0432 \u043f\u0430\u0440\u0430\u043b\u043b\u0435\u043b\u044c\u043d\u043e\u043c \u0440\u0435\u0436\u0438\u043c\u0435, \u0430 \u0442\u0430\u043a\u0436\u0435 \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u044b, \u0441 \u043a\u043e\u0442\u043e\u0440\u044b\u043c\u0438 \u043c\u044b \u043c\u043e\u0436\u0435\u043c \u0432\u0441\u0442\u0440\u0435\u0442\u0438\u0442\u044c\u0441\u044f.\u00a0<\/p>\n<pre><code>** \u0441\u043e\u0437\u0434\u0430\u043d\u043d\u0430\u044f \u0442\u0430\u0431\u043b\u0438\u0446\u0430  CREATE TABLE employees ( emp_no\u00a0 INT \u00a0 \u00a0 \u00a0 \u00a0 NOT NULL, birth_date\u00a0 DATE\u00a0 \u00a0 \u00a0 \u00a0 NOT NULL, first_name\u00a0 VARCHAR(14) NOT NULL, last_name \u00a0 VARCHAR(16) NOT NULL, gender\u00a0 gender\u00a0 \u00a0 \u00a0 NULL, hire_date \u00a0 DATE\u00a0 \u00a0 \u00a0 \u00a0 NOT NULL, PRIMARY KEY (emp_no) );  ** \u0441\u043e\u0437\u0434\u0430\u043d\u043d\u0430\u044f \u0442\u0430\u0431\u043b\u0438\u0446\u0430  CREATE TABLE employees ( emp_no\u00a0 INT \u00a0 \u00a0 \u00a0 \u00a0 NOT NULL, birth_date\u00a0 DATE\u00a0 \u00a0 \u00a0 \u00a0 NOT NULL, first_name\u00a0 VARCHAR(14) NOT NULL, last_name \u00a0 VARCHAR(16) NOT NULL, gender\u00a0 gender\u00a0 \u00a0 \u00a0 NULL, hire_date \u00a0 DATE\u00a0 \u00a0 \u00a0 \u00a0 NOT NULL, PRIMARY KEY (emp_no) ) PARTITION BY HASH (emp_no);<\/code><\/pre>\n<p>\u0412 \u0437\u0430\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0435 \u043f\u0440\u0438\u0433\u043b\u0430\u0448\u0430\u044e \u0432\u0441\u0435\u0445 \u0436\u0435\u043b\u0430\u044e\u0449\u0438\u0445 \u043d\u0430 \u043e\u0442\u043a\u0440\u044b\u0442\u043e\u0435 \u0437\u0430\u043d\u044f\u0442\u0438\u0435 \u00abSpark \u0432 Kubernetes\u00bb. \u041d\u0430 \u0443\u0440\u043e\u043a\u0435 \u043c\u044b:<\/p>\n<ul>\n<li>\n<p>\u041a\u0440\u0430\u0442\u043a\u043e \u0440\u0430\u0441\u0441\u043c\u043e\u0442\u0440\u0438\u043c, \u0447\u0442\u043e \u0442\u0430\u043a\u043e\u0435 Spark \u0438 \u0447\u0442\u043e \u0442\u0430\u043a\u043e\u0435 Kubernetes;<\/p>\n<\/li>\n<li>\n<p>\u0420\u0430\u0441\u0441\u043c\u043e\u0442\u0440\u0438\u043c \u043e\u0441\u043e\u0431\u0435\u043d\u043d\u043e\u0441\u0442\u0438 \u0438 \u0432\u0430\u0440\u0438\u0430\u043d\u0442\u044b \u0437\u0430\u043f\u0443\u0441\u043a\u0430 Spark \u0432 Kubernetes;<\/p>\n<\/li>\n<li>\n<p>\u0421\u0440\u0430\u0432\u043d\u0438\u043c \u0440\u0430\u0431\u043e\u0442\u0443 Spark \u0432 Kubernetus \u0438 Hadoop Yarn.<\/p>\n<\/li>\n<\/ul>\n<p><a href=\"https:\/\/otus.pw\/VSL0j\/\">\u0420\u0435\u0433\u0438\u0441\u0442\u0440\u0430\u0446\u0438\u044f \u043d\u0430 \u0443\u0440\u043e\u043a.<\/a><\/p>\n<\/p>\n<\/div>\n<\/div>\n<\/div>\n<p> <!----> <!----><\/div>\n<p> <!----> <!----><br \/> \u0441\u0441\u044b\u043b\u043a\u0430 \u043d\u0430 \u043e\u0440\u0438\u0433\u0438\u043d\u0430\u043b \u0441\u0442\u0430\u0442\u044c\u0438 <a href=\"https:\/\/habr.com\/ru\/company\/otus\/blog\/704010\/\"> https:\/\/habr.com\/ru\/company\/otus\/blog\/704010\/<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<div><\/div>\n<div id=\"post-content-body\">\n<div>\n<div class=\"article-formatted-body article-formatted-body article-formatted-body_version-2\">\n<div xmlns=\"http:\/\/www.w3.org\/1999\/xhtml\">\n<figure class=\"full-width\"><figcaption><\/figcaption><\/figure>\n<div class=\"persona\" persona=\"true\">\n<h5 class=\"persona__heading\" persona=\"true\">\u0410\u0432\u0442\u043e\u0440 \u0441\u0442\u0430\u0442\u044c\u0438: \u0412\u0430\u0434\u0438\u043c \u041e\u043f\u043e\u043b\u044c\u0441\u043a\u0438\u0439<\/h5>\n<p>Luxoft DXC Technology, Scala Big Data \u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a  <\/p>\n<\/div>\n<p><a href=\"https:\/\/habr.com\/ru\/company\/otus\/blog\/686142\/\">\u0412 \u043f\u0440\u043e\u0448\u043b\u043e\u0439 \u0441\u0442\u0430\u0442\u044c\u0435<\/a> \u043c\u044b \u0440\u0430\u0441\u0441\u043c\u043e\u0442\u0440\u0435\u043b\u0438 \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u043f\u0430\u0440\u0442\u0438\u0446\u0438\u0439, \u043a\u043e\u0442\u043e\u0440\u043e\u0435 \u043f\u043e \u0443\u043c\u043e\u043b\u0447\u0430\u043d\u0438\u044e \u0441\u043e\u0437\u0434\u0430\u0435\u0442\u0441\u044f Apache Spark \u043f\u0440\u0438 \u0438\u043d\u0438\u0446\u0438\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438 DataFrame, DataSet:<\/p>\n<ol>\n<li>\n<p>\u0441\u043e\u0437\u0434\u0430\u043d\u043d\u044b\u0445 \u043d\u0430 \u043e\u0441\u043d\u043e\u0432\u0435 Scala \u043a\u043e\u043b\u043b\u0435\u043a\u0446\u0438\u0438;<\/p>\n<\/li>\n<li>\n<p>\u0441\u043e\u0437\u0434\u0430\u043d\u043d\u044b\u0445 \u0438\u0437 \u043f\u0430\u043c\u044f\u0442\u0438;\u00a0<\/p>\n<\/li>\n<li>\n<p>\u0441\u043e\u0437\u0434\u0430\u043d\u043d\u044b\u0445 \u0438\u0437 RDD;<\/p>\n<\/li>\n<li>\n<p>\u0441\u043e\u0437\u0434\u0430\u043d\u043d\u044b\u0445 \u0438\u0437 \u0444\u0430\u0439\u043b\u0430 \u043d\u0430 Hadoop Distributed File System;<\/p>\n<\/li>\n<li>\n<p>\u0441\u043e\u0437\u0434\u0430\u043d\u043d\u044b\u0445 \u0438\u0437 \u0444\u0430\u0439\u043b\u0430 \u043d\u0430 AWS S3;<\/p>\n<\/li>\n<li>\n<p>\u043f\u043e\u043b\u0443\u0447\u0435\u043d\u043d\u043e\u0433\u043e \u0438\u0437 \u0434\u0436\u043e\u0439\u043d\u0430 \u0434\u0432\u0443\u0445 DataFrame \u0438\u043b\u0438 DataSet.<\/p>\n<\/li>\n<\/ol>\n<p>\u0412 \u0442\u0435\u043a\u0443\u0449\u0435\u0439 \u0441\u0442\u0430\u0442\u044c\u0435 \u043f\u0440\u043e\u0434\u043e\u043b\u0436\u0438\u043c \u0440\u0430\u0441\u0441\u043c\u0430\u0442\u0440\u0438\u0432\u0430\u0442\u044c \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u043f\u0430\u0440\u0442\u0438\u0446\u0438\u0439 \u0443 Spark DataFrame \u0438 DataSet, \u0441\u043e\u0437\u0434\u0430\u043d\u043d\u044b\u0445 \u043d\u0430 \u043e\u0441\u043d\u043e\u0432\u0435 \u0442\u0430\u0431\u043b\u0438\u0446\u044b \u0432 Relational Database\u00a0<\/p>\n<p>\u041a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u043f\u0430\u0440\u0442\u0438\u0446\u0438\u0439 \u0432 \u0441\u043e\u0437\u0434\u0430\u043d\u043d\u043e\u043c DataFrame \u043c\u043e\u0436\u0435\u0442 \u0434\u0430\u0442\u044c \u043e\u0442\u0432\u0435\u0442 \u043d\u0430 \u0432\u043e\u043f\u0440\u043e\u0441: \u0441\u043a\u043e\u043b\u044c\u043a\u043e Apache Spark \u0441\u043e\u0437\u0434\u0430\u043b \u0435\u0444\u043b\u043e\u0432 \u0434\u043b\u044f \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u044f \u043f\u0430\u0440\u0430\u043b\u043b\u0435\u043b\u044c\u043d\u043e\u0439 \u0437\u0430\u0433\u0440\u0443\u0437\u043a\u0438 \u0434\u0430\u043d\u043d\u044b\u0445 \u0438\u0437 \u0432\u044b\u0448\u0435\u043f\u0435\u0440\u0435\u0447\u0438\u0441\u043b\u0435\u043d\u043d\u044b\u0445 \u0441\u0442\u043e\u0440\u0430\u0434\u0436\u0435\u0439. \u0418 \u0442\u0430\u043a \u043a\u0430\u043a \u043e\u0441\u043d\u043e\u0432\u043d\u043e\u0435 \u043f\u0440\u0435\u0438\u043c\u0443\u0449\u0435\u0441\u0442\u0432\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u044f Apache Spark \u044d\u0442\u043e \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u044c \u043e\u0440\u0433\u0430\u043d\u0438\u0437\u0430\u0446\u0438\u0438 \u043f\u0430\u0440\u0430\u043b\u043b\u0435\u043b\u044c\u043d\u043e\u0439 \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u043a\u0438 \u0440\u0430\u0441\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u043d\u044b\u0445 \u0434\u0430\u043d\u043d\u044b\u0445 \u043d\u0430 \u043c\u0430\u0448\u0438\u043d\u0430\u0445 \u0441 \u043e\u0433\u0440\u0430\u043d\u0438\u0447\u0435\u043d\u043d\u043e\u0439 \u043c\u043e\u0449\u043d\u043e\u0441\u0442\u044c\u044e, \u0442\u043e \u0434\u043b\u044f Data ENgineer \u0432\u0430\u0436\u043d\u043e \u043a\u0430\u043a \u0440\u0430\u0441\u043f\u0430\u0440\u0430\u043b\u043b\u0435\u043b\u0438\u0442\u044c \u0437\u0430\u0433\u0440\u0443\u0437\u043a\u0443 \u0432 \u0441\u0430\u043c\u043e\u043c \u043d\u0430\u0447\u0430\u043b\u0435.\u00a0\u00a0\u00a0\u00a0<\/p>\n<p>\u0414\u0430\u0432\u0430\u0439\u0442\u0435 \u043d\u0430\u0447\u043d\u0435\u043c \u0441 DataFrame \u0441\u043e\u0437\u0434\u0430\u043d\u043d\u043e\u0433\u043e \u043d\u0430 \u043e\u0441\u043d\u043e\u0432\u0435 \u0442\u0430\u0431\u043b\u0438\u0446\u044b Relational DataBase.\u00a0<\/p>\n<p>\u0414\u043b\u044f \u0442\u0430\u043a\u0438\u0445 Relational DataBase \u043a\u0430\u043a:<\/p>\n<ul>\n<li>\n<p>DB2<\/p>\n<\/li>\n<li>\n<p>MariaDB<\/p>\n<\/li>\n<li>\n<p>MS Sql<\/p>\n<\/li>\n<li>\n<p>Oracle<\/p>\n<\/li>\n<li>\n<p>PostgreSQL<\/p>\n<\/li>\n<\/ul>\n<p>\u0421\u0430\u043c\u044b\u0439 \u043f\u0440\u043e\u0441\u0442\u043e\u0439 \u0432\u0430\u0440\u0438\u0430\u043d\u0442 \u0447\u0442\u0435\u043d\u0438\u044f \u0442\u0430\u0431\u043b\u0438\u0446\u044b Relational Database employee \u0438\u0437 \u0441\u0445\u0435\u043c\u044b HR** \u0441 \u043f\u0440\u0438\u043c\u0435\u0440\u0430\u043c\u0438 \u0432\u044b\u0433\u043b\u044f\u0434\u0438\u0442 \u043a\u0430\u043a:<\/p>\n<pre><code>val parallelism = 3 val spark = SparkSession \u00a0\u00a0.builder() \u00a0\u00a0.appName(\"Integrating Postgres\") \u00a0\u00a0.master(s\"local[$parallelism]\") \u00a0\u00a0.getOrCreate() val jdbcEmployeesDF: DataFrame = spark.read \u00a0\u00a0.format(\"jdbc\") \u00a0\u00a0.option(\"url\", \"jdbc:postgresql:\/\/localhost:5432\/spark\") \u00a0\u00a0.option(\"dbtable\", \"public.employees\") \u00a0\u00a0.option(\"user\", \"docker\") \u00a0\u00a0.option(\"password\", \"docker\") \u00a0\u00a0.load() println(s\"Partitions number is ${jdbcEmployeesDF.rdd.getNumPartitions}\") println(s\"Raw Count of employee is ${jdbcEmployeesDF.count()}\")<\/code><\/pre>\n<p>\u0412 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u0435 \u0442\u0430\u043a\u043e\u0433\u043e \u0447\u0442\u0435\u043d\u0438\u044f \u0431\u0443\u0434\u0435\u0442 \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u043e \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0435\u0435:<\/p>\n<pre><code>\"Partitions number is 1\"  \"Raw Count of employee is 3003\"<\/code><\/pre>\n<p>\u0412\u044b\u0445\u043e\u0434\u0438\u0442, \u0447\u0442\u043e \u043f\u043e \u0434\u0435\u0444\u043e\u043b\u0442\u0443 Apache Spark \u0441\u043e\u0437\u0434\u0430\u0435\u0442 \u043e\u0434\u0438\u043d task \u0438 \u0447\u0438\u0442\u0430\u0435\u0442 \u0434\u0430\u043d\u043d\u044b\u0435 \u0432 \u043e\u0434\u0438\u043d \u043f\u043e\u0442\u043e\u043a. \u0427\u0442\u043e \u0441 \u0442\u043e\u0447\u043a\u0438 \u0437\u0440\u0435\u043d\u0438\u044f \u043d\u0430\u043b\u0438\u0447\u0438\u044f \u043a\u043b\u0430\u0441\u0442\u0435\u0440\u0430 \u0438 \u0434\u0430\u043b\u044c\u043d\u0435\u0439\u0448\u0435\u0439 \u0440\u0430\u0441\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u043d\u043e\u0439 \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u043a\u0438 \u043d\u0435\u0430\u0434\u0435\u043a\u0432\u0430\u0442\u043d\u043e.<\/p>\n<p>\u0422\u0430\u043a\u043e\u0439 \u0436\u0435 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442 \u043c\u044b \u043f\u043e\u043b\u0443\u0447\u0438\u043c, \u0435\u0441\u043b\u0438 \u0431\u0443\u0434\u0435\u043c \u0447\u0438\u0442\u0430\u0442\u044c \u0434\u0430\u043d\u043d\u044b\u0435 \u0438\u0437 <a href=\"https:\/\/www.postgresql.org\/docs\/current\/ddl-partitioning.html#:~:text=2.-,Declarative%20Partitioning,used%20as%20the%20partition%20key\">\u043f\u0430\u0440\u0442\u0438\u0446\u0438\u043e\u043d\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u043e\u0439\u00a0\u0442\u0430\u0431\u043b\u0438\u0446\u044b Postgres<\/a>.\u00a0\u00a0<\/p>\n<p>\u0422.\u0435. Apache Spark, \u0432\u044b\u0447\u0438\u0442\u044b\u0432\u0430\u044f \u0434\u0430\u043d\u043d\u044b\u0435, \u043d\u0435 \u043c\u0430\u043f\u043f\u0438\u0442 \u043f\u0430\u0440\u0442\u0438\u0446\u0438\u0438 Postgres \u043d\u0430 \u043f\u0430\u0440\u0442\u0438\u0446\u0438\u0438 Spark Dataframe.<\/p>\n<h3>\u041a\u0430\u043a \u0436\u0435 \u0443\u043f\u0440\u0430\u0432\u043b\u044f\u0442\u044c \u043f\u0430\u0440\u0430\u043b\u043b\u0435\u043b\u044c\u043d\u044b\u043c \u0447\u0442\u0435\u043d\u0438\u0435\u043c \u0438 \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e\u043c \u043f\u0430\u0440\u0442\u0438\u0446\u0438\u0439?<\/h3>\n<p>\u041c\u0435\u0442\u043e\u0434 <code>.repartition(n)<\/code> \u0438 <code>.repartition(col(colName))<\/code> \u043d\u0435 \u043f\u043e\u0434\u0445\u043e\u0434\u044f\u0442, \u0442\u0430\u043a \u043a\u0430\u043a \u043f\u0430\u0440\u0430\u043b\u0435\u043b\u0438\u0437\u0430\u0446\u0438\u044f \u0431\u0443\u0434\u0435\u0442 \u043f\u0440\u043e\u0438\u0441\u0445\u043e\u0434\u0438\u0442\u044c \u0443\u0436\u0435 \u043f\u043e\u0441\u043b\u0435 \u0442\u043e\u0433\u043e \u043a\u0430\u043a \u0434\u0430\u043d\u043d\u044b\u0435 \u0438\u0437 \u0431\u0430\u0437\u044b \u0431\u0443\u0434\u0443\u0442 \u0432 \u043f\u0430\u043c\u044f\u0442\u0438 Spark.\u00a0<\/p>\n<p>Apache Spark \u043f\u043e\u0434\u0434\u0435\u0440\u0436\u0438\u0432\u0430\u0435\u0442 \u0441\u043f\u0435\u0446\u0438\u0430\u043b\u044c\u043d\u044b\u0435\u00a0\u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u044b \u0434\u043b\u044f DataFrame, DataSet, \u0441\u043e\u0437\u0434\u0430\u043d\u043d\u044b\u0445 \u043d\u0430 \u043e\u0441\u043d\u043e\u0432\u0435 \u0442\u0430\u0431\u043b\u0438\u0446\u0435. \u0412\u0441\u0435 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u044b \u043f\u043e\u0434\u0440\u043e\u0431\u043d\u043e \u043e\u043f\u0438\u0441\u0430\u043d\u044b \u0432 <a href=\"https:\/\/spark.apache.org\/docs\/latest\/sql-data-sources-jdbc.html#data-source-option\">\u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u0430\u0446\u0438\u0438<\/a>.\u00a0<\/p>\n<p>\u0414\u043b\u044f \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438 \u043f\u0430\u0440\u0430\u043b\u043b\u0435\u043b\u0438\u0437\u043c\u0430 \u043d\u0430\u043c \u0438\u043d\u0442\u0435\u0440\u0435\u0441\u043d\u044b \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0435:<\/p>\n<p><code>columnName<\/code> \u0438\u043b\u0438 <code>partitionColumn<\/code> \u2014 \u043a\u043e\u043b\u043e\u043d\u043a\u0430, \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u0431\u0443\u0434\u0435\u0442 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c\u0441\u044f \u0434\u043b\u044f \u0444\u043e\u0440\u043c\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f \u0444\u0438\u043b\u044c\u0442\u0440\u0430 \u0432 SQL \u0437\u0430\u043f\u0440\u043e\u0441\u0430\u0445 \u0441 \u0440\u0430\u0437\u043b\u0438\u0447\u043d\u044b\u0445 \u0431\u0440\u043e\u043a\u0435\u0440\u043e\u0432;<\/p>\n<p><code>lowerBound<\/code>, <code>upperBound<\/code> \u2014 \u043d\u0438\u0436\u043d\u044f\u044f \u0433\u0440\u0430\u043d\u0438\u0446\u0430 \u0438 \u0432\u0435\u0440\u0445\u043d\u044f\u044f \u0433\u0440\u0430\u043d\u0438\u0446\u0430;<\/p>\n<p><code>numPartitions<\/code> \u2014 \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u0447\u0430\u0441\u0442\u0435\u0439 \u043d\u0430 \u043a\u043e\u0442\u043e\u0440\u043e\u0435 \u0431\u0443\u0434\u0435\u0442 \u0440\u0430\u0437\u0431\u0438\u0442\u0430 \u0442\u0430\u0431\u043b\u0438\u0446\u0430 \u0434\u043b\u044f \u043f\u0430\u0440\u0430\u043b\u043b\u0435\u043b\u044c\u043d\u043e\u0433\u043e \u0447\u0442\u0435\u043d\u0438\u044f.<\/p>\n<pre><code>val jdbcEmployeesPartitionedByEmpNoDF: DataSet[Employee] = \u00a0\u00a0spark.read \u00a0\u00a0.jdbc(url = \"jdbc:postgresql:\/\/localhost:5432\/spark\", table = \"public.employees\", columnName = \"emp_no\", lowerBound = 110010, upperBound =\u00a0 499990, numPartitions = 10, connectionProperties \u00a0\u00a0).as[Employee] println(s\"Partitions number is ${jdbcEmployeesPartitionedByEmpNoDF.rdd.getNumPartitions}\") println(s\"Raw Count of employee is ${jdbcEmployeesPartitionedByEmpNoDF.count()}\")<\/code><\/pre>\n<p>\u0412 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u0435 \u0442\u0430\u043a\u043e\u0433\u043e \u0447\u0442\u0435\u043d\u0438\u044f \u0431\u0443\u0434\u0435\u0442 \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u043e \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0435\u0435:<\/p>\n<pre><code>\"Partitions count 0 min emp_no = 10010 and max emp_no = 111400 Partitions count 10003 min emp_no = 200000 and max emp_no = 227000 Partitions count 2701 min emp_no = 227010 and max emp_no = 266000 Partitions count 3900 min emp_no = 266010 and max emp_no = 299990 Partitions count 3399 Partitions count 0 Partitions count 0 min emp_no = 400000 and max emp_no = 421990 Partitions count 2200 min emp_no = 422000 and max emp_no = 460990 Partitions count 3900 min emp_no = 461000 and max emp_no = 499990 Partitions count 3900 Partitions number is 10 Raw Count of employee is 30003\"<\/code><\/pre>\n<p>\u041a\u0430\u043a \u0432\u0438\u0434\u043d\u043e \u043d\u0430 \u043b\u043e\u0433\u0430\u0445 \u0432 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u0435 \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u044f \u043a\u043e\u0434\u0430 \u0437\u0430\u0433\u0440\u0443\u0437\u043a\u0430 \u043f\u0440\u043e\u0438\u0441\u0445\u043e\u0434\u0438\u0442 \u0432 7 \u043f\u043e\u0442\u043e\u043a\u043e\u0432, \u043a\u0430\u0436\u0434\u044b\u0439 \u0438\u0437 \u043a\u043e\u0442\u043e\u0440\u044b\u0445 \u0447\u0438\u0442\u0430\u0435\u0442 \u0441\u0432\u043e\u044e \u0447\u0430\u0441\u0442\u044c \u0434\u0430\u043d\u043d\u044b\u0445 \u0438\u0437 \u0431\u0430\u0437\u044b. \u041d\u0430\u043b\u0438\u0447\u0438\u0435 \u0437\u0430\u043f\u0438\u0441\u0435\u0439 \u0441 \u043d\u043e\u043c\u0435\u0440\u0430\u043c\u0438 \u043c\u0435\u043d\u044c\u0448\u0435 110010 \u0433\u043e\u0432\u043e\u0440\u0438\u0442 \u043e \u0442\u043e\u043c, \u0447\u0442\u043e <code>lowerBound<\/code>\u00a0 \u0438 <code>upperBound<\/code> \u0438\u0437 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u043e\u0432 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044e\u0442\u0441\u044f \u0442\u043e\u043b\u044c\u043a\u043e\u00a0 \u0434\u043b\u044f \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u0438\u044f \u0448\u0430\u0433\u0430 \u0440\u0430\u0437\u0434\u0435\u043b\u0430, \u0430 \u043d\u0435 \u0434\u043b\u044f \u0444\u0438\u043b\u044c\u0442\u0440\u0430\u0446\u0438\u0438 \u0441\u0442\u0440\u043e\u043a \u0432 \u0442\u0430\u0431\u043b\u0438\u0446\u0435. \u0422\u0430\u043a\u0438\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c, \u0432\u0441\u0435 \u0441\u0442\u0440\u043e\u043a\u0438 \u0432 \u0442\u0430\u0431\u043b\u0438\u0446\u0435 \u0431\u0443\u0434\u0443\u0442 \u0440\u0430\u0437\u0434\u0435\u043b\u0435\u043d\u044b \u0438 \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0435\u043d\u044b.<\/p>\n<p>\u041d\u0435 \u043f\u043e\u0441\u043b\u0435\u0434\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u043d\u043e \u0438\u0434\u0443\u0449\u0438\u0435 \u043d\u043e\u043c\u0435\u0440\u0430 <code>emp_no<\/code>\u00a0 \u0432 <code>employees<\/code>\u00a0\u043f\u0440\u0438\u0432\u043e\u0434\u0438\u0442 \u043a \u0442\u043e\u043c, \u0447\u0442\u043e \u0435\u0441\u0442\u044c \u043f\u0435\u0440\u0435\u043a\u043e\u0441 \u0432 \u043f\u0430\u0440\u0442\u0438\u0446\u0438\u044f\u0445.\u00a0<\/p>\n<p>\u0420\u0435\u0448\u0438\u0442\u044c \u044d\u0442\u0443 \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u0443 \u043c\u043e\u0436\u043d\u043e \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u0438\u043c\u0438 \u0441\u043f\u043e\u0441\u043e\u0431\u0430\u043c\u0438:\u00a0<\/p>\n<p>\u041f\u0435\u0440\u0432\u043e\u0435, \u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u043f\u043e\u0434\u043e\u0431\u0440\u0430\u0442\u044c \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u044b <code>lowerBound<\/code>\u00a0 \u0438 <code>upperBound<\/code> \u0434\u043b\u044f \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u0438\u044f \u043e\u043f\u0442\u0438\u043c\u0430\u043b\u044c\u043d\u043e\u0433\u043e \u0448\u0430\u0433\u0430.\u00a0<\/p>\n<p>\u0422\u0430\u043a\u0436\u0435 \u043c\u043e\u0436\u043d\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c DataSource v2 \u0438 \u043d\u0430\u043f\u0438\u0441\u0430\u0442\u044c \u0441\u043e\u0431\u0441\u0442\u0432\u0435\u043d\u043d\u044b\u0439 \u043a\u0430\u0441\u0442\u043e\u043c\u043d\u044b\u0439 \u043a\u043e\u043d\u043d\u0435\u043a\u0442\u043e\u0440. \u041a\u0430\u0441\u0442\u043e\u043c\u043d\u044b\u0439 \u043a\u043e\u043d\u043d\u0435\u043a\u0442\u043e\u0440 \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u0442\u0441\u044f \u0442\u0430\u043a\u0436\u0435 \u0440\u0435\u0430\u043b\u0438\u0437\u043e\u0432\u0430\u0442\u044c \u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440 \u043c\u0430\u043f\u043f\u0438\u043d\u0433 \u043f\u0430\u0440\u0442\u0438\u0446\u0438\u0439 \u0442\u0430\u0431\u043b\u0438\u0446\u044b Postgres \u043d\u0430 \u043f\u0430\u0440\u0442\u0438\u0446\u0438\u0438 DataFrame. \u0427\u0442\u043e\u0431\u044b \u0440\u0435\u0430\u043b\u0438\u0437\u043e\u0432\u0430\u0442\u044c \u043d\u0430\u043f\u0438\u0441\u0430\u0442\u044c \u043a\u0430\u0441\u0442\u043e\u043c\u043d\u044b\u0439 \u043a\u043e\u043d\u043d\u0435\u043a\u0442\u043e\u0440, \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u044b \u0431\u0430\u0437\u043e\u0432\u044b\u0435 \u0437\u043d\u0430\u043d\u0438\u044f Scala (\u0442\u0430\u043a \u043a\u0430\u043a Apache Spark \u043d\u0430\u043f\u0438\u0441\u0430\u043d \u043d\u0430 Scala) \u0438 \u0437\u043d\u0430\u043d\u0438\u044f \u0440\u0430\u0431\u043e\u0442\u044b RDD, DataFrame, DataSet \u043f\u043e\u0434 \u043a\u0430\u043f\u043e\u0442\u043e\u043c. \u041d\u0430 \u043a\u0443\u0440\u0441\u0435 \u041e\u0422\u0423\u0421\u0430 <a href=\"https:\/\/otus.pw\/Zy0t\/\">Spark Developer<\/a> \u043c\u043e\u0436\u043d\u043e \u0431\u044b\u0441\u0442\u0440\u043e \u043e\u0441\u0432\u043e\u0438\u0442\u044c \u0432\u0441\u0435 \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u044b\u0435 \u0437\u043d\u0430\u043d\u0438\u044f \u0438 \u043d\u0430\u043f\u0438\u0441\u0430\u0442\u044c \u043a\u0430\u0441\u0442\u043e\u043c\u043d\u044b\u0439 \u043a\u043e\u043d\u043d\u0435\u043a\u0442\u043e\u0440.<\/p>\n<p>\u041f\u0430\u0440\u0430\u043c\u0435\u0442\u0440 \u0434\u043b\u044f DataFrame \u043c\u0430\u0441\u0441\u0438\u0432 \u043f\u0440\u0435\u0434\u0438\u043a\u0430\u0442\u043e\u0432 \u044d\u0442\u043e \u0435\u0449\u0435 \u043e\u0434\u0438\u043d \u0441\u043f\u043e\u0441\u043e\u0431 \u0440\u0430\u0437\u0431\u0438\u0442\u044c \u0438\u0441\u0445\u043e\u0434\u043d\u0443\u044e \u0442\u0430\u0431\u043b\u0438\u0446\u0443 \u0432 \u0440\u0435\u043b\u044f\u0446\u0438\u043e\u043d\u043d\u043e\u0439 \u0431\u0430\u0437\u0435 \u0434\u0430\u043d\u043d\u044b\u0445, \u043a\u043e\u0433\u0434\u0430, \u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u0443 \u043d\u0430\u0441 \u043d\u0435\u0442 \u043a\u043e\u043b\u043e\u043d\u043a\u0438 \u0441 \u043f\u043e\u0441\u043b\u0435\u0434\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u043d\u043e \u0438\u0434\u0443\u0449\u0438\u043c\u0438 \u043d\u0435\u043f\u043e\u0432\u0442\u043e\u0440\u044f\u044e\u0449\u0438\u043c\u0441\u044f \u0447\u0438\u0441\u043b\u043e\u0432\u044b\u043c\u0438 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f\u043c\u0438, \u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440 id.\u00a0<\/p>\n<p>\u0412 \u043f\u0440\u043e\u0441\u0442\u043e\u043c \u0441\u043b\u0443\u0447\u0430\u0435 \u043c\u044b \u043c\u043e\u0436\u0435\u043c \u0440\u0430\u0437\u0434\u0435\u043b\u0438\u0442\u044c DataFrame \u043d\u0430 \u0434\u0432\u0435 \u0447\u0430\u0441\u0442\u0438, \u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u0432\u0441\u0435 \u0437\u0430\u043f\u0438\u0441\u0438 \u0441 gender male \u0431\u0443\u0434\u0443\u0442 \u0432 \u043e\u0434\u043d\u043e\u043c \u0434\u0430\u0442\u0430 \u0444\u0440\u0435\u0439\u043c\u0435, \u0432\u0441\u0435 \u043e\u0441\u0442\u0430\u043b\u044c\u043d\u044b\u0435 \u0432 \u0434\u0440\u0443\u0433\u043e\u043c.\u00a0\u041a\u043e\u0434, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043f\u043e\u0437\u0432\u043e\u043b\u0438\u0442 \u0437\u0430\u0433\u0440\u0443\u0436\u0430\u0442\u044c \u0434\u0430\u043d\u043d\u044b\u0435 \u043f\u043e \u043f\u043e\u043b\u043e\u0432\u043e\u043c\u0443 \u043f\u0440\u0438\u0437\u043d\u0430\u043a\u0443, \u0431\u0443\u0434\u0435\u0442 \u0432\u044b\u0433\u043b\u044f\u0434\u0435\u0442\u044c \u0442\u0430\u043a:<\/p>\n<pre><code>val jdbcEmployeesPartitionedByGenderDF = \u00a0\u00a0spark.read .jdbc(url = \"jdbc:postgresql:\/\/localhost:5432\/spark\", \u00a0\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 table = \"public.employees\", \u00a0\u00a0\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 predicates = Array(\"gender = 'M'\", \"gender = 'F'\"), \u00a0\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 connectionProperties = connectionProperties) jdbcEmployeesPartitionedByGenderDF.rdd.foreachPartition { it => \u00a0\u00a0\u00a0println(s\"Partitions count = ${it.length}\") }  Partitions count = 12091 Partitions count = 17912 Partitions number is 2 Raw Count of employee is 30003<\/code><\/pre>\n<p>\u0422\u0430\u043a\u043e\u0439 \u0432\u0430\u0440\u0438\u0430\u043d\u0442 \u043d\u0435\u043c\u043d\u043e\u0433\u043e \u043b\u0443\u0447\u0448\u0435, \u0447\u0435\u043c \u0437\u0430\u0433\u0440\u0443\u0437\u043a\u0430 \u0434\u0430\u043d\u043d\u044b\u0445 \u0432 \u043e\u0434\u0438\u043d \u043f\u043e\u0442\u043e\u043a.\u00a0<\/p>\n<p>\u0415\u0441\u043b\u0438 \u0437\u0430\u043f\u0443\u0441\u0442\u0438\u0442\u044c \u043a\u043e\u0434 \u0441 \u0442\u0430\u043a\u0438\u043c \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u043e\u043c:<\/p>\n<pre><code>predicates = Array(\"gender = 'M'\", \"gender = 'F'\", \"gender = 'M'\")<\/code><\/pre>\n<p>\u0420\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u043e\u043c \u0431\u0443\u0434\u0435\u0442\u00a0<\/p>\n<pre><code>Partitions count = 12091 Partitions count = 17912 Partitions count = 17912 Partitions number is 3 Raw Count of employee is 47915<\/code><\/pre>\n<p>\u041a\u0430\u043a \u0432\u0438\u0434\u043d\u043e \u0438\u0437 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u0430, \u0431\u044b\u043b\u0430 \u0441\u043e\u0437\u0434\u0430\u043d\u0430 \u0435\u0449\u0435 \u043e\u0434\u043d\u0430 \u043f\u0430\u0440\u0442\u0438\u0446\u0438\u044f \u0438 \u0434\u0430\u043d\u043d\u044b\u0435 \u0431\u044b\u043b\u0438 \u0434\u0443\u043f\u043b\u0438\u0446\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u044b\u0435. \u0418\u043c\u0435\u043d\u043d\u043e \u043f\u043e\u044d\u0442\u043e\u043c\u0443 \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e \u0430\u043a\u043a\u0443\u0440\u0430\u0442\u043d\u043e \u0432\u044b\u0431\u0438\u0440\u0430\u0442\u044c \u043f\u0440\u0435\u0434\u0438\u043a\u0430\u0442\u044b \u0434\u043b\u044f \u0440\u0430\u0431\u043e\u0442\u044b.<\/p>\n<p>\u0412 \u0441\u0442\u0430\u0442\u044c\u0435 \u043c\u044b \u0440\u0430\u0437\u043e\u0431\u0440\u0430\u043b\u0438, \u043a\u0430\u043a \u0443\u0432\u0435\u043b\u0438\u0447\u0438\u0442\u044c \u0441\u043a\u043e\u0440\u043e\u0441\u0442\u044c \u0437\u0430\u0433\u0440\u0443\u0437\u043a\u0438 \u0434\u0430\u043d\u043d\u044b\u0445 \u0438\u0437 \u0440\u0435\u043b\u044f\u0446\u0438\u043e\u043d\u043d\u043e\u0439 \u0431\u0430\u0437\u044b \u0432 Spark \u0432 \u043f\u0430\u0440\u0430\u043b\u043b\u0435\u043b\u044c\u043d\u043e\u043c \u0440\u0435\u0436\u0438\u043c\u0435, \u0430 \u0442\u0430\u043a\u0436\u0435 \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u044b, \u0441 \u043a\u043e\u0442\u043e\u0440\u044b\u043c\u0438 \u043c\u044b \u043c\u043e\u0436\u0435\u043c \u0432\u0441\u0442\u0440\u0435\u0442\u0438\u0442\u044c\u0441\u044f.\u00a0<\/p>\n<pre><code>** \u0441\u043e\u0437\u0434\u0430\u043d\u043d\u0430\u044f \u0442\u0430\u0431\u043b\u0438\u0446\u0430  CREATE TABLE employees ( emp_no\u00a0 INT \u00a0 \u00a0 \u00a0 \u00a0 NOT NULL, birth_date\u00a0 DATE\u00a0 \u00a0 \u00a0 \u00a0 NOT NULL, first_name\u00a0 VARCHAR(14) NOT NULL, last_name \u00a0 VARCHAR(16) NOT NULL, gender\u00a0 gender\u00a0 \u00a0 \u00a0 NULL, hire_date \u00a0 DATE\u00a0 \u00a0 \u00a0 \u00a0 NOT NULL, PRIMARY KEY (emp_no) );  ** \u0441\u043e\u0437\u0434\u0430\u043d\u043d\u0430\u044f \u0442\u0430\u0431\u043b\u0438\u0446\u0430  CREATE TABLE employees ( emp_no\u00a0 INT \u00a0 \u00a0 \u00a0 \u00a0 NOT NULL, birth_date\u00a0 DATE\u00a0 \u00a0 \u00a0 \u00a0 NOT NULL, first_name\u00a0 VARCHAR(14) NOT NULL, last_name \u00a0 VARCHAR(16) NOT NULL, gender\u00a0 gender\u00a0 \u00a0 \u00a0 NULL, hire_date \u00a0 DATE\u00a0 \u00a0 \u00a0 \u00a0 NOT NULL, PRIMARY KEY (emp_no) ) PARTITION BY HASH (emp_no);<\/code><\/pre>\n<p>\u0412 \u0437\u0430\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0435 \u043f\u0440\u0438\u0433\u043b\u0430\u0448\u0430\u044e \u0432\u0441\u0435\u0445 \u0436\u0435\u043b\u0430\u044e\u0449\u0438\u0445 \u043d\u0430 \u043e\u0442\u043a\u0440\u044b\u0442\u043e\u0435 \u0437\u0430\u043d\u044f\u0442\u0438\u0435 \u00abSpark \u0432 Kubernetes\u00bb. \u041d\u0430 \u0443\u0440\u043e\u043a\u0435 \u043c\u044b:<\/p>\n<ul>\n<li>\n<p>\u041a\u0440\u0430\u0442\u043a\u043e \u0440\u0430\u0441\u0441\u043c\u043e\u0442\u0440\u0438\u043c, \u0447\u0442\u043e \u0442\u0430\u043a\u043e\u0435 Spark \u0438 \u0447\u0442\u043e \u0442\u0430\u043a\u043e\u0435 Kubernetes;<\/p>\n<\/li>\n<li>\n<p>\u0420\u0430\u0441\u0441\u043c\u043e\u0442\u0440\u0438\u043c \u043e\u0441\u043e\u0431\u0435\u043d\u043d\u043e\u0441\u0442\u0438 \u0438 \u0432\u0430\u0440\u0438\u0430\u043d\u0442\u044b \u0437\u0430\u043f\u0443\u0441\u043a\u0430 Spark \u0432 Kubernetes;<\/p>\n<\/li>\n<li>\n<p>\u0421\u0440\u0430\u0432\u043d\u0438\u043c \u0440\u0430\u0431\u043e\u0442\u0443 Spark \u0432 Kubernetus \u0438 Hadoop Yarn.<\/p>\n<\/li>\n<\/ul>\n<p><a href=\"https:\/\/otus.pw\/VSL0j\/\">\u0420\u0435\u0433\u0438\u0441\u0442\u0440\u0430\u0446\u0438\u044f \u043d\u0430 \u0443\u0440\u043e\u043a.<\/a><\/p>\n<\/p>\n<\/div>\n<\/div>\n<\/div>\n<p> <!----> <!----><\/div>\n<p> <!----> <!----><br \/> \u0441\u0441\u044b\u043b\u043a\u0430 \u043d\u0430 \u043e\u0440\u0438\u0433\u0438\u043d\u0430\u043b \u0441\u0442\u0430\u0442\u044c\u0438 <a href=\"https:\/\/habr.com\/ru\/company\/otus\/blog\/704010\/\"> https:\/\/habr.com\/ru\/company\/otus\/blog\/704010\/<\/a><br \/><\/br><\/br><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[],"tags":[],"class_list":["post-342289","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/342289","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=342289"}],"version-history":[{"count":0,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/342289\/revisions"}],"wp:attachment":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=342289"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=342289"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=342289"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}