/home/hadoop/hive-0.14.0-bin/bin/hive -e "CREATE TABLE pv_$1 AS SELECT COUNT(1) AS PV FROM ubas WHERE logdate='$1';"
## 3.stats ip
/home/hadoop/hive-0.14.0-bin/bin/hive -e "CREATE TABLE ip_$1 AS SELECT COUNT(DISTINCT ip) AS IP FROM ubas WHERE logdate='$1';"
## 4.stats amount hour
/home/hadoop/hive-0.14.0-bin/bin/hive -e "CREATE TABLE amount_$1 ROW FORMAT DELIMITED FIELDS TERMINATED BY ',' AS SELECT '$1',hour AS HOUR_TAG, COUNT(hour) AS HOUR,'' AS UPDATE_DATE FROM ubas WHERE logdate='$1' GROUP BY hour;"
## 5.stats jr
/home/hadoop/hive-0.14.0-bin/bin/hive -e "CREATE TABLE jr_$1 AS SELECT COUNT(1) AS JR FROM (SELECT COUNT(ip) AS times FROM ubas WHERE logdate='$1' GROUP BY ip HAVING times=1) e;"
## 6.combine pv,ip,jr and tr to ubas table
/home/hadoop/hive-0.14.0-bin/bin/hive -e "CREATE TABLE ubas_$1 ROW FORMAT DELIMITED FIELDS TERMINATED BY ',' AS SELECT '$1', a.pv, b.ip, c.jr, ROUND(COALESCE(CAST(b.ip AS DOUBLE), 0)/a.pv, 2),'' AS UPDATE_DATE FROM pv_$1 a JOIN ip_$1 b ON 1=1 JOIN jr_$1 c ON 1=1 ;"
@SuppressWarnings({ "rawtypes", "unchecked" })
private void start() {
try {
TNonblockingServerSocket socket = new TNonblockingServerSocket(PORT);
final UBASService.Processor processor = new UBASService.Processor(new UBASServiceImpl());
THsHaServer.Args arg = new THsHaServer.Args(socket);
/*
* Binary coded format efficient, intensive data transmission, The
* use of non blocking mode of transmission, according to the> * of the block, similar to the Java of NIO
*/
arg.protocolFactory(new TCompactProtocol.Factory());
arg.transportFactory(new TFramedTransport.Factory());
arg.processorFactory(new TProcessorFactory(processor));
TServer server = new THsHaServer(arg);
server.serve();
} catch (Exception ex) {
ex.printStackTrace();
}
}
public static void main(String[] args) {
try {
logger.info("start thrift server...");
StatsServer stats = new StatsServer();
stats.start();
} catch (Exception ex) {
ex.printStackTrace();
logger.error(String.format("run thrift server has error,msg is %s", ex.getMessage()));
}
}