Skip to content

Commit 2bd222e

Browse files
committed
add ut
1 parent c6f2271 commit 2bd222e

File tree

1 file changed

+63
-1
lines changed

1 file changed

+63
-1
lines changed

src/test/java/com/treasuredata/client/TestTDClient.java

Lines changed: 63 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -396,6 +396,58 @@ public void submitJob()
396396
}
397397
});
398398
}
399+
@Test
400+
public void submitTrinoJob()
401+
throws Exception
402+
{
403+
String jobId = client.submit(TDJobRequest.newTrinoQuery("sample_datasets", "-- td-client-java test\nselect count(*) cnt from nasdaq"));
404+
logger.debug("job id: " + jobId);
405+
406+
int retryCount = 0;
407+
408+
TDJobSummary tdJob = waitJobCompletion(jobId);
409+
TDJob jobInfo = client.jobInfo(jobId);
410+
logger.debug("job show result: " + tdJob);
411+
logger.debug("job info: " + jobInfo);
412+
Optional<String> schema = jobInfo.getResultSchema();
413+
assertTrue(schema.isPresent());
414+
assertEquals("[[\"cnt\", \"bigint\"]]", schema.get());
415+
416+
String[] array = client.jobResult(jobId, TDResultFormat.JSON, input -> {
417+
try (BufferedReader reader = new BufferedReader(new InputStreamReader(input, StandardCharsets.UTF_8))) {
418+
String result = reader.lines().collect(Collectors.joining());
419+
logger.info("result:\n" + result);
420+
return objectMapper.readValue(result, String[].class);
421+
}
422+
catch (Exception e) {
423+
throw new RuntimeException(e);
424+
}
425+
});
426+
assertEquals(1, array.length);
427+
assertEquals(1, jobInfo.getNumRecords());
428+
assertTrue(Long.parseLong(array[0]) > 0);
429+
430+
// test msgpack.gz format
431+
client.jobResult(jobId, TDResultFormat.MESSAGE_PACK_GZ, input -> {
432+
try {
433+
logger.debug("Reading job result in msgpack.gz");
434+
MessageUnpacker unpacker = MessagePack.newDefaultUnpacker(new GZIPInputStream(input));
435+
int rowCount = 0;
436+
while (unpacker.hasNext()) {
437+
ArrayValue array1 = unpacker.unpackValue().asArrayValue();
438+
assertEquals(1, array1.size());
439+
int numRows = array1.get(0).asIntegerValue().toInt();
440+
assertTrue(numRows > 0);
441+
rowCount++;
442+
}
443+
assertEquals(rowCount, 1);
444+
return null;
445+
}
446+
catch (IOException e) {
447+
throw new RuntimeException(e);
448+
}
449+
});
450+
}
399451

400452
@Test
401453
public void submitJobWithInvalidEngineVersionPresto()
@@ -506,6 +558,17 @@ public void submitJobWithResultOutput()
506558
client.existsTable(SAMPLE_DB, "sample_output");
507559
}
508560

561+
@Test
562+
public void submitTrinoJobWithResultOutput()
563+
throws Exception
564+
{
565+
client.deleteTableIfExists(SAMPLE_DB, "sample_output");
566+
String resultOutput = String.format("td://%s@/%s/sample_output?mode=replace", client.config.apiKey.get(), SAMPLE_DB);
567+
String jobId = client.submit(TDJobRequest.newTrinoQuery("sample_datasets", "-- td-client-java test\nselect count(*) from nasdaq", resultOutput));
568+
TDJobSummary tdJob = waitJobCompletion(jobId);
569+
client.existsTable(SAMPLE_DB, "sample_output");
570+
}
571+
509572
@Test
510573
public void submitJobWithPoolName()
511574
throws Exception
@@ -531,7 +594,6 @@ public void submitPrestoJobWithPoolName()
531594
assertEquals(400, e.getStatusCode());
532595
}
533596
}
534-
535597
@Test
536598
public void submitPrestoJobWithInvalidPoolName()
537599
throws Exception

0 commit comments

Comments
 (0)