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

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

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

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

        一種從Mysql讀取表數據到Pig的方法

        A way to read table data from Mysql to Pig(一種從Mysql讀取表數據到Pig的方法)

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

            • <tfoot id='FtuK0'></tfoot>

                <legend id='FtuK0'><style id='FtuK0'><dir id='FtuK0'><q id='FtuK0'></q></dir></style></legend>
                  <tbody id='FtuK0'></tbody>
                  <bdo id='FtuK0'></bdo><ul id='FtuK0'></ul>
                  本文介紹了一種從Mysql讀取表數據到Pig的方法的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

                  問題描述

                  大家都知道Pig已經支持DBStorage,但它們只支持從 Pig 到 mysql 這樣的加載結果

                  Everyone know that Pig have supported DBStorage, but they are only supported load results from Pig to mysql like that

                  STORE data INTO DBStorage('com.mysql.jdbc.Driver', 'dbc:mysql://host/db', 'INSERT ...');
                  

                  但是請告訴我像那樣從 mysql 讀取表的方法

                  But Please show me the way to read table from mysql like that

                  data = LOAD 'my_table' AS DBStorage('com.mysql.jdbc.Driver', 'dbc:mysql://host/db', 'SELECT * FROM my_table');
                  

                  這是我的代碼

                  public class DBLoader extends LoadFunc {
                      private final Log log = LogFactory.getLog(getClass());
                      private ArrayList mProtoTuple = null;
                      private Connection con;
                      private String jdbcURL;
                      private String user;
                      private String pass;
                      private int batchSize;
                      private int count = 0;
                      private String query;
                      ResultSet result;
                      protected TupleFactory mTupleFactory = TupleFactory.getInstance();
                  
                      public DBLoader() {
                      }
                  
                      public DBLoader(String driver, String jdbcURL, String user, String pass,
                              String query) {
                  
                          try {
                              Class.forName(driver);
                          } catch (ClassNotFoundException e) {
                              log.error("can't load DB driver:" + driver, e);
                              throw new RuntimeException("Can't load DB Driver", e);
                          }
                          this.jdbcURL = jdbcURL;
                          this.user = user;
                          this.pass = pass;
                          this.query = query;
                  
                      }
                  
                      @Override
                      public InputFormat getInputFormat() throws IOException {
                          // TODO Auto-generated method stub
                          return new TextInputFormat();
                      }
                  
                      @Override
                      public Tuple getNext() throws IOException {
                          // TODO Auto-generated method stub
                          boolean next = false;
                  
                          try {
                              next = result.next();
                          } catch (SQLException e) {
                              // TODO Auto-generated catch block
                              e.printStackTrace();
                          }
                  
                          if (!next)
                              return null;
                          int numColumns = 0;
                          // Get result set meta data
                          ResultSetMetaData rsmd;
                          try {
                              rsmd = result.getMetaData();
                              numColumns = rsmd.getColumnCount();
                          } catch (SQLException e) {
                              // TODO Auto-generated catch block
                              e.printStackTrace();
                          }
                  
                          for (int i = 0; i < numColumns; i++) {
                  
                              try {
                                  Object field = result.getObject(i);
                  
                                  switch (DataType.findType(field)) {
                                  case DataType.NULL:
                  
                                      mProtoTuple.add(null);
                  
                                      break;
                  
                                  case DataType.BOOLEAN:
                                      mProtoTuple.add((Boolean) field);
                  
                                      break;
                  
                                  case DataType.INTEGER:
                                      mProtoTuple.add((Integer) field);
                  
                                      break;
                  
                                  case DataType.LONG:
                                      mProtoTuple.add((Long) field);
                  
                                      break;
                  
                                  case DataType.FLOAT:
                                      mProtoTuple.add((Float) field);
                  
                                      break;
                  
                                  case DataType.DOUBLE:
                                      mProtoTuple.add((Double) field);
                  
                                      break;
                  
                                  case DataType.BYTEARRAY:
                                      byte[] b = ((DataByteArray) field).get();
                                      mProtoTuple.add(b);
                  
                                      break;
                                  case DataType.CHARARRAY:
                                      mProtoTuple.add((String) field);
                  
                                      break;
                                  case DataType.BYTE:
                                      mProtoTuple.add((Byte) field);
                  
                                      break;
                  
                                  case DataType.MAP:
                                  case DataType.TUPLE:
                                  case DataType.BAG:
                                      throw new RuntimeException("Cannot store a non-flat tuple "
                                              + "using DbStorage");
                  
                                  default:
                                      throw new RuntimeException("Unknown datatype "
                                              + DataType.findType(field));
                  
                                  }
                  
                              } catch (Exception ee) {
                                  throw new RuntimeException(ee);
                              }
                          }
                  
                          Tuple t = mTupleFactory.newTuple(mProtoTuple);
                          mProtoTuple.clear();
                          return t;
                  
                      }
                  
                      @Override
                      public void prepareToRead(RecordReader arg0, PigSplit arg1)
                              throws IOException {
                  
                          con = null;
                          if (query == null) {
                              throw new IOException("SQL Insert command not specified");
                          }
                          try {
                              if (user == null || pass == null) {
                                  con = DriverManager.getConnection(jdbcURL);
                              } else {
                                  con = DriverManager.getConnection(jdbcURL, user, pass);
                              }
                              con.setAutoCommit(false);
                              result = con.createStatement().executeQuery(query);
                          } catch (SQLException e) {
                              log.error("Unable to connect to JDBC @" + jdbcURL);
                              throw new IOException("JDBC Error", e);
                          }
                          count = 0;
                      }
                  
                      @Override
                      public void setLocation(String location, Job job) throws IOException {
                          // TODO Auto-generated method stub
                  
                          //TextInputFormat.setInputPaths(job, location);
                  
                      }
                  
                      class MyDBInputFormat extends InputFormat<NullWritable, NullWritable>{
                  
                          @Override
                          public RecordReader<NullWritable, NullWritable> createRecordReader(
                                  InputSplit arg0, TaskAttemptContext arg1) throws IOException,
                                  InterruptedException {
                              // TODO Auto-generated method stub
                              return null;
                          }
                  
                          @Override
                          public List<InputSplit> getSplits(JobContext arg0) throws IOException,
                                  InterruptedException {
                              // TODO Auto-generated method stub
                              return null;
                          }
                  
                      }
                  
                  }
                  

                  我嘗試了很多次寫 UDF 但都沒有成功.....

                  I try many times to write UDF but not success.....

                  推薦答案

                  就像你說的,DBStorage 只支持將結果保存到數據庫中.

                  Like you say, DBStorage only supports saving results to a database.

                  要從 MySQL 加載數據,您可以查看名為 sqoop(將數據從數據庫復制到HDFS),或者您可以執行 mysql 轉儲,然后將文件復制到 HDFS.兩種方式都需要一些交互,不能直接從 Pig 內部使用.

                  To load data from MySQL you could look into a project called sqoop (that copies data from a database to HDFS), or you could perform a mysql dump and then copy the file into HDFS. Both ways required some interaction and cannot be directly used from inside Pig.

                  第三種選擇是考慮編寫 Pig LoadFunc(您說您嘗試編寫 UDF).這應該不會太難,您需要傳遞與 DBStorage 相同的選項(驅動程序、連接憑據和要執行的 SQL 查詢),并且您可能也可以使用一些結果集元數據檢查來自動生成模式.

                  A third option would be to look into writing a Pig LoadFunc (you say your tried to write a UDF). It shouldn't be too difficult, you'll need to pass much the same options as DBStorage (driver, connection credentials and a SQL query to execute), and you can probably use some result set metadata inspection to auto generate a schema too.

                  這篇關于一種從Mysql讀取表數據到Pig的方法的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持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屋-程序員軟件開發技
                  Error while using INSERT INTO table ON DUPLICATE KEY, using a for loop array(使用 INSERT INTO table ON DUPLICATE KEY 時出錯,使用 for 循環數組)
                  pyspark mysql jdbc load An error occurred while calling o23.load No suitable driver(pyspark mysql jdbc load 調用 o23.load 時發生錯誤 沒有合適的驅動程序)
                  How to integrate Apache Spark with MySQL for reading database tables as a spark dataframe?(如何將 Apache Spark 與 MySQL 集成以將數據庫表作為 Spark 數據幀讀取?)
                    <bdo id='dzORJ'></bdo><ul id='dzORJ'></ul>
                    <legend id='dzORJ'><style id='dzORJ'><dir id='dzORJ'><q id='dzORJ'></q></dir></style></legend>

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

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

                        • <tfoot id='dzORJ'></tfoot>
                              <tbody id='dzORJ'></tbody>
                          1. 主站蜘蛛池模板: 午夜影院视频在线观看 | 亚洲一区二区三区免费视频 | 色综合久久88色综合天天 | 日韩在线视频网址 | 一区二区三区久久久 | 性高湖久久久久久久久 | 国产视频一视频二 | 日韩av免费在线观看 | 中文字幕国产 | 精品一级电影 | 精品视频在线播放 | 日韩国产欧美 | 日本三级电影在线免费观看 | 色婷婷亚洲一区二区三区 | 性色av一区二区三区 | 国产精品一区二区无线 | 一级黄色毛片a | 免费观看一级特黄欧美大片 | 精品婷婷 | 免费一区二区三区在线视频 | 97成人免费 | 久久精品国产一区二区三区不卡 | 亚洲一区日韩 | 国产毛片视频 | 亚洲在线一区 | 一区二区三区在线 | 欧美九九九 | 午夜三区| 国产午夜精品一区二区三区在线观看 | 欧美精品久久 | 国产亚洲精品久久久久久牛牛 | 成人在线视频免费观看 | 中文字幕成人在线 | 在线91 | 久久亚洲一区二区三区四区 | 99综合| 91精品国产91久久综合桃花 | 精品一区av | 国产欧美一级二级三级在线视频 | 国产男人的天堂 | 天天影视色综合 |