久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

<tfoot id='OxeNC'></tfoot>

        • <bdo id='OxeNC'></bdo><ul id='OxeNC'></ul>

      1. <legend id='OxeNC'><style id='OxeNC'><dir id='OxeNC'><q id='OxeNC'></q></dir></style></legend>
        <i id='OxeNC'><tr id='OxeNC'><dt id='OxeNC'><q id='OxeNC'><span id='OxeNC'><b id='OxeNC'><form id='OxeNC'><ins id='OxeNC'></ins><ul id='OxeNC'></ul><sub id='OxeNC'></sub></form><legend id='OxeNC'></legend><bdo id='OxeNC'><pre id='OxeNC'><center id='OxeNC'></center></pre></bdo></b><th id='OxeNC'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='OxeNC'><tfoot id='OxeNC'></tfoot><dl id='OxeNC'><fieldset id='OxeNC'></fieldset></dl></div>

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

        在 Apache Spark 中連接到 SQLite

        Connect to SQLite in Apache Spark(在 Apache Spark 中連接到 SQLite)
          <bdo id='VKQ14'></bdo><ul id='VKQ14'></ul>
          • <legend id='VKQ14'><style id='VKQ14'><dir id='VKQ14'><q id='VKQ14'></q></dir></style></legend>

              <tfoot id='VKQ14'></tfoot>
            1. <i id='VKQ14'><tr id='VKQ14'><dt id='VKQ14'><q id='VKQ14'><span id='VKQ14'><b id='VKQ14'><form id='VKQ14'><ins id='VKQ14'></ins><ul id='VKQ14'></ul><sub id='VKQ14'></sub></form><legend id='VKQ14'></legend><bdo id='VKQ14'><pre id='VKQ14'><center id='VKQ14'></center></pre></bdo></b><th id='VKQ14'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='VKQ14'><tfoot id='VKQ14'></tfoot><dl id='VKQ14'><fieldset id='VKQ14'></fieldset></dl></div>

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

                    <tbody id='VKQ14'></tbody>
                  本文介紹了在 Apache Spark 中連接到 SQLite的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

                  問題描述

                  我想對 SQLite 數據庫中的所有表運行自定義函數.該功能或多或少相同,但取決于單個表的架構.此外,表及其模式僅在運行時才知道(調用程序時使用指定數據庫路徑的參數).

                  I want to run a custom function on all tables in a SQLite database. The function is more or less the same, but depends on the schema of the individual table. Also, the tables and their schemata are only known at runtime (the program is called with an argument that specifies the path of the database).

                  這是我目前所擁有的:

                  val conf = new SparkConf().setAppName("MyApp")
                  val sc = new SparkContext(conf)
                  val sqlContext = new org.apache.spark.sql.SQLContext(sc)
                  
                  // somehow bind sqlContext to DB
                  
                  val allTables = sqlContext.tableNames
                  
                  for( t <- allTables) {
                      val df = sqlContext.table(t)
                      val schema = df.columns
                      sqlContext.sql("SELECT * FROM " + t + "...").map(x => myFunc(x,schema))
                  }
                  

                  我目前發現的唯一提示需要提前知道表格,在我的場景中不是這樣的:

                  The only hint I found so far needs to know the table in advance, which is not the case in my scenario:

                  val tableData = 
                    sqlContext.read.format("jdbc")
                      .options(Map("url" -> "jdbc:sqlite:/path/to/file.db", "dbtable" -> t))
                      .load()
                  

                  我使用的是 xerial sqlite jdbc 驅動程序.那么我怎樣才能只連接到一個數據庫,而不是一個表呢?

                  I am using the xerial sqlite jdbc driver. So how can I conntect solely to a database, not to a table?

                  使用 Beryllium 的答案作為開始,我將代碼更新為:

                  Using Beryllium's answer as a start I updated my code to this:

                  val sqlContext = new org.apache.spark.sql.SQLContext(sc)
                  
                  val metaData = sqlContext.read.format("jdbc")
                      .options(Map("url" -> "jdbc:sqlite:/path/to/file.db",
                                   "dbtable" -> "(SELECT * FROM sqlite_master) AS t")).load()
                  
                  val myTableNames = metaData.select("tbl_name").distinct()
                  
                  for (t <- myTableNames) {
                      println(t.toString)
                  
                      val tableData = sqlContext.table(t.toString)
                  
                      for (record <- tableData.select("*")) {
                          println(record)
                      }
                  }
                  

                  至少我可以在運行時讀取表名,這對我來說是一個巨大的進步.但是我看不懂表格.我兩個都試了

                  At least I can read the table names at runtime which is a huge step forward for me. But I can't read the tables. I tried both

                  val tableData = sqlContext.table(t.toString)
                  

                  val tableData = sqlContext.read.format("jdbc")
                      .options(Map("url" -> "jdbc:sqlite:/path/to/file.db",
                                   "dbtable" -> t.toString)).load()
                  

                  在循環中,但在這兩種情況下,我都會收到 NullPointerException.雖然我可以打印表名,但似乎我無法連接到它們.

                  in the loop, but in both cases I get a NullPointerException. Although I can print the table names it seems I cannot connect to them.

                  最后但并非最不重要的一點是,我總是收到 SQLITE_ERROR: Connection is closed 錯誤.它看起來與此問題中描述的問題相同:SQLITE_ERROR: 當通過 JDBC 從 Spark 連接到 SQLite 數據庫時,連接被關閉

                  Last but not least I always get an SQLITE_ERROR: Connection is closed error. It looks to be the same issue described in this question: SQLITE_ERROR: Connection is closed when connecting from Spark via JDBC to SQLite database

                  推薦答案

                  您可以嘗試兩種選擇

                  • 在您的 Spark 作業中打開一個單獨的普通 JDBC 連接
                  • 從 JDBC 元數據中獲取表名
                  • 將這些融入您的 for 理解

                  您可以將查詢指定為 dbtable 參數的值.在語法上,這個查詢必須看起來"像一個表,所以它必須包含在一個子查詢中.

                  You can specify a query as the value for the dbtable argument. Syntactically this query must "look" like a table, so it must be wrapped in a sub query.

                  在該查詢中,從數據庫中獲取元數據:

                  In that query, get the meta data from the database:

                  val df = sqlContext.read.format("jdbc").options(
                    Map(
                      "url" -> "jdbc:postgresql:xxx",
                      "user" -> "x",
                      "password" -> "x",
                      "dbtable" -> "(select * from pg_tables) as t")).load()
                  

                  此示例適用于 PostgreSQL,您必須將其調整為適用于 SQLite.

                  This example works with PostgreSQL, you have to adapt it for SQLite.

                  更新

                  似乎JDBC驅動程序只支持迭代一個結果集.無論如何,當您使用 collect() 來具體化表名列表時,以下代碼段應該可以工作:

                  It seems that the JDBC driver only supports to iterate over one result set. Anyway, when you materialize the list of table names using collect(), then the following snippet should work:

                  val myTableNames = metaData.select("tbl_name").map(_.getString(0)).collect()
                  
                  for (t <- myTableNames) {
                    println(t.toString)
                  
                    val tableData = sqlContext.read.format("jdbc")
                      .options(
                        Map(
                          "url" -> "jdbc:sqlite:/x.db",
                          "dbtable" -> t)).load()
                  
                    tableData.show()
                  }
                  

                  這篇關于在 Apache Spark 中連接到 SQLite的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!

                  【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!

                  相關文檔推薦

                  How to use windowing functions efficiently to decide next N number of rows based on N number of previous values(如何有效地使用窗口函數根據 N 個先前值來決定接下來的 N 個行)
                  reuse the result of a select expression in the quot;GROUP BYquot; clause?(在“GROUP BY中重用選擇表達式的結果;條款?)
                  Does ignore option of Pyspark DataFrameWriter jdbc function ignore entire transaction or just offending rows?(Pyspark DataFrameWriter jdbc 函數的 ignore 選項是忽略整個事務還是只是有問題的行?) - IT屋-程序員軟件開發技
                  How to integrate Apache Spark with MySQL for reading database tables as a spark dataframe?(如何將 Apache Spark 與 MySQL 集成以將數據庫表作為 Spark 數據幀讀取?)
                  In Apache Spark 2.0.0, is it possible to fetch a query from an external database (rather than grab the whole table)?(在 Apache Spark 2.0.0 中,是否可以從外部數據庫獲取查詢(而不是獲取整個表)?) - IT屋-程序員軟件開
                  Dropping MySQL table with SparkSQL(使用 SparkSQL 刪除 MySQL 表)
                  <legend id='Diorr'><style id='Diorr'><dir id='Diorr'><q id='Diorr'></q></dir></style></legend>

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

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

                          <tfoot id='Diorr'></tfoot>
                            <tbody id='Diorr'></tbody>

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

                            主站蜘蛛池模板: 天天夜夜操 | 午夜视频导航 | 日本色高清 | 盗摄精品av一区二区三区 | 久久久免费观看视频 | 午夜在线视频 | jlzzjlzz欧美大全 | 91麻豆精品国产91久久久久久久久 | 欧美成人精品一区二区男人看 | 91视频在线观看免费 | 久久精品视频在线观看 | 色网站入口 | 欧美日本一区二区 | 免费黄色的视频 | 国产一区二区小视频 | 久久福利 | 国产激情视频在线 | 亚洲在线免费观看 | 国产美女黄色 | 国产一区二区三区在线 | 高清久久 | 在线观看毛片网站 | 欧美精品一 | 精品国产免费一区二区三区演员表 | 91精品国产乱码久久蜜臀 | 欧美精品三区 | 欧美精品一区二区在线观看 | 激情五月婷婷在线 | 在线视频国产一区 | 亚洲精品电影网在线观看 | 一区二区视屏 | 亚洲成人久久久 | 久久精品成人 | dy天堂| 日韩精品一区二区三区中文字幕 | 亚洲成人免费在线观看 | 四色成人av永久网址 | 99精品一区二区 | 亚洲一区二区三区免费观看 | 欧美视频1区| 亚洲天堂成人在线视频 |