<bdo id='j3z6h'></bdo><ul id='j3z6h'></ul>

  • <legend id='j3z6h'><style id='j3z6h'><dir id='j3z6h'><q id='j3z6h'></q></dir></style></legend>
  • <small id='j3z6h'></small><noframes id='j3z6h'>

    <tfoot id='j3z6h'></tfoot>
  • <i id='j3z6h'><tr id='j3z6h'><dt id='j3z6h'><q id='j3z6h'><span id='j3z6h'><b id='j3z6h'><form id='j3z6h'><ins id='j3z6h'></ins><ul id='j3z6h'></ul><sub id='j3z6h'></sub></form><legend id='j3z6h'></legend><bdo id='j3z6h'><pre id='j3z6h'><center id='j3z6h'></center></pre></bdo></b><th id='j3z6h'></th></span></q></dt></tr></i><div id='j3z6h'><tfoot id='j3z6h'></tfoot><dl id='j3z6h'><fieldset id='j3z6h'></fieldset></dl></div>

        spark从mysql并行读取数据

        时间:2023-08-22

        <small id='tJMOL'></small><noframes id='tJMOL'>

        • <tfoot id='tJMOL'></tfoot>
            <bdo id='tJMOL'></bdo><ul id='tJMOL'></ul>

                  <tbody id='tJMOL'></tbody>
              • <legend id='tJMOL'><style id='tJMOL'><dir id='tJMOL'><q id='tJMOL'></q></dir></style></legend>
                  <i id='tJMOL'><tr id='tJMOL'><dt id='tJMOL'><q id='tJMOL'><span id='tJMOL'><b id='tJMOL'><form id='tJMOL'><ins id='tJMOL'></ins><ul id='tJMOL'></ul><sub id='tJMOL'></sub></form><legend id='tJMOL'></legend><bdo id='tJMOL'><pre id='tJMOL'><center id='tJMOL'></center></pre></bdo></b><th id='tJMOL'></th></span></q></dt></tr></i><div id='tJMOL'><tfoot id='tJMOL'></tfoot><dl id='tJMOL'><fieldset id='tJMOL'></fieldset></dl></div>
                  本文介绍了spark从mysql并行读取数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                  问题描述

                  我正在尝试从 mysql 读取数据并将其写回 s3 中具有特定分区的 parquet 文件,如下所示:

                  Im trying to read data from mysql and write it back to parquet file in s3 with specific partitions as follows:

                  df=sqlContext.read.format('jdbc')\
                     .options(driver='com.mysql.jdbc.Driver',url="""jdbc:mysql://<host>:3306/<>db?user=<usr>&password=<pass>""",
                           dbtable='tbl',
                           numPartitions=4 )\
                     .load()
                  
                  
                  df2=df.withColumn('updated_date',to_date(df.updated_at))
                  df2.write.parquet(path='s3n://parquet_location',mode='append',partitionBy=['updated_date'])
                  

                  我的问题是它只打开一个到 mysql 的连接(而不是 4 个),并且在它从 mysql 获取所有数据之前它不会写入 parquert,因为我在 mysql 中的表很大(100M 行)进程失败内存不足.

                  My problem is that it open only one connection to mysql (instead of 4) and it doesn't write to parquert until it fetches all the data from mysql, because my table in mysql is huge (100M rows) the process failed on OutOfMemory.

                  有没有办法配置Spark打开多个mysql连接并将部分数据写入parquet?

                  Is there a way to configure Spark to open more than one connection to mysql and to write partial data to parquet?

                  推荐答案

                  你应该设置这些属性:

                  partitionColumn, 
                  lowerBound, 
                  upperBound, 
                  numPartitions
                  

                  正如这里记录的那样:http://spark.apache.org/docs/latest/sql-programming-guide.html#jdbc-to-other-databases

                  这篇关于spark从mysql并行读取数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                  上一篇:使用 INSERT INTO table ON DUPLICATE KEY 时出错,使用 下一篇:如何在 jdbc 数据源中使用 dbtable 选项的子查询?

                  相关文章

                  最新文章

                      <legend id='ULyWG'><style id='ULyWG'><dir id='ULyWG'><q id='ULyWG'></q></dir></style></legend>

                    1. <small id='ULyWG'></small><noframes id='ULyWG'>

                      <tfoot id='ULyWG'></tfoot>

                        <bdo id='ULyWG'></bdo><ul id='ULyWG'></ul>

                      <i id='ULyWG'><tr id='ULyWG'><dt id='ULyWG'><q id='ULyWG'><span id='ULyWG'><b id='ULyWG'><form id='ULyWG'><ins id='ULyWG'></ins><ul id='ULyWG'></ul><sub id='ULyWG'></sub></form><legend id='ULyWG'></legend><bdo id='ULyWG'><pre id='ULyWG'><center id='ULyWG'></center></pre></bdo></b><th id='ULyWG'></th></span></q></dt></tr></i><div id='ULyWG'><tfoot id='ULyWG'></tfoot><dl id='ULyWG'><fieldset id='ULyWG'></fieldset></dl></div>