|
@@ -5,8 +5,11 @@ import com.aliyun.odps.account.Account;
|
|
|
import com.aliyun.odps.account.AliyunAccount;
|
|
|
import com.aliyun.odps.data.Record;
|
|
|
import com.aliyun.odps.task.SQLTask;
|
|
|
+import com.tzld.piaoquan.ad.engine.commons.util.DateUtils;
|
|
|
import org.springframework.beans.factory.annotation.Value;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
+
|
|
|
+import javax.annotation.PostConstruct;
|
|
|
import java.util.*;
|
|
|
@Service
|
|
|
public class ODPSClient {
|
|
@@ -17,15 +20,29 @@ public class ODPSClient {
|
|
|
public String odpsAAccessKey;
|
|
|
@Value("${ad.odps.endpoint:http://service.cn.maxcompute.aliyun.com/api}")
|
|
|
public String odpsEndpoint;
|
|
|
+ public static final String sqlExp="select * from top_return_videolist_hh where dt={dt};";
|
|
|
|
|
|
private Odps odps;
|
|
|
|
|
|
+ @PostConstruct
|
|
|
public void initClient(){
|
|
|
Account account = new AliyunAccount(odpsAccessId, odpsAAccessKey);
|
|
|
odps = new Odps(account);
|
|
|
odps.setEndpoint(odpsEndpoint);
|
|
|
odps.setDefaultProject("loghubods");
|
|
|
}
|
|
|
+ public List<Record> getCurrentTopVideoRecords(){
|
|
|
+ List<Record> records=new ArrayList<>();
|
|
|
+ Instance i;
|
|
|
+ try {
|
|
|
+ i = SQLTask.run(odps, sqlExp.replace("{dt}",DateUtils.getCurrentDateStr("yyyyMMddHH")));
|
|
|
+ i.waitForSuccess();
|
|
|
+ records = SQLTask.getResult(i);
|
|
|
+ } catch (OdpsException e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+ return records;
|
|
|
+ }
|
|
|
|
|
|
|
|
|
public static void main(String[] args) throws Exception{
|
|
@@ -34,19 +51,17 @@ public class ODPSClient {
|
|
|
odps.setEndpoint("http://service.cn.maxcompute.aliyun.com/api");
|
|
|
odps.setDefaultProject("loghubods");
|
|
|
Instance i;
|
|
|
- String sql="select * from top_return_videolist_hh where dt=2024011710;";
|
|
|
try {
|
|
|
- i = SQLTask.run(odps, sql);
|
|
|
+ i = SQLTask.run(odps, sqlExp.replace("{dt}",DateUtils.getCurrentDateStr("yyyyMMddHH")));
|
|
|
i.waitForSuccess();
|
|
|
List<Record> records = SQLTask.getResult(i);
|
|
|
for(Record r:records){
|
|
|
- System.out.println(r.get("apptype").toString());
|
|
|
- System.out.println(r.get("videoid").toString());
|
|
|
- System.out.println(r.get("rank").toString());
|
|
|
+ System.out.println(r.get("apptype").toString()+"----"+r.get("videoid").toString()+"----"+r.get("rank").toString());
|
|
|
System.out.println("-0-----------------");
|
|
|
}
|
|
|
} catch (OdpsException e) {
|
|
|
e.printStackTrace();
|
|
|
}
|
|
|
+ System.out.println();
|
|
|
}
|
|
|
}
|