use of com.treasuredata.client.model.TDDatabase in project td-client-java by treasure-data.
the class TestTDClient method listDatabases.
@Test
public void listDatabases() throws Exception {
List<String> dbList = client.listDatabaseNames();
assertTrue("should contain sample_datasets", dbList.contains("sample_datasets"));
String dbListStr = Joiner.on(", ").join(dbList);
logger.debug(dbListStr);
List<TDDatabase> detailedDBList = client.listDatabases();
Iterable<String> dbStr = Iterables.transform(detailedDBList, new Function<TDDatabase, String>() {
@Override
public String apply(TDDatabase input) {
String summary = String.format("name:%s, count:%s, createdAt:%s, updatedAt:%s, organization:%s, permission:%s", input.getName(), input.getCount(), input.getCreatedAt(), input.getUpdatedAt(), input.getOrganization(), input.getPermission());
return summary;
}
});
String detailedDbListStr = Joiner.on(", ").join(dbStr);
logger.trace(detailedDbListStr);
}
use of com.treasuredata.client.model.TDDatabase in project td-client-java by treasure-data.
the class Example method main.
public static void main(String[] args) {
TDClient client = TDClient.newClient();
try {
// Retrieve database and table names
List<TDDatabase> databases = client.listDatabases();
TDDatabase db = databases.get(0);
System.out.println("database: " + db.getName());
for (TDTable table : client.listTables(db.getName())) {
System.out.println(" table: " + table);
}
// Submit a new Presto query
String jobId = client.submit(TDJobRequest.newPrestoQuery("sample_datasets", "select count(1) cnt from www_access"));
// Wait until the query finishes
ExponentialBackOff backOff = new ExponentialBackOff();
TDJobSummary job = client.jobStatus(jobId);
while (!job.getStatus().isFinished()) {
Thread.sleep(backOff.nextWaitTimeMillis());
job = client.jobStatus(jobId);
}
// Read the detailed job information
TDJob jobInfo = client.jobInfo(jobId);
System.out.println("log:\n" + jobInfo.getCmdOut());
System.out.println("error log:\n" + jobInfo.getStdErr());
// Read the job results in msgpack.gz format
client.jobResult(jobId, TDResultFormat.MESSAGE_PACK_GZ, new Function<InputStream, Integer>() {
@Override
public Integer apply(InputStream input) {
int count = 0;
try {
MessageUnpacker unpacker = MessagePack.newDefaultUnpacker(new GZIPInputStream(input));
while (unpacker.hasNext()) {
// Each row of the query result is array type value (e.g., [1, "name", ...])
ArrayValue array = unpacker.unpackValue().asArrayValue();
System.out.println(array);
count++;
}
unpacker.close();
} catch (Exception e) {
throw Throwables.propagate(e);
}
return count;
}
});
} catch (Exception e) {
e.printStackTrace();
} finally {
client.close();
}
}
Aggregations