Package com.etao.adhoc.metric

Examples of com.etao.adhoc.metric.Metric


    String day = fmt.format(new Date());
 
    String store = (String) conf.get("higo.download.offline.store")
        + "/" + day + "/" + java.util.UUID.randomUUID().toString();
   
    Metric metric = null;
    String sql = String.format(sqlFormat, thedate);
   
    HiveExecute hivexec=new HiveExecute();
    hivexec.setConfdir(hdpConf);
    hivexec.setStoreDir(store);
    hivexec.setHql("INSERT OVERWRITE DIRECTORY '" + store +"' "+sql+"");
    hivexec.setCallback(this);
    hivexec.init();
    hivexec.run();
   
   
    Configuration hconf=new Configuration();
     HadoopBaseUtils.grabConfiguration(hdpConf, hconf);
    FileSystem fs = FileSystem.get(hconf);
    Path dir = new Path(store);
    if (!fs.exists(dir)) {
      throw new IOException("can not found path:" + store);
    }
    FileStatus[] filelist = fs.listStatus(dir);
 
    Long bytesRead = 0l;
    long maxsize = 1024l * 1024 * 1024 * 10;
 
    String[] result=null;
   
    boolean isbreak=false;
    for (FileStatus f : filelist) {
      System.out.println(f.getPath().toString());
      if(isbreak)
      {
        break;
      }
      if (!f.isDir() && !f.getPath().getName().startsWith("_")) {
        FSDataInputStream in = fs.open(f.getPath());
        BufferedReader bf=new BufferedReader(new InputStreamReader(in));
        String line;
        while ((line = bf.readLine()) != null) {
          bytesRead += line.getBytes().length;
          String towrite=line.replaceAll("\001", ",").replaceAll("\t", ",");
          System.out.println(towrite);
          if(!towrite.isEmpty())
          {
            result=towrite.split(",");
            if(result.length<8)
            {
              isbreak=true;
              result=null;
            }
          }
          if (bytesRead >= maxsize) {
            bf.close();
            in.close();
            isbreak=true;
          }
         
          if(isbreak)
          {
            break;
          }
        }
        bf.close();
        in.close();
      }
    }
   
    System.out.println(Arrays.toString(result));
    if(result!=null&&result.length>=8)
    {
      metric = new Metric();
      metric.setThedate(thedate);
      metric.setType(0);
      metric.setTablename(tablename);
      metric.setLineCnt((long)Float.parseFloat(result[0]));
      metric.setImpression((long)Float.parseFloat(result[1]));
      metric.setFinClick((long)Float.parseFloat(result[2]));
      metric.setFinPrice(Float.parseFloat(result[3]));
      metric.setAlipayDirectNum((long)Float.parseFloat(result[4]));
      metric.setAlipayDirectAmt(Float.parseFloat(result[5]));
      metric.setAlipayIndirectNum((long)Float.parseFloat(result[6]));
      metric.setAlipayIndirectAmt(Float.parseFloat(result[7]));
      System.out.println(metric.toString());
    }
    return metric;
 
  }
View Full Code Here


    } else {
      System.out.println("UpdateService: unknown query type " + queryFrom);
    }
  }
  public void load(String tablename, String thedate) throws IOException {
    Metric metric = queryServer.getMetric(tablename, thedate);
    String queryServiceName = queryServer.getName();
 
    if(metric == null){
      System.out.println(queryServiceName + " RETURN NULL");
    } else {
View Full Code Here

    }
   
  }
  public Metric getMetric(String tablename, String thedate) throws IOException{
    String sqlFormat=(String) conf.get("adhoc.metric.mdrill.sql."+tablename);
    Metric metric = null;
    String sql = String.format(sqlFormat, thedate);
    System.out.println("Higo SQL:" + sql);
    MdrillQueryResultSet rs;
    try {
      rs = (MdrillQueryResultSet) stmt.executeQuery(sql);
      if(rs.next()){
        metric = new Metric();
        metric.setThedate(thedate);
        metric.setType(1);
        metric.setTablename(tablename);
        metric.setLineCnt((long)Float.parseFloat(rs.getString(1)));
        metric.setImpression((long)Float.parseFloat(rs.getString(2)));
        metric.setFinClick((long)Float.parseFloat(rs.getString(3)));
        metric.setFinPrice(Float.parseFloat(rs.getString(4)));
        metric.setAlipayDirectNum((long)Float.parseFloat(rs.getString(5)));
        metric.setAlipayDirectAmt(Float.parseFloat(rs.getString(6)));
        metric.setAlipayIndirectNum((long)Float.parseFloat(rs.getString(7)));
        metric.setAlipayIndirectAmt(Float.parseFloat(rs.getString(8)));
      }
    } catch (SQLException e) {
      System.err.println("[" + sdf.format(new Date(System.currentTimeMillis())) + "] "
          + "Error when execute Higo SQL: "
          + sql);
View Full Code Here

TOP

Related Classes of com.etao.adhoc.metric.Metric

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.