use of co.cask.cdap.client.QueryClient in project cdap by caskdata.
the class GenerateClientUsageExample method queryClient.
public void queryClient() throws Exception {
// Construct the client used to interact with CDAP
QueryClient queryClient = new QueryClient(clientConfig);
// Perform an ad-hoc query using the Purchase example
ListenableFuture<ExploreExecutionResult> resultFuture = queryClient.execute(NamespaceId.DEFAULT, "SELECT * FROM dataset_history WHERE customer IN ('Alice','Bob')");
ExploreExecutionResult results = resultFuture.get();
// Fetch schema
List<ColumnDesc> schema = results.getResultSchema();
String[] header = new String[schema.size()];
for (int i = 0; i < header.length; i++) {
ColumnDesc column = schema.get(i);
// Hive columns start at 1
int index = column.getPosition() - 1;
header[index] = column.getName() + ": " + column.getType();
}
}
use of co.cask.cdap.client.QueryClient in project cdap by caskdata.
the class CLIMainTest method setUpClass.
@BeforeClass
public static void setUpClass() throws Exception {
cliConfig = createCLIConfig(STANDALONE.getBaseURI());
LaunchOptions launchOptions = new LaunchOptions(LaunchOptions.DEFAULT.getUri(), true, true, false);
cliMain = new CLIMain(launchOptions, cliConfig);
programClient = new ProgramClient(cliConfig.getClientConfig());
queryClient = new QueryClient(cliConfig.getClientConfig());
cli = cliMain.getCLI();
testCommandOutputContains(cli, "connect " + STANDALONE.getBaseURI(), "Successfully connected");
testCommandOutputNotContains(cli, "list apps", FakeApp.NAME);
File appJarFile = createAppJarFile(FakeApp.class);
testCommandOutputContains(cli, String.format("load artifact %s name %s version %s", appJarFile.getAbsolutePath(), FakeApp.NAME, V1), "Successfully added artifact");
testCommandOutputContains(cli, "deploy app " + appJarFile.getAbsolutePath(), "Successfully deployed app");
testCommandOutputContains(cli, String.format("create app %s version %s %s %s %s", FakeApp.NAME, V1_SNAPSHOT, FakeApp.NAME, V1, ArtifactScope.USER), "Successfully created application");
File pluginJarFile = createPluginJarFile(FakePlugin.class);
testCommandOutputContains(cli, String.format("load artifact %s config-file %s", pluginJarFile.getAbsolutePath(), createPluginConfig().getAbsolutePath()), "Successfully");
if (!appJarFile.delete()) {
LOG.warn("Failed to delete temporary app jar file: {}", appJarFile.getAbsolutePath());
}
}
Aggregations