Mdrill測試數(shù)據(jù)寫入程序的示例分析

Mdrill測試數(shù)據(jù)寫入程序的示例分析,針對這個問題,這篇文章詳細(xì)介紹了相對應(yīng)的分析和解答,希望可以幫助更多想解決這個問題的小伙伴找到更簡單易行的方法。

創(chuàng)新互聯(lián)公司專注于企業(yè)全網(wǎng)整合營銷推廣、網(wǎng)站重做改版、墨江網(wǎng)站定制設(shè)計、自適應(yīng)品牌網(wǎng)站建設(shè)、H5高端網(wǎng)站建設(shè)、購物商城網(wǎng)站建設(shè)、集團(tuán)公司官網(wǎng)建設(shè)、外貿(mào)營銷網(wǎng)站建設(shè)、高端網(wǎng)站制作、響應(yīng)式網(wǎng)頁設(shè)計等建站業(yè)務(wù),價格優(yōu)惠性價比高,為墨江等各大城市提供網(wǎng)站開發(fā)制作服務(wù)。

需要寫入數(shù)據(jù)的表的sql:

CREATE TABLE tv (

thedate string,

tv string

)

寫入的java代碼:

import java.io.BufferedWriter;

import java.io.IOException;

import java.io.OutputStreamWriter;

import java.text.SimpleDateFormat;

import java.util.Calendar;

import java.util.Date;

import org.apache.hadoop.conf.Configuration;

import org.apache.hadoop.fs.FSDataOutputStream;

import org.apache.hadoop.fs.FileSystem;

import org.apache.hadoop.fs.Path;

public class ImportData {

 static Configuration conf = null;

 static FileSystem fs = null;

 public static void main(String[] args) throws IOException {

  conf = ConfigurationUtil.getConf();

  fs = FileSystem.get(conf);

  // TODO Auto-generated method stub

  String pathStirng = "/group/tbdp-etao-adhoc/p4padhoc/tablelist/tv";

  // 生成一年的文件夾(365個),并將數(shù)據(jù)寫入到文件夾中 文件夾名稱:dt=20140201

  Calendar calendar = Calendar.getInstance(); // 創(chuàng)建一個日歷對象

  calendar.setTime(new Date());

  calendar.set(2013, 1, 1);

  SimpleDateFormat sf = new SimpleDateFormat("yyyyMMdd");

  while (calendar.get(Calendar.YEAR) < 2014) {

   System.out.println(sf.format(calendar.getTime()));

   String dateStr = sf.format(calendar.getTime());

   String path = pathStirng + "/dt=" + dateStr;

   mkdir(path);

   writeTVData(path, dateStr);

   calendar.add(Calendar.DAY_OF_YEAR, 1);

  }

  fs.close();

 }

 /**

  * 寫入100000條數(shù)字

  * @param dir

  * @throws  IOException

  */

 public static void writeTVData(String dir, String dateStr)

   throws IOException {

  FSDataOutputStream fos = null;

  OutputStreamWriter osw = null;

  BufferedWriter bw;

  fos = fs.create(new Path(dir + "/data.txt"), false);

  osw = new OutputStreamWriter(fos);

  bw = new BufferedWriter(osw);

  //給data.txt 一行行追加數(shù)據(jù)

  for (int i = 0; i < 100000; i++) {

   StringBuffer strBuffer = new StringBuffer();

   strBuffer.append(dateStr);

   strBuffer.append((char) 1);

   strBuffer.append(i);

   strBuffer.append(System.lineSeparator());

   bw.write(strBuffer.toString());

  }

  bw.close();

  osw.close();

  fos.close();

 }

 public static void mkdir(String dir) throws IOException {

  Path p = new Path(dir);

  if (!fs.exists(p)) {

   fs.mkdirs(p);

  }

 }

}

關(guān)于Mdrill測試數(shù)據(jù)寫入程序的示例分析問題的解答就分享到這里了,希望以上內(nèi)容可以對大家有一定的幫助,如果你還有很多疑惑沒有解開,可以關(guān)注創(chuàng)新互聯(lián)行業(yè)資訊頻道了解更多相關(guān)知識。

文章名稱:Mdrill測試數(shù)據(jù)寫入程序的示例分析
文章地址:http://bm7419.com/article4/pcisie.html

成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供營銷型網(wǎng)站建設(shè)、ChatGPT、App設(shè)計、軟件開發(fā)、微信公眾號服務(wù)器托管

廣告

聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時需注明來源: 創(chuàng)新互聯(lián)

h5響應(yīng)式網(wǎng)站建設(shè)