pbootcms网站模板|日韩1区2区|织梦模板||网站源码|日韩1区2区|jquery建站特效-html5模板网

<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="s2o0eum" 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="yu2q2gy" 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))
                  }
                  

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

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

                  在循環(huán)中,但在這兩種情況下,我都會收到 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 作業(yè)中打開一個單獨的普通 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屋-程序員軟件開發(fā)技
                  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="cieousu" 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'>

                            主站蜘蛛池模板: 黑龙江「京科脑康」医院-哈尔滨失眠医院_哈尔滨治疗抑郁症医院_哈尔滨精神心理医院 | 大米加工设备|大米加工机械|碾米成套设备|大米加工成套设备-河南成立粮油机械有限公司 | 深圳律师咨询_深圳律师事务所_华荣【免费在线法律咨询】网 | 特材真空腔体_哈氏合金/镍基合金/纯镍腔体-无锡国德机械制造有限公司 | 缓蚀除垢剂_循环水阻垢剂_反渗透锅炉阻垢剂_有机硫化物-郑州威大水处理材料有限公司 | 氧化铁红厂家-淄博宗昂化工 | 不锈钢拉手厂家|浴室门拉手厂家|江门市蓬江区金志翔五金制品有限公司 | 地脚螺栓_材质_标准-永年县德联地脚螺栓厂家 | 纯水设备_苏州皙全超纯水设备水处理设备生产厂家 | 无锡市珂妮日用化妆品有限公司|珂妮日化官网|洗手液厂家 | 数码听觉统合训练系统-儿童感觉-早期言语评估与训练系统-北京鑫泰盛世科技发展有限公司 | 奥运星-汽车性能网评-提供个性化汽车资讯 | 宜兴市恺瑞德环保科技有限公司 | 今日扫码_溯源二维码_产品防伪一物一码_红包墙营销方案 | QQ房产导航-免费收录优秀房地产网站_房地产信息网 | 氧氮氢联合测定仪-联测仪-氧氮氢元素分析仪-江苏品彦光电 | 发电机价格|发电机组价格|柴油发电机价格|柴油发电机组价格网 | 网站建设_网站制作_SEO优化推广_百度推广开户_朋友圈网络科技 | 环保袋,无纺布袋,无纺布打孔袋,保温袋,环保袋定制,环保袋厂家,环雅包装-十七年环保袋定制厂家 | 干粉砂浆设备_干混砂浆生产线_腻子粉加工设备_石膏抹灰砂浆生产成套设备厂家_干粉混合设备_砂子烘干机--郑州铭将机械设备有限公司 | 哈希余氯测定仪,分光光度计,ph在线监测仪,浊度测定仪,试剂-上海京灿精密机械有限公司 | 避光流动池-带盖荧光比色皿-生化流动比色皿-宜兴市晶科光学仪器 东莞爱加真空科技有限公司-进口真空镀膜机|真空镀膜设备|Polycold维修厂家 | 厂房出租-厂房规划-食品技术-厂房设计-厂房装修-建筑施工-设备供应-设备求购-龙爪豆食品行业平台 | 合肥注册公司|合肥代办营业执照、2024注册公司流程 | 水上浮桥-游艇码头-浮动码头-游船码头-码瑞纳游艇码头工程 | 蓝米云-专注于高性价比香港/美国VPS云服务器及海外公益型免费虚拟主机 | 硬齿面减速机[型号全],ZQ减速机-淄博久增机械 | 物流之家新闻网-最新物流新闻|物流资讯|物流政策|物流网-匡匡奈斯物流科技 | 24位ADC|8位MCU-芯易德科技有限公司| 专业生物有机肥造粒机,粉状有机肥生产线,槽式翻堆机厂家-郑州华之强重工科技有限公司 | 新能源汽车电池软连接,铜铝复合膜柔性连接,电力母排-容发智能科技(无锡)有限公司 | 垃圾处理设备_餐厨垃圾处理设备_厨余垃圾处理设备_果蔬垃圾处理设备-深圳市三盛环保科技有限公司 | 雷冲击高压发生器-水内冷直流高压发生器-串联谐振分压器-武汉特高压电力科技有限公司 | 布袋除尘器-单机除尘器-脉冲除尘器-泊头市兴天环保设备有限公司 布袋除尘器|除尘器设备|除尘布袋|除尘设备_诺和环保设备 | 视觉检测设备_自动化检测设备_CCD视觉检测机_外观缺陷检测-瑞智光电 | 翻斗式矿车|固定式矿车|曲轨侧卸式矿车|梭式矿车|矿车配件-山东卓力矿车生产厂家 | 蒸汽吸附分析仪-进口水分活度仪|康宝百科 | 施工围挡-施工PVC围挡-工程围挡-深圳市旭东钢构技术开发有限公司 | 铣床|万能铣床|立式铣床|数控铣床|山东滕州万友机床有限公司 | 点焊机-缝焊机-闪光对焊机-电阻焊设备生产厂家-上海骏腾发智能设备有限公司 | 管形母线,全绝缘铜管母线厂家-山东佰特电气科技有限公司 |