Java SDK

    This document describes how to use Java SDK for Rockset. This client allows you to:

    • securely connect to Rockset service
    • create, manage and administer collections
    • issue queries against collections

    Check out the Java SDK code.

    Check out the JavaDocs.

    #Installation

    Add this Maven dependency to your project's POM:

    <dependency>
        <groupId>com.rockset</groupId>
        <artifactId>rockset-java</artifactId>
        <version>0.6.1</version>
    </dependency>

    or create a jar file rockset-java-${version}.jar

    mvn package

    #Connect

    Client objects allow you to connect securely to Rockset service. All other API calls require a valid client object.

    In order to create a client object, you will need a valid Rockset API key. If you have access to the Rockset Console, then you can use the console to create an API key. If not, please contact the Rockset team at support@rockset.com

    import com.rockset.client.RocksetClient;
    
    RocksetClient client = new RocksetClient("<apiKey>", "<apiServer>");

    Use api.rs2.usw2.rockset.com as the apiServer.

    #Usage

    #Create a Collection

    Create a collection using the client object as follows:

    CreateCollectionRequest request = new CreateCollectionRequest()
                                        .name("my-first-collection");
    CreateCollectionResponse response = client.createCollection("commons", request);

    #Create an Integration

    If you have an Amazon S3 bucket that you want to ingest data from, create a Rockset Integration to store credentials required to access the bucket. Create an integration object using the client object as follows:

    CreateIntegrationRequest request = new CreateIntegrationRequest()
                                        .name("my-first-integration")
                                        .aws(new AwsKeyIntegration()
                                            .awsAccessKeyId(".....")
                                            .awsSecretAccessKey("....."));
    CreateIntegrationResponse response = client.createIntegration(request);

    #Create a Collection from Amazon S3

    Prior to creating a collection using Amazon S3 as source, create an integration first.

    SourceS3 sourceS3 = new SourceS3();
    sourceS3.setBucket("<bucket>");
    List<Source> sources = new ArrayList<Source>();
    sources.add(new Source().s3(sourceS3).integrationName("<integration>"));
    CreateCollectionRequest request = new CreateCollectionRequest()
                                        .name("my-first-s3-collection")
                                        .sources(sources);
    CreateCollectionResponse response = client.createCollection("commons", request);

    #Add Documents

    Add documents to an existing collection using the client object.

    // load json from a file or create a list of objects to be inserted
    LinkedList <Object> list = new LinkedList<null>();
    Map<String , Object> json = new LinkedHashMap<null>();
    json.put("name", "foo");
    json.put("address", "bar");
    list.add(json);
    
    AddDocumentsRequest documentsRequest =
         new AddDocumentsRequest().data(list);
    AddDocumentsResponse documentsResponse =
         client.addDocuments("commons", "my-first-collection", documentsRequest);

    #Query

    Make queries to Rockset using the client object.

    QueryRequest request = new QueryRequest()
                                .sql(new QueryRequestSql()
                                .query("select * from \"_events\""));
    QueryResponse response = client.query(request);

    There are more Java examples available.