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());
}
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());
}
}
Aggregations