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'>

                            主站蜘蛛池模板: 智能楼宇-楼宇自控系统-楼宇智能化-楼宇自动化-三水智能化 | 浙江华锤电器有限公司_地磅称重设备_防作弊地磅_浙江地磅售后维修_无人值守扫码过磅系统_浙江源头地磅厂家_浙江工厂直营地磅 | 煤矿人员精确定位系统_矿用无线通信系统_煤矿广播系统 | 德国BOSCH电磁阀-德国HERION电磁阀-JOUCOMATIC电磁阀|乾拓百科 | 体坛网_体坛+_体坛周报新闻客户端 | 全自动过滤器_反冲洗过滤器_自清洗过滤器_量子除垢环_量子环除垢_量子除垢 - 安士睿(北京)过滤设备有限公司 | 真空冷冻干燥机_国产冻干机_冷冻干燥机_北京四环冻干 | loft装修,上海嘉定酒店式公寓装修公司—曼城装饰 | 合肥白癜风医院_合肥治疗白癜风医院_合肥看白癜风医院哪家好_合肥华研白癜风医院 | 识禅_对禅的了解,从这里开始 | H型钢切割机,相贯线切割机,数控钻床,数控平面钻,钢结构设备,槽钢切割机,角钢切割机,翻转机,拼焊矫一体机 | POS机办理_个人pos机免费领取-银联pos机申请首页 | T恤衫定做,企业文化衫制作订做,广告T恤POLO衫定制厂家[源头工厂]-【汉诚T恤定制网】 | 生产自动包装秤_颗粒包装秤_肥料包装秤等包装机械-郑州鑫晟重工科技有限公司 | China plate rolling machine manufacturer,cone rolling machine-Saint Fighter | 农业仪器网 - 中国自动化农业仪器信息交流平台 | 滁州高低温冲击试验箱厂家_安徽高低温试验箱价格|安徽希尔伯特 | 考勤系统_考勤管理系统_网络考勤软件_政企|集团|工厂复杂考勤工时统计排班管理系统_天时考勤 | 振动筛,震动筛,圆形振动筛,振动筛价格,振动筛厂家-新乡巨宝机电 蒸汽热收缩机_蒸汽发生器_塑封机_包膜机_封切收缩机_热收缩包装机_真空机_全自动打包机_捆扎机_封箱机-东莞市中堡智能科技有限公司 | 国产频谱分析仪-国产网络分析仪-上海坚融实业有限公司 | 附着力促进剂-尼龙处理剂-PP处理剂-金属附着力处理剂-东莞市炅盛塑胶科技有限公司 | 精密五金冲压件_深圳五金冲压厂_钣金加工厂_五金模具加工-诚瑞丰科技股份有限公司 | 气象监测系统_气象传感器_微型气象仪_气象环境监测仪-山东风途物联网 | 浙江华锤电器有限公司_地磅称重设备_防作弊地磅_浙江地磅售后维修_无人值守扫码过磅系统_浙江源头地磅厂家_浙江工厂直营地磅 | 托盘租赁_塑料托盘租赁_托盘出租_栈板出租_青岛托盘租赁-优胜必达 | 周口风机|周风风机|河南省周口通用风机厂 | 厦门ISO认证|厦门ISO9001认证|厦门ISO14001认证|厦门ISO45001认证-艾索咨询专注ISO认证行业 | 地磅-电子地磅维修-电子吊秤-汽车衡-无人值守系统-公路治超-鹰牌衡器 | hc22_hc22价格_hc22哈氏合金—东锜特殊钢| 单电机制砂机,BHS制砂机,制沙机设备,制砂机价格-正升制砂机厂家 单级/双级旋片式真空泵厂家,2xz旋片真空泵-浙江台州求精真空泵有限公司 | 全自动不干胶贴标机_套标机-上海今昂贴标机生产厂家 | 酵素生产厂家_酵素OEM_酵素加盟_酵素ODM_酵素原料厂家_厦门益力康 | 一体化预制泵站-一体化提升泵站-一体化泵站厂家-山东康威环保 | 振动筛-交叉筛-螺旋筛-滚轴筛-正弦筛-方形摇摆筛「新乡振动筛厂家」 | 液压油缸生产厂家-山东液压站-济南捷兴液压机电设备有限公司 | 二次元影像仪|二次元测量仪|拉力机|全自动影像测量仪厂家_苏州牧象仪器 | 天津试验仪器-电液伺服万能材料试验机,恒温恒湿标准养护箱,水泥恒应力压力试验机-天津鑫高伟业科技有限公司 | 铝合金电阻-无源谐波滤波器-上海稳达电讯设备厂 | 紧急切断阀_气动切断阀_不锈钢阀门_截止阀_球阀_蝶阀_闸阀-上海上兆阀门制造有限公司 | 红立方品牌应急包/急救包加盟,小成本好项目代理_应急/消防/户外用品加盟_应急好项目加盟_新奇特项目招商 - 中红方宁(北京) 供应链有限公司 | 高通量组织研磨仪-多样品组织研磨仪-全自动组织研磨仪-研磨者科技(广州)有限公司 |