Search in sources :

Example 1 with QueryClient

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();
    }
}
Also used : ColumnDesc(co.cask.cdap.proto.ColumnDesc) ExploreExecutionResult(co.cask.cdap.explore.client.ExploreExecutionResult) QueryClient(co.cask.cdap.client.QueryClient)

Example 2 with QueryClient

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());
    }
}
Also used : ProgramClient(co.cask.cdap.client.ProgramClient) File(java.io.File) QueryClient(co.cask.cdap.client.QueryClient) BeforeClass(org.junit.BeforeClass)

Aggregations

QueryClient (co.cask.cdap.client.QueryClient)2 ProgramClient (co.cask.cdap.client.ProgramClient)1 ExploreExecutionResult (co.cask.cdap.explore.client.ExploreExecutionResult)1 ColumnDesc (co.cask.cdap.proto.ColumnDesc)1 File (java.io.File)1 BeforeClass (org.junit.BeforeClass)1