Search in sources :

Example 1 with TDSavedQueryHistory

use of com.treasuredata.client.model.TDSavedQueryHistory in project td-client-java by treasure-data.

the class Example method saveQueryExample.

public static void saveQueryExample() {
    TDClient client = TDClient.newClient();
    // Register a new scheduled query
    TDSaveQueryRequest query = TDSavedQuery.newBuilder("my_saved_query", TDJob.Type.PRESTO, "testdb", "select 1", "Asia/Tokyo").setCron("40 * * * *").setResult("mysql://testuser:pass@somemysql.address/somedb/sometable").build();
    client.saveQuery(query);
    // List saved queries
    List<TDSavedQuery> savedQueries = client.listSavedQueries();
    // Run a saved query
    Date scheduledTime = new Date(System.currentTimeMillis());
    client.startSavedQuery(query.getName(), scheduledTime);
    // Get saved query job history (first page)
    TDSavedQueryHistory firstPage = client.getSavedQueryHistory(query.getName());
    // Get second page
    long from = firstPage.getTo().get();
    long to = from + 20;
    TDSavedQueryHistory secondPage = client.getSavedQueryHistory(query.getName(), from, to);
    // Get result of last job
    TDJob lastJob = firstPage.getHistory().get(0);
    System.out.println("Last job:" + lastJob);
    // Update a saved query
    TDSavedQueryUpdateRequest updateRequest = TDSavedQuery.newUpdateRequestBuilder().setQuery("select 2").setDelay(3600).build();
    client.updateSavedQuery("my_saved_query", updateRequest);
    // Delete a saved query
    client.deleteSavedQuery(query.getName());
}
Also used : TDJob(com.treasuredata.client.model.TDJob) TDSavedQueryHistory(com.treasuredata.client.model.TDSavedQueryHistory) TDSavedQueryUpdateRequest(com.treasuredata.client.model.TDSavedQueryUpdateRequest) TDSavedQuery(com.treasuredata.client.model.TDSavedQuery) Date(java.util.Date) TDSaveQueryRequest(com.treasuredata.client.model.TDSaveQueryRequest)

Example 2 with TDSavedQueryHistory

use of com.treasuredata.client.model.TDSavedQueryHistory in project td-client-java by treasure-data.

the class TestTDClient method getSavedQueryHistory.

@Test
public void getSavedQueryHistory() {
    List<TDSavedQuery> allQueries = client.listSavedQueries();
    List<TDSavedQuery> queries = FluentIterable.from(allQueries).limit(10).toList();
    for (TDSavedQuery query : queries) {
        TDSavedQueryHistory firstPage = client.getSavedQueryHistory(query.getName());
        logger.info("count: {}, from: {}, to: {}, jobs: {}", firstPage.getCount(), firstPage.getFrom(), firstPage.getTo(), firstPage.getHistory().size());
        TDSavedQueryHistory secondPage = client.getSavedQueryHistory(query.getName(), firstPage.getTo().get(), firstPage.getTo().get() + 20L);
        logger.info("count: {}, from: {}, to: {}, jobs: {}", secondPage.getCount(), secondPage.getFrom(), secondPage.getTo(), secondPage.getHistory().size());
    }
}
Also used : TDSavedQueryHistory(com.treasuredata.client.model.TDSavedQueryHistory) TDSavedQuery(com.treasuredata.client.model.TDSavedQuery) Test(org.junit.Test)

Aggregations

TDSavedQuery (com.treasuredata.client.model.TDSavedQuery)2 TDSavedQueryHistory (com.treasuredata.client.model.TDSavedQueryHistory)2 TDJob (com.treasuredata.client.model.TDJob)1 TDSaveQueryRequest (com.treasuredata.client.model.TDSaveQueryRequest)1 TDSavedQueryUpdateRequest (com.treasuredata.client.model.TDSavedQueryUpdateRequest)1 Date (java.util.Date)1 Test (org.junit.Test)1