use of com.treasuredata.client.model.TDTable in project td-client-java by treasure-data.
the class TestProxyAccess method proxyApiAccess.
@Test
public void proxyApiAccess() {
TDClient client = TDClient.newBuilder().setProxy(proxyBaseConfig()).build();
try {
client.serverStatus();
List<TDTable> tableList = client.listTables("sample_datasets");
assertTrue(tableList.size() >= 2);
TDJobList jobList = client.listJobs();
assertTrue(jobList.getJobs().size() > 0);
} finally {
logger.debug("proxy access count: {}", proxyAccessCount);
assertEquals(1, proxyAccessCount.get());
}
}
use of com.treasuredata.client.model.TDTable in project td-client-java by treasure-data.
the class TestSSLProxyAccess method proxyApiAccess.
@Test
public void proxyApiAccess() {
ProxyConfig.ProxyConfigBuilder proxy = new ProxyConfig.ProxyConfigBuilder();
proxy.useSSL(true);
proxy.setHost("localhost");
proxy.setPort(proxyPort);
proxy.setUser(PROXY_USER);
proxy.setPassword(PROXY_PASS);
TDClient client = TDClient.newBuilder().setProxy(proxy.createProxyConfig()).build();
try {
client.serverStatus();
List<TDTable> tableList = client.listTables("sample_datasets");
assertTrue(tableList.size() >= 2);
TDJobList jobList = client.listJobs();
assertTrue(jobList.getJobs().size() > 0);
} finally {
logger.debug("proxy access count: {}", proxyAccessCount);
assertEquals(1, proxyAccessCount.get());
}
}
use of com.treasuredata.client.model.TDTable in project td-client-java by treasure-data.
the class TestTDClient method showTables.
@Test
public void showTables() throws Exception {
TDTable table;
// nasdaq
table = client.showTable("sample_datasets", "nasdaq");
assertTrue(table.getColumns().size() == 6);
// www_access
table = client.showTable("sample_datasets", "www_access");
assertTrue(table.getColumns().size() == 8);
}
use of com.treasuredata.client.model.TDTable in project td-client-java by treasure-data.
the class TestTDClient method authenticate.
@Test
public void authenticate() throws Exception {
// authenticate() method should retrieve apikey, and set it to the TDClient
// [NOTE] To pass this you need to add password config to ~/.td/td.conf
Properties p = TDClientConfig.readTDConf();
// Set no API key
TDClient client = new TDClientBuilder(false).build();
String user = firstNonNull(p.getProperty("user"), System.getenv("TD_USER"));
String password = firstNonNull(p.getProperty("password"), System.getenv("TD_PASS"));
TDClient newClient = client.authenticate(user, password);
List<TDTable> tableList = newClient.listTables("sample_datasets");
assertTrue(tableList.size() >= 2);
}
use of com.treasuredata.client.model.TDTable 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