{"id":329203,"date":"2022-02-07T15:00:45","date_gmt":"2022-02-07T15:00:45","guid":{"rendered":"http:\/\/savepearlharbor.com\/?p=329203"},"modified":"-0001-11-30T00:00:00","modified_gmt":"2022-02-07T15:00:45","slug":"","status":"publish","type":"post","link":"https:\/\/savepearlharbor.com\/?p=329203","title":{"rendered":"<span>\u041a\u0430\u043a \u043e\u0431\u0440\u0430\u0431\u0430\u0442\u044b\u0432\u0430\u0442\u044c \u043e\u0431\u044a\u0435\u043a\u0442\u044b Avro \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u0434\u0430\u0442\u0430\u0441\u0435\u0442\u043e\u0432 Spark 3.2 &amp; Scala 2.12<\/span>"},"content":{"rendered":"<div><\/div>\n<div id=\"post-content-body\">\n<div>\n<div class=\"article-formatted-body article-formatted-body_version-2\">\n<div xmlns=\"http:\/\/www.w3.org\/1999\/xhtml\">\n<figure class=\"full-width\"><img decoding=\"async\" src=\"\/img\/image-loader.svg\" height=\"439\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/38d\/3c6\/625\/38d3c66257f3f4226f009062c97ac593.png\" data-width=\"780\"\/><figcaption><\/figcaption><\/figure>\n<p>\u041f\u0440\u0438\u0432\u0435\u0442!<\/p>\n<p>\u0412 \u044d\u0442\u043e\u043c \u043f\u043e\u0441\u0442\u0435 \u0440\u0430\u0437\u0431\u0435\u0440\u0435\u043c, \u043a\u0430\u043a \u043e\u0431\u0440\u0430\u0431\u0430\u0442\u044b\u0432\u0430\u0442\u044c \u043e\u0431\u044a\u0435\u043a\u0442\u044b JVM, \u0441\u0433\u0435\u043d\u0435\u0440\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u044b\u0435 \u0438\u0437 \u0441\u0445\u0435\u043c Avro, \u0432 \u0434\u0430\u0442\u0430\u0441\u0435\u0442\u0430\u0445 Spark. \u0412\u043c\u0435\u0441\u0442\u0435 \u0441 \u044d\u0442\u0438\u043c \u0440\u0430\u0441\u0441\u043c\u043e\u0442\u0440\u0438\u043c, \u043a\u0430\u043a \u043e\u0440\u0433\u0430\u043d\u0438\u0437\u043e\u0432\u0430\u0442\u044c \u043a\u043e\u0434 \u043f\u0440\u0438 \u043f\u043e\u043c\u043e\u0449\u0438 \u0448\u0430\u0431\u043b\u043e\u043d\u0430 \u0444\u0443\u043d\u043a\u0446\u0438\u043e\u043d\u0430\u043b\u044c\u043d\u043e\u0433\u043e \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f &#171;\u0442\u0438\u043f\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u044b\u0439 \u043a\u043b\u0430\u0441\u0441&#187; (type class) \u043d\u0430 \u044f\u0437\u044b\u043a\u0435 Scala.<\/p>\n<p>\u0414\u0430\u0442\u0430\u0444\u0440\u0435\u0439\u043c \u0432 Spark &#8212; \u0430\u0431\u0441\u0442\u0440\u0430\u043a\u0446\u0438\u044f \u0442\u0430\u0431\u043b\u0438\u0446\u044b \u0441\u043e \u0441\u0442\u043e\u043b\u0431\u0446\u0430\u043c\u0438 \u0438 \u0441\u0442\u0440\u043e\u043a\u0430\u043c\u0438, \u043f\u043e\u043a\u0440\u044b\u0432\u0430\u0435\u0442 \u0431\u043e\u043b\u044c\u0448\u0438\u043d\u0441\u0442\u0432\u043e \u043a\u0435\u0439\u0441\u043e\u0432 \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u043a\u0438 \u0434\u0430\u043d\u043d\u044b\u0445. \u0422\u0435\u043c \u043d\u0435 \u043c\u0435\u043d\u0435\u0435, \u0431\u044b\u0432\u0430\u0435\u0442 \u0442\u0430\u043a, \u0447\u0442\u043e \u0434\u0430\u043d\u043d\u044b\u0435 \u0438\u043c\u0435\u044e\u0442 \u043d\u0430\u0441\u0442\u043e\u043b\u044c\u043a\u043e \u0441\u043f\u0435\u0446\u0438\u0444\u0438\u0447\u043d\u0443\u044e \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u0443, \u0447\u0442\u043e \u043f\u0440\u0438\u0432\u0435\u0441\u0442\u0438 \u0438\u0445 \u043a \u043e\u0431\u0449\u0435\u043c\u0443 \u0437\u043d\u0430\u043c\u0435\u043d\u0430\u0442\u0435\u043b\u044e \u0432 \u0434\u0430\u0442\u0430\u0444\u0440\u0435\u0439\u043c\u0435 \u0434\u043e\u0441\u0442\u0430\u0442\u043e\u0447\u043d\u043e \u0441\u043b\u043e\u0436\u043d\u043e. \u0412 \u044d\u0442\u043e\u043c \u0441\u043b\u0443\u0447\u0430\u0435 \u043c\u043e\u0436\u043d\u043e \u043f\u0440\u0438\u0431\u0435\u0433\u043d\u0443\u0442\u044c \u043a \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u043d\u043e\u043c\u0443 \u0438\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441\u0443 Spark Dataset. \u041e\u043d \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u0442 \u043c\u0430\u043d\u0438\u043f\u0443\u043b\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u043d\u0435 \u0430\u0431\u0441\u0442\u0440\u0430\u043a\u0442\u043d\u044b\u043c\u0438 \u0441\u0442\u0440\u043e\u043a\u0430\u043c\u0438 \u0438 \u0441\u0442\u043e\u043b\u0431\u0446\u0430\u043c\u0438, \u0430 \u043a\u043e\u043d\u043a\u0440\u0435\u0442\u043d\u044b\u043c\u0438 \u043e\u0431\u044a\u0435\u043a\u0442\u0430\u043c\u0438 \u0432\u0438\u0440\u0442\u0443\u0430\u043b\u044c\u043d\u043e\u0439 \u043c\u0430\u0448\u0438\u043d\u044b Java.<\/p>\n<p>\u0422\u0438\u043f\u0438\u0447\u043d\u044b\u0439 \u043a\u0435\u0439\u0441 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u044f \u0434\u0430\u0442\u0430\u0441\u0435\u0442\u043e\u0432 &#8212; \u0447\u0442\u0435\u043d\u0438\u0435 \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u0439 Kafka \u0432 \u0444\u043e\u0440\u043c\u0430\u0442\u0435 Avro.  <\/p>\n<p>\u041f\u0440\u043e\u0446\u0435\u0441\u0441 \u0441\u043e\u0441\u0442\u043e\u0438\u0442 \u0438\u0437 4 \u044d\u0442\u0430\u043f\u043e\u0432:<\/p>\n<ol>\n<li>\n<p>\u0413\u0435\u043d\u0435\u0440\u0430\u0446\u0438\u044f \u043a\u043b\u0430\u0441\u0441\u043e\u0432-\u043e\u0431\u0440\u0430\u0437\u0446\u043e\u0432 (case class) \u0438\u0441\u0445\u043e\u0434\u044f \u0438\u0437 \u0441\u0445\u0435\u043c\u044b Avro-\u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u044f.<\/p>\n<\/li>\n<li>\n<p>\u0427\u0442\u0435\u043d\u0438\u0435 Avro-\u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u0439 \u0432 Dataset Spark, \u0442\u0438\u043f\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u044b\u0439 \u043a\u043b\u0430\u0441\u0441\u043e\u043c-\u043e\u0431\u0440\u0430\u0437\u0446\u043e\u043c.<\/p>\n<\/li>\n<li>\n<p>\u0420\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044f \u043e\u043f\u0435\u0440\u0430\u0446\u0438\u0438 \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u043a\u0438 \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u044f. \u0412 \u0447\u0430\u0441\u0442\u043d\u043e\u0441\u0442\u0438, \u043d\u0430\u043f\u0438\u0448\u0435\u043c \u0444\u0443\u043d\u043a\u0446\u0438\u044e, \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u043f\u0440\u0438\u0432\u0435\u0434\u0435\u0442 \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u0435 \u043a \u043f\u043b\u043e\u0441\u043a\u043e\u0439 \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u0435.<\/p>\n<\/li>\n<\/ol>\n<p>\u0421 \u043a\u043e\u0434\u043e\u043c \u043c\u043e\u0436\u043d\u043e \u043e\u0437\u043d\u0430\u043a\u043e\u043c\u0438\u0442\u044c\u0441\u044f <a href=\"https:\/\/github.com\/aleksandrachasch\/SparkAvroProject\">\u0437\u0434\u0435\u0441\u044c<\/a>.<\/p>\n<h3>\u0413\u0435\u043d\u0435\u0440\u0430\u0446\u0438\u044f \u043a\u043b\u0430\u0441\u0441\u043e\u0432-\u043e\u0431\u0440\u0430\u0437\u0446\u043e\u0432 Scala<\/h3>\n<p>\u041f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u0438\u043c, \u0447\u0442\u043e \u043d\u0430\u043c \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e \u043e\u0431\u0440\u0430\u0431\u0430\u0442\u044b\u0432\u0430\u0442\u044c \u0434\u0430\u043d\u043d\u044b\u0435 \u043a\u043b\u0438\u0435\u043d\u0442\u0430 \u0441\u043e \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0435\u0439 \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u043e\u0439:<\/p>\n<figure class=\"\"><img decoding=\"async\" src=\"\/img\/image-loader.svg\" alt=\"\u041c\u043e\u0434\u0435\u043b\u044c \u0434\u0430\u043d\u043d\u044b\u0445 \u043a\u043b\u0438\u0435\u043d\u0442\u0430\" title=\"\u041c\u043e\u0434\u0435\u043b\u044c \u0434\u0430\u043d\u043d\u044b\u0445 \u043a\u043b\u0438\u0435\u043d\u0442\u0430\" height=\"406\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/570\/8ae\/109\/5708ae1098f937c350681ce598265e8b.png\" data-width=\"431\"\/><figcaption>\u041c\u043e\u0434\u0435\u043b\u044c \u0434\u0430\u043d\u043d\u044b\u0445 \u043a\u043b\u0438\u0435\u043d\u0442\u0430<\/figcaption><\/figure>\n<p>\u041a\u043b\u0438\u0435\u043d\u0442 (<code>Customer<\/code>) \u043c\u043e\u0436\u0435\u0442 \u0438\u043c\u0435\u0442\u044c \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u0430\u043a\u043a\u0430\u0443\u043d\u0442\u043e\u0432. \u0410\u043a\u043a\u0430\u0443\u043d\u0442, \u0432 \u0441\u0432\u043e\u044e \u043e\u0447\u0435\u0440\u0435\u0434\u044c, \u0438\u043c\u0435\u0435\u0442 \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u0433\u0440\u0443\u043f\u043f \u0432\u0437\u0430\u0438\u043c\u043e\u0434\u0435\u0439\u0441\u0442\u0432\u0438\u044f (<code>InteractionGroups<\/code>). \u0413\u0440\u0443\u043f\u043f\u0430 \u0432\u0437\u0430\u0438\u043c\u043e\u0434\u0435\u0439\u0441\u0442\u0432\u0438\u044f \u0441\u043e\u0434\u0435\u0440\u0436\u0438\u0442 \u0432 \u0441\u0435\u0431\u0435 \u0432\u0437\u0430\u0438\u043c\u043e\u0434\u0435\u0439\u0441\u0442\u0432\u0438\u044f, \u0441\u043e\u0432\u0435\u0440\u0448\u0435\u043d\u043d\u044b\u0435 \u043a\u043b\u0438\u0435\u043d\u0442\u043e\u043c \u0432 \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u043d\u0443\u044e \u0434\u0430\u0442\u0443. \u0412\u0437\u0430\u0438\u043c\u043e\u0434\u0435\u0439\u0441\u0442\u0432\u0438\u0435 \u0438\u043c\u0435\u0435\u0442 \u043e\u0434\u0438\u043d \u0438\u0437 \u0442\u0438\u043f\u043e\u0432, \u043e\u0431\u043e\u0437\u043d\u0430\u0447\u0430\u044e\u0449\u0438\u0439 \u043a\u0430\u043d\u0430\u043b \u0432\u0437\u0430\u0438\u043c\u043e\u0434\u0435\u0439\u0441\u0442\u0432\u0438\u044f: \u0441\u0430\u0439\u0442, \u0442\u0432\u0438\u0442\u0442\u0435\u0440, \u0438\u043d\u0441\u0442\u0430\u0433\u0440\u0430\u043c \u0438\u043b\u0438 \u0437\u0432\u043e\u043d\u043e\u043a.<\/p>\n<details class=\"spoiler\">\n<summary>\u041e\u0442\u0441\u0442\u0443\u043f\u043b\u0435\u043d\u0438\u0435<\/summary>\n<div class=\"spoiler__content\">\n<p>\u041d\u0430\u0432\u0435\u0440\u043d\u044f\u043a\u0430, \u0443 \u0432\u0430\u0441 \u0432\u043e\u0437\u043d\u0438\u043a\u043b\u0438 \u043f\u0440\u0435\u0442\u0435\u043d\u0437\u0438\u0438 \u043a \u044d\u0442\u043e\u0439 \u043c\u043e\u0434\u0435\u043b\u0438 \ud83d\ude42 \u042d\u0442\u043e \u0441\u043f\u0440\u0430\u0432\u0435\u0434\u043b\u0438\u0432\u043e. \u0414\u0430\u043d\u043d\u044b\u0435 \u0441\u043f\u0435\u0446\u0438\u0430\u043b\u044c\u043d\u043e \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u0438\u0440\u043e\u0432\u0430\u043d\u044b &#171;\u043a\u0440\u0438\u0432\u043e&#187;, \u0447\u0442\u043e\u0431\u044b \u0441\u043c\u043e\u0434\u0435\u043b\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0440\u0435\u0430\u043b\u044c\u043d\u044b\u0439 \u043a\u0435\u0439\u0441. \u0417\u0430\u0447\u0430\u0441\u0442\u0443\u044e \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e \u043e\u0431\u0440\u0430\u0431\u0430\u0442\u044b\u0432\u0430\u0442\u044c \u0434\u0430\u043d\u043d\u044b\u0435 \u0438\u0437 \u0443\u0441\u0442\u0430\u0440\u0435\u0432\u0448\u0438\u0445 \u0441\u0438\u0441\u0442\u0435\u043c, \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u0443 \u043a\u043e\u0442\u043e\u0440\u044b\u0445 \u043c\u044b \u0438\u0437\u043c\u0435\u043d\u0438\u0442\u044c \u043d\u0435 \u043c\u043e\u0436\u0435\u043c. \u041f\u0440\u0438\u0445\u043e\u0434\u0438\u0442\u0441\u044f \u0440\u0430\u0431\u043e\u0442\u0430\u0442\u044c \u0441 \u0442\u0435\u043c, \u0447\u0442\u043e \u0435\u0441\u0442\u044c. <\/p>\n<\/div>\n<\/details>\n<p>\u0421\u0445\u0435\u043c\u0430 \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u044f Avro, \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0443\u044e\u0449\u0430\u044f \u0434\u0430\u043d\u043d\u043e\u0439 \u043c\u043e\u0434\u0435\u043b\u0438, \u0431\u0443\u0434\u0435\u0442 \u0432\u044b\u0433\u043b\u044f\u0434\u0435\u0442\u044c \u0442\u0430\u043a:<\/p>\n<pre><code class=\"json\">{   \"type\": \"record\",   \"name\": \"Customer\",   \"namespace\": \"com.github.aleksandrachasch.avro\",   \"fields\": [     {       \"name\": \"Id\",       \"type\": \"string\"     },     {       \"name\": \"Name\",       \"type\": \"string\"     },     {       \"name\": \"Surname\",       \"type\": \"string\"     },     {       \"name\": \"Accounts\",       \"type\": {         \"type\": \"array\",         \"items\": {           \"type\": \"record\",           \"name\": \"Account\",           \"namespace\": \"com.github.aleksandrachasch.avro\",           \"fields\": [             {               \"name\": \"AccountId\",               \"type\": \"int\"             },             {               \"name\": \"AccountType\",               \"type\": \"string\"             },             {               \"name\": \"InteractionGroups\",               \"type\": {                 \"type\": \"array\",                 \"items\": {                   \"type\": \"record\",                   \"name\": \"InteractionGroup\",                   \"namespace\": \"com.github.aleksandrachasch.avro\",                   \"fields\": [                     {                       \"name\": \"Id\",                       \"type\": \"string\"                     },                     {                       \"name\": \"date\",                       \"type\": \"string\"                     },                     {                       \"name\": \"interactions\",                       \"type\": {                         \"type\": \"array\",                         \"items\": {                           \"type\": \"record\",                           \"name\": \"Interaction\",                           \"namespace\": \"com.github.aleksandrachasch.avro\",                           \"fields\": [                             {                               \"name\": \"Id\",                               \"type\": \"string\"                             },                             {                               \"name\": \"type\",                               \"type\": {                                 \"type\": \"enum\",                                 \"name\": \"InteractionType\",                                 \"namespace\": \"com.github.aleksandrachasch.avro\",                                 \"symbols\": [                                   \"WEBSITE\",                                   \"TWITTER\",                                   \"CALL\",                                   \"INSTAGRAM\"                                 ]                               }                             }                           ]                         }                       }                     }                   ]                 }               }             }           ]         }       }     }   ] }<\/code><\/pre>\n<p>\u0422\u0435\u043f\u0435\u0440\u044c \u0438\u0437 \u044d\u0442\u043e\u0439 \u0441\u0445\u0435\u043c\u044b \u043c\u043e\u0436\u043d\u043e \u0441\u0433\u0435\u043d\u0435\u0440\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u043a\u043b\u0430\u0441\u0441\u044b-\u043e\u0431\u0440\u0430\u0437\u0446\u044b Scala. \u0417\u0430\u0442\u0435\u043c \u043c\u044b \u0431\u0443\u0434\u0435\u043c \u043e\u043f\u0435\u0440\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u044d\u043a\u0437\u0435\u043c\u043f\u043b\u044f\u0440\u0430\u043c\u0438 \u044d\u0442\u0438\u0445 \u043a\u043b\u0430\u0441\u0441\u043e\u0432.  <\/p>\n<p>\u0412 \u0440\u0435\u0430\u043b\u044c\u043d\u043e\u0439 \u0436\u0438\u0437\u043d\u0438 \u043f\u0440\u043e\u0446\u0435\u0441\u0441 \u0433\u0435\u043d\u0435\u0440\u0430\u0446\u0438\u0438 \u043a\u043b\u0430\u0441\u0441\u043e\u0432-\u043e\u0431\u0440\u0430\u0437\u0446\u043e\u0432 \u0432\u044b\u0433\u043b\u044f\u0434\u0438\u0442 \u043f\u0440\u0438\u043c\u0435\u0440\u043d\u043e \u0442\u0430\u043a:<\/p>\n<ol>\n<li>\n<p>\u0427\u0442\u0435\u043d\u0438\u0435 \u0441\u0445\u0435\u043c\u044b Avro. \u041d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u0438\u0437 <code>Confluent Schema Registry<\/code><strong> <\/strong>&#8212; \u0440\u0435\u0433\u0438\u0441\u0442\u0440\u0430 c\u0445\u0435\u043c \u0442\u043e\u043f\u0438\u043a\u043e\u0432 \u043a\u043b\u0430\u0441\u0442\u0435\u0440\u0430 Kafka, \u043a \u043a\u043e\u0442\u043e\u0440\u043e\u043c\u0443 \u043c\u043e\u0436\u043d\u043e \u043e\u0431\u0440\u0430\u0449\u0430\u0442\u044c\u0441\u044f \u0447\u0435\u0440\u0435\u0437 API.<\/p>\n<\/li>\n<li>\n<p>\u0413\u0435\u043d\u0435\u0440\u0430\u0446\u0438\u044f \u043a\u043b\u0430\u0441\u0441\u043e\u0432-\u043e\u0431\u0440\u0430\u0437\u0446\u043e\u0432 \u0432 \u0444\u0430\u0437\u0435 \u043a\u043e\u043c\u043f\u0438\u043b\u044f\u0446\u0438\u0438 <code>Maven<\/code> \u0438\u043b\u0438 <code>SBT<\/code> . \u0421\u0433\u0435\u043d\u0435\u0440\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u044b\u0435 \u043a\u043b\u0430\u0441\u0441\u044b \u043f\u0440\u0438 \u044d\u0442\u043e\u043c \u043a\u043e\u043f\u0438\u0440\u0443\u044e\u0442\u0441\u044f \u043f\u0440\u044f\u043c\u043e \u0432 <code>src\/<\/code> \u043f\u0440\u043e\u0435\u043a\u0442\u0430. \u0412 \u0441\u043b\u0443\u0447\u0430\u0435 \u043e\u0431\u043d\u043e\u0432\u043b\u0435\u043d\u0438\u044f \u0441\u0445\u0435\u043c\u044b \u0432 \u0440\u0435\u0433\u0438\u0441\u0442\u0440\u0435 \u043c\u044b \u0443\u0432\u0438\u0434\u0438\u043c \u0438\u0437\u043c\u0435\u043d\u0435\u043d\u0438\u044f \u0432 \u043d\u0430\u0448\u0435\u043c \u043f\u0440\u043e\u0435\u043a\u0442\u0435. \u0411\u0443\u0434\u0435\u0442 \u043f\u043e\u043d\u044f\u0442\u043d\u043e \u0443\u0436\u0435 \u0432 \u0444\u0430\u0437\u0435 \u043a\u043e\u043c\u043f\u0438\u043b\u044f\u0446\u0438\u0438, \u043d\u0430\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u0441\u043e\u0432\u043c\u0435\u0441\u0442\u0438\u043c\u044b \u044d\u0442\u0438 \u0438\u0437\u043c\u0435\u043d\u0435\u043d\u0438\u044f \u0441 \u0441\u0443\u0449\u0435\u0441\u0442\u0432\u0443\u044e\u0449\u0438\u043c \u043a\u043e\u0434\u043e\u043c.<\/p>\n<\/li>\n<\/ol>\n<p>\u0412 \u044d\u0442\u043e\u043c \u043f\u0440\u043e\u0435\u043a\u0442\u0435 \u0431\u0443\u0434\u0435\u043c \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c <code>Maven<\/code> \u0438 <code>avrohugger-maven-plugin<\/code>. \u041f\u043b\u0430\u0433\u0438\u043d \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442 \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0443 <a href=\"https:\/\/github.com\/julianpeeters\/avrohugger\">AvroHugger<\/a> \u0434\u043b\u044f \u0433\u0435\u043d\u0435\u0440\u0430\u0446\u0438\u0438 \u043a\u043b\u0430\u0441\u0441\u043e\u0432 Scala.<\/p>\n<p>\u0412 <code>pom.xml<\/code> \u0434\u043e\u0431\u0430\u0432\u043b\u044f\u0435\u043c \u043f\u043b\u0430\u0433\u0438\u043d: <\/p>\n<pre><code class=\"xml\">&lt;plugin>     &lt;groupId>at.makubi.maven.plugin&lt;\/groupId>     &lt;artifactId>avrohugger-maven-plugin&lt;\/artifactId>     &lt;version>1.6&lt;\/version>     &lt;configuration>         &lt;sourceDirectory>${basedir}\/src\/main\/resources&lt;\/sourceDirectory>         &lt;outputDirectory>${basedir}\/src\/main\/scala&lt;\/outputDirectory>            &lt;sourceGenerationFormat>STANDARD&lt;\/sourceGenerationFormat>   &lt;\/configuration>     &lt;executions>         &lt;execution>             &lt;phase>generate-sources&lt;\/phase>             &lt;goals>                 &lt;goal>generate-scala-sources&lt;\/goal>             &lt;\/goals>         &lt;\/execution>     &lt;\/executions> &lt;\/plugin><\/code><\/pre>\n<p>\u0412 \u043a\u043e\u043d\u0444\u0438\u0433\u0443\u0440\u0430\u0446\u0438\u0438 \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e \u0443\u043a\u0430\u0437\u0430\u0442\u044c \u043f\u0443\u0442\u044c \u043a \u0444\u0430\u0439\u043b\u0443 \u0441 \u0441\u0445\u0435\u043c\u043e\u0439 Avro (\u043f\u043e \u0443\u043c\u043e\u043b\u0447\u0430\u043d\u0438\u044e  <code>src\/main\/avro<\/code>), \u0430 \u0442\u0430\u0436\u0435 \u043f\u0443\u0442\u044c \u043a \u0441\u0433\u0435\u043d\u0435\u0440\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u044b\u043c \u043a\u043b\u0430\u0441\u0441\u0430\u043c (\u043f\u043e \u0443\u043c\u043e\u043b\u0447\u0430\u043d\u0438\u044e <code>target\/generated-sources\/avro<\/code>):<\/p>\n<pre><code class=\"xml\">&lt;sourceDirectory>${basedir}\/src\/main\/resources&lt;\/sourceDirectory>     &lt;outputDirectory>${basedir}\/src\/main\/scala&lt;\/outputDirectory>  <\/code><\/pre>\n<p><strong>\u0412\u043d\u0438\u043c\u0430\u043d\u0438\u0435!<\/strong> \u0441\u0433\u0435\u043d\u0435\u0440\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u044b\u0435 \u0444\u0430\u0439\u043b\u044b \u043f\u0435\u0440\u0435\u043f\u0438\u0448\u0443\u0442 \u0443\u0436\u0435 \u0441\u0443\u0449\u0435\u0441\u0442\u0432\u0443\u044e\u0449\u0438\u0435 \u043a\u043b\u0430\u0441\u0441\u044b-\u043e\u0431\u0440\u0430\u0437\u0446\u044b \u0432 \u043f\u0430\u043f\u043a\u0435 <code>src\/main\/scala.<\/code> <\/p>\n<p>\u0422\u0430\u043a\u0436\u0435 \u0443\u043a\u0430\u0437\u044b\u0432\u0430\u0435\u043c \u0442\u0438\u043f \u0437\u0430\u043f\u0438\u0441\u0438 Avro (<code>SpecificRecord<\/code> \u0438\u043b\u0438 <code>GenericRecord<\/code>). <\/p>\n<p>\u041f\u043e \u0443\u043c\u043e\u043b\u0447\u0430\u043d\u0438\u044e \u043f\u043b\u0430\u0433\u0438\u043d \u0433\u0435\u043d\u0435\u0440\u0438\u0440\u0443\u0435\u0442 \u0441\u043f\u0435\u0446\u0438\u0444\u0438\u0447\u0435\u0441\u043a\u0438\u0439 \u0442\u0438\u043f \u0437\u0430\u043f\u0438\u0441\u0438 (<code>SpecificRecord<\/code>). \u0412 \u044d\u0442\u043e\u043c \u0441\u043b\u0443\u0447\u0430\u0435 \u0432\u0441\u0435 \u043a\u043b\u0430\u0441\u0441\u044b-\u043e\u0431\u0440\u0430\u0437\u0446\u044b \u0431\u0443\u0434\u0443\u0442 \u043d\u0430\u0441\u043b\u0435\u0434\u043e\u0432\u0430\u0442\u044c \u0430\u0431\u0441\u0442\u0440\u0430\u043a\u0442\u043d\u044b\u0439 \u043a\u043b\u0430\u0441\u0441 <code>org.apache.avro.specific.SpecificRecordBase<\/code>. \u041f\u043e\u043c\u0438\u043c\u043e \u0441\u0430\u043c\u043e\u0433\u043e \u043a\u043b\u0430\u0441\u0441\u0430-\u043e\u0431\u0440\u0430\u0437\u0446\u0430 \u0438 \u0430\u0440\u0433\u0443\u043c\u0435\u043d\u0442\u043e\u0432 \u0441\u043e\u0437\u0434\u0430\u0434\u0443\u0442\u0441\u044f \u043c\u0435\u0442\u043e\u0434\u044b \u0447\u0442\u0435\u043d\u0438\u044f \u0438 \u0437\u0430\u043f\u0438\u0441\u0438 \u043d\u043e\u0432\u044b\u0445 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0439 \u0430\u0442\u0440\u0438\u0431\u0443\u0442\u043e\u0432. \u0420\u0435\u043a\u043e\u043c\u0435\u043d\u0434\u0443\u0435\u0442\u0441\u044f \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u044d\u0442\u043e\u0442 \u0442\u0438\u043f \u0437\u0430\u043f\u0438\u0441\u0438, \u0435\u0441\u043b\u0438 \u043f\u043b\u0430\u043d\u0438\u0440\u0443\u0435\u0442\u0441\u044f \u043e\u0431\u0440\u0430\u0431\u0430\u0442\u044b\u0432\u0430\u0442\u044c \u0434\u0430\u043d\u043d\u044b\u0435 \u0441\u043f\u0435\u0446\u0438\u0444\u0438\u0447\u043d\u044b\u043c\u0438 Avro-\u0444\u0443\u043d\u043a\u0446\u0438\u044f\u043c\u0438, \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044e\u0449\u0438\u043c\u0438 <code>Avro Specific API<\/code>. <\/p>\n<p>\u0412 \u043d\u0430\u0448\u0435\u043c \u0441\u043b\u0443\u0447\u0430\u0435 \u043c\u044b \u0441\u0430\u043c\u0438 \u0431\u0443\u0434\u0435\u043c \u043f\u0438\u0441\u0430\u0442\u044c \u0444\u0443\u043d\u043a\u0446\u0438\u044e \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u043a\u0438, \u043f\u043e\u044d\u0442\u043e\u043c\u0443 \u043f\u043e\u0434\u043e\u0439\u0434\u0435\u0442 <code>GenericRecord<\/code>:<\/p>\n<pre><code class=\"xml\">&lt;sourceGenerationFormat>STANDARD&lt;\/sourceGenerationFormat><\/code><\/pre>\n<p>\u042d\u0442\u043e\u0442 \u0442\u0438\u043f \u0437\u0430\u043f\u0438\u0441\u0438 \u0433\u0435\u043d\u0435\u0440\u0438\u0440\u0443\u0435\u0442 \u043e\u0431\u044b\u0447\u043d\u044b\u0435 \u043a\u043b\u0430\u0441\u0441\u044b-\u043e\u0431\u0440\u0430\u0437\u0446\u044b, \u0431\u0435\u0437 \u0434\u043e\u043f\u043e\u043b\u043d\u0438\u0442\u0435\u043b\u044c\u043d\u044b\u0445 \u043c\u0435\u0442\u043e\u0434\u043e\u0432 \u0438 \u0430\u0431\u0441\u0442\u0440\u0430\u043a\u0446\u0438\u0439. <\/p>\n<p>\u0412\u044b\u043f\u043e\u043b\u043d\u044f\u0435\u043c \u043a\u043e\u043c\u0430\u043d\u0434\u0443 <code>Maven<\/code>:<\/p>\n<pre><code class=\"bash\">mvn avrohugger:generate-scala-sources<\/code><\/pre>\n<p>\u0412 \u043f\u0430\u043f\u043a\u0435 <code>src\/main\/scala <\/code>\u043f\u043e\u044f\u0432\u044f\u0442\u0441\u044f \u043f\u044f\u0442\u044c \u0441\u0433\u0435\u043d\u0435\u0440\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u044b\u0445 \u043a\u043b\u0430\u0441\u0441\u043e\u0432-\u043e\u0431\u0440\u0430\u0437\u0446\u043e\u0432, \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0443\u044e\u0449\u0438\u0445 \u043f\u044f\u0442\u0438 \u043e\u0431\u044a\u0435\u043a\u0442\u0430\u043c \u0434\u0430\u043d\u043d\u044b\u0445.<\/p>\n<figure class=\"float bordered full-width\"><img decoding=\"async\" src=\"\/img\/image-loader.svg\" alt=\"\u0421\u0433\u0435\u043d\u0435\u0440\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u044b\u0435 \u043a\u043b\u0430\u0441\u0441\u044b-\u043e\u0431\u0440\u0430\u0437\u0446\u044b\" title=\"\u0421\u0433\u0435\u043d\u0435\u0440\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u044b\u0435 \u043a\u043b\u0430\u0441\u0441\u044b-\u043e\u0431\u0440\u0430\u0437\u0446\u044b\" height=\"598\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/350\/8ff\/042\/3508ff042339b9c2601b7fdd463be0f0.png\" data-width=\"648\"\/><figcaption>\u0421\u0433\u0435\u043d\u0435\u0440\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u044b\u0435 \u043a\u043b\u0430\u0441\u0441\u044b-\u043e\u0431\u0440\u0430\u0437\u0446\u044b<\/figcaption><\/figure>\n<p>\u041a\u043b\u0430\u0441\u0441\u044b \u043f\u0440\u0438\u043d\u0430\u0434\u043b\u0435\u0436\u0430\u0442 \u043f\u0430\u043a\u0435\u0442\u0443 <code>com.github.aleksandrachasch.avro<\/code>, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0443\u043a\u0430\u0437\u0430\u043d \u0432 \u043f\u043e\u043b\u0435 <code>namespace<\/code> \u0432 \u0441\u0445\u0435\u043c\u0435 Avro.<\/p>\n<p>\u0412\u043e\u0442 \u043a\u0430\u043a \u0432\u044b\u0433\u043b\u044f\u0434\u0438\u0442, \u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u043a\u043b\u0430\u0441\u0441 <code>Customer<\/code>:<\/p>\n<pre><code class=\"scala\">\/** MACHINE-GENERATED FROM AVRO SCHEMA. DO NOT EDIT DIRECTLY *\/ package com.github.aleksandrachasch.avro  case class Customer(Id: String, Name: String, Surname: String, Accounts: Seq[Account])<\/code><\/pre>\n<h3>\u0427\u0442\u0435\u043d\u0438\u0435 Avro \u0432 Spark Dataset<\/h3>\n<p>\u0422\u0435\u043f\u0435\u0440\u044c \u0441\u043e\u0437\u0434\u0430\u0434\u0438\u043c \u0434\u0430\u0442\u0430\u0441\u0435\u0442 Spark, \u0442\u0438\u043f\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u044b\u0439 \u0441\u0433\u0435\u043d\u0435\u0440\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u044b\u043c \u043a\u043b\u0430\u0441\u0441\u043e\u043c <code>Customer<\/code>. <\/p>\n<p>\u0412 \u043a\u0430\u0447\u0435\u0441\u0442\u0432\u0435 \u043f\u0440\u0438\u043c\u0435\u0440\u0430 \u0441\u043e\u0437\u0434\u0430\u0434\u0438\u043c \u043a\u043b\u0438\u0435\u043d\u0442\u0430 \u0441 \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u0438\u043c\u0438 \u0430\u043a\u043a\u0430\u043d\u0443\u0442\u0430\u043c\u0438 \u0438 \u0432\u0437\u0430\u0438\u043c\u043e\u0434\u0435\u0439\u0441\u0442\u0432\u0438\u044f\u043c\u0438:<\/p>\n<pre><code class=\"json\">{   \"Id\": \"1\",   \"Name\": \"John\",   \"Surname\": \"Doe\",   \"Accounts\": [     {       \"AccountId\": 111,       \"AccountType\": \"private\",       \"InteractionGroups\": [         {           \"Id\": 222,           \"date\": \"20220102\",           \"interactions\": [             {               \"Id\": \"1\",               \"type\": \"WEBSITE\"             },             {               \"Id\": \"2\",               \"type\": \"INSTAGRAM\"             }           ]         },         {           \"Id\": 223,           \"date\": \"20220103\",           \"interactions\": [             {               \"Id\": \"4\",               \"type\": \"TWITTER\"             }           ]         }       ]     },     {       \"AccountId\": 112,       \"AccountType\": \"public\",       \"InteractionGroups\": [         {           \"Id\": 333,           \"date\": \"20220105\",           \"interactions\": [             {               \"Id\": \"6\",               \"type\": \"TWITTER\"             },             {               \"Id\": \"7\",               \"type\": \"INSTAGRAM\"             }           ]         }       ]     }   ] }<\/code><\/pre>\n<p><code>Avro<\/code> &#8212; \u044d\u0442\u043e \u0431\u0438\u043d\u0430\u0440\u043d\u044b\u0439 \u0444\u043e\u0440\u043c\u0430\u0442 \u0434\u0430\u043d\u043d\u044b\u0445. \u0418\u043c\u0435\u043d\u043d\u043e \u0442\u0430\u043a \u0431\u0443\u0434\u0435\u0442 \u0432\u044b\u0433\u043b\u044f\u0434\u0435\u0442\u044c \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u0435, \u0435\u0441\u043b\u0438 \u0435\u0433\u043e \u0434\u0435\u0441\u0435\u0440\u0435\u0430\u043b\u0438\u0437\u043e\u0432\u0430\u0442\u044c, \u043f\u0440\u0438\u043c\u0435\u043d\u0438\u0432 \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0443\u044e\u0449\u0443\u044e c\u0445\u0435\u043c\u0443. <\/p>\n<p>\u0421\u043e\u0437\u0434\u0430\u0434\u0438\u043c \u0434\u0430\u0442\u0430\u0441\u0435\u0442:<\/p>\n<pre><code class=\"scala\">import org.apache.spark.sql.catalyst.ScalaReflection import org.apache.spark.sql.types.StructType  import com.github.aleksandrachasch.avro.Customer  import spark.implicits._  val ds = spark.read.format(\"json\") .schema(ScalaReflection.schemaFor[Customer].dataType.asInstanceOf[StructType]) .option(\"mode\", \"FAILFAST\") .option(\"multiline\", true) .load(\"src\/main\/resources\/customer-data.json\") .as[Customer]<\/code><\/pre>\n<p>\u0422\u0438\u043f\u043e\u043c \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u043e\u0439 <code>ds<\/code> \u0431\u0443\u0434\u0435\u0442 <code>Dataset[Customer]<\/code>.<\/p>\n<p>\u0415\u0441\u043b\u0438 \u0432\u0445\u043e\u0434\u043d\u044b\u0435 \u0434\u0430\u043d\u043d\u044b\u0435 \u043d\u0435 \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0443\u044e\u0442 \u043a\u043b\u0430\u0441\u0441\u0430\u043c-\u043e\u0431\u0440\u0430\u0437\u0446\u0430\u043c, \u0442\u043e \u043f\u043e\u044f\u0432\u0438\u0442\u0441\u044f \u043e\u0448\u0438\u0431\u043a\u0430 \u0432\u043e \u0432\u0440\u0435\u043c\u044f \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u044f (runtime). \u041d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u0435\u0441\u043b\u0438 \u0432\u0432\u0435\u0441\u0442\u0438 \u043d\u0435c\u0443\u0449\u0435\u0441\u0442\u0432\u0443\u044e\u0449\u0438\u0439 \u0442\u0438\u043f \u0432\u0437\u0430\u0438\u043c\u043e\u0434\u0435\u0439\u0441\u0442\u0432\u0438\u044f <code>InteractionType<\/code> :<\/p>\n<pre><code class=\"json\">\"interactions\": [   {     \"Id\": \"6\",     \"type\": \"TWITTER\"   },   {     \"Id\": \"7\",     \"type\": \"VK\"   } ]<\/code><\/pre>\n<pre><code class=\"java\">Caused by: java.util.NoSuchElementException: No value found for 'VK' at scala.Enumeration.withName$2(Enumeration.scala:125) at scala.Enumeration.withName(Enumeration.scala:125) at com.github.aleksandrachasch.avro.InteractionType.withName(InteractionType.scala)<\/code><\/pre>\n<h3>\u0421\u043e\u0437\u0434\u0430\u043d\u0438\u0435 \u0444\u0443\u043d\u043a\u0446\u0438\u0438 \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u043a\u0438 \u043a\u043b\u0430\u0441\u0441\u0430-\u043e\u0431\u0440\u0430\u0437\u0446\u0430 \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u0448\u0430\u0431\u043b\u043e\u043d\u0430 \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f type class<\/h3>\n<p>\u0414\u043e\u043f\u0443\u0441\u0442\u0438\u043c, \u043d\u0430\u043c \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e \u043f\u0440\u0438\u0432\u0435\u0441\u0442\u0438 \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u044e \u043e \u0432\u0437\u0430\u0438\u043c\u043e\u0434\u0435\u0439\u0441\u0442\u0432\u0438\u044f\u0445 \u043a\u043b\u0438\u0435\u043d\u0442\u0430 \u043a \u043f\u043b\u043e\u0441\u043a\u043e\u0439 \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u0435:<\/p>\n<figure class=\"\"><img decoding=\"async\" src=\"\/img\/image-loader.svg\" alt=\"\u041c\u043e\u0434\u0435\u043b\u044c \u0434\u0430\u043d\u043d\u044b\u0445 FlattenedCustomer\" title=\"\u041c\u043e\u0434\u0435\u043b\u044c \u0434\u0430\u043d\u043d\u044b\u0445 FlattenedCustomer\" height=\"242\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/1ae\/5d9\/95f\/1ae5d995f6d207559c55a50600b697c6.png\" data-width=\"181\"\/><figcaption>\u041c\u043e\u0434\u0435\u043b\u044c \u0434\u0430\u043d\u043d\u044b\u0445 FlattenedCustomer<\/figcaption><\/figure>\n<p>\u0421\u043e\u0437\u0434\u0430\u0434\u0438\u043c \u043a\u043b\u0430\u0441\u0441-\u043e\u0431\u0440\u0430\u0437\u0435\u0446, \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0443\u044e\u0449\u0438\u0439 \u044d\u0442\u043e\u0439 \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u0435:<\/p>\n<pre><code class=\"scala\">case class FlattenedCustomer(CustomerId: String, Name: String, Surname: String,                              AccountId: Int, AccountType: String,                              InteractionGroupId: String, InteractionGroupDate: String,                              InteractionId: String, InteractionType : String)<\/code><\/pre>\n<p>\u0417\u0430\u0434\u0430\u0447\u0430 \u0441\u0432\u043e\u0434\u0438\u0442\u0441\u044f \u043a \u0442\u043e\u043c\u0443, \u0447\u0442\u043e\u0431\u044b \u043f\u0440\u0435\u043e\u0431\u0440\u0430\u0437\u043e\u0432\u0430\u0442\u044c <code>Dataset[Customer]<\/code>\u00a0\u0432 <code>Dataset[FlattenedCustomer]<\/code>. \u0422\u043e\u0433\u0434\u0430 \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0443\u044e\u0449\u0430\u044f \u0444\u0443\u043d\u043a\u0446\u0438\u044f \u0431\u0443\u0434\u0435\u0442 \u0431\u0440\u0430\u0442\u044c \u0432 \u043a\u0430\u0447\u0435\u0441\u0442\u0432\u0435 \u0430\u0440\u0433\u0443\u043c\u0435\u043d\u0442\u0430 \u043e\u0431\u044a\u0435\u043a\u0442 <code>Customer<\/code> \u0438 \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0442\u044c \u0441\u043f\u0438\u0441\u043e\u043a \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u043e\u0432 <code>FlattenedCustomer<\/code>&#8212; \u043f\u043e \u043e\u0434\u043d\u043e\u043c\u0443 \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u0443 \u043d\u0430 \u043a\u0430\u0436\u0434\u043e\u0435 \u0432\u0437\u0430\u0438\u043c\u043e\u0434\u0435\u0439\u0441\u0442\u0432\u0438\u0435:<\/p>\n<pre><code class=\"scala\">def customerFlatten(c : Customer): Seq[FlattenedCustomer] = ???<\/code><\/pre>\n<p>\u0412\u043e\u0437\u043d\u0438\u043a\u0430\u0435\u0442 \u0432\u043e\u043f\u0440\u043e\u0441, \u0433\u0434\u0435 \u044d\u0442\u0443 \u0444\u0443\u043d\u043a\u0446\u0438\u044e \u0440\u0435\u0430\u043b\u0438\u0437\u043e\u0432\u0430\u0442\u044c. \u041c\u043e\u0436\u043d\u043e \u0431\u044b\u043b\u043e \u0431\u044b \u0434\u043e\u0431\u0430\u0432\u0438\u0442\u044c \u0435\u0435 \u0432 \u043a\u0430\u0447\u0435\u0441\u0442\u0432\u0435 \u043c\u0435\u0442\u043e\u0434\u0430 \u043a \u043a\u043b\u0430\u0441\u0441\u0443 <code>Customer<\/code>:<\/p>\n<pre><code class=\"scala\">case class Customer(Id: String, Name: String, Surname: String, Accounts: Seq[Account]) { def customerFlatten: Seq[FlattenedCustomer] = ??? }<\/code><\/pre>\n<p>\u041d\u043e, \u0432 \u0441\u0432\u044f\u0437\u0438 \u0441 \u0442\u0435\u043c, \u0447\u0442\u043e \u043a\u043b\u0430\u0441\u0441\u044b-\u043e\u0431\u0440\u0430\u0437\u0446\u044b \u0433\u0435\u043d\u0435\u0440\u0438\u0440\u0443\u044e\u0442\u0441\u044f \u0430\u0432\u0442\u043e\u043c\u0430\u0442\u0438\u0447\u0435\u0441\u043a\u0438, \u043a\u0430\u0436\u0434\u0430\u044f \u043d\u043e\u0432\u0430\u044f \u0433\u0435\u043d\u0435\u0440\u0430\u0446\u0438\u044f \u0443\u0434\u0430\u043b\u0438\u0442 \u0441\u043e\u0437\u0434\u0430\u043d\u043d\u044b\u0439 \u0432\u0440\u0443\u0447\u043d\u0443\u044e \u043c\u0435\u0442\u043e\u0434. \u0412\u043e\u043e\u0431\u0449\u0435, \u043d\u0435 \u0440\u0435\u043a\u043e\u043c\u0435\u043d\u0434\u0443\u0435\u0442\u0441\u044f \u0438\u0437\u043c\u0435\u043d\u044f\u0442\u044c \u043a\u043b\u0430\u0441\u0441\u044b \u0438 \u0444\u0430\u0439\u043b\u044b, \u0441\u043e\u0437\u0434\u0430\u043d\u043d\u044b\u0435 \u0430\u0432\u0442\u043e\u043c\u0430\u0442\u0438\u0447\u0435\u0441\u043a\u0438.<\/p>\n<p>\u0421 \u0434\u0440\u0443\u0433\u043e\u0439 \u0441\u0442\u043e\u0440\u043e\u043d\u044b, \u043c\u043e\u0436\u043d\u043e \u0440\u0435\u0430\u043b\u0438\u0437\u043e\u0432\u0430\u0442\u044c \u0444\u0443\u043d\u043a\u0446\u0438\u044e \u0432 \u043e\u0442\u0434\u0435\u043b\u044c\u043d\u043e\u043c \u043e\u0431\u044a\u0435\u043a\u0442\u0435 \u0438 \u0438\u043c\u043f\u043e\u0440\u0442\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0435\u0435 \u043f\u0440\u0438 \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u043a\u0435 \u0434\u0430\u0442\u0430\u0441\u0435\u0442\u0430. <\/p>\n<p>\u041e\u0434\u043d\u0430\u043a\u043e, \u0435\u0441\u0442\u044c \u0431\u043e\u043b\u0435\u0435 \u043b\u0430\u043a\u043e\u043d\u0438\u0447\u043d\u044b\u0439 \u0438 \u0444\u0443\u043d\u043a\u0446\u0438\u043e\u043d\u0430\u043b\u044c\u043d\u044b\u0439 \u0441\u043f\u043e\u0441\u043e\u0431 &#8212; \u0442\u0438\u043f\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u044b\u0439 \u043a\u043b\u0430\u0441\u0441 (<strong><em>type class<\/em><\/strong>).<\/p>\n<p><strong><em>Type class<\/em><\/strong> \u2014 \u044d\u0442\u043e \u0448\u0430\u0431\u043b\u043e\u043d \u0444\u0443\u043d\u043a\u0446\u0438\u043e\u043d\u0430\u043b\u044c\u043d\u043e\u0433\u043e \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u0442 \u0441\u043e\u0437\u0434\u0430\u0432\u0430\u0442\u044c &#171;ad hoc&#187; \u043f\u043e\u043b\u0438\u043c\u043e\u0440\u0444\u0438\u0437\u043c \u043d\u0430 \u043e\u0431\u044a\u0435\u043a\u0442\u0430\u0445, \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044e \u043a\u043e\u0442\u043e\u0440\u044b\u0445 \u043c\u043e\u0434\u0438\u0444\u0438\u0446\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u043d\u0435\u043b\u044c\u0437\u044f. \u041d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u0435\u0441\u043b\u0438 \u0432\u044b \u0438\u043c\u0435\u0435\u0442\u0435 \u0434\u0435\u043b\u043e \u0441\u043e \u0441\u0442\u043e\u0440\u043e\u043d\u043d\u0435\u0439 \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u043e\u0439, \u043a\u043e\u0442\u043e\u0440\u0443\u044e \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e \u0440\u0430\u0441\u0448\u0438\u0440\u0438\u0442\u044c \u0432\u0430\u0448\u0438\u043c \u0441\u043e\u0431\u0441\u0442\u0432\u0435\u043d\u043d\u044b\u043c \u0444\u0443\u043d\u043a\u0446\u0438\u043e\u043d\u0430\u043b\u043e\u043c.<\/p>\n<p>\u0412 \u043d\u0430\u0448\u0435\u043c \u0441\u043b\u0443\u0447\u0430\u0435 &#171;\u0441\u0442\u043e\u0440\u043e\u043d\u043d\u044f\u044f \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0430&#187; \u2014 \u044d\u0442\u043e \u0430\u0432\u0442\u043e\u043c\u0430\u0442\u0438\u0447\u0435\u0441\u043a\u0438 \u0441\u0433\u0435\u043d\u0435\u0440\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u044b\u0435 \u043a\u043b\u0430\u0441\u0441\u044b-\u043e\u0431\u0440\u0430\u0437\u0446\u044b, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043c\u044b \u043d\u0435 \u043c\u043e\u0436\u0435\u043c \u0438\u0437\u043c\u0435\u043d\u044f\u0442\u044c. <\/p>\n<p>\u0428\u0430\u0431\u043b\u043e\u043d <strong><em>type class<\/em><\/strong> \u043e\u0431\u0435\u0441\u043f\u0435\u0447\u0438\u0442 \u0447\u0435\u0442\u043a\u043e\u0435 \u0440\u0430\u0434\u0435\u043b\u0435\u043d\u0438\u0435 \u043a\u043e\u0434\u0430, \u0437\u0430\u0432\u0438\u0441\u044f\u0449\u0435\u0433\u043e \u043e\u0442 \u0432\u043d\u0435\u0448\u043d\u0438\u0445 \u0438\u0441\u0442\u043e\u0447\u043d\u0438\u043a\u043e\u0432 \u0438 \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c (\u0441\u0445\u0435\u043c\u044b Avro), \u0438 \u0441\u043e\u0431\u0441\u0442\u0432\u0435\u043d\u043d\u043e\u0433\u043e \u043a\u043b\u044e\u0447\u0435\u0432\u043e\u0433\u043e \u0444\u0443\u043d\u043a\u0446\u0438\u043e\u043d\u0430\u043b\u0430 \u043d\u0430\u0448\u0435\u0439 \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u044b.<\/p>\n<p>\u041a \u0442\u043e\u043c\u0443 \u0436\u0435 \u0448\u0430\u0431\u043b\u043e\u043d \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u0442 \u043b\u0435\u0433\u043a\u043e \u0434\u043e\u0431\u0430\u0432\u043b\u044f\u0442\u044c \u043c\u0435\u0442\u043e\u0434\u044b \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u043a\u0438 \u0434\u0440\u0443\u0433\u0438\u0445 \u043e\u0431\u044a\u0435\u043a\u0442\u043e\u0432.<\/p>\n<p>\u0428\u0430\u0431\u043b\u043e\u043d <strong><em>type class<\/em><\/strong> \u0441\u043e\u0441\u0442\u043e\u0438\u0442 \u0438\u0437 \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u0438\u0445 \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u043e\u0432:<\/p>\n<ol>\n<li>\n<p>\u0422\u0440\u0435\u0439\u0442 \u0441 \u043c\u0435\u0442\u043e\u0434\u043e\u043c <code>customerFlatten<\/code> \u0438 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u0430\u043c\u0438 \u0432\u0445\u043e\u0434\u0430 (<code>T<\/code>) \u0438 \u0432\u044b\u0445\u043e\u0434\u0430 (<code>C<\/code>):  <\/p>\n<pre><code class=\"scala\">trait DataProcessor[T, C] { def customerFlatten(t: T): Seq[C] }<\/code><\/pre>\n<\/li>\n<\/ol>\n<ol start=\"2\">\n<li>\n<p>\u041e\u0431\u044a\u0435\u043a\u0442-\u043a\u043e\u043c\u043f\u0430\u043d\u044c\u043e\u043d \u0441\u043e \u0432\u0441\u043f\u043e\u043c\u043e\u0433\u0430\u0442\u0435\u043b\u044c\u043d\u044b\u043c\u0438 \u0444\u0443\u043d\u043a\u0446\u0438\u044f\u043c\u0438:<\/p>\n<pre><code class=\"scala\">object DataProcessor {   def apply[T, C](implicit processor: DataProcessor[T, C]): DataProcessor[T, C] =     processor   implicit class DataProcessorOps[T, C](val t : T) extends AnyVal {     def customerFlatten(implicit processor: DataProcessor[T, C]): Seq[C] = {       processor.customerFlatten(t)     }   } }<\/code><\/pre>\n<p>\u0424\u0443\u043d\u043a\u0446\u0438\u044f <code>apply<\/code>, \u0432 \u0437\u0430\u0432\u0438\u0441\u0438\u043c\u043e\u0441\u0442\u0438 \u043e\u0442 \u0442\u0438\u043f\u043e\u0432 <code>T<\/code> \u0438 <code>\u0421<\/code>, \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442 \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0443\u044e\u0449\u0438\u0439 \u044d\u043a\u0437\u0435\u043c\u043f\u043b\u044f\u0440 <code>DataProcessor<\/code>. \u042d\u0442\u043e \u043f\u0440\u043e\u0438\u0441\u0445\u043e\u0434\u0438\u0442 \u0437\u0430 \u0441\u0447\u0435\u0442 \u043d\u0435\u044f\u0432\u043d\u043e\u0433\u043e (<code>implicit<\/code>) \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u0430 <code>processor<\/code>. \u041d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u043f\u0440\u0438 \u0432\u044b\u0437\u043e\u0432\u0435 \u0444\u0443\u043d\u043a\u0446\u0438\u0438 <code>apply[Customer, FlattenedCustomer] <\/code>\u043a\u043e\u043c\u043f\u0438\u043b\u044f\u0442\u043e\u0440 Scala \u0430\u0432\u0442\u043e\u043c\u0430\u0442\u0438\u0447\u0435\u0441\u043a\u0438 \u043d\u0430\u0439\u0434\u0435\u0442 \u0438 \u0432\u0435\u0440\u043d\u0435\u0442 \u044d\u043a\u0437\u0435\u043c\u043f\u043b\u044f\u0440 \u043a\u043b\u0430\u0441\u0441\u0430 <code>DataProcessor[Customer, FlattenedCustomer]<\/code>.<\/p>\n<p>\u0417\u0430 \u0441\u0447\u0451\u0442 \u0442\u043e\u0433\u043e \u0436\u0435 \u043c\u0435\u0445\u0430\u043d\u0438\u0437\u043c\u0430 \u043d\u0435\u044f\u0432\u043d\u044b\u0445 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u043e\u0432 \u043d\u0435\u044f\u0432\u043d\u044b\u0439 \u043a\u043b\u0430\u0441\u0441 <code>DataProcessorOps<\/code> \u043f\u043e\u0437\u0432\u043e\u043b\u044fe\u0442 \u0432\u044b\u0437\u044b\u0432\u0430\u0442\u044c \u0444\u0443\u043d\u043a\u0446\u0438\u044e <code>customerFlatten<\/code> \u043d\u0430 \u044d\u043a\u0437\u0435\u043c\u043f\u043b\u044f\u0440\u0430\u0445 \u043a\u043b\u0430\u0441\u0441\u0430 <code>T<\/code>, \u043a\u0430\u043a \u0435\u0441\u043b\u0438 \u0431\u044b \u043e\u043d \u0431\u044b\u043b \u0441\u043e\u0431\u0441\u0442\u0432\u0435\u043d\u043d\u044b\u043c \u043c\u0435\u0442\u043e\u0434\u043e\u043c \u043a\u043b\u0430\u0441\u0441\u0430 <code>T<\/code> (\u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, <code>t.customerFlatten<\/code>).<\/p>\n<\/li>\n<li>\n<p>\u041d\u0430\u043a\u043e\u043d\u0435\u0446, \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044f <code>DataProcessor<\/code> \u0434\u043b\u044f \u043a\u043e\u043d\u043a\u0440\u0435\u0442\u043d\u044b\u0445 \u043e\u0431\u044a\u0435\u043a\u0442\u043e\u0432 <code>Customer<\/code> \u0438 <code>FlattenedCustomer<\/code>:<\/p>\n<pre><code class=\"scala\">package com.github.aleksandrachasch.avro.ops  object CustomerDataProcessor {    implicit val customerDataProcessor: DataProcessor[Customer, FlattenedCustomer] =     (t: Customer) => t.Accounts.flatMap(acc => acc.InteractionGroups.flatMap(       group => group.interactions.map(         interaction => FlattenedCustomer.apply(t.Id, t.Name, t.Surname, acc.AccountId, acc.AccountType,           group.Id, group.date, interaction.Id, interaction.`type`.toString)       )     )     ) }<\/code><\/pre>\n<p>\u0420\u0435\u0430\u043b\u0438\u0437\u043e\u0432\u0430\u043d\u043d\u0430\u044f \u0444\u0443\u043d\u043a\u0446\u0438\u044f \u0430\u0432\u0442\u043e\u043c\u0430\u0442\u0438\u0447\u0435\u0441\u043a\u0438 \u0441\u043e\u043e\u0442\u043d\u043e\u0441\u0438\u0442\u0441\u044f \u0441 \u0444\u0443\u043d\u043a\u0446\u0438\u0435\u0439 <code>customerFlatten,<\/code> \u0442.\u043a. \u0442\u0438\u043f\u044b \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u0430 (<code>Customer<\/code>) \u0438 \u0432\u044b\u0445\u043e\u0434\u0430 (<code>Seq[FlattenedCustomer]<\/code>) \u0441\u043e\u0432\u043f\u0430\u0434\u0430\u044e\u0442.<\/p>\n<p>\u041a\u0430\u043a \u043c\u043e\u0436\u043d\u043e \u0437\u0430\u043c\u0435\u0442\u0438\u0442\u044c, \u0432 \u0441\u0430\u043c\u043e\u0439 \u0444\u0443\u043d\u043a\u0446\u0438\u0438 \u043e\u043f\u0435\u0440\u0438\u0440\u0443\u0435\u043c \u0430\u0442\u0440\u0438\u0431\u0443\u0442\u0430\u043c\u0438 \u043a\u043b\u0430\u0441\u0441\u043e\u0432-\u043e\u0431\u0440\u0430\u0437\u0446\u043e\u0432. \u0412 \u0434\u0430\u0442\u0430\u0444\u0440\u0435\u0439\u043c\u0435 \u044d\u0442\u043e \u0431\u044b\u043b\u0438 \u0431\u044b \u043d\u0430\u0437\u0432\u0430\u043d\u0438\u044f \u0441\u0442\u043e\u043b\u0431\u0446\u043e\u0432 \u0438 \u0432\u043b\u043e\u0436\u0435\u043d\u043d\u044b\u0445 \u043f\u043e\u043b\u0435\u0439. \u0412 \u043e\u0442\u043b\u0438\u0447\u0438\u0435 \u043e\u0442 \u0434\u0430\u0442\u0430\u0444\u0440\u0435\u0439\u043c\u0430, \u0437\u0434\u0435\u0441\u044c \u043e\u0448\u0438\u0431\u043a\u0438 \u0431\u0443\u0434\u0443\u0442 \u0432\u0438\u0434\u043d\u044b \u0443\u0436\u0435 \u0432 \u0445\u043e\u0434\u0435 \u043a\u043e\u043c\u043f\u0438\u043b\u044f\u0446\u0438\u0438. <\/p>\n<\/li>\n<\/ol>\n<p>\u0418\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435 \u0444\u0443\u043d\u043a\u0446\u0438\u0438 \u043d\u0430 \u0434\u0430\u0442\u0430\u0441\u0435\u0442\u0435 \u043f\u043e\u043b\u0443\u0447\u0430\u0435\u0442\u0441\u044f \u043a\u0440\u0430\u0442\u043a\u0438\u043c \u0438 \u043b\u0430\u043a\u043e\u043d\u0438\u0447\u043d\u044b\u043c:<\/p>\n<pre><code class=\"scala\">import com.github.aleksandrachasch.avro.ops.CustomerDataProcessor._  val flattenedDs = ds.flatMap(_.customerFlatten) flattenedDs.show(false)<\/code><\/pre>\n<figure class=\"full-width\"><img decoding=\"async\" src=\"\/img\/image-loader.svg\" alt=\"flattenedDs\" title=\"flattenedDs\" height=\"191\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/1d4\/b1a\/0e1\/1d4b1a0e13add47b68f786d50a0157eb.png\" data-width=\"982\"\/><figcaption>flattenedDs<\/figcaption><\/figure>\n<p>\u041a\u0430\u043a \u043c\u043e\u0436\u043d\u043e \u0437\u0430\u043c\u0435\u0442\u0438\u0442\u044c, \u0432 \u043a\u043e\u0434\u0435 \u043d\u0435\u0442 \u0434\u0435\u043a\u043b\u0430\u0440\u0430\u0446\u0438\u0438 \u043d\u043e\u0432\u044b\u0445 \u044d\u043a\u0437\u0435\u043c\u043f\u043b\u044f\u0440\u043e\u0432 \u043a\u043b\u0430\u0441\u0441\u043e\u0432 (<code>new<\/code>). \u041c\u0435\u0445\u0430\u043d\u0438\u0437\u043c \u043d\u0435\u044f\u0432\u043d\u044b\u0445 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u043e\u0432 \u0438 \u043a\u043b\u0430\u0441\u0441\u043e\u0432 (<code>implicit<\/code>) \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u0442 \u043c\u0438\u043d\u0438\u043c\u0438\u0437\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u044d\u043a\u0437\u0435\u043c\u043f\u043b\u044f\u0440\u043e\u0432 \u0432 JVM, \u0430 \u0442\u0430\u043a\u0436\u0435 \u0440\u0430\u0437\u043b\u0438\u0447\u043d\u044b\u0445 \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u044b\u0445 \u0432 \u043a\u043e\u0434\u0435. \u041d\u0435\u0442 \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e\u0441\u0442\u0438 \u0441\u043e\u0431\u0441\u0442\u0432\u0435\u043d\u043d\u043e\u0440\u0443\u0447\u043d\u043e \u0438\u043d\u0438\u0446\u0438\u0430\u043b\u0438\u0437\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u043a\u043b\u0430\u0441\u0441\u044b &#8212; \u0437\u0430 \u043d\u0430\u0441 \u044d\u0442\u043e \u0434\u0435\u043b\u0430\u0435\u0442 Scala.<\/p>\n<p>\u0414\u043b\u044f \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u043a\u0438 \u0434\u0440\u0443\u0433\u043e\u0433\u043e \u043e\u0431\u044a\u0435\u043a\u0442\u0430 \u0434\u043e\u0441\u0442\u0430\u0442\u043e\u0447\u043d\u043e \u0440\u0435\u0430\u043b\u0438\u0437\u043e\u0432\u0430\u0442\u044c <code>DataProcessor[T, C]<\/code>  \u0441 \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0443\u044e\u0449\u0438\u043c\u0438 \u0442\u0438\u043f\u0430\u043c\u0438 \u0432\u0445\u043e\u0434\u0430 <code>T<\/code> \u0438 \u0432\u044b\u0445\u043e\u0434\u0430 <code>C<\/code>. <\/p>\n<p>\u041d\u0430\u0434\u0435\u044e\u0441\u044c, \u044d\u0442\u043e\u0442 \u043f\u043e\u0441\u0442 \u0431\u044b\u043b \u0432\u0430\u043c \u043f\u043e\u043b\u0435\u0437\u0435\u043d. <\/p>\n<p>\u041a\u0441\u0442\u0430\u0442\u0438, \u0443\u0436\u0435 \u0432 \u043a\u043e\u043d\u0446\u0435 \u0444\u0435\u0432\u0440\u0430\u043b\u044f \u0432 OTUS \u0441\u0442\u0430\u0440\u0442\u0443\u0435\u0442 \u043d\u043e\u0432\u044b\u0439 \u043f\u043e\u0442\u043e\u043a \u043a\u0443\u0440\u0441\u0430 DataOps. \u0412 \u043f\u0440\u0435\u0434\u0434\u0432\u0435\u0440\u0438\u0438 \u0441\u0442\u0430\u0440\u0442\u0430 \u043a\u0443\u0440\u0441\u0430 \u043f\u0440\u0438\u0433\u043b\u0430\u0448\u0430\u044e \u0432\u0441\u0435\u0445 \u0436\u0435\u043b\u0430\u044e\u0449\u0438\u0445 \u043d\u0430 \u0431\u0435\u0441\u043f\u043b\u0430\u0442\u043d\u044b\u0439 \u0434\u0435\u043c\u043e\u0443\u0440\u043e\u043a. \u0420\u0435\u0433\u0438\u0441\u0442\u0440\u0430\u0446\u0438\u044f <a href=\"https:\/\/otus.pw\/sPYc\/\">\u0434\u043e\u0441\u0442\u0443\u043f\u043d\u0430 \u043f\u043e \u0441\u0441\u044b\u043b\u043a\u0435<\/a>.<\/p>\n<p>\u0414\u043e \u0432\u0441\u0442\u0440\u0435\u0447\u0438!<\/p>\n<\/div>\n<\/div>\n<\/div>\n<div class=\"v-portal\" style=\"display:none;\"><\/div>\n<\/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\/650125\/\"> https:\/\/habr.com\/ru\/company\/otus\/blog\/650125\/<\/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_version-2\">\n<div xmlns=\"http:\/\/www.w3.org\/1999\/xhtml\">\n<figure class=\"full-width\"><figcaption><\/figcaption><\/figure>\n<p>\u041f\u0440\u0438\u0432\u0435\u0442!<\/p>\n<p>\u0412 \u044d\u0442\u043e\u043c \u043f\u043e\u0441\u0442\u0435 \u0440\u0430\u0437\u0431\u0435\u0440\u0435\u043c, \u043a\u0430\u043a \u043e\u0431\u0440\u0430\u0431\u0430\u0442\u044b\u0432\u0430\u0442\u044c \u043e\u0431\u044a\u0435\u043a\u0442\u044b JVM, \u0441\u0433\u0435\u043d\u0435\u0440\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u044b\u0435 \u0438\u0437 \u0441\u0445\u0435\u043c Avro, \u0432 \u0434\u0430\u0442\u0430\u0441\u0435\u0442\u0430\u0445 Spark. \u0412\u043c\u0435\u0441\u0442\u0435 \u0441 \u044d\u0442\u0438\u043c \u0440\u0430\u0441\u0441\u043c\u043e\u0442\u0440\u0438\u043c, \u043a\u0430\u043a \u043e\u0440\u0433\u0430\u043d\u0438\u0437\u043e\u0432\u0430\u0442\u044c \u043a\u043e\u0434 \u043f\u0440\u0438 \u043f\u043e\u043c\u043e\u0449\u0438 \u0448\u0430\u0431\u043b\u043e\u043d\u0430 \u0444\u0443\u043d\u043a\u0446\u0438\u043e\u043d\u0430\u043b\u044c\u043d\u043e\u0433\u043e \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f &#171;\u0442\u0438\u043f\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u044b\u0439 \u043a\u043b\u0430\u0441\u0441&#187; (type class) \u043d\u0430 \u044f\u0437\u044b\u043a\u0435 Scala.<\/p>\n<p>\u0414\u0430\u0442\u0430\u0444\u0440\u0435\u0439\u043c \u0432 Spark &#8212; \u0430\u0431\u0441\u0442\u0440\u0430\u043a\u0446\u0438\u044f \u0442\u0430\u0431\u043b\u0438\u0446\u044b \u0441\u043e \u0441\u0442\u043e\u043b\u0431\u0446\u0430\u043c\u0438 \u0438 \u0441\u0442\u0440\u043e\u043a\u0430\u043c\u0438, \u043f\u043e\u043a\u0440\u044b\u0432\u0430\u0435\u0442 \u0431\u043e\u043b\u044c\u0448\u0438\u043d\u0441\u0442\u0432\u043e \u043a\u0435\u0439\u0441\u043e\u0432 \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u043a\u0438 \u0434\u0430\u043d\u043d\u044b\u0445. \u0422\u0435\u043c \u043d\u0435 \u043c\u0435\u043d\u0435\u0435, \u0431\u044b\u0432\u0430\u0435\u0442 \u0442\u0430\u043a, \u0447\u0442\u043e \u0434\u0430\u043d\u043d\u044b\u0435 \u0438\u043c\u0435\u044e\u0442 \u043d\u0430\u0441\u0442\u043e\u043b\u044c\u043a\u043e \u0441\u043f\u0435\u0446\u0438\u0444\u0438\u0447\u043d\u0443\u044e \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u0443, \u0447\u0442\u043e \u043f\u0440\u0438\u0432\u0435\u0441\u0442\u0438 \u0438\u0445 \u043a \u043e\u0431\u0449\u0435\u043c\u0443 \u0437\u043d\u0430\u043c\u0435\u043d\u0430\u0442\u0435\u043b\u044e \u0432 \u0434\u0430\u0442\u0430\u0444\u0440\u0435\u0439\u043c\u0435 \u0434\u043e\u0441\u0442\u0430\u0442\u043e\u0447\u043d\u043e \u0441\u043b\u043e\u0436\u043d\u043e. \u0412 \u044d\u0442\u043e\u043c \u0441\u043b\u0443\u0447\u0430\u0435 \u043c\u043e\u0436\u043d\u043e \u043f\u0440\u0438\u0431\u0435\u0433\u043d\u0443\u0442\u044c \u043a \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u043d\u043e\u043c\u0443 \u0438\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441\u0443 Spark Dataset. \u041e\u043d \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u0442 \u043c\u0430\u043d\u0438\u043f\u0443\u043b\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u043d\u0435 \u0430\u0431\u0441\u0442\u0440\u0430\u043a\u0442\u043d\u044b\u043c\u0438 \u0441\u0442\u0440\u043e\u043a\u0430\u043c\u0438 \u0438 \u0441\u0442\u043e\u043b\u0431\u0446\u0430\u043c\u0438, \u0430 \u043a\u043e\u043d\u043a\u0440\u0435\u0442\u043d\u044b\u043c\u0438 \u043e\u0431\u044a\u0435\u043a\u0442\u0430\u043c\u0438 \u0432\u0438\u0440\u0442\u0443\u0430\u043b\u044c\u043d\u043e\u0439 \u043c\u0430\u0448\u0438\u043d\u044b Java.<\/p>\n<p>\u0422\u0438\u043f\u0438\u0447\u043d\u044b\u0439 \u043a\u0435\u0439\u0441 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u044f \u0434\u0430\u0442\u0430\u0441\u0435\u0442\u043e\u0432 &#8212; \u0447\u0442\u0435\u043d\u0438\u0435 \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u0439 Kafka \u0432 \u0444\u043e\u0440\u043c\u0430\u0442\u0435 Avro.  <\/p>\n<p>\u041f\u0440\u043e\u0446\u0435\u0441\u0441 \u0441\u043e\u0441\u0442\u043e\u0438\u0442 \u0438\u0437 4 \u044d\u0442\u0430\u043f\u043e\u0432:<\/p>\n<ol>\n<li>\n<p>\u0413\u0435\u043d\u0435\u0440\u0430\u0446\u0438\u044f \u043a\u043b\u0430\u0441\u0441\u043e\u0432-\u043e\u0431\u0440\u0430\u0437\u0446\u043e\u0432 (case class) \u0438\u0441\u0445\u043e\u0434\u044f \u0438\u0437 \u0441\u0445\u0435\u043c\u044b Avro-\u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u044f.<\/p>\n<\/li>\n<li>\n<p>\u0427\u0442\u0435\u043d\u0438\u0435 Avro-\u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u0439 \u0432 Dataset Spark, \u0442\u0438\u043f\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u044b\u0439 \u043a\u043b\u0430\u0441\u0441\u043e\u043c-\u043e\u0431\u0440\u0430\u0437\u0446\u043e\u043c.<\/p>\n<\/li>\n<li>\n<p>\u0420\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044f \u043e\u043f\u0435\u0440\u0430\u0446\u0438\u0438 \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u043a\u0438 \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u044f. \u0412 \u0447\u0430\u0441\u0442\u043d\u043e\u0441\u0442\u0438, \u043d\u0430\u043f\u0438\u0448\u0435\u043c \u0444\u0443\u043d\u043a\u0446\u0438\u044e, \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u043f\u0440\u0438\u0432\u0435\u0434\u0435\u0442 \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u0435 \u043a \u043f\u043b\u043e\u0441\u043a\u043e\u0439 \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u0435.<\/p>\n<\/li>\n<\/ol>\n<p>\u0421 \u043a\u043e\u0434\u043e\u043c \u043c\u043e\u0436\u043d\u043e \u043e\u0437\u043d\u0430\u043a\u043e\u043c\u0438\u0442\u044c\u0441\u044f <a href=\"https:\/\/github.com\/aleksandrachasch\/SparkAvroProject\">\u0437\u0434\u0435\u0441\u044c<\/a>.<\/p>\n<h3>\u0413\u0435\u043d\u0435\u0440\u0430\u0446\u0438\u044f \u043a\u043b\u0430\u0441\u0441\u043e\u0432-\u043e\u0431\u0440\u0430\u0437\u0446\u043e\u0432 Scala<\/h3>\n<p>\u041f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u0438\u043c, \u0447\u0442\u043e \u043d\u0430\u043c \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e \u043e\u0431\u0440\u0430\u0431\u0430\u0442\u044b\u0432\u0430\u0442\u044c \u0434\u0430\u043d\u043d\u044b\u0435 \u043a\u043b\u0438\u0435\u043d\u0442\u0430 \u0441\u043e \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0435\u0439 \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u043e\u0439:<\/p>\n<figure class=\"\"><figcaption>\u041c\u043e\u0434\u0435\u043b\u044c \u0434\u0430\u043d\u043d\u044b\u0445 \u043a\u043b\u0438\u0435\u043d\u0442\u0430<\/figcaption><\/figure>\n<p>\u041a\u043b\u0438\u0435\u043d\u0442 (<code>Customer<\/code>) \u043c\u043e\u0436\u0435\u0442 \u0438\u043c\u0435\u0442\u044c \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u0430\u043a\u043a\u0430\u0443\u043d\u0442\u043e\u0432. \u0410\u043a\u043a\u0430\u0443\u043d\u0442, \u0432 \u0441\u0432\u043e\u044e \u043e\u0447\u0435\u0440\u0435\u0434\u044c, \u0438\u043c\u0435\u0435\u0442 \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u0433\u0440\u0443\u043f\u043f \u0432\u0437\u0430\u0438\u043c\u043e\u0434\u0435\u0439\u0441\u0442\u0432\u0438\u044f (<code>InteractionGroups<\/code>). \u0413\u0440\u0443\u043f\u043f\u0430 \u0432\u0437\u0430\u0438\u043c\u043e\u0434\u0435\u0439\u0441\u0442\u0432\u0438\u044f \u0441\u043e\u0434\u0435\u0440\u0436\u0438\u0442 \u0432 \u0441\u0435\u0431\u0435 \u0432\u0437\u0430\u0438\u043c\u043e\u0434\u0435\u0439\u0441\u0442\u0432\u0438\u044f, \u0441\u043e\u0432\u0435\u0440\u0448\u0435\u043d\u043d\u044b\u0435 \u043a\u043b\u0438\u0435\u043d\u0442\u043e\u043c \u0432 \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u043d\u0443\u044e \u0434\u0430\u0442\u0443. \u0412\u0437\u0430\u0438\u043c\u043e\u0434\u0435\u0439\u0441\u0442\u0432\u0438\u0435 \u0438\u043c\u0435\u0435\u0442 \u043e\u0434\u0438\u043d \u0438\u0437 \u0442\u0438\u043f\u043e\u0432, \u043e\u0431\u043e\u0437\u043d\u0430\u0447\u0430\u044e\u0449\u0438\u0439 \u043a\u0430\u043d\u0430\u043b \u0432\u0437\u0430\u0438\u043c\u043e\u0434\u0435\u0439\u0441\u0442\u0432\u0438\u044f: \u0441\u0430\u0439\u0442, \u0442\u0432\u0438\u0442\u0442\u0435\u0440, \u0438\u043d\u0441\u0442\u0430\u0433\u0440\u0430\u043c \u0438\u043b\u0438 \u0437\u0432\u043e\u043d\u043e\u043a.<\/p>\n<details class=\"spoiler\">\n<summary>\u041e\u0442\u0441\u0442\u0443\u043f\u043b\u0435\u043d\u0438\u0435<\/summary>\n<div class=\"spoiler__content\">\n<p>\u041d\u0430\u0432\u0435\u0440\u043d\u044f\u043a\u0430, \u0443 \u0432\u0430\u0441 \u0432\u043e\u0437\u043d\u0438\u043a\u043b\u0438 \u043f\u0440\u0435\u0442\u0435\u043d\u0437\u0438\u0438 \u043a \u044d\u0442\u043e\u0439 \u043c\u043e\u0434\u0435\u043b\u0438 \ud83d\ude42 \u042d\u0442\u043e \u0441\u043f\u0440\u0430\u0432\u0435\u0434\u043b\u0438\u0432\u043e. \u0414\u0430\u043d\u043d\u044b\u0435 \u0441\u043f\u0435\u0446\u0438\u0430\u043b\u044c\u043d\u043e \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u0438\u0440\u043e\u0432\u0430\u043d\u044b &#171;\u043a\u0440\u0438\u0432\u043e&#187;, \u0447\u0442\u043e\u0431\u044b \u0441\u043c\u043e\u0434\u0435\u043b\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0440\u0435\u0430\u043b\u044c\u043d\u044b\u0439 \u043a\u0435\u0439\u0441. \u0417\u0430\u0447\u0430\u0441\u0442\u0443\u044e \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e \u043e\u0431\u0440\u0430\u0431\u0430\u0442\u044b\u0432\u0430\u0442\u044c \u0434\u0430\u043d\u043d\u044b\u0435 \u0438\u0437 \u0443\u0441\u0442\u0430\u0440\u0435\u0432\u0448\u0438\u0445 \u0441\u0438\u0441\u0442\u0435\u043c, \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u0443 \u043a\u043e\u0442\u043e\u0440\u044b\u0445 \u043c\u044b \u0438\u0437\u043c\u0435\u043d\u0438\u0442\u044c \u043d\u0435 \u043c\u043e\u0436\u0435\u043c. \u041f\u0440\u0438\u0445\u043e\u0434\u0438\u0442\u0441\u044f \u0440\u0430\u0431\u043e\u0442\u0430\u0442\u044c \u0441 \u0442\u0435\u043c, \u0447\u0442\u043e \u0435\u0441\u0442\u044c. <\/p>\n<\/div>\n<\/details>\n<p>\u0421\u0445\u0435\u043c\u0430 \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u044f Avro, \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0443\u044e\u0449\u0430\u044f \u0434\u0430\u043d\u043d\u043e\u0439 \u043c\u043e\u0434\u0435\u043b\u0438, \u0431\u0443\u0434\u0435\u0442 \u0432\u044b\u0433\u043b\u044f\u0434\u0435\u0442\u044c \u0442\u0430\u043a:<\/p>\n<pre><code class=\"json\">{   \"type\": \"record\",   \"name\": \"Customer\",   \"namespace\": \"com.github.aleksandrachasch.avro\",   \"fields\": [     {       \"name\": \"Id\",       \"type\": \"string\"     },     {       \"name\": \"Name\",       \"type\": \"string\"     },     {       \"name\": \"Surname\",       \"type\": \"string\"     },     {       \"name\": \"Accounts\",       \"type\": {         \"type\": \"array\",         \"items\": {           \"type\": \"record\",           \"name\": \"Account\",           \"namespace\": \"com.github.aleksandrachasch.avro\",           \"fields\": [             {               \"name\": \"AccountId\",               \"type\": \"int\"             },             {               \"name\": \"AccountType\",               \"type\": \"string\"             },             {               \"name\": \"InteractionGroups\",               \"type\": {                 \"type\": \"array\",                 \"items\": {                   \"type\": \"record\",                   \"name\": \"InteractionGroup\",                   \"namespace\": \"com.github.aleksandrachasch.avro\",                   \"fields\": [                     {                       \"name\": \"Id\",                       \"type\": \"string\"                     },                     {                       \"name\": \"date\",                       \"type\": \"string\"                     },                     {                       \"name\": \"interactions\",                       \"type\": {                         \"type\": \"array\",                         \"items\": {                           \"type\": \"record\",                           \"name\": \"Interaction\",                           \"namespace\": \"com.github.aleksandrachasch.avro\",                           \"fields\": [                             {                               \"name\": \"Id\",                               \"type\": \"string\"                             },                             {                               \"name\": \"type\",                               \"type\": {                                 \"type\": \"enum\",                                 \"name\": \"InteractionType\",                                 \"namespace\": \"com.github.aleksandrachasch.avro\",                                 \"symbols\": [                                   \"WEBSITE\",                                   \"TWITTER\",                                   \"CALL\",                                   \"INSTAGRAM\"                                 ]                               }                             }                           ]                         }                       }                     }                   ]                 }               }             }           ]         }       }     }   ] }<\/code><\/pre>\n<p>\u0422\u0435\u043f\u0435\u0440\u044c \u0438\u0437 \u044d\u0442\u043e\u0439 \u0441\u0445\u0435\u043c\u044b \u043c\u043e\u0436\u043d\u043e \u0441\u0433\u0435\u043d\u0435\u0440\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u043a\u043b\u0430\u0441\u0441\u044b-\u043e\u0431\u0440\u0430\u0437\u0446\u044b Scala. \u0417\u0430\u0442\u0435\u043c \u043c\u044b \u0431\u0443\u0434\u0435\u043c \u043e\u043f\u0435\u0440\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u044d\u043a\u0437\u0435\u043c\u043f\u043b\u044f\u0440\u0430\u043c\u0438 \u044d\u0442\u0438\u0445 \u043a\u043b\u0430\u0441\u0441\u043e\u0432.  <\/p>\n<p>\u0412 \u0440\u0435\u0430\u043b\u044c\u043d\u043e\u0439 \u0436\u0438\u0437\u043d\u0438 \u043f\u0440\u043e\u0446\u0435\u0441\u0441 \u0433\u0435\u043d\u0435\u0440\u0430\u0446\u0438\u0438 \u043a\u043b\u0430\u0441\u0441\u043e\u0432-\u043e\u0431\u0440\u0430\u0437\u0446\u043e\u0432 \u0432\u044b\u0433\u043b\u044f\u0434\u0438\u0442 \u043f\u0440\u0438\u043c\u0435\u0440\u043d\u043e \u0442\u0430\u043a:<\/p>\n<ol>\n<li>\n<p>\u0427\u0442\u0435\u043d\u0438\u0435 \u0441\u0445\u0435\u043c\u044b Avro. \u041d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u0438\u0437 <code>Confluent Schema Registry<\/code><strong> <\/strong>&#8212; \u0440\u0435\u0433\u0438\u0441\u0442\u0440\u0430 c\u0445\u0435\u043c \u0442\u043e\u043f\u0438\u043a\u043e\u0432 \u043a\u043b\u0430\u0441\u0442\u0435\u0440\u0430 Kafka, \u043a \u043a\u043e\u0442\u043e\u0440\u043e\u043c\u0443 \u043c\u043e\u0436\u043d\u043e \u043e\u0431\u0440\u0430\u0449\u0430\u0442\u044c\u0441\u044f \u0447\u0435\u0440\u0435\u0437 API.<\/p>\n<\/li>\n<li>\n<p>\u0413\u0435\u043d\u0435\u0440\u0430\u0446\u0438\u044f \u043a\u043b\u0430\u0441\u0441\u043e\u0432-\u043e\u0431\u0440\u0430\u0437\u0446\u043e\u0432 \u0432 \u0444\u0430\u0437\u0435 \u043a\u043e\u043c\u043f\u0438\u043b\u044f\u0446\u0438\u0438 <code>Maven<\/code> \u0438\u043b\u0438 <code>SBT<\/code> . \u0421\u0433\u0435\u043d\u0435\u0440\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u044b\u0435 \u043a\u043b\u0430\u0441\u0441\u044b \u043f\u0440\u0438 \u044d\u0442\u043e\u043c \u043a\u043e\u043f\u0438\u0440\u0443\u044e\u0442\u0441\u044f \u043f\u0440\u044f\u043c\u043e \u0432 <code>src\/<\/code> \u043f\u0440\u043e\u0435\u043a\u0442\u0430. \u0412 \u0441\u043b\u0443\u0447\u0430\u0435 \u043e\u0431\u043d\u043e\u0432\u043b\u0435\u043d\u0438\u044f \u0441\u0445\u0435\u043c\u044b \u0432 \u0440\u0435\u0433\u0438\u0441\u0442\u0440\u0435 \u043c\u044b \u0443\u0432\u0438\u0434\u0438\u043c \u0438\u0437\u043c\u0435\u043d\u0435\u043d\u0438\u044f \u0432 \u043d\u0430\u0448\u0435\u043c \u043f\u0440\u043e\u0435\u043a\u0442\u0435. \u0411\u0443\u0434\u0435\u0442 \u043f\u043e\u043d\u044f\u0442\u043d\u043e \u0443\u0436\u0435 \u0432 \u0444\u0430\u0437\u0435 \u043a\u043e\u043c\u043f\u0438\u043b\u044f\u0446\u0438\u0438, \u043d\u0430\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u0441\u043e\u0432\u043c\u0435\u0441\u0442\u0438\u043c\u044b \u044d\u0442\u0438 \u0438\u0437\u043c\u0435\u043d\u0435\u043d\u0438\u044f \u0441 \u0441\u0443\u0449\u0435\u0441\u0442\u0432\u0443\u044e\u0449\u0438\u043c \u043a\u043e\u0434\u043e\u043c.<\/p>\n<\/li>\n<\/ol>\n<p>\u0412 \u044d\u0442\u043e\u043c \u043f\u0440\u043e\u0435\u043a\u0442\u0435 \u0431\u0443\u0434\u0435\u043c \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c <code>Maven<\/code> \u0438 <code>avrohugger-maven-plugin<\/code>. \u041f\u043b\u0430\u0433\u0438\u043d \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442 \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0443 <a href=\"https:\/\/github.com\/julianpeeters\/avrohugger\">AvroHugger<\/a> \u0434\u043b\u044f \u0433\u0435\u043d\u0435\u0440\u0430\u0446\u0438\u0438 \u043a\u043b\u0430\u0441\u0441\u043e\u0432 Scala.<\/p>\n<p>\u0412 <code>pom.xml<\/code> \u0434\u043e\u0431\u0430\u0432\u043b\u044f\u0435\u043c \u043f\u043b\u0430\u0433\u0438\u043d: <\/p>\n<pre><code class=\"xml\">&lt;plugin>     &lt;groupId>at.makubi.maven.plugin&lt;\/groupId>     &lt;artifactId>avrohugger-maven-plugin&lt;\/artifactId>     &lt;version>1.6&lt;\/version>     &lt;configuration>         &lt;sourceDirectory>${basedir}\/src\/main\/resources&lt;\/sourceDirectory>         &lt;outputDirectory>${basedir}\/src\/main\/scala&lt;\/outputDirectory>            &lt;sourceGenerationFormat>STANDARD&lt;\/sourceGenerationFormat>   &lt;\/configuration>     &lt;executions>         &lt;execution>             &lt;phase>generate-sources&lt;\/phase>             &lt;goals>                 &lt;goal>generate-scala-sources&lt;\/goal>             &lt;\/goals>         &lt;\/execution>     &lt;\/executions> &lt;\/plugin><\/code><\/pre>\n<p>\u0412 \u043a\u043e\u043d\u0444\u0438\u0433\u0443\u0440\u0430\u0446\u0438\u0438 \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e \u0443\u043a\u0430\u0437\u0430\u0442\u044c \u043f\u0443\u0442\u044c \u043a \u0444\u0430\u0439\u043b\u0443 \u0441 \u0441\u0445\u0435\u043c\u043e\u0439 Avro (\u043f\u043e \u0443\u043c\u043e\u043b\u0447\u0430\u043d\u0438\u044e  <code>src\/main\/avro<\/code>), \u0430 \u0442\u0430\u0436\u0435 \u043f\u0443\u0442\u044c \u043a \u0441\u0433\u0435\u043d\u0435\u0440\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u044b\u043c \u043a\u043b\u0430\u0441\u0441\u0430\u043c (\u043f\u043e \u0443\u043c\u043e\u043b\u0447\u0430\u043d\u0438\u044e <code>target\/generated-sources\/avro<\/code>):<\/p>\n<pre><code class=\"xml\">&lt;sourceDirectory>${basedir}\/src\/main\/resources&lt;\/sourceDirectory>     &lt;outputDirectory>${basedir}\/src\/main\/scala&lt;\/outputDirectory>  <\/code><\/pre>\n<p><strong>\u0412\u043d\u0438\u043c\u0430\u043d\u0438\u0435!<\/strong> \u0441\u0433\u0435\u043d\u0435\u0440\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u044b\u0435 \u0444\u0430\u0439\u043b\u044b \u043f\u0435\u0440\u0435\u043f\u0438\u0448\u0443\u0442 \u0443\u0436\u0435 \u0441\u0443\u0449\u0435\u0441\u0442\u0432\u0443\u044e\u0449\u0438\u0435 \u043a\u043b\u0430\u0441\u0441\u044b-\u043e\u0431\u0440\u0430\u0437\u0446\u044b \u0432 \u043f\u0430\u043f\u043a\u0435 <code>src\/main\/scala.<\/code> <\/p>\n<p>\u0422\u0430\u043a\u0436\u0435 \u0443\u043a\u0430\u0437\u044b\u0432\u0430\u0435\u043c \u0442\u0438\u043f \u0437\u0430\u043f\u0438\u0441\u0438 Avro (<code>SpecificRecord<\/code> \u0438\u043b\u0438 <code>GenericRecord<\/code>). <\/p>\n<p>\u041f\u043e \u0443\u043c\u043e\u043b\u0447\u0430\u043d\u0438\u044e \u043f\u043b\u0430\u0433\u0438\u043d \u0433\u0435\u043d\u0435\u0440\u0438\u0440\u0443\u0435\u0442 \u0441\u043f\u0435\u0446\u0438\u0444\u0438\u0447\u0435\u0441\u043a\u0438\u0439 \u0442\u0438\u043f \u0437\u0430\u043f\u0438\u0441\u0438 (<code>SpecificRecord<\/code>). \u0412 \u044d\u0442\u043e\u043c \u0441\u043b\u0443\u0447\u0430\u0435 \u0432\u0441\u0435 \u043a\u043b\u0430\u0441\u0441\u044b-\u043e\u0431\u0440\u0430\u0437\u0446\u044b \u0431\u0443\u0434\u0443\u0442 \u043d\u0430\u0441\u043b\u0435\u0434\u043e\u0432\u0430\u0442\u044c \u0430\u0431\u0441\u0442\u0440\u0430\u043a\u0442\u043d\u044b\u0439 \u043a\u043b\u0430\u0441\u0441 <code>org.apache.avro.specific.SpecificRecordBase<\/code>. \u041f\u043e\u043c\u0438\u043c\u043e \u0441\u0430\u043c\u043e\u0433\u043e \u043a\u043b\u0430\u0441\u0441\u0430-\u043e\u0431\u0440\u0430\u0437\u0446\u0430 \u0438 \u0430\u0440\u0433\u0443\u043c\u0435\u043d\u0442\u043e\u0432 \u0441\u043e\u0437\u0434\u0430\u0434\u0443\u0442\u0441\u044f \u043c\u0435\u0442\u043e\u0434\u044b \u0447\u0442\u0435\u043d\u0438\u044f \u0438 \u0437\u0430\u043f\u0438\u0441\u0438 \u043d\u043e\u0432\u044b\u0445 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0439 \u0430\u0442\u0440\u0438\u0431\u0443\u0442\u043e\u0432. \u0420\u0435\u043a\u043e\u043c\u0435\u043d\u0434\u0443\u0435\u0442\u0441\u044f \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u044d\u0442\u043e\u0442 \u0442\u0438\u043f \u0437\u0430\u043f\u0438\u0441\u0438, \u0435\u0441\u043b\u0438 \u043f\u043b\u0430\u043d\u0438\u0440\u0443\u0435\u0442\u0441\u044f \u043e\u0431\u0440\u0430\u0431\u0430\u0442\u044b\u0432\u0430\u0442\u044c \u0434\u0430\u043d\u043d\u044b\u0435 \u0441\u043f\u0435\u0446\u0438\u0444\u0438\u0447\u043d\u044b\u043c\u0438 Avro-\u0444\u0443\u043d\u043a\u0446\u0438\u044f\u043c\u0438, \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044e\u0449\u0438\u043c\u0438 <code>Avro Specific API<\/code>. <\/p>\n<p>\u0412 \u043d\u0430\u0448\u0435\u043c \u0441\u043b\u0443\u0447\u0430\u0435 \u043c\u044b \u0441\u0430\u043c\u0438 \u0431\u0443\u0434\u0435\u043c \u043f\u0438\u0441\u0430\u0442\u044c \u0444\u0443\u043d\u043a\u0446\u0438\u044e \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u043a\u0438, \u043f\u043e\u044d\u0442\u043e\u043c\u0443 \u043f\u043e\u0434\u043e\u0439\u0434\u0435\u0442 <code>GenericRecord<\/code>:<\/p>\n<pre><code class=\"xml\">&lt;sourceGenerationFormat>STANDARD&lt;\/sourceGenerationFormat><\/code><\/pre>\n<p>\u042d\u0442\u043e\u0442 \u0442\u0438\u043f \u0437\u0430\u043f\u0438\u0441\u0438 \u0433\u0435\u043d\u0435\u0440\u0438\u0440\u0443\u0435\u0442 \u043e\u0431\u044b\u0447\u043d\u044b\u0435 \u043a\u043b\u0430\u0441\u0441\u044b-\u043e\u0431\u0440\u0430\u0437\u0446\u044b, \u0431\u0435\u0437 \u0434\u043e\u043f\u043e\u043b\u043d\u0438\u0442\u0435\u043b\u044c\u043d\u044b\u0445 \u043c\u0435\u0442\u043e\u0434\u043e\u0432 \u0438 \u0430\u0431\u0441\u0442\u0440\u0430\u043a\u0446\u0438\u0439. <\/p>\n<p>\u0412\u044b\u043f\u043e\u043b\u043d\u044f\u0435\u043c \u043a\u043e\u043c\u0430\u043d\u0434\u0443 <code>Maven<\/code>:<\/p>\n<pre><code class=\"bash\">mvn avrohugger:generate-scala-sources<\/code><\/pre>\n<p>\u0412 \u043f\u0430\u043f\u043a\u0435 <code>src\/main\/scala <\/code>\u043f\u043e\u044f\u0432\u044f\u0442\u0441\u044f \u043f\u044f\u0442\u044c \u0441\u0433\u0435\u043d\u0435\u0440\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u044b\u0445 \u043a\u043b\u0430\u0441\u0441\u043e\u0432-\u043e\u0431\u0440\u0430\u0437\u0446\u043e\u0432, \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0443\u044e\u0449\u0438\u0445 \u043f\u044f\u0442\u0438 \u043e\u0431\u044a\u0435\u043a\u0442\u0430\u043c \u0434\u0430\u043d\u043d\u044b\u0445.<\/p>\n<figure class=\"float bordered full-width\"><figcaption>\u0421\u0433\u0435\u043d\u0435\u0440\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u044b\u0435 \u043a\u043b\u0430\u0441\u0441\u044b-\u043e\u0431\u0440\u0430\u0437\u0446\u044b<\/figcaption><\/figure>\n<p>\u041a\u043b\u0430\u0441\u0441\u044b \u043f\u0440\u0438\u043d\u0430\u0434\u043b\u0435\u0436\u0430\u0442 \u043f\u0430\u043a\u0435\u0442\u0443 <code>com.github.aleksandrachasch.avro<\/code>, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0443\u043a\u0430\u0437\u0430\u043d \u0432 \u043f\u043e\u043b\u0435 <code>namespace<\/code> \u0432 \u0441\u0445\u0435\u043c\u0435 Avro.<\/p>\n<p>\u0412\u043e\u0442 \u043a\u0430\u043a \u0432\u044b\u0433\u043b\u044f\u0434\u0438\u0442, \u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u043a\u043b\u0430\u0441\u0441 <code>Customer<\/code>:<\/p>\n<pre><code class=\"scala\">\/** MACHINE-GENERATED FROM AVRO SCHEMA. DO NOT EDIT DIRECTLY *\/ package com.github.aleksandrachasch.avro  case class Customer(Id: String, Name: String, Surname: String, Accounts: Seq[Account])<\/code><\/pre>\n<h3>\u0427\u0442\u0435\u043d\u0438\u0435 Avro \u0432 Spark Dataset<\/h3>\n<p>\u0422\u0435\u043f\u0435\u0440\u044c \u0441\u043e\u0437\u0434\u0430\u0434\u0438\u043c \u0434\u0430\u0442\u0430\u0441\u0435\u0442 Spark, \u0442\u0438\u043f\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u044b\u0439 \u0441\u0433\u0435\u043d\u0435\u0440\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u044b\u043c \u043a\u043b\u0430\u0441\u0441\u043e\u043c <code>Customer<\/code>. <\/p>\n<p>\u0412 \u043a\u0430\u0447\u0435\u0441\u0442\u0432\u0435 \u043f\u0440\u0438\u043c\u0435\u0440\u0430 \u0441\u043e\u0437\u0434\u0430\u0434\u0438\u043c \u043a\u043b\u0438\u0435\u043d\u0442\u0430 \u0441 \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u0438\u043c\u0438 \u0430\u043a\u043a\u0430\u043d\u0443\u0442\u0430\u043c\u0438 \u0438 \u0432\u0437\u0430\u0438\u043c\u043e\u0434\u0435\u0439\u0441\u0442\u0432\u0438\u044f\u043c\u0438:<\/p>\n<pre><code class=\"json\">{   \"Id\": \"1\",   \"Name\": \"John\",   \"Surname\": \"Doe\",   \"Accounts\": [     {       \"AccountId\": 111,       \"AccountType\": \"private\",       \"InteractionGroups\": [         {           \"Id\": 222,           \"date\": \"20220102\",           \"interactions\": [             {               \"Id\": \"1\",               \"type\": \"WEBSITE\"             },             {               \"Id\": \"2\",               \"type\": \"INSTAGRAM\"             }           ]         },         {           \"Id\": 223,           \"date\": \"20220103\",           \"interactions\": [             {               \"Id\": \"4\",               \"type\": \"TWITTER\"             }           ]         }       ]     },     {       \"AccountId\": 112,       \"AccountType\": \"public\",       \"InteractionGroups\": [         {           \"Id\": 333,           \"date\": \"20220105\",           \"interactions\": [             {               \"Id\": \"6\",               \"type\": \"TWITTER\"             },             {               \"Id\": \"7\",               \"type\": \"INSTAGRAM\"             }           ]         }       ]     }   ] }<\/code><\/pre>\n<p><code>Avro<\/code> &#8212; \u044d\u0442\u043e \u0431\u0438\u043d\u0430\u0440\u043d\u044b\u0439 \u0444\u043e\u0440\u043c\u0430\u0442 \u0434\u0430\u043d\u043d\u044b\u0445. \u0418\u043c\u0435\u043d\u043d\u043e \u0442\u0430\u043a \u0431\u0443\u0434\u0435\u0442 \u0432\u044b\u0433\u043b\u044f\u0434\u0435\u0442\u044c \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u0435, \u0435\u0441\u043b\u0438 \u0435\u0433\u043e \u0434\u0435\u0441\u0435\u0440\u0435\u0430\u043b\u0438\u0437\u043e\u0432\u0430\u0442\u044c, \u043f\u0440\u0438\u043c\u0435\u043d\u0438\u0432 \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0443\u044e\u0449\u0443\u044e c\u0445\u0435\u043c\u0443. <\/p>\n<p>\u0421\u043e\u0437\u0434\u0430\u0434\u0438\u043c \u0434\u0430\u0442\u0430\u0441\u0435\u0442:<\/p>\n<pre><code class=\"scala\">import org.apache.spark.sql.catalyst.ScalaReflection import org.apache.spark.sql.types.StructType  import com.github.aleksandrachasch.avro.Customer  import spark.implicits._  val ds = spark.read.format(\"json\") .schema(ScalaReflection.schemaFor[Customer].dataType.asInstanceOf[StructType]) .option(\"mode\", \"FAILFAST\") .option(\"multiline\", true) .load(\"src\/main\/resources\/customer-data.json\") .as[Customer]<\/code><\/pre>\n<p>\u0422\u0438\u043f\u043e\u043c \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u043e\u0439 <code>ds<\/code> \u0431\u0443\u0434\u0435\u0442 <code>Dataset[Customer]<\/code>.<\/p>\n<p>\u0415\u0441\u043b\u0438 \u0432\u0445\u043e\u0434\u043d\u044b\u0435 \u0434\u0430\u043d\u043d\u044b\u0435 \u043d\u0435 \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0443\u044e\u0442 \u043a\u043b\u0430\u0441\u0441\u0430\u043c-\u043e\u0431\u0440\u0430\u0437\u0446\u0430\u043c, \u0442\u043e \u043f\u043e\u044f\u0432\u0438\u0442\u0441\u044f \u043e\u0448\u0438\u0431\u043a\u0430 \u0432\u043e \u0432\u0440\u0435\u043c\u044f \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u044f (runtime). \u041d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u0435\u0441\u043b\u0438 \u0432\u0432\u0435\u0441\u0442\u0438 \u043d\u0435c\u0443\u0449\u0435\u0441\u0442\u0432\u0443\u044e\u0449\u0438\u0439 \u0442\u0438\u043f \u0432\u0437\u0430\u0438\u043c\u043e\u0434\u0435\u0439\u0441\u0442\u0432\u0438\u044f <code>InteractionType<\/code> :<\/p>\n<pre><code class=\"json\">\"interactions\": [   {     \"Id\": \"6\",     \"type\": \"TWITTER\"   },   {     \"Id\": \"7\",     \"type\": \"VK\"   } ]<\/code><\/pre>\n<pre><code class=\"java\">Caused by: java.util.NoSuchElementException: No value found for 'VK' at scala.Enumeration.withName$2(Enumeration.scala:125) at scala.Enumeration.withName(Enumeration.scala:125) at<\/code><\/pre>\n<\/div>\n<\/div>\n<\/div>\n<\/div>\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-329203","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/329203","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=329203"}],"version-history":[{"count":0,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/329203\/revisions"}],"wp:attachment":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=329203"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=329203"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=329203"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}