Illustration Image

Cassandra.Link

The best knowledge base on Apache Cassandra®

Helping platform leaders, architects, engineers, and operators build scalable real time data platforms.

10/23/2020

Reading time:1 min

DataStax-Examples/paging-graph-results-java

by DataStax-Examples

This example shows you how to handle page graph result sets on a DataStax Graph traversal. It contains three different methods for processing results:Unpaged results - This does not use paging at all and is included for comparisons sakeSynchronously Paged Results - This using the continuous paging functionality of DataStax Graph along with synchronous processing of resultsAsynchronously Paged Results - This using the continuous paging functionality of DataStax Graph along with asynchronous processing of resultsContinuous paging is method within the DataStax Java Driver which allows for streaming of bulk records byhaving the server continuously prepare pages of results of the specified size.With this method the driver returns a "page" of results to allow for processing of those results whileadditional "pages" are being retrieved.Contributors: Dave BechbergerObjectivesTo understand the three different methods of processing graph results in JavaProject LayoutApp.java - This file contains the three functions that show the paging optionsHow this Sample WorksThis code contains methods for processing unpaged results (unpagedResults), synchronously paged results (continuousPagingSynchronous), and asynchronously paged results (continuousPagingAsynchronous).In both methods (continuousPagingSynchronous and continuousPagingAsynchronous) where paging is configured itis enabled by setting the Paging Options on the specific graph statement as seen below:ContinuousPagingOptions options = ContinuousPagingOptions.builder().withPageSize(pageSize, ContinuousPagingOptions.PageUnit.ROWS).build();statement.setPagingEnabled(true).setPagingOptions(options);Using the ContinuousPagingOptions.builder() you can set the page size that you would like to return. With graph results the only valid PageUnit is ROWS.Setup and RunningPrerequisitesJava 8A DSE Cluster running a DS Core Graph ( available at DataStax Labs )The DataStax Enterprise Java Driver for the 1.8.2.20190711-LABS Experimental 6.8 DataStax Graph ReleaseMavenBuildingIn order to build this we need to run a Maven build using:mvn clean packageThis will build and package a fat jar.RunningOnce completed you can run this program from the command line using where you must include the Cluster contact point and the graph name you want run against. This graph must existjava -cp ./target/paging-graph-results-0.1-jar-with-dependencies.jar com.datastax.graphpractice.example.App <insert cluster contact point> <insert graph name>

Illustration Image

This example shows you how to handle page graph result sets on a DataStax Graph traversal. It contains three different methods for processing results:

  • Unpaged results - This does not use paging at all and is included for comparisons sake
  • Synchronously Paged Results - This using the continuous paging functionality of DataStax Graph along with synchronous processing of results
  • Asynchronously Paged Results - This using the continuous paging functionality of DataStax Graph along with asynchronous processing of results

Continuous paging is method within the DataStax Java Driver which allows for streaming of bulk records by having the server continuously prepare pages of results of the specified size.
With this method the driver returns a "page" of results to allow for processing of those results while additional "pages" are being retrieved.

Contributors: Dave Bechberger

Objectives

  • To understand the three different methods of processing graph results in Java

Project Layout

  • App.java - This file contains the three functions that show the paging options

How this Sample Works

This code contains methods for processing unpaged results (unpagedResults), synchronously paged results (continuousPagingSynchronous), and asynchronously paged results (continuousPagingAsynchronous).

In both methods (continuousPagingSynchronous and continuousPagingAsynchronous) where paging is configured it is enabled by setting the Paging Options on the specific graph statement as seen below:

ContinuousPagingOptions options = ContinuousPagingOptions.builder().withPageSize(pageSize, ContinuousPagingOptions.PageUnit.ROWS).build();statement.setPagingEnabled(true).setPagingOptions(options);

Using the ContinuousPagingOptions.builder() you can set the page size that you would like to return. With graph results the only valid PageUnit is ROWS.

Setup and Running

Prerequisites

  • Java 8
  • A DSE Cluster running a DS Core Graph ( available at DataStax Labs )
  • The DataStax Enterprise Java Driver for the 1.8.2.20190711-LABS Experimental 6.8 DataStax Graph Release
  • Maven

Building

In order to build this we need to run a Maven build using:

mvn clean package

This will build and package a fat jar.

Running

Once completed you can run this program from the command line using where you must include the Cluster contact point and the graph name you want run against. This graph must exist

java -cp ./target/paging-graph-results-0.1-jar-with-dependencies.jar com.datastax.graphpractice.example.App <insert cluster contact point> <insert graph name>

Related Articles

jvm
rest
search

Para - backend for busy developers

John Doe

1/28/2024

Checkout Planet Cassandra

Claim Your Free Planet Cassandra Contributor T-shirt!

Make your contribution and score a FREE Planet Cassandra Contributor T-Shirt! 
We value our incredible Cassandra community, and we want to express our gratitude by sending an exclusive Planet Cassandra Contributor T-Shirt you can wear with pride.

Join Our Newsletter!

Sign up below to receive email updates and see what's going on with our company

Explore Related Topics

AllKafkaSparkScyllaSStableKubernetesApiGithubGraphQl

Explore Further

rest