/**
   * Kick-offer
   *
   * @param sql sql string
   * @return an intance
   * @throws SQLException
   */
  private Instance runClientSQL(String sql) throws SQLException {
    Instance instance;
    try {
      Map<String, String> hints = new HashMap<String, String>();
      Map<String, String> aliases = new HashMap<String, String>();

      // If the client forget to end with a semi-colon, append it.
      if (!sql.contains(";")) {
        sql += ";";
      }

      Odps odps = connHanlde.getOdps();
      instance = SQLTask.run(odps, odps.getDefaultProject(), sql, "SQL", hints, aliases);
      LogView logView = new LogView(odps);
      if (connHanlde.getLogviewHost() != null) {
        logView.setLogViewHost(connHanlde.getLogviewHost());
      }

      String logViewUrl = logView.generateLogView(instance, 7 * 24);
      connHanlde.log.fine("Run SQL: " + sql);
      connHanlde.log.info(logViewUrl);
      warningChain = new SQLWarning(logViewUrl);
    } catch (OdpsException e) {
      connHanlde.log.severe("fail to run sql: " + sql);
      throw new SQLException(e);
    }
    return instance;
  }
 @Override
 @Before
 public void setUp() {
   Account account = new AliyunAccount(ACCESS_ID, ACCESS_KEY);
   odps = new Odps(account);
   odps.setDefaultProject(PROJECT);
   odps.setEndpoint(ENDPOINT);
   super.setUp();
 }
示例#3
0
 /**
  * 通过匿名Instance运行LOTTask
  *
  * @param odps
  * @param input
  * @return
  * @throws OdpsException
  */
 public static Instance run(Odps odps, String input, boolean runSQL) throws OdpsException {
   String project = odps.getDefaultProject();
   if (project == null) {
     throw new OdpsException("default project required.");
   }
   return run(odps, project, input, runSQL, "AnonymousLOTTask", null, null);
 }
示例#4
0
  public static void main(String[] args) throws Exception {
    String testDateYmd = "20140102";
    String extraPartitions = "";

    SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMdd");
    MapreduceConfigInfo conf = parseConfig(extraPartitions);
    JobConf job = makeMapreduceJobConf(conf, sdf.parse(testDateYmd));
    if (job == null) {
      throw new Exception("Create mapreduce job failed");
    }

    Account account = new AliyunAccount("x", "x");
    Odps odps = new Odps(account);
    odps.setDefaultProject("local");
    SessionState sessionState = SessionState.get();
    sessionState.setLocalRun(true);
    sessionState.setOdps(odps);

    JobClient.runJob(job);
  }
 protected void createOdpsTable(
     String tableName, String[] partitionCols, ColumnGenerator... extraCols) throws OdpsException {
   TableSchema schema = new TableSchema();
   schema.addColumn(new Column("id", OdpsType.BIGINT));
   schema.addColumn(new Column("msg", OdpsType.STRING));
   int colNum = 0;
   for (ColumnGenerator generator : extraCols) {
     schema.addColumn(new Column(forIdx(colNum++), generator.getOdpsType()));
   }
   if (partitionCols != null) {
     for (String partition : partitionCols) {
       schema.addPartitionColumn(new Column(partition, OdpsType.STRING));
     }
   }
   odps.tables().create(tableName, schema);
 }
示例#6
0
  /**
   * 运行LOTTask
   *
   * @param odps
   * @param project
   * @param input
   * @param hints
   * @return
   * @throws OdpsException
   */
  public static Instance run(
      Odps odps,
      String project,
      String input,
      boolean runSQL,
      String taskName,
      Map<String, String> hints,
      Map<String, String> aliases)
      throws OdpsException {
    LOTTask task = new LOTTask();
    if (runSQL) {
      task.setQuery(input);
    } else {
      Plan plan = new Plan();
      plan.setResourceName(input);
      plan.setProject(project);

      task.setPlan(plan);
    }

    task.setName(taskName);

    if (hints != null) {
      try {
        String json = JSON.toJSONString(hints);
        task.setProperty("settings", json);
      } catch (Exception e) {
        throw new OdpsException(e.getMessage(), e);
      }
    }

    if (aliases != null) {
      try {
        String json = JSON.toJSONString(aliases);
        task.setProperty("aliases", json);
      } catch (Exception e) {
        throw new OdpsException(e.getMessage(), e);
      }
    }

    return odps.instances().create(project, task);
  }
 protected void deleteTable(String tableName) throws OdpsException {
   odps.tables().delete(tableName, true);
 }
 protected boolean isTableExist(String tableName) throws OdpsException {
   return odps.tables().exists(tableName);
 }