use of com.treasuredata.client.model.TDJobSummary in project td-client-java by treasure-data.
the class TestTDClient method invalidJobStatus.
@Test
public void invalidJobStatus() {
try {
TDJobSummary invalidJob = client.jobStatus("xxxxxx");
logger.debug("invalid job: " + invalidJob);
fail("should not reach here");
} catch (TDClientException e) {
assertEquals(TDClientException.ErrorType.TARGET_NOT_FOUND, e.getErrorType());
}
}
use of com.treasuredata.client.model.TDJobSummary in project td-client-java by treasure-data.
the class TestTDClient method submitExportJob.
@Test
public void submitExportJob() throws Exception {
TDExportJobRequest jobRequest = new TDExportJobRequest(SAMPLE_DB, "sample_output", new Date(0L), new Date(1456522300L * 1000), TDExportFileFormatType.JSONL_GZ, "access key id", "secret access key", "bucket", "prefix/", Optional.<String>absent());
client.createDatabaseIfNotExists(SAMPLE_DB);
client.createTableIfNotExists(SAMPLE_DB, "sample_output");
String jobId = client.submitExportJob(jobRequest);
TDJobSummary tdJob = waitJobCompletion(jobId);
// this job will do nothing because sample_output table is empty
}
use of com.treasuredata.client.model.TDJobSummary in project td-client-java by treasure-data.
the class TestTDClient method submitJob.
@Test
public void submitJob() throws Exception {
String jobId = client.submit(TDJobRequest.newPrestoQuery("sample_datasets", "-- td-client-java test\nselect count(*) cnt from nasdaq"));
logger.debug("job id: " + jobId);
int retryCount = 0;
TDJobSummary tdJob = waitJobCompletion(jobId);
TDJob jobInfo = client.jobInfo(jobId);
logger.debug("job show result: " + tdJob);
logger.debug("job info: " + jobInfo);
Optional<String> schema = jobInfo.getResultSchema();
assertTrue(schema.isPresent());
assertEquals("[[\"cnt\", \"bigint\"]]", schema.get());
JSONArray array = client.jobResult(jobId, TDResultFormat.JSON, new Function<InputStream, JSONArray>() {
@Override
public JSONArray apply(InputStream input) {
try {
String result = new String(ByteStreams.toByteArray(input), StandardCharsets.UTF_8);
logger.info("result:\n" + result);
return new JSONArray(result);
} catch (Exception e) {
throw Throwables.propagate(e);
}
}
});
assertEquals(1, array.length());
assertEquals(8807278, array.getLong(0));
// test msgpack.gz format
client.jobResult(jobId, TDResultFormat.MESSAGE_PACK_GZ, new Function<InputStream, Object>() {
@Override
public Object apply(InputStream input) {
try {
logger.debug("Reading job result in msgpack.gz");
MessageUnpacker unpacker = MessagePack.newDefaultUnpacker(new GZIPInputStream(input));
int rowCount = 0;
while (unpacker.hasNext()) {
ArrayValue array = unpacker.unpackValue().asArrayValue();
assertEquals(1, array.size());
int numColumns = array.get(0).asIntegerValue().toInt();
assertEquals(8807278, numColumns);
rowCount++;
}
assertEquals(rowCount, 1);
return null;
} catch (IOException e) {
throw Throwables.propagate(e);
}
}
});
}
use of com.treasuredata.client.model.TDJobSummary in project td-client-java by treasure-data.
the class TestTDClient method submitJobWithResultOutput.
@Test
public void submitJobWithResultOutput() throws Exception {
client.deleteTableIfExists(SAMPLE_DB, "sample_output");
String resultOutput = String.format("td://%s@/%s/sample_output?mode=replace", client.config.apiKey.get(), SAMPLE_DB);
String jobId = client.submit(TDJobRequest.newPrestoQuery("sample_datasets", "-- td-client-java test\nselect count(*) from nasdaq", resultOutput));
TDJobSummary tdJob = waitJobCompletion(jobId);
client.existsTable(SAMPLE_DB, "sample_output");
}
use of com.treasuredata.client.model.TDJobSummary in project td-client-java by treasure-data.
the class TestTDClient method submitPrestoJobWithInvalidPoolName.
@Test
public void submitPrestoJobWithInvalidPoolName() throws Exception {
exception.expect(TDClientHttpException.class);
exception.expectMessage("Presto resource pool with name 'no_such_pool' does not exist");
client.deleteTableIfExists(SAMPLE_DB, "sample_output");
String poolName = "no_such_pool";
String jobId = client.submit(TDJobRequest.newPrestoQuery("sample_datasets", "-- td-client-java test\nselect count(*) from nasdaq", null, poolName));
TDJobSummary tdJob = waitJobCompletion(jobId);
client.existsTable(SAMPLE_DB, "sample_output");
}
Aggregations