|
|
@@ -0,0 +1,33 @@
|
|
|
+package com.tzld.videoVector.util;
|
|
|
+
|
|
|
+import com.aliyun.odps.Instance;
|
|
|
+import com.aliyun.odps.Odps;
|
|
|
+import com.aliyun.odps.OdpsException;
|
|
|
+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 java.util.List;
|
|
|
+
|
|
|
+public class OdpsUtil {
|
|
|
+
|
|
|
+ public static List<Record> getOdpsData(String sql) {
|
|
|
+ String accessId = "LTAI9EBa0bd5PrDa";
|
|
|
+ String accessKey = "vAalxds7YxhfOA2yVv8GziCg3Y87v5";
|
|
|
+ String endpoint = "http://service.odps.aliyun.com/api";
|
|
|
+ Account account = new AliyunAccount(accessId, accessKey);
|
|
|
+ Odps odps = new Odps(account);
|
|
|
+ odps.setEndpoint(endpoint);
|
|
|
+ odps.setDefaultProject("loghubods");
|
|
|
+ Instance i;
|
|
|
+ try {
|
|
|
+ i = SQLTask.run(odps, sql);
|
|
|
+ i.waitForSuccess();
|
|
|
+ return SQLTask.getResult(i);
|
|
|
+ } catch (OdpsException e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+}
|