Skip to content

Commit

Permalink
add more examples for queries (#61)
Browse files Browse the repository at this point in the history
  • Loading branch information
kwadhwa18 authored Dec 14, 2023
1 parent f9ce073 commit 7fc0ef9
Showing 1 changed file with 25 additions and 1 deletion.
26 changes: 25 additions & 1 deletion src/main/java/com/rockset/examples/QueryExample.java
Original file line number Diff line number Diff line change
@@ -1,12 +1,16 @@
package com.rockset.examples;

import com.google.gson.internal.LinkedTreeMap;
import com.rockset.client.RocksetClient;
import com.rockset.client.model.*;

import java.util.Map;

public class QueryExample {
public static void main(String[] args) {
public static void main(String[] args) throws Exception {
RocksetClient rs = new RocksetClient("<apiKey>", "<apiServer>");

// query to default VI
QueryRequest request =
new QueryRequest().sql(new QueryRequestSql().query("SELECT * FROM \"_events\" LIMIT 10"));

Expand All @@ -16,5 +20,25 @@ public static void main(String[] args) {
} catch (Exception e) {
e.printStackTrace();
}

// query to a specific VI
try {
QueryResponse response = rs.virtualInstances.query("vi-id", request);
System.out.println(response);
} catch (Exception e) {
e.printStackTrace();
}

// send query lamdba to a specific VI
QueryParameter exParam = new QueryParameter();
exParam.setName("param");
exParam.setType("string");
exParam.setValue("All work and no play makes Jack a dull boy");
ExecuteQueryLambdaRequest exReq = new ExecuteQueryLambdaRequest();
exReq.addParametersItem(exParam);
exReq.setVirtualInstanceId("vi-id");
QueryResponse qr = rs.queryLambdas.execute("commons", "ql-name", "production", exReq);
Map<String, String> result = (LinkedTreeMap) qr.getResults().get(0);
System.out.println(result.toString());
}
}

0 comments on commit 7fc0ef9

Please sign in to comment.