|
@@ -0,0 +1,52 @@
|
|
|
+package com.tzld.piaoquan.ad.engine.service.predict.odps;
|
|
|
+
|
|
|
+import com.aliyun.odps.*;
|
|
|
+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 org.springframework.beans.factory.annotation.Value;
|
|
|
+import org.springframework.stereotype.Service;
|
|
|
+import java.util.*;
|
|
|
+@Service
|
|
|
+public class ODPSClient {
|
|
|
+
|
|
|
+ @Value("${ad.odps.access.id:LTAIWYUujJAm7CbH}")
|
|
|
+ public String odpsAccessId;
|
|
|
+ @Value("${ad.odps.access.key:RfSjdiWwED1sGFlsjXv0DlfTnZTG1P}")
|
|
|
+ public String odpsAAccessKey;
|
|
|
+ @Value("${ad.odps.endpoint:http://service.cn.maxcompute.aliyun.com/api}")
|
|
|
+ public String odpsEndpoint;
|
|
|
+
|
|
|
+ private Odps odps;
|
|
|
+
|
|
|
+ public void initClient(){
|
|
|
+ Account account = new AliyunAccount(odpsAccessId, odpsAAccessKey);
|
|
|
+ odps = new Odps(account);
|
|
|
+ odps.setEndpoint(odpsEndpoint);
|
|
|
+ odps.setDefaultProject("loghubods");
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ public static void main(String[] args) throws Exception{
|
|
|
+ Account account = new AliyunAccount("LTAIWYUujJAm7CbH", "RfSjdiWwED1sGFlsjXv0DlfTnZTG1P");
|
|
|
+ Odps odps = new Odps(account);
|
|
|
+ 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.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("-0-----------------");
|
|
|
+ }
|
|
|
+ } catch (OdpsException e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+ }
|
|
|
+}
|