From 7fc0ef9b4ccccb20634e2728b3dd31829bec8c4e Mon Sep 17 00:00:00 2001 From: Kshitij Wadhwa Date: Thu, 14 Dec 2023 13:02:30 -0800 Subject: [PATCH] add more examples for queries (#61) --- .../com/rockset/examples/QueryExample.java | 26 ++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) diff --git a/src/main/java/com/rockset/examples/QueryExample.java b/src/main/java/com/rockset/examples/QueryExample.java index 3ecbf878..3167ce41 100644 --- a/src/main/java/com/rockset/examples/QueryExample.java +++ b/src/main/java/com/rockset/examples/QueryExample.java @@ -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("", ""); + // query to default VI QueryRequest request = new QueryRequest().sql(new QueryRequestSql().query("SELECT * FROM \"_events\" LIMIT 10")); @@ -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 result = (LinkedTreeMap) qr.getResults().get(0); + System.out.println(result.toString()); } }