<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Ryan on Medium]]></title>
        <description><![CDATA[Stories by Ryan on Medium]]></description>
        <link>https://medium.com/@Ryan-Kh?source=rss-50aa1c648e04------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/proxy/1*TGH72Nnw24QL3iV9IOm4VA.png</url>
            <title>Stories by Ryan on Medium</title>
            <link>https://medium.com/@Ryan-Kh?source=rss-50aa1c648e04------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sun, 06 Dec 2026 11:08:36 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@Ryan-Kh/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Deploy Yugabyte to Azure with CDKTF]]></title>
            <link>https://medium.com/@Ryan-Kh/deploy-yugabyte-to-azure-with-cdktf-anant-1ae6b3692450?source=rss-50aa1c648e04------2</link>
            <guid isPermaLink="false">https://medium.com/p/1ae6b3692450</guid>
            <category><![CDATA[cdktf]]></category>
            <category><![CDATA[aws-cdk]]></category>
            <category><![CDATA[terraform]]></category>
            <category><![CDATA[yugabyte]]></category>
            <dc:creator><![CDATA[Ryan]]></dc:creator>
            <pubDate>Mon, 03 Oct 2022 22:27:08 GMT</pubDate>
            <atom:updated>2022-11-04T03:46:34.061Z</atom:updated>
            <content:encoded><![CDATA[<p>In this blog post, we will explore CDKTF, testing out its ease of use with a non-AWS cloud and with a generic Terraform module. Specifically, we will see what it looks like to deploy a Yugabyte cluster to Azure using CDKTF. This post will start with an introduction to CDKTF, followed by a tutorial, and conclude with an overall evaluation of CDKTF.</p><h3>Introduction to CDKTF</h3><p>When AWS released their <a href="https://docs.aws.amazon.com/cdk/v2/guide/home.html">Cloud Development Kit </a>(CDK) for provisioning AWS resources programmatically, the benefits were obvious and made <a href="https://awsmaniac.com/hey-azure-and-google-cloud-we-need-the-aws-cdk-from-you-too/">DevOps engineers wish there was something similar for other clouds</a> such as Azure and GCP. And understandably so — being able to deploy infrastructure as code using familiar languages such as Python, Javascript, Python, and C# applies infrastructure as code (IaC) principles on a whole new level.</p><p>Enter <a href="https://www.terraform.io/cdktf">CDKTF</a> — Cloud Development Kit for Terraform. The niche is clear: CDKTF is not just language-agnostic like CDK, but is also cloud-agnostic like Terraform. Indeed, we can use any Terraform provider or module within CDKTF.</p><p>The docs say it best:</p><blockquote><em>Cloud Development Kit for Terraform (CDKTF) allows you to use familiar programming languages to define cloud infrastructure and provision it through HashiCorp Terraform. This gives you access to the entire Terraform ecosystem without learning HashiCorp Configuration Language (HCL) and lets you leverage the power of your existing toolchain for testing, dependency management, etc.</em></blockquote><h3>How CDKTF Works</h3><p>In regard to high level architecture, this diagram helps quite a bit:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*qr43Hkc9xlBSthWT.png" /><figcaption><em>(</em><a href="https://github.com/hashicorp/terraform-cdk#cdk-for-terraform"><em>CDKTF docs</em></a><em>)</em></figcaption></figure><p>As you can see, CDKTF is basically just another API to access any Terraform provider or module that’s out there. In fact, you can even mix-and-match: if you want to use CDKTF with HCL or JSON there are supported processes to do that as well.</p><p>The development process looks something like this: How it works is that (1) you start with a codebase in your chosen programming language, optionally starting from templated code using the cdktf CLI command cdktf init. (2) After writing out your app, you generate Terraform config files using the cdktf synth command. (3) At this point you have fully functioning Terraform code that you can deploy using cdktf deploy or if you want, using Terraform CLI (i.e., terraform apply).</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*eE8ro-_XPBz2A7AR.png" /><figcaption><em>(</em><a href="https://www.terraform.io/cdktf/concepts/cdktf-architecture"><em>source</em></a><em>)</em></figcaption></figure><h3>Tutorial: Deploy Yugabyte to Azure with CDKTF</h3><p>For this post we will use the <a href="https://github.com/cdktf/cdktf-provider-azurerm">CDKTF AzureRM provider</a>. CDKTF Providers are similar to a Terraform provider in function, and stand in between Terraform core with the target API (i.e., the Cloud Provider’s API).</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*MqM79FgKwzPzPsSp.png" /><figcaption><em>(</em><a href="https://www.terraform.io/cdktf/concepts/providers"><em>source</em></a><em>)</em></figcaption></figure><p>Why Azure? Well, with just straight CDK, we could build resources on AWS, and moreover, it seems like it’s easier to find guides for AWS on CDKTF already ( <a href="https://learn.hashicorp.com/tutorials/terraform/cdktf-build">e.g., here</a>). This being the case, let’s do something that requires CDKTF in particular by targeting a different cloud provider. Again, one main use case for CDKTF as opposed to just CDK is that it works on other clouds than just AWS!</p><p>There are several <a href="https://www.terraform.io/cdktf/concepts/providers#install-pre-built-providers">pre-built CDKTF providers</a> for an extra level of abstraction ( <a href="https://github.com/orgs/hashicorp/repositories?page=2&amp;q=cdktf-provider-">full list here</a>), and you can also use any Terraform provider by <a href="https://www.terraform.io/cdktf/concepts/providers#import-providers">importing the Terraform provider</a> and then using CDKTF to generate a <a href="https://www.terraform.io/language/syntax/json">JSON Terraform configuration file</a> which can then be used. For this demo though, we will be using the <a href="https://github.com/hashicorp/cdktf-provider-azurerm">CDKTF Azure Provider</a> along with the Yugabyte DB Cluster module.</p><p>We will be mostly <a href="https://learn.hashicorp.com/tutorials/terraform/cdktf-install?in=terraform/cdktf">following this</a> guide to start, but with adjusted steps in order to use <a href="https://github.com/hashicorp/cdktf-provider-azurerm">CDKTF AzureRM Provider</a> instead of AWS Provider. We will also be using the <a href="https://docs.yugabyte.com/preview/deploy/public-clouds/azure/terraform/">Yugabyte Terraform module</a> to test out CDKTF’s compatibility with Terraform Modules.</p><p>You can find the finished code base at: <a href="https://github.com/Anant/example-cdktf-yugabyte-azure">https://github.com/Anant/example-cdktf-yugabyte-azure</a></p><p>By the way: this post is a bit over the top in the amount of steps it records, even to the point of being pedantic. This is purposeful to some degree however. As I will comment on later, one major shortcoming of CDKTF is the lack of documentation and examples. Hopefully this will prove to be useful for at least somebody.</p><h3>Prereqs</h3><ul><li><a href="https://www.python.org/downloads/">Python</a> v3.7 and <a href="https://pipenv.pypa.io/en/latest/install/#installing-pipenv/">pipenv</a> v2021.5.29</li><li><a href="https://learn.hashicorp.com/tutorials/terraform/install-cli">Terraform CLI</a>. This is what the CDKTF CLI will be running under the hood.</li><li><a href="https://docs.microsoft.com/en-us/cli/azure/install-azure-cli-linux?view=azure-cli-latest">Azure CLI</a>. This is a prerequisite in general for using the AzureRM Terraform provider. After you install the CLI, make sure to run az login to authenticate to your Azure account.</li></ul><h3>Initialize CDKTF Project</h3><p>CDKTF CLI can be used to generate your boilerplate code, which is what we will do here. We will be using Python code for this example, so we will use something like this:</p><pre>mkdir cdktf-azure-demo <br>cd cdktf-azure-demo/ <br>cdktf init --template=python --local</pre><p>This will give us the main CDKTF configuration files as well as a main.py file to start coding on.</p><h3>Setup CDKTF Azure Provider</h3><p>Next we need to add and setup the CDKTF AzureRM Provider.</p><p>First, <a href="https://www.terraform.io/cdktf/concepts/providers#add-provider-to-cdktf-json">add the provider using CDKTF CLI</a>. We will use version 2.0 in order to be compatible with the Yugabyte module that we’re adding later.</p><pre>cdktf provider add &quot;azurerm@~&gt;2.0&quot;</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/894/0*niqgUzRP8iYsnrSt.png" /></figure><p>We can see that this command made changes to our Pipfile as well:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/550/0*_o_S1SWCDbFTJ186.png" /></figure><h3>Add Azure Provider to cdktf.json</h3><p>The preceding steps added the Azure provider to our pipenv, but as far as I can tell, we still need to add it to this specific project. For that, we will need to add it to our cdktf.json file. At this point our cdktf.json file should look something like this:</p><pre>{ <br>  &quot;language&quot;: &quot;python&quot;, <br>  &quot;app&quot;: &quot;pipenv run python main.py&quot;, <br>  &quot;projectId&quot;: &quot;your-project-id&quot;, <br>  &quot;sendCrashReports&quot;: &quot;true&quot;, <br>  &quot;terraformProviders&quot;: [&quot;azurerm@~&gt; 2.0&quot;], <br>  &quot;terraformModules&quot;: [], <br>  &quot;codeMakerOutput&quot;: &quot;imports&quot;, <br>  &quot;context&quot;: { <br>    &quot;excludeStackIdFromLogicalIds&quot;: &quot;true&quot;, <br>    &quot;allowSepCharsInLogicalIds&quot;: &quot;true&quot; <br>  } <br>}</pre><h3>Generate CDKTF Constructs for Azure Provider</h3><pre>cdktf get</pre><p>This won’t output much, but should give a generic success message:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*K6NeKJIqgW0RhQZK.png" /></figure><p>We can see the downloaded cdktf provider is now in the project directory’s imports folder.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/222/0*z40xhvMCo5R9uQ9O.png" /></figure><h3>Import Azure Classes into CDKTF Python code</h3><p>We can now <a href="https://www.terraform.io/cdktf/concepts/providers#import-classes">import the AzureRM classes</a> from the new generated folder in our main.py file and write some Python. For this we will start simple, and go from there. You can find some <a href="https://github.com/hashicorp/terraform-cdk/tree/main/examples/python/azure">sample code in the terraform-cdk repo</a> that will get us started. Mine looks like this:</p><pre>#!/usr/bin/env python<br>from constructs import Construct<br>from cdktf import App, TerraformStack, TerraformOutput, Token<br>from imports.azurerm import AzurermProvider, ResourceGroup, VirtualNetwork</pre><pre>class MyStack(TerraformStack):<br>  def __init__(self, scope: Construct, ns: str):<br>    super().__init__(scope, ns)</pre><pre>## define resources here<br>    location=&quot;Southeast Asia&quot;<br>    address_space=[&quot;10.12.0.0/27&quot;]<br>    resource_group_name=&quot;yugabyte-rg&quot;<br>    tag = {<br>      &quot;ENV&quot;: &quot;Dev&quot;,<br>      &quot;PROJECT&quot;: &quot;AZ_TF.Yugabyte&quot;<br>    }<br>    features = {}</pre><pre>AzurermProvider(self, &quot;Azurerm&quot;,<br>      features=features<br>    )<br>    resource_group = ResourceGroup(self, &#39;yugabyte-rg&#39;,<br>      name=resource_group_name,<br>      location = location,<br>      tags = tag<br>      )<br>    example_vnet = VirtualNetwork(self, &#39;example_vnet&#39;,<br>      depends_on =[resource_group],<br>      name=&quot;example_vnet&quot;,<br>   location=location,<br>      address_space=address_space,<br>   resource_group_name=Token().as_string(resource_group.name),<br>      tags = tag<br>      )<br>    TerraformOutput(self, &#39;vnet_id&#39;,<br>      value=example_vnet.id<br>      )</pre><pre>app = App()<br>MyStack(app, &quot;cdktf-azure-demo&quot;)</pre><pre>app.synth()</pre><p>Nothing fancy so far, just creates a resource group and a Virtual network.</p><h4>Test Deploy to Azure</h4><p>Run cdktf deploy and it should start. Select &quot;Approve&quot; and your resources should be created.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*5Y_axzpN9632Nvvy.png" /></figure><p>You can check in Azure under “Resource Groups” to make sure it got created:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*Th5Jx1eQnuAClPTe.png" /></figure><p><strong>Cleanup resources</strong></p><p>This was enough to confirm that everything is wired up between CDKTF, Terraform core, and Azure. Now we’re ready to also deploy a Yugabyte cluster. Let’s cleanup first though before going any further:</p><pre>cdktf destroy</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*doLy4SECMZTjENAa.png" /></figure><h3>Configuring the Yugabyte-Azure Module for CDKTF</h3><p>Now that Terraform is successfully connecting to Azure, let’s deploy Yugabyte. We chose Yugabyte for this demo since it has a module for Terraform already, but at the same time is not a widely used module (it is not even in the Terraform registry) and so we should hopefully be able to get a feel for whether CDKTF really works with any arbitrary Terraform module that we want to use. We will use the <a href="https://www.terraform.io/cdktf/concepts/modules">CDKTF Modules API</a> to get this working.</p><p>Now to be clear, often this kind of configuration is done in Ansible rather than Terraform. The general rule of thumb is to provision infrastructure using Terraform and manage configuration (installation, set config files, etc) using Ansible.</p><p>However, one difference that CDK-TF has over straight Terraform is that it allows you to write pure Python, which could be enough of an advantage to put both provisioning and configuration on a single tool. Let’s give it a try.</p><h4>Add Yugabyte module to cdktf.json</h4><p>First we need to <a href="https://www.terraform.io/cdktf/concepts/modules#add-module-to-cdktf-json">add the module</a> to our cdktf.json file, under terraformModules. It should now look something like this:</p><pre>{<br>  &quot;language&quot;: &quot;python&quot;,<br>  &quot;app&quot;: &quot;pipenv run python main.py&quot;,<br>  &quot;projectId&quot;: &quot;your-project-id&quot;,<br>  &quot;sendCrashReports&quot;: &quot;true&quot;,<br>  &quot;terraformProviders&quot;: [&quot;azurerm@~&gt; 2.0&quot;],<br>  &quot;terraformModules&quot;: [{ <br>    &quot;name&quot;: &quot;terraform_azure_yugabyte&quot;, <br>    &quot;source&quot;: &quot;github.com/yugabyte/terraform-azure-yugabyte.git&quot;<br>  }],<br>  &quot;codeMakerOutput&quot;: &quot;imports&quot;,<br>  &quot;context&quot;: {<br>    &quot;excludeStackIdFromLogicalIds&quot;: &quot;true&quot;,<br>    &quot;allowSepCharsInLogicalIds&quot;: &quot;true&quot;<br>  }<br>}</pre><p>It appears that you can use any value for the &quot;name&quot; key that you want, but whatever you use will determine the class import in your python code.</p><p>We will then use the same command that we did before to generate bindings, but this time for the Yugabyte module.</p><pre>cdktf get</pre><h4>Update main.py file</h4><p><a href="https://docs.yugabyte.com/preview/deploy/public-clouds/azure/terraform/#create-a-terraform-configuration-file">The Yugabyte Azure module documentation</a> for using Vanilla Terraform gives the variables that we would need to set if using this module in Terraform arguments. We take those variables and instead of passing them into the module definition in the .tf file, we pass them into the YugabyteCluster class instance.</p><pre>yugabyte_cluster = TerraformAzureYugabyte(self, &quot;yugabyte-cluster&quot;, <br> ssh_private_key = os.environ[&quot;PATH_TO_SSH_PRIVATE_KEY_FILE&quot;],<br> ssh_public_key =  os.environ[&quot;PATH_TO_SSH_PUBLIC_KEY_FILE&quot;],<br> ssh_user = &quot;SSH_USER_NAME&quot;,<br> ## The region name where the nodes should be spawned. <br> region_name = location, <br> ## The name of resource group in which all Azure resource will be created. <br> resource_group = &quot;test-yugabyte&quot;,<br> ## Replication factor. <br> replication_factor = &quot;3&quot;,<br> ## The number of nodes in the cluster, this cannot be lower than the replication factor. <br> node_count = &quot;3&quot;,<br>)</pre><p>How did I know this is the way to do it? And how did I know that the class to import was called TerraformAzureYugabyte in the first place?</p><p>Well…to be honest it was just a guess. Maybe it’s documented somewhere, but if so, I couldn’t find it. For the classname TerraformAzureYugabyte, I used the exact name that I set in the cdktf.json for the module ( terraform_azure_yugabyte), but in camel case instead of snake case.</p><p>For what keyword args we are to pass into the TerraformAzureYugabyte instead, I basically just copied and pasted in the HCL variables, adding commas at the end of lines so that it works as keyword arg, and replacing some of their sample strings with variables that we already set when running Azure stuff.</p><p>More on this later, but again, documentation seems to be a weak spot for the CDKTF project overall.</p><h3>Deploy Yugabyte to Azure with CDKTF</h3><p>Anyways, continuing on: since we are reading from env vars in our Python code, we will need to set those in the terminal:</p><pre>export PATH_TO_SSH_PRIVATE_KEY_FILE=&lt;your path&gt; <br>export PATH_TO_SSH_PUBLIC_KEY_FILE=&lt;your path&gt;</pre><p>In our case, since the Yugabyte module sets up the infrastructure as well, we also need to make sure to delete the resource definitions we made before for resource group and virtual network. For the final result of what the code looks like, <a href="https://github.com/Anant/example-cdktf-yugabyte-azure/blob/master/main.py">see our sample repo</a>.</p><p>Finally, deploy using cdktf deploy. As before, first it will &quot;synthesize&quot; (generate Terraform config files from your python code):</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*IujQpfjDOrx284wu.png" /></figure><p>Then it will come up with a plan (similar to terraform plan) and ask for your approval:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*wYIOUp6DFnz8-uWO.png" /></figure><p>Looking good!</p><p>In Azure, you should be able to see a three node cluster in your resource group (based on the resource group configured in your python code), complete with a security group, Public IPs, and everything else that the Yugabyte module configures for you:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*tgANULShQDkJca1R.png" /></figure><h3>Test CDKTF Compatibility with Terraform CLI</h3><p>CDKTF can also generate tf.json files that we can use with the Terraform cli. We could generate these files using <a href="https://www.terraform.io/cdktf/cli-reference/commands#synth">cdktf synth</a>, but this is unnecessary in our case since we already ran cdktf deploy, which generates these files just as well.</p><p>First, navigate to the folder for your particular <a href="https://www.terraform.io/cdktf/concepts/stacks">CDKTF stack</a>.</p><pre>cd ./cdktf.out/stacks/cdktf-azure-demo</pre><p>In this folder, we see the cdk.tf.json file that contains the Terraform configuration for our setup (written according to <a href="https://www.terraform.io/language/syntax/json">Terraform JSON specs</a>), as well as the <a href="https://stackoverflow.com/a/59289696/6952495">.terraform directory</a> that contains other Terraform metafiles.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/662/0*KbBzPMHdOXSgE5x3.png" /></figure><p>All of these files and concepts should be fairly familiar to you if you have used regular vanilla Terraform in the past.</p><p>With this .tf.json file, you can run arbitrary Terraform CLI commands. For example, here is the output of terraform plan:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*aYodr_LNBGu0cwXi.png" /></figure><p>Or you can deploy the code using terraform apply. This would have the same net effect as doing cdktf deploy from the project&#39;s main directory, but using standard Terraform procedures. For example, in the screenshot below, you can see that the terraform apply command runs the plan then prompts for whether to create the resources, just like normal terraform:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*Z4SIR8tPt79RKxeY.png" /></figure><p>In our case, we don’t need to do this, since we already deployed our infrastructure using cdktf deploy. However, we can benefit from the Terraform CLI compatibility for accessing other information about our Terraform deployed infrastructure, such as to SSH into our nodes.</p><p>In our main.py we specified that the user would be yugabyte, so we can use that user to ssh in. You can get the ip address from the Azure GUI, but who wants to do that? We can use the terraform files that CDKTF automatically generated by doing something like this:</p><pre>cd ./cdktf.out/stacks/cdktf-azure-demo <br>terraform state show module.yugabyte-cluster.azurerm_public_ip.YugaByte_Public_IP[0]</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*4wwttpRYpfcrQN6N.png" /></figure><p>In this way, we can access all kinds of terraform internals. For example, we can use the information from Terraform deployment metadata to SSH into the provisioned node. The Yugabyte module relied on the PATH_TO_SSH_PRIVATE_KEY_FILE env var to interact with your VMs before, so you should be able to use that same env var to ssh in now.</p><pre>ssh yugabyte@20.198.220.125 -i $PATH_TO_SSH_PRIVATE_KEY_FILE</pre><h3>Cleanup Yugabyte cluster in Azure with CDKTF</h3><p>Then of course, run cdktf destroy to tear it all down:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*QiPgahn57y-_0_8q.png" /></figure><h3>Some concluding thoughts on CDKTF</h3><p>Overall, CDKTF is a fun tool to try out. There is clearly a lot of potential here and many reasons why someone would want to try it out. Being able to make use of the entire Terraform ecosystem, but with Python or Java instead of config files opens up a whole set of new possibilities.</p><p>At the same time, there are a couple key concerns that make me hesitant to recommend CDKTF without reservations. Please bear in mind that I am speaking only from my limited experience, but these are the two concerns that jumped out at me: (1) documentation and (2) overall community support.</p><h3>Concern about Documentation</h3><p>First, documentation. Perhaps because it is a relatively newer tool, documentation and guides are a bit lacking. Relatively speaking, there does seem to be more examples and documentation given for AWS and Javascript as opposed to other clouds or languages (e.g., <a href="https://youtu.be/pj6iEqtYVsQ">the Mozilla Pocket project</a>). Unfortunately, if you wanted to use straight AWS, it might make sense to just use vanilla CDK rather than CDKTF. And if you want to Javascript for DevOps…well, that’s your prerogative, but at the very least we can agree that often we would want to use some other programming language instead like Python, and would want that to be documented as well.</p><p>To make matters worse, the Terraform modules can often be under-documented as well. In such cases, sometimes the best (or only) option is to do some source code diving. While this problem is not unique to this tool by any means, this is particularly a concern for CDKTF, where a key selling point is to have a language-agnostic abstraction over your Terraform code.</p><p>This kind of defeats the purpose of one of the advertised benefits of using CDKTF, namely that you don’t have to learn HashiCorp Configuration Language (HCL). You will have to learn it anyways if you use any modules or any Terraform provider that hasn’t been ported into a CDKTF provider (of which there are plenty). And then you have to translate that into Python (or whatever language you chose) on top of that, thereby creating just one more way for things to go wrong.</p><p>Hopefully this project will become better documented in time.</p><h3>Concern about Community and Support</h3><p>A second concern is related: the overall community and support surrounding CDKTF. Overall, my impression at this point at least is that this is a bigger issue potentially. In fact, a lack of a strong community, which goes hand in hand with lack of adoption in general, can often be both a cause and effect of under-documented projects.</p><p>At the time of writing, the <a href="https://github.com/hashicorp/terraform-cdk">Terraform-CDK repo in Github</a> has just a bit less than four thousand stars and <a href="https://github.com/aws/aws-cdk">CDK</a> (the parent project) has over nine thousand stars, which is pretty decent actually. But there just doesn’t seem to be enough activity, enough example code, or enough of a thriving community to the point where I would be able to confidently recommend building a platform’s entire architecture on it for most projects.</p><h3>Potential Use Cases</h3><p>That said, there are still use cases where I could CDKTF to be worth consideration. One example is if your project has some fairly unique deployment needs where the flexibility of a full-on programming language is a better fit than HCL files. For instance, perhaps if your deployment code will need to have a lot of dynamic variables, including perhaps calculation or other flow-control operations, then being able to do that in a programming language like Python could make a lot of sense.</p><h3>Alternatives</h3><p>Depending on your use case, there are other alternatives that are worth considering. Depending on how much abstraction makes sense for your project, you might consider using tools such as:</p><ul><li><a href="https://github.com/beelit94/python-terraform">python-terraform</a> (a Python wrapper around the Terraform CLI)</li><li><a href="https://www.pulumi.com/">Pulumi</a> (I don’t have experience with it, but seems similar in concept to CDKTF in that you can use various programming languages to employ architecture to your choice of cloud)</li><li><a href="https://cdk8s.io/">CDK8s</a> (CDK for Kubernetes)</li><li>Or of course, just make some Bash or Python script wrappers around your regular Terraform code</li></ul><p><em>Originally published at </em><a href="https://anant.us/blog/deploy-yugabyte-to-azure-with-cdktf/"><em>https://anant.us</em></a><em> on October 3, 2022.</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=1ae6b3692450" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Visualize Data from Cassandra in Superset]]></title>
            <link>https://medium.com/@Ryan-Kh/visualize-data-from-cassandra-in-superset-e35500a95e06?source=rss-50aa1c648e04------2</link>
            <guid isPermaLink="false">https://medium.com/p/e35500a95e06</guid>
            <category><![CDATA[apache-cassandra]]></category>
            <category><![CDATA[tutorial]]></category>
            <category><![CDATA[presto]]></category>
            <category><![CDATA[data-visualization]]></category>
            <category><![CDATA[apache-superset]]></category>
            <dc:creator><![CDATA[Ryan]]></dc:creator>
            <pubDate>Wed, 21 Sep 2022 20:14:55 GMT</pubDate>
            <atom:updated>2022-09-27T13:29:32.566Z</atom:updated>
            <content:encoded><![CDATA[<p>In this post, I will walk through how to visualize data from Cassandra in Superset (by means of <a href="https://prestodb.io/">Presto</a>), and along the way share some observations about my experience and potential use cases that might be interesting for you.</p><p><a href="https://superset.apache.org/">Apache Superset</a> has been around for a while now and has gained quite a bit of traction. I personally heard about it through an interview on the Astronomer podcast with <a href="https://twitter.com/mistercrunch">Maxime Beauchemin</a>, who is the creator of not only Apache Airflow, but Superset as well. Having an interest in data visualization, I’ve been looking forward to exploring Superset and seeing what it contributes to the larger data visualization ecosystem as a whole.</p><p>Quick disclaimer: I approach this topic more as a data engineer than a data scientist and will be writing from that perspective, so I will be writing from that perspective. Hopefully, it will be helpful for other data engineers who, like me, have limited experience with data visualization but want to learn more.</p><h3>Introduction to Superset</h3><p>Superset bills itself as “a modern data exploration and visualization platform.” It will come as no surprise to learn that it is built to work well with distributed platforms, given that its creator also created Apache Airflow. In its docs, Superset claims that it is “cloud-native and designed to be highly available. It was designed to scale out to large, distributed environments and works very well inside containers. While you can easily test drive Superset on a modest setup or simply on your laptop, <strong>there’s virtually no limit around scaling out the platform</strong>.”</p><p>Part of how it does this is through its infrastructure, which requires a webserver, a metadata db engine, a message queue, a results backend, and a caching layer. Some of these components can overlap — for example, in the setup for this tutorial, we will cover these five requirements with just these three components: Gunicorn webserver, Redis (for the message queue, results backend, and caching), and Postgres (for the metadata db).</p><h3>Ingesting your Cassandra data into Superset</h3><p>In regard to how you ingest your data, Superset works with most interfaces that support SQL queries. This means that while <a href="https://www.yugabyte.com/">Yugabyte</a> for example, <a href="https://superset.apache.org/docs/databases/yugabytedb">works out of the box</a> due to its Postgres compatibility, <a href="https://github.com/apache/superset/issues/3228">Cassandra does not</a>. For this reason, if you want to visualize data from Cassandra in Superset, a post by the Senior Developer Advocate for Superset <a href="https://stackoverflow.com/a/68317908/6952495">recommends using an intermediate query engine like Trino or Presto</a>. This setup provides the SQL compatibility to Cassandra that we need, as well as other benefits that come with such a tool in the process.</p><h4>What we cover in this post</h4><p>First, we will connect Cassandra with Presto using docker-compose. From there, we will follow <a href="https://superset.apache.org/docs/installation/installing-superset-using-docker-compose/#:~:text=connect%20to%20other%20databases">this guide to setting up Superset in docker-compose</a> to connect Superset to Presto. You can find the code behind this post <a href="https://github.com/Anant/example-cassandra-presto-superset">on GitHub</a>.</p><h3>Step 1: Connecting Presto with Cassandra</h3><p>For connecting Presto with Cassandra, there is nothing too novel with this process, as it has been <a href="https://prestodb.io/docs/current/connector/cassandra.html">well documented already</a>. We will be using the docker image provided by Ahana; for more information on that container, <a href="https://hub.docker.com/r/ahanaio/prestodb-sandbox">see here</a>.</p><p>In order to avoid putting more details in here than we need to, for this part of the tutorial you can follow the <a href="https://prestodb.io/docs/current/connector/cassandra.html">README in the GitHub repo</a> for a step-by-step guide.</p><p>The gist of it is to start up the Docker containers using docker-compose, then create a catalog in Presto for Cassandra. We will name ours cassandra (go figure).</p><h3>Ingest Sample Data into Cassandra</h3><p>We will also ingest some sample data at this point as explained in the GitHub README. For this, you can ingest by doing writes through Presto (using SQL) or CQLSH (using CQL).</p><p>At this point, our data is now accessible in two ways: 1) From Cassandra directly:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*JKVy6cw3wuBZbPG8.png" /></figure><p>Or 2) Using Presto, e.g., using the Presto CLI:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*8tnr-lVyU8PFqX08.png" /></figure><p>Again, although our main point of this exercise is to connect Cassandra to Superset, we also get other benefits of having Presto in the process, e.g., if you run some queries here, you can see a record of what queries were run in the Presto GUI Dashboard:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*WcuGoeDO9P3G2xEH.png" /></figure><h3>Step 2: Connecting Superset to Cassandra with Presto</h3><p>Now that we have Cassandra hooked up to Presto, we can connect Presto with Superset.</p><h3>Setup Superset</h3><p>First, we will <a href="https://superset.apache.org/docs/installation/installing-superset-using-docker-compose">install Superset using docker compose</a>. The recommended way to do this is through cloning the <a href="https://github.com/apache/superset">Superset repo</a> and using their Dockerfiles and docker-compose yaml files directly. (Again, more detailed instructions can be found in <a href="https://github.com/Anant/example-cassandra-presto-superset/blob/main/README.md#setup-superset">our repo’s README</a>).</p><p>This will set us up with a Superset instance with the following components:</p><ul><li>Web server: Gunicorn</li><li>Metadata database engine: Postgres</li><li>Message queue: Redis</li><li>Results backend: Redis</li><li>Caching layer: Redis</li></ul><p>After running docker-compose up, it is now set up here: <a href="http://localhost:8088.">http://localhost:8088.</a> After you log in, you are greeted with a screen that looks like this:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*vuL_xmh8ZaWSy6-o.png" /></figure><p>As nice as it is to start off with a “clean slate” as it were, it is even better to have some sample datasets without having to connect anything, and Superset provides just that. For example, there is a sample dashboard with World Bank Data:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*3NeVMi1I7HI3ytGZ.png" /></figure><p>That won’t help us however, we want to see our data from Cassandra!</p><h3>Connect Superset to Cassandra through Presto</h3><p>First, add a Data connection using “Data &gt; Connect Database”:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*rA4Wi157nJwzUAcS.png" /></figure><p>From there, select “Presto”:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/748/0*MeKS6SpT1HVvjYPg.png" /></figure><p>One way to access Presto from Superset would be to put them in the same docker network, e.g., by putting in same docker-compose.yml file or chaining the two docker-compose.yml files using something like:</p><pre>docker-compose -f ../superset/docker-compose-non-dev.yml -f docker-compose.yml up -d</pre><p>However, instead, we will just take advantage of the exposed ports on the Presto container. Get our host IP using:</p><pre>hostname -I | awk &#39;{print $2}&#39;</pre><p>This will result in the connection address looking something like this (using cassandra as path, since that is what we named our catalog that connects to our Cassandra instance):</p><pre>presto://&lt;result-from-last-step&gt;:8080/cassandra</pre><p>Insert that into the box, and test the connection to make sure it looks good:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*t4cD-sc3aVFutZHK.png" /></figure><h3>Test Some Queries in Superset</h3><p>You should now be ready to run some SQL queries through Presto to read from your C* db. Superset includes an SQL IDE called <a href="https://apache-superset.readthedocs.io/en/latest/sqllab.html">SQL Lab</a> expressly for this purpose.</p><p>Navigate to SQL &gt; SQL Lab to get started:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/870/0*VZOV28GXFrqn_gLG.png" /></figure><p>Make sure to select “Presto” as your Database, and then you can run arbitrary Presto SQL in the query command box. The result should look like this:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*G5-UgNUxf5mm2gDe.png" /></figure><h3>Step 3: Visualize Your Cassandra Data</h3><p>Of course, we didn’t go through all this trouble just so we could query our data! We want to visualize it!</p><p>Finally, we are ready to visualize data from Cassandra in Superset. First, we need to create a “Dataset” in Superset. Navigate to “Datasets” and click the “+ Dataset” button:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*8Wpn886UAc1MxoJ0.png" /></figure><p>Let’s start with demo.spacecraft_journey_catalog:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/900/0*rwDr8EYQJJtFW8HP.png" /></figure><p>Now let’s make some charts for demo.spacecraft_journey_catalog. Adding the table as a dataset will bring us to this view automatically, so we can just start creating some charts.</p><h3>Visualize Spacecraft Data</h3><p>Some examples include:</p><p><strong>A pie chart showing “Journeys per spacecraft”</strong></p><p>We can use a COUNT(*) query to see how many unique journey_id&#39;s there are per spacecraft name.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*XiMjg8RYEvmSJQO5.png" /></figure><p><strong>A time series chart for “Journeys per year”</strong></p><p>By using the start column, we can do some time series line charts, such as finding out how many journeys started in a given year.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*_cI_J7-Ax9R50HDp.png" /></figure><p><strong>Speed over time</strong></p><p>We can also do a similar thing with demo.spacecraft_speed_over_time. Make sure to set up the Dataset for this as well, just as we did with the previous C* table.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*Gy9E2LbubiR96zSZ.png" /></figure><h3>Visualize Cassandra Data using Joins</h3><p>Part of the advantage of using Presto is that it allows joins between tables, which is not allowed in raw CQL. Of course, depending on your data model you might have to be careful running these operations so you don’t bring down your nodes (!).</p><p>As before, make sure to create all of the needed datasets first. Then run the join in SQL Lab:</p><pre>select spacecraft_journey_catalog.spacecraft_name, spacecraft_journey_catalog.summary, spacecraft_speed_over_time.speed, spacecraft_speed_over_time.reading_time from spacecraft_journey_catalog inner join spacecraft_speed_over_time on spacecraft_journey_catalog.journey_id = spacecraft_speed_over_time.journey_id;</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*6qP2rmeBikXYkmDq.png" /></figure><p>From there, click the “Create Chart” button to visualize the results.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/532/0*5zP2-0eHteZTsfFm.png" /></figure><p>Put the visualizations together, and you have the start of a working dashboard:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*PLXuzlcIjbSFOiki.png" /></figure><h4>Geocoding Visualizations</h4><p>Using <a href="https://github.com/DataStax-Academy/data-modeling-sensor-data/blob/main/assets/sensor_data.cql">Datastax Academy Sample sensor data</a> we can also get some cool maps going in Superset. This will require a Mapbox API token (the <a href="https://docs.mapbox.com/accounts/guides/tokens/#default-public-access-token">default public token</a> worked great for me).</p><p>With a basic setup and the sample scripts included here, you can quickly generate some maps from your data:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*rb2zOAWSCko_E8g1.png" /></figure><p>You can limit “Clustering Radius” to 0 (so that sensors are not grouped together at all) and filter by network name to see specific locations of sensors within a given network:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*iHqPrA99FdITWSw9.png" /></figure><p>Making a chart representing temperatures for sensors is also pretty straightforward:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*S2zRf30o-ytWuRqq.png" /></figure><p>Already we see the advantages of what Superset calls their “simple no-code viz builder”. Even with such fairly generic datasets as we used here, we are able to derive insights and create visualizations without very much hassle or configuration at all. It did not matter that I have never even tried Mapbox before — all it took was a couple of columns with “latitude” and “longitude” data and we were able to create several visualizations that could be plotted directly to several different kinds of maps.</p><p>And again, using the charts we put together, we can view them together in a single dashboard:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*vogXFGNVCLWsGefu.png" /></figure><h3>Other Potential Use Case: Visualize Cassandra System Metrics</h3><p>Before concluding this post, I thought I would share another potential use case for Mapbox with Cassandra in particular. Without much effort at all, Apache Superset allows you to create custom visualizations for Cassandra system data using the system keyspace.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/807/0*dv7nFnn_G5CNgGaG.png" /></figure><p>Of course, there are other tools made especially for Cassandra cluster metrics such as Prometheus with Grafana, but it is a possibility that might be worth exploring.</p><h3>Conclusion</h3><p>It is easy to tell why Superset has become so popular: it is powerful, it creates beautiful visualizations, and <em>it is simple</em>. Frankly, I was surprised at how seamless the whole process was. Having dabbled with various Python and Javascript charting libraries before, I found Apache Superset was extremely easy to use and well documented. There are sane defaults for what kinds of visualizations you want to make, but with quite a lot of customization allowed as well.</p><p>The initial integration process was also pretty straightforward. It would be nice to have some docker-compose files available that didn’t require cloning the whole Superset repo, but that is not even worth complaining about, and will probably come with time.</p><p>At the same time, this much infrastructure might or might not be reasonable for your project. Just to run Superset on its own, we needed to add Redis and Postgres. To visualize Cassandra data specifically in Superset, there is no direct connector at this point, unfortunately, which means users need to add an intermediate layer such as Presto or Trino in addition. If your project has some of these tools already, this might not be a problem, but it is something to consider.</p><p>Another potential concern would be if your charts need to have a lot of interaction, especially custom interaction. I did not explore thoroughly enough to say anything for certain and there is some interactivity available (e.g., see this demo from ApacheCon Asia 2022). However, in general, “no-code” means limitations for customization, so I would be careful in this regard if you have specific needs.</p><h4>Credits</h4><p>This post on how to visualize Cassandra data in Superset is built off of <a href="https://anant.us/blog/open-source-bi-tools-and-cassandra/">the more general post</a> about Open Source BI Tools written by my teammate <a href="https://anant.us/blog/author/arpanpatel/">Arpan Patel</a>.</p><p>Our spaceship dataset is based on the SparkSQL notebook from <a href="https://www.datastax.com/dev/datastax-studio">Datastax Studio</a>. For the basic schema on which this was based, see the <a href="https://github.com/DataStax-Examples/getting-started-with-astra-python/blob/master/schema.cql">examples provided here</a>. Data entries and schema were modified slightly by Arpan Patel and made available by <a href="https://github.com/Anant/example-cassandra-presto-airflow/blob/main/setup.cql">his demo for Presto, Airflow, and Cassandra here</a>. The data was modified again for this current demo.</p><p>We also borrowed from Datastax Academy Sample sensor data. Slight modifications were made to make sure it runs in the correct keyspace.</p><p><em>Originally published at </em><a href="https://anant.us/blog/visualize-data-from-cassandra-in-superset/"><em>https://anant.us</em></a><em> on September 21, 2022.</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=e35500a95e06" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[DSE Graph in G.V() IDE]]></title>
            <link>https://medium.com/@Ryan-Kh/dse-graph-in-g-v-ide-business-platform-team-84279d58b3f9?source=rss-50aa1c648e04------2</link>
            <guid isPermaLink="false">https://medium.com/p/84279d58b3f9</guid>
            <category><![CDATA[developer-tools]]></category>
            <category><![CDATA[tinkerpop]]></category>
            <category><![CDATA[visualization]]></category>
            <category><![CDATA[datastax]]></category>
            <category><![CDATA[graph]]></category>
            <dc:creator><![CDATA[Ryan]]></dc:creator>
            <pubDate>Fri, 03 Jun 2022 20:01:00 GMT</pubDate>
            <atom:updated>2022-11-04T03:46:06.335Z</atom:updated>
            <content:encoded><![CDATA[<p>For several months now I have had my eye on <a href="https://gdotv.com/">G.V() IDE</a>, an exciting new development in the Tinkerpop/Gremlin world. However, I wanted to wait for G.V() IDE to have compatibility with DSE Graph before giving it a test run — which became true as of the recent <a href="https://twitter.com/gdotv_ltd/status/1516025768580636673">0.9.14 release</a>. Why is this an exciting new development, you may ask? A major hurdle for new developers getting started with Tinkerpop is the query language. While there is documentation and an active community that is (surprisingly) responsive and willing to help beginners, the Gremlin query language still creates a learning curve.</p><p>Add to that the difficulty of identifying mistakes until runtime, and the process of developing applications in Gremlin can become quite demanding.</p><p>However, lately, there have been various efforts at helping mitigate this learning curve. <a href="https://blog.anant.us/janusgraph-on-jupyter-using-notebooks-with-graph/">Previously</a> I reviewed AWS Graph Notebook, a tool that provides a Jupyter notebook environment for graph databases. In this post, I will be taking a look at another tool that provides out-of-the-book visualization and REPL interactivity for Tinkerpop, but this time around in the form of an IDE: <a href="https://gdotv.com/">G.V()</a>.</p><p>The name of the IDE (pronounced “g dot v”) might be strange for the uninitiated, but it refers to the core syntax that starts a vast majority of Gremlin queries: g.v(), which we perhaps can say is somewhat akin to the famous SELECT * from the relational DB world.</p><p>Beyond just visualization, I’d say its main selling point is help in both writing Gremlin queries (through code autocompletion, linting, etc) and parsing the queries’ results, which can be a journey in itself.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*oSDt7Sbj5f4jPXZxnoY_7g.png" /><figcaption><em>(Just to say: Sometimes the gremlin console output can be something of a head-scratcher)</em></figcaption></figure><p>In its own words:</p><blockquote>G.V() is an all-in-one Gremlin IDE to write, test and analyze results for your Gremlin graph database. It offers rich a UI with smart autocomplete, graph visualization, editing and connection management.</blockquote><p>In this post, I will provide a quick-start guide (complete with <a href="https://github.com/Anant/dse-gdotv-demo">docker-compose file and bash startup scripts</a>) as well as some initial impressions.</p><h3>Getting started</h3><p>The G.V() IDE GUI is overall pretty intuitive to use, and there’s even a one-click option to start playing around in a Gremlin Playground.<br>However, one thing, in particular, that wasn’t as clear for me at least was how to create a connection to DSE. In the next section, I outline a way to get quickly set up with DSE Graph and G.V() IDE.</p><h3>Setup your DSE Graph</h3><p>Actually, before you can make a connection from G.V() IDE to your DSE Graph, you need to initialize your graph in DSE first, or else it will refuse to connect, saying There is no graph available.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/768/1*DpimTx6tXdxc7QI2IOr4uw.png" /></figure><p>We have some scripts and a docker-compose file you can use if you want to follow along on your own machine, which you can find here: <a href="https://github.com/Anant/dse-gdotv-demo">https://github.com/Anant/dse-gdotv-demo</a>. Follow the instructions in the README there, and then come back here when you’re finished.</p><h3>Configure a connection from G.V() IDE to DSE Graph</h3><p>After accepting some EULA agreements and so on, we are greeted with a screen that looks like this:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/768/1*Z5p2Jbx4GFTwBq__je6fdQ.png" /></figure><p>Click the “Add New Connection” button and then, in the modal that pops up, “Advanced Settings”.</p><p>With DSE 6.8 running on docker on my local machine, I simply put in the following:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/768/1*Z5p2Jbx4GFTwBq__je6fdQ.png" /></figure><p>Note that neighborhoods_dev.g is because our graph is called neighborhoods_dev, so this creates an alias to that graph in particular. If you are using a different data set you will have to change this to match your graph name.</p><h3>Some Highlights in G.V() IDE</h3><p>There’s much to say about G.V() IDE, but here are some features in particular that are worth highlighting.</p><h3>Graph Model Explorer</h3><p>With just a click, you can see what your data model is and how different entities relate to each other:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/768/1*uLFjwg5CU914p4r-QFLfdA.png" /></figure><p>This even fetches counts of vertices — though I’m not sure how this works for larger graphs, where running several counts like that might take some time.</p><h3>Graph Data Explorer</h3><p>G.V() IDE comes with a data explorer GUI to quickly visualize your graph data.</p><p>First, you select a basic subset of your data to start with using a form:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/768/1*B-iRLmWB_HDPjOOv11zJ8g.png" /></figure><p>The default vertices, 25, are a bit much for our dataset, but if you change it to 1 or 2, you can start getting a feel for your data, all before writing a single Gremlin query. In my case, I will start with a credit card that has a given credit card number:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/768/1*aIYOQ80FEGnNuzA0OHlY4Q.png" /></figure><p>Results come out to this:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/768/1*etMEUDp-oKB9ftLFI3jdqg.png" /></figure><p>Enable “Data Explorer” mode, and when you click on nodes it automatically populates “neighboring nodes” (i.e., adjacent vertices). For example, after clicking on a “transaction” for this credit card, I find the “vendor” vertex that is attached:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/768/1*uRTtNuW-tAQgBV8sc1yK-A.png" /></figure><p>Or you can click around to see the status of a loan payment from the credit card owner:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/768/1*K6BsfgNXLUya8UQ3D9KVRQ.png" /></figure><h3>Visualization Customization</h3><p>There are many options available to customize how vertices and edges show up in your graph, including color, text style, border style, and more.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/768/1*bZLPhRk2sXRm_ojQyo_ilg.png" /></figure><p>Changing the node label, in particular, can make for a much more pleasant graph to look at:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/768/1*1lFSV6uQzDK6sD1qsThSdw.png" /></figure><p>It would be nice to have some sort of templating ability here, to customize this further. Regardless, as it is it still helps quite a bit.</p><h3>Visualization Presets / Effects</h3><p>One other feature that is really nice is that you can also change the base organization of the visualization from a number of preset options. Here’s just a handle of examples (among many we could give) for the curious.</p><h4>D3 Force layout:</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/768/1*2Z0xnp34-IvTSPO2Bk6nwg.png" /></figure><h4>AVSDF:</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/274/1*fR8PWHGcGeW8EYT3m-Tx4Q.png" /></figure><h4>Breadth First:</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/768/1*Tl0jP7bDow1-R6NVXrX8QA.png" /></figure><h3>Quickly add or edit vertices and vertices within the GUI</h3><p>One surprising feature is that you can perform writes to your graph data straight from the GUI.</p><p>For example, by clicking on a vertex, you can edit its properties:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/768/1*I5h0o6V4EqAiU15HTBOKNw.png" /></figure><p>You can even create vertices or edges. For example by clicking on a vertex and drawing a line to another vertex. Since we’re using DSE, you have to make sure the new edges and vertices fit your schema though. G.V() IDE will try to help you some, for example by populating available properties when you select an edge or vertex label to create, but in the end, you have to know your schema yourself as well for this.</p><p>For example below, I created a new vertex for label “Customer” named “Bill” and made him an owner of one of the accounts:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/768/1*zWH4-oeaIQYyGPW2ThL5gQ.png" /></figure><h3>Query Builder</h3><p>Perhaps the biggest draw for G.V() IDE is the query builder:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/768/1*kUji5rrwo6MhJ5vLKkYb_w.png" /></figure><p>This is the main rationale for calling G.V() an “IDE”. Not only can you run and save queries in different tabs, but as you write the queries it gives a variety of helps.</p><h3>Autocompletion for steps</h3><p>For example, it has autocomplete for traversal steps as you type:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*QnKJEHlg8d1QKRY78Fshmg.png" /></figure><p>As you can see above, this even shows official Tinkerpop documentation on the right-hand side, or optionally you can toggle to java docs instead.</p><h3>Autocomplete based on your schema</h3><p>G.V() IDE also provides suggestions based on your schema. For example, knowing that the has step can take a label or a property name as its first argument, the IDE provides a list of labels and property names from your schema.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*H3_tVWg9hh6CZZv0KzSupw.png" /></figure><p>Once again, it shows details about the currently selected label in the sidebar, as shown above.</p><h3>Output Parsing</h3><p>The output of the Gremlin query is returned in various forms.</p><h3>Output: Raw</h3><p>This is the output view that is to be expected: the raw data.</p><p>Included here is the gremlin console output as well as a JSON formatted output:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*1SCUaK_JejKsxzUcLGaXCA.png" /></figure><p>As those who have tried to use Gremlin before know quite well, this is often not very human-friendly to read. Fortunately, there are other views as well.</p><h3>Output: Vertex View</h3><p>There is also a “Vertex View”, which shows just the vertices in a nice chart:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/768/1*9fIRsviGxs46GEnoBsZHBw.png" /></figure><p>This view is searchable and filterable by label, making it even easier to navigate your graph.</p><p>There is even the option to delete these vertices from the GUI itself.</p><p>Even traversals that ended in an edge (e.g., g.V().outE()) showed this without any issue.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/768/1*GoKHy8sHa4LNRS53drnbPw.png" /></figure><h3>Output: Edge View</h3><p>For Gremlin queries that include edge data, you can use the “Edge View” to explore just the edges:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/768/1*gFSlU8CbrpEo6gPTs33ZpA.png" /></figure><p>This provides a much nicer interface for browsing your edges than the raw data, which is often only barely human-readable.</p><p>Note that traversals that terminate at a vertex don’t show edges, even if edges were traversed on the way there (e.g., g.V().out()). Only traversals that ended in an edge (e.g., g.V().outE()) showed these.</p><p>If you enable the option to “Fetch all edges between vertices” however, then traversals ending in a path (e.g., g.V().out().path()) also show the edge view and all edges in the path:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/768/1*yTyr-ShWg2wVTqy0FRNyEg.png" /></figure><p>Furthermore, though this option won’t necessarily show edges on the path that were traversed along the way, this option will show edges that happen to be connected between vertices that are returned. For example, for this query that returns a bunch of random vertices, G.V() IDE identifies edges between these vertices and returns them as well, something that doesn’t happen in DSE Studio or AWS Graph Notebook.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/768/1*NKKwB09VWqBfKbst6p9JSA.png" /></figure><p>This is also important to make sure that the Graph View has nicely connected vertices:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/768/1*pE4YpTJK0kafaL59uYqJIg.png" /></figure><p>Without enabling this option which returns these edges, it just returns a bunch of disconnected nodes:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/768/1*0BtOej5oiodLfxeGrZ_6oQ.png" /></figure><p>For those of you who have struggled to get a nice looking visualization of your queries to display in other tools like DSE Studio or AWS Graph Notebook (say, for a blog post or presentation for example), I’m sure that you know the helpfulness of this feature!</p><h3>Comparison to DSE Studio</h3><p>Before wrapping up, I just wanted to highlight some pros and cons in comparison to <a href="https://docs.datastax.com/en/studio/6.8/studio/gs/usingGraphInNotebook.html">DSE Studio</a> and <a href="https://github.com/aws/graph-notebook">AWS Graph Notebook</a> really quick. Of course, each of these is a very different tool, but due to a decent amount of overlap in functionality, it might be helpful when deciding what to try out for your graph project.</p><p><strong>Areas where I like G.V() better:</strong></p><ul><li>IDE features such as built-in docs and code completion can be extremely helpful, especially for beginners.</li><li>Has greater flexibility for which traversals can be visualized, especially with its feature to Fetch edges between vertices.</li><li>Can switch what type of visualization to use (e.g., force-directed graph, AVSDF, etc)</li><li>Translation to target language (JS, Python, or .net) and code formatting using <a href="https://tinkerpop.apache.org/gremlint/">Gremlint</a>.</li><li>Ability to edit nodes and edges from the GUI.</li><li>“Vertex View” and “Edge View” tabs in the output.</li><li>Compatibility for several other Tinkerpop graphs, not just DSE Graph.</li></ul><p><strong>Areas where I like DSE Studio better:</strong></p><ul><li>G.V() is not a notebook. This means you cannot layout commands in a sequence, cannot programmatically export and save these sequences of commands to source control (though you can save queries in the desktop app itself), and (as far as I can tell) can’t seem to save query results or visualizations between sessions.</li><li>Not as programmatic to setup — You can’t just run a script and get it up and running with the settings you want, or run it out of a docker-container.</li><li>Serving over HTTP. Being a Desktop application, G.V() IDE is not served over HTTP, which has implications for setup, connecting remotely, etc.</li><li>Windows support — Windows desktop app seems more buggy.</li><li>More buggy, still working out kinks (which will probably get resolved more and more as time goes on)</li><li>Label text can be totally customized in DSE Studio, using templating format</li></ul><h3>Comparison to AWS Graph Notebook</h3><p>The comparison between G.V() IDE and <a href="https://github.com/aws/graph-notebook">AWS Graph Notebook</a> is similar to the comparison made to DSE Studio in a lot of ways, but also to add:</p><p><strong>Areas where I like G.V() better:</strong></p><ul><li>Similar to when compared to DSE Studio, G.V() IDE has the advantage of code completion, built-in docs, and the ability to edit notes from the GUI.</li><li>Easier to configure visualization (AWS Graph Notebook has a syntax to do styling, but for styling like that GUI is easier). However, Graph notebook can have everything configured programmatically</li><li>Ability to easily traverse out to nearest neighbors just by clicking on a node, which is in both DSE Studio and G.V() IDE.</li></ul><p><strong>Areas where I like AWS Graph Notebook better:</strong></p><ul><li>AWS Graph notebook has much more in the way of datasets to get started with, and instructions on how to start playing around with the data.</li><li>AWS Graph returns more in the way of query metadata by default in its “Query Metadata” output.</li><li>Not open source</li></ul><h3>Wishlist</h3><p>A review of a new tool like this would be incomplete without a wish list 🙂 Some things that would be great to see at some point in the future:</p><ul><li>Error message popup when something breaks. There are logs you can access (e.g., for Linux found at ~/.config/gdotv/logs/main.log) but given this is a GUI-focused tool, it would be nice to see something in the UI also.</li><li>Did not work as well from Windows — in particular, hover boxes were misplaced and when you clicked on the auto-suggestions it didn’t do anything. However, it worked fine on my Linux desktop (i.e., not WSL).</li><li>Renaming tabs (or at very least, “Graph Model explorer” and “Graph Data Explorer” should have tabs that are named accordingly)</li></ul><h3>Conclusion</h3><p>Even without any of the suggested additions and features mentioned above, <a href="https://gdotv.com/">G.V() IDE</a> is a major addition to the Tinkerpop ecosystem and for DSE Graph in particular. It shows a lot of promise, especially when doing development. Personally, I plan on continuing to try it out on graph projects as opportunity allows. I am not sure what the planning model might end up being in the future but at least for now, it’s free and definitely worth checking out if you get a chance.</p><p><em>Originally published at </em><a href="https://blog.anant.us/dse-graph-in-g-v-ide/"><em>https://blog.anant.us</em></a><em> on June 3, 2022.</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=84279d58b3f9" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[JanusGraph on Jupyter: Using Notebooks with Graph]]></title>
            <link>https://medium.com/@Ryan-Kh/janusgraph-on-jupyter-using-notebooks-with-graph-business-platform-team-7c476a9bb18f?source=rss-50aa1c648e04------2</link>
            <guid isPermaLink="false">https://medium.com/p/7c476a9bb18f</guid>
            <category><![CDATA[cassandra]]></category>
            <category><![CDATA[jupyter-notebook]]></category>
            <category><![CDATA[graph-database]]></category>
            <category><![CDATA[tinkerpop]]></category>
            <category><![CDATA[review]]></category>
            <dc:creator><![CDATA[Ryan]]></dc:creator>
            <pubDate>Wed, 16 Mar 2022 15:16:06 GMT</pubDate>
            <atom:updated>2022-11-04T03:46:56.326Z</atom:updated>
            <content:encoded><![CDATA[<p>Graph data readily lends itself to visualization — and notebooks make it easy to do just that. In this post, we will test out the Graph Notebook tool put out by the AWS team on JanusGraph.</p><h3>Introduction</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*B_PDdRajN-9clhIq.png" /></figure><p>One of the key selling points of graph technology is that the data model matches how we think. Many refer to this as being “whiteboard-friendly”, in that what you draw during your initial whiteboarding ends up looking like more or less what you put into your database.</p><p>That being the case, graph databases lend themselves to visualization, and indeed there are a number of visualization tools out there for graph databases. It is, therefore, no surprise that there are various <a href="https://github.com/JanusGraph/janusgraph/#visualization">visualization tools for JanusGraph</a> and <a href="https://neo4j.com/developer/tools-graph-visualization/">for Neo4j</a>.</p><p>The advantages to visualize a graph becomes compounded when combined with all of the advantages of the notebook format. The notebook format facilitates data experimentation by making it easy to run commands, see (and save!) the output, and share results. It is like a REPL with a GUI, that you can put into source code or publish online. This is one of the reasons why <a href="https://docs.datastax.com/en/dse/6.8/dse-dev/datastax_enterprise/graph/quickStart/graphQSTOC.html">DSE Graph works so well with DSE Studio</a> since DSE Studio provides this notebook interface to its Tinkerpop enabled graph implementation. However, DSE Studio is specific for DSE Graph — this solution does not work with other Tinkerpop graphs, such as JanusGraph.</p><p>This is where the <a href="https://github.com/aws/graph-notebook/">Graph Notebook</a>, put out by the team at AWS comes in. Although we can understand how to a certain degree it was built with <a href="https://aws.amazon.com/neptune/">AWS Neptune</a> in mind, it works with any graph that implements <a href="https://tinkerpop.apache.org/">Apache TinkerPop</a>, <a href="https://github.com/opencypher/openCypher">openCypher</a>, or <a href="https://www.w3.org/TR/rdf-sparql-query/">RDF SPARQL</a>. Not only does this provide a notebook interface for your graph database, but comes prebuilt to visualize the connectivity of your graph as well — not just in a bar chart or histogram.</p><p>In this post, we will explore what this looks like specifically using <a href="https://janusgraph.org/">JanusGraph</a>, a popular open-source Tinkerpop graph database. We will start with some instructions for getting set up, then explore its visualization capabilities, and then conclude with some evaluation and first impressions.</p><h3>Setup the Environment</h3><p>First, we’ll need to set up our sandbox. For this, we set up a docker-compose to make it easy to get started. You can check it out here: <a href="https://github.com/Anant/janusgraph-notebook">https://github.com/Anant/janusgraph-notebook</a>.</p><p>After you clone the repo, you just need to run this one command to get started:</p><pre>docker-compose up -d</pre><p>Once everything builds and connects properly, you can start playing around in your Jupyter notebooks here: <a href="http://localhost:8888/">http://localhost:8888</a></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/523/0*iK4GLy5sUkn2qzvO.png" /></figure><p>For the authentication page, use password `tensorflow` and then you’re all set.</p><h3>Setup the Graph and the Notebook</h3><p>Out of the box, the Graph Notebook lib provides dozens of notebooks to try out.</p><p>Unfortunately, those with seed data for loading into your graph mostly don’t work since they use custom string ids, and <a href="https://github.com/JanusGraph/janusgraph/issues/1221">JanusGraph doesn’t support that</a>.</p><p>However, we can load in the air routes data manually using the commands below, which will allow us to use the Air-Routes-Gremlin notebook.</p><p><em>Disclaimer: This seed data and notebook are not my own. Some of the commands are modified slightly from what was originally in the notebook.</em></p><h4>Load seed data</h4><pre># download the seed data from <a href="https://github.com/krlawrence/graph">Kelvin Lawrence&#39;s repository</a> and copy into janusgraph docker container ./scripts/load-in-airroutes.sh docker cp ./tmp jg-notebook-janusgraph:/opt/tmp/ # start console docker exec -it jg-notebook-janusgraph ./bin/gremlin.sh</pre><p>Then, in the console:</p><pre>:remote connect tinkerpop.server conf/remote.yaml g = traversal().withRemote(&#39;conf/remote-graph.properties&#39;) path = &quot;/opt/tmp/air-routes.xml&quot;; g.io(path).read().iterate();</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/832/0*9r200wlSbGnCnLXz.png" /></figure><p>Quickly testing to get some counts of our new data confirms it worked:</p><h4>Setup Air Routes Notebook</h4><p>Now we’re ready to set up our notebook. This link will navigate right to it: <a href="http://localhost:8888/notebooks/02-Visualization/Air-Routes-Gremlin.ipynb">http://localhost:8888/notebooks/02-Visualization/Air-Routes-Gremlin.ipynb</a></p><p>To set up a notebook, run the following configuration command:</p><pre>%%graph_notebook_config { &quot;host&quot;: &quot;janusgraph&quot;, &quot;port&quot;: 8182, &quot;ssl&quot;: false, &quot;gremlin&quot;: { &quot;traversal_source&quot;: &quot;g&quot; } } </pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/937/0*qX5XtZrad3hTCJ0w.png" /></figure><h3>Visualize Our Graph</h3><p>Now you should be set up to run through some commands. Go ahead and skip the other setup commands, like the seed data ones and other config commands, since we did that already.</p><p>There are some things worth noting here before you get too far, however. In order for Graph Notebook to visualize your Gremlin traversal, there are some requirements it needs to fulfill.</p><h4>Requirement: Needs to Return a Path</h4><p>It’s important to note that not all Gremlin traversals will return a nice visualization. Our current notebook gives us some guidelines here:</p><blockquote><em>“The results of any Gremlin query that </em><strong>returns a path</strong><em> can be explored visually” (emphasis added)</em></blockquote><p>What this means is that if I just grab five adjacent vertices, our notebook doesn’t automatically know what to do with them, so will just display a table of results.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*_X1kNQFAdVzIyXeO.png" /><figcaption>Five adjacent vertices — note the absence of the “Graph” tab.</figcaption></figure><p>No visualization is possible — even if they are connected to each other since it is <strong>not returning a path</strong>.</p><h4>Requirement for a good visualization: Needs to give some hints</h4><p>This one isn’t a requirement to return a graph visualization but is a requirement to return a good graph visualization. As it is currently implemented, the graph notebook does not know what is an edge or what is a vertex just by looking at the results.</p><p>For example, take the following traversal, which goes out from an airport, and comes back into another airport, but only returns the “code” for the airport edge and the distance (“dist”) property of the edge:</p><pre>g.V().hasLabel(&#39;airport&#39;).outE().inV().path().by(&#39;code&#39;).by(&#39;dist&#39;).limit(5)</pre><p>This will return results that look like this:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*hbTEXPBql1H16Req.png" /><figcaption><em>First three results, without hint</em></figcaption></figure><p>Now, we know that this is a list of paths, each with three items, which represent an airport, a route, and the destination airport. However, the notebook just sees a string, an integer, and another string — it doesn’t know if the strings or integers represent edges or vertices. Accordingly, when we look at the visualization, it shows the connections, but edges (the circles with integers) look the same as vertices (the circles with strings):</p><p>Now suppose we add this hint in the notebook:</p><pre>--path-pattern v,oute,inv</pre><p>This tells the notebook that the first item in the path is a vertex ( v), followed by an out edge ( oute), followed by an in vertex ( inv). We send in these hints using the --path-pattern argument, or -p for short. Now we get a much better result:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*eAhjxPYX8aVQbAuF.png" /><figcaption><em>First three results, with hint</em></figcaption></figure><p>There’s a ton of other customization that you can do on the graph as well — I won’t get into it here though, that’s enough instructions for now. Instead, let’s try to get some cool visualizations from our graph.</p><h3>Click on a Node or Edge to View Details</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*muCg5ZXAJGavWkxG.png" /></figure><h3>First 50 Routes from Seattle to Phnom Penh, grouped by country</h3><pre>my_node_labels = &#39;{&quot;airport&quot;:&quot;city&quot;}&#39; %%gremlin -p v,oute,inv,oute,inv,oute,inv -g country -d $my_node_labels -l 20 g.V().has(&#39;airport&#39;,&#39;code&#39;,&#39;SEA&#39;). repeat(outE().inV().simplePath()). until(has(&#39;code&#39;,&#39;PNH&#39;)). limit(50). path(). by(valueMap(true)). by(&#39;dist&#39;)</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*EnExWlLUj3TKBeIT.png" /></figure><h3>Custom Icons</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1017/0*ejIw077HQnJw0ozg.png" /><figcaption><em>Using custom icons, set by country</em></figcaption></figure><h3>Evaluation</h3><p>Overall, this is a great tool that adds a lot of value to the graph ecosystem. For one thing, a major challenge for Gremlin that many have identified is the learning curve, and having notebooks with sample commands, visualizations, and clear instructions helps to make it easier to get started. Notebooks are helpful for experienced users as well since they make it easy to experiment, create visualizations, and share with others.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1001/0*mWwWWskszAwgOsKk.png" /></figure><p>There are some features that I would make this even better, however, such as it would be nice to be able to customize the length of the edges as well as the strength of the push/pull force between nodes. It is possible to set these but must be done ahead of time using %%graph_notebook_vis_options. This is great, but being able to set this live within the visualization would be even better.</p><p>An initial comparison from my limited experience with DSE Studio: DSE Studio has some additional nice features and looks better out of the box (it’s a personal preference, but the light blue nodes on the dark background just work better for Graph). On the other hand, the Graph Notebook project is open source, and the visualization seems to be more customizable. It also has clearer instructions on how to create the visual you want to create, in contrast to DSE Studio, where it takes some trial and error to figure out what traversals return a nice looking graph (at least for me, I had trouble finding instructions for DSE Studio). Also for Graph Notebook, you can change the settings programmatically using %%graph_notebook_vis_options which gives you a lot of control, whereas in DSE Studio, unless I&#39;m mistaken you have some powerful configuration settings in the visualization itself, but aren&#39;t able to configure programmatically. Both are powerful in their own way.</p><p>All that said, it’s a great tool and I’m looking forward to seeing how it continues to improve and develop. They are continually developing this tool and the Gremlin community overall is very active and welcoming. Even while preparing this post, I received great help and support from the community in getting my environment set up. And undoubtedly, as more and more great tools for graph-like Graph Notebook come out, the community is only going to continue to grow.</p><p>I’d love to hear if you had any thoughts as well — let me know!</p><p><em>Originally published at </em><a href="https://blog.anant.us/janusgraph-on-jupyter-using-notebooks-with-graph/"><em>https://blog.anant.us</em></a><em> on March 16, 2022.</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=7c476a9bb18f" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Solving Wide Partitions caused by Supernodes in DSE 6.8 (Part three)]]></title>
            <link>https://medium.com/@Ryan-Kh/solving-wide-partitions-caused-by-supernodes-in-dse-6-8-part-three-12fa14e371d0?source=rss-50aa1c648e04------2</link>
            <guid isPermaLink="false">https://medium.com/p/12fa14e371d0</guid>
            <category><![CDATA[super-nodes]]></category>
            <category><![CDATA[graph-database]]></category>
            <category><![CDATA[datastax]]></category>
            <category><![CDATA[cassandra]]></category>
            <category><![CDATA[graph-data-model]]></category>
            <dc:creator><![CDATA[Ryan]]></dc:creator>
            <pubDate>Fri, 04 Mar 2022 04:32:17 GMT</pubDate>
            <atom:updated>2022-03-04T04:40:43.339Z</atom:updated>
            <content:encoded><![CDATA[<h3>Introduction</h3><p>In <a href="https://medium.com/@RyanQuey/partitioning-in-dse-graph-part-one-91f1cce6a0ba">the first part</a> of this blog series, we looked at the underlying issue that supernodes cause in DSE Graph due to how partitioning in Cassandra works and solutions that have been put forward for DSE Graph 5.x and 6.0–6.7. In <a href="https://medium.com/@RyanQuey/solving-wide-partitions-caused-by-supernodes-in-dse-6-7-part-two-6a2609e86776">the second part</a>, we took a look at what this actually looks like within DSE 6.7 via some hands-on experimentation with intermediary vertices. We saw that although intermediary vertices successfully break apart the wide partitions, there are some problems inherent in introducing an extra hop like that.</p><p>In this third and final part of the series, we will look at how we can take advantage of the changes made in DSE 6.8 in order to implement a better solution than what was possible in DSE 6.7.</p><h3>What changed in DSE Graph 6.8</h3><p>I will leave it to you to read the <a href="https://docs.datastax.com/en/dse/6.8/dse-dev/datastax_enterprise/releaseNotes/RNdse.html#RNdse680__680graph">release notes for DSE 6.8</a> yourself, but this quote from <a href="https://www.datastax.com/blog/whats-new-datastax-enterprise-68">the Datastax blog</a> gives a good overview to get us started:</p><blockquote><em>With DSE 6.8, DataStax is taking the next step in the evolution of distributed graphs by moving the graph storage engine deeper into Cassandra.</em></blockquote><p>Now in DSE 6.8, the Tinkerpop graph vertices and edges can be read or written from either Gremlin or CQLSH. You can even take an existing Cassandra keyspace and turn it into a graph by running some alter statements. All of this is on top of a reported <a href="https://www.datastax.com/blog/whats-new-datastax-enterprise-68">10 times faster</a> performance boost. (Of course, saying “10x faster!” is kind of vague and I can’t tell you precisely what it means, but you know it has to be good!)</p><p>There are many interesting implications of the changes that they made here, but for our particular use case, we see that DSE 6.8 allows us to solve wide-partition issues caused by supernodes in a much more elegant way than intermediate vertices. In DSE 6.7 we could control the partitioning of vertices by way of custom vertex ids, but we had no way to partition the edges directly. Now in DSE 6.8 however, since we can specify edges’ the primary key as they are actually stored in Cassandra, we are able to partition the edges as needed.</p><p>When creating the schema using Gremlin, <a href="https://docs.datastax.com/en/dse/6.8/dse-dev/datastax_enterprise/graph/reference/schema/refEdgeLabel.html">this is accomplished by using </a><a href="https://docs.datastax.com/en/dse/6.8/dse-dev/datastax_enterprise/graph/reference/schema/refEdgeLabel.html">.partitionBy() and </a><a href="https://docs.datastax.com/en/dse/6.8/dse-dev/datastax_enterprise/graph/reference/schema/refEdgeLabel.html">.clusterBy()</a>. If you don’t use these steps, the <a href="https://community.datastax.com/questions/11493/partitioning-vertices-in-dse-graph-6x.html?childToView=11539#answer-11539">default behavior</a> is that the Cassandra table for these edges will have a primary key based on the origin (aka outgoing) side of the edge. In other words, if son isChildOf father, then by default, the isChildOf edge would have a partition key that is based on the son vertex. If you use .partitionBy however then you can choose a different property instead.</p><p>As an aside: It is worth noting that regardless, you will need to include the columns of the primary key of both the origin and destination vertex within the primary key of the edge, however. When you think about how edges work in Tinkerpop and how primary keys work in Cassandra, this makes sense. In Tinkerpop, an edge needs to be associated with a particular origin vertex and destination vertex and <a href="https://tinkerpop.apache.org/docs/current/recipes/#edge-move">these cannot be changed</a> (to “change” which vertex an edge is associated with, you just have to drop it and make a new one). Accordingly, using the primary keys in Cassandra (which are themselves immutable) to associate the edge with particular vertices is quite logical. All that to say: be careful of this when thinking about picking your primary keys for these vertices and edges. As always, picking the right primary key is crucial for your data model in Cassandra.</p><p>Anyways, for our use case, the important thing is that now we can divide up our edges for our supernode into different partitions without intermediate vertices: all we have to do is add some other property to our edge’s partition key.</p><h3>Our approach</h3><p>Our general process will be the same as what we did in part two. We will be using code from the same repo as before for setting up our experiment: <a href="https://github.com/Anant/dse-graph-supernode-generator">https://github.com/Anant/dse-graph-supernode-generator</a>. We will also likewise start with a control by creating the supernode using default partitioning behavior, and then we will show how to solve the wide-partition issue with our proposed solution.</p><h3>Trial #1: Control</h3><p>For our control, we will set up a graph similar to before, but due to default behavior in DSE 6.8, the direction of the edges needs to be in reverse order for our experiment to work correctly. By default edge partitions are based on the partition key of the origin vertex, rather than duplicated and stored with both vertices like before. Unfortunately, I learned about this behavior the hard way. I haven’t found official documentation that discusses this point, but it was confirmed in the comments of <a href="https://community.datastax.com/answers/11539/view.html">this Datastax Community answer</a>.</p><p>This won’t make a major difference for us, but just note that our supernode will not be “liked” by 1 million people, rather they will “like” 1 million other people instead.</p><h3>Step 1: Create schema</h3><p>Even though we create the same vertices and edges schema <a href="https://blog.anant.us/solving-wide-partitions-caused-by-supernodes-in-dse-6-7-part-two">as we did for DSE 6.7</a>, the outcome in CQLSH is pretty different, and for the better.</p><p>Notice that there are no extra fields beside the primary key in the properties that we specified. Again, this was done intentionally by the developers of DSE 6.8 in order to make it possible to query your entities using CQL or Gremlin interchangeably.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*e2XVngIY6heorvON" /><figcaption><em>CQL for vertex table </em><em>person</em></figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*SjCfD_Wv5tqBQvKk" /><figcaption>CQL for edge table person__likes__person</figcaption></figure><p>Also, note that while the primary key of the edge refers to the primary keys for both the origin vertex (out_uuid) and the destination vertex (in_uuid), the <em>partition key</em> of the edge is out_uuid, not in_uuid. This aligns with what we mentioned above, that the default behavior for edges is that they are stored in with the origin vertex.</p><h3>Step 2: Send CSV data using DSE Bulk Loader</h3><p>Now that we are using DSE 6.8, we will also use DSE Bulk Loader instead of DSE GraphLoader. There are various advantages to this, but for our case, the result is the same: we load in our data and we are left with some brand new supernodes.</p><p>Here is the output when loaded in the sample data from the generated CSV:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*qrpZgbQSM3acp7MN" /></figure><h3>Step 3: Confirm Edge Count in Gremlin</h3><p>Using a Gremlin traversal, we can confirm that our supernode “likes” 1 million other people:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*aGQATI_Wgfb181zX" /></figure><p>So far so good!</p><h3>Step 4: Confirm Wide-partitions in Cassandra</h3><p>Let’s also just quickly confirm that we really did make some wide partitions here. Just like we did for DSE 6.7, we again flushed to disk and then used tablestats to check partition size.</p><p>The vertex table (person) is more or less what we expected, with many small partitions for the vertices: 4,014,418 estimated partitions, with “Compacted partition maximum bytes” of 179 bytes.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/785/0*kvSAyn12mR_Ti7vT" /></figure><p>One unexpected result though was that the “Space used (total)” came out to around 366 MB instead of the 485 MB that we saw in our DSE 6.7 control trial.</p><p>Turning then to the edge table (persion__likes__person), we can see some other interesting results:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/703/0*gVqLQxQBUd1Rf73r" /></figure><p>As was the case for vertices, the total space used (149,624,294 bytes, around 149 MB) is less than what we saw in DSE 6.7 — around 334 MB, almost twice as much. In other words, the data stored in DSE 6.8 appears to be half as much, at least for this sample. This was unexpected, but a possible explanation for why is that there are some extra fields that get added into the partition key automatically in 6.7. Perhaps this is part of how DSE 6.8 delivers that advertised “10x performance” boost.</p><p>In regard to partitions, here we see there are four partitions (one per supernode), and a “compacted partition maximum bytes” of 52,066,354 bytes (roughly 52 MB). This is smaller than the size of partitions we had for test control for 6.7 (around 90 MB), but this makes sense as well given that it seems like the edge records are taking half the size. Of course, these are not really very wide as far as partitions go, but at least we have a number that we can refer to for the sake of testing.</p><h3>Step 5: Verify shape of graph in DSE Studio</h3><p>When we visualize the shape of the graph in DSE Studio, we see a similar shape to what we saw for our experiments regarding DSE 6.7, though now our arrows are going in a different direction since our edges are going out from the supernode instead of in.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*Q7875wGZgbiDp8TW" /></figure><p>Now that we have confirmed that we have some supernodes and wide partitions (or at least, wide enough for testing against), we can move on to our final trial, where we will attempt to break apart the wide partitions using the</p><h3>Trial #2: Try to Break Apart Supernodes Using Partition Keys</h3><h3>Step 1: Create schema</h3><p>We can keep the same schema for vertices, but we will add another column to our edge table’s partition key:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*j2XETbzLP1UeMh6l" /></figure><p>Now our primary key looks like this:</p><p>1PRIMARY KEY ((custom_partition_key, out_uuid), in_uuid)</p><p>The out_uuid field is still part of the partition key, but now it is part of a composite partition key along with another field, custom_partition_key.</p><h3>Step 2: Send CSV data using DSE Bulk Loader</h3><p>Now that we have a schema, we are ready to load our data in using DSE Bulk Loader.<br>Here is the output for loading our 4 supernodes with 1 million edges each:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*bJ1KbsZXDQRSMuuz" /></figure><h3>Step 3: Confirm Edge Count in Gremlin</h3><p>I started to get a little more creative with my Gremlin traversals here, but the result is still the same: 1 million edges per supernode.</p><p>1supernodes = g.with(&#39;allow-filtering&#39;).V().hasLabel(&quot;person&quot;).has(&#39;uuid&#39;, within(sn_uuids)).project(&#39;supernode_id&#39;, &#39;people-whom-they-like&#39;).by(id).by(outE(&quot;likes&quot;).count())</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*e4qkNnZ_mrUN1C46" /></figure><h3>Step 4: Confirm Smaller Partition Size in Cassandra</h3><p>And finally, the moment of truth: tablestats for edge table (person__likes_person)</p><p>Here we see that the estimated number of partitions comes out to 4000. This makes sense, since we have four supernodes, each with 1,000,000 adjacent vertices, and they were divided into partitions with 1000 edges max per partition.</p><p>The compacted partition maximum bytes comes out to 51,012 (around 50 KB). Success! This is roughly 1000x less than what we saw for our test control, which had partitions of roughly 52 MB, matching our expectations, since we divided up edges so that there were 1000 edges per partition.</p><p>If we visualize in DSE Studio, we see that the shape of the graph is unchanged.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/801/0*aKPbXPzsFeMYfaIX" /></figure><h3>Conclusion</h3><p>My hope is that by running through this exercise, it helps to clarify the differences between DSE Graph 6.7 and 6.8, and how you would go about splitting apart wide partitions caused by supernodes in both versions. The solution that we see here for DSE 6.8 has several advantages over introducing intermediary vertices like we had to do for DSE 6.7, but perhaps what is most appealing is its simplicity. There would be no extra hop when traversing from the supernode, and therefore there would not be any code changes required either.</p><p>However, it is worth noting that this does not solve everything. In particular, this solution still introduces “edge cut” since the edges are no longer co-located with the vertex. This is a trade-off that you will have to weigh out depending on your traversal patterns and how wide your partitions are. Thank you for following along with the Wide partitions and supernodes in DSE Series. If you missed parts 1 and 2, they are linked below.</p><h3>Wide partitions and Supernodes in DSE Series</h3><ol><li><a href="https://medium.com/@RyanQuey/partitioning-in-dse-graph-part-one-91f1cce6a0ba">Partitioning in DSE Graph</a></li><li><a href="https://medium.com/@RyanQuey/solving-wide-partitions-caused-by-supernodes-in-dse-6-7-part-two-6a2609e86776">Solving Wide Partitions caused by Supernodes in DSE 6.7</a></li><li><a href="https://medium.com/@RyanQuey/solving-wide-partitions-caused-by-supernodes-in-dse-6-8-part-three-12fa14e371d0">Solving Wide Partitions caused by Supernodes in DSE 6.8</a></li></ol><p><a href="https://medium.com/@RyanQuey/solving-wide-partitions-caused-by-supernodes-in-dse-6-8-part-three-12fa14e371d0"><em>Originally published on the Anant blog</em></a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=12fa14e371d0" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Solving Wide Partitions caused by Supernodes in DSE 6.7 (Part two)]]></title>
            <link>https://medium.com/@Ryan-Kh/solving-wide-partitions-caused-by-supernodes-in-dse-6-7-part-two-6a2609e86776?source=rss-50aa1c648e04------2</link>
            <guid isPermaLink="false">https://medium.com/p/6a2609e86776</guid>
            <category><![CDATA[datastax]]></category>
            <category><![CDATA[cassandra]]></category>
            <category><![CDATA[graph-database]]></category>
            <category><![CDATA[graph-data-model]]></category>
            <category><![CDATA[super-nodes]]></category>
            <dc:creator><![CDATA[Ryan]]></dc:creator>
            <pubDate>Fri, 04 Mar 2022 04:28:24 GMT</pubDate>
            <atom:updated>2022-03-04T04:40:02.734Z</atom:updated>
            <content:encoded><![CDATA[<h3>Introduction</h3><p>In <a href="https://medium.com/@RyanQuey/partitioning-in-dse-graph-part-one-91f1cce6a0ba">part one</a> of this series, we explored differences between DSE Graph 5.x and 6.0–6.7 regarding how it partitions edges and vertices in Cassandra, and what this meant in regard to how you would go about breaking apart your supernodes in order to avoid wide partitions in your DSE cluster. In this second part, we will see how it works hands-on.</p><p>As we will see, while intermediary vertices is a solution available for breaking up supernodes in 6.7, it is less than ideal in many ways. This will prepare us for our <a href="https://medium.com/@RyanQuey/solving-wide-partitions-caused-by-supernodes-in-dse-6-8-part-three-12fa14e371d0">third post</a>, about what solving the same issue looks like in DSE Graph 6.8.</p><h3>Our Approach</h3><p>To aid us in our experiment, we put together some quick and dirty python code and some docker-compose files for quickly spinning up DSE Graph environments and loading in mock data.</p><p>You can find the repo here: <a href="https://github.com/Anant/dse-graph-supernode-generator">https://github.com/Anant/dse-graph-supernode-generator</a></p><p>In order to confirm the effectiveness of intermediary vertices, we will create a control dataset and load it into a DSE 6.7 graph. The goal here is to set a baseline for how a wide partition can be created when there are supernodes within the graph. Then after that, we will show how the same amount of edges can be connected to the supernode, but with the wide partitions broken up using intermediary vertices.</p><p>To reproduce the experiment, you can follow the <a href="https://github.com/Anant/dse-graph-supernode-generator#instructions">instructions in the README</a>; for this blog post I will just give a summary with the results.</p><h3>Trial #1: Create a Control Graph, with Supernodes and Wide-partitions</h3><h3>Step 1: Create schema</h3><p>For this experiment, we will use a simple schema, with a single vertex person and an edge likes. Our graph will be called demo_who_likes_whom. For our experiment we just care about creating a wide-partitions caused by a supernodes, so we don’t need anything complicated here: a couple properties for our person vertex (name and info) and a simple partition key (uuid) is sufficient.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*CRyXlF9iJ2S5MIIA.png" /></figure><p>We can use CQLSH to check what’s going on inside Cassandra, thereby confirming that see that the person vertex is partitioned by the partition key we specified using the gremlin code (uuid). However, there are also some clustering columns added automatically by DSE Graph (~~property_key_id and ~~property_id).</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/734/0*5HsFlw-bHHxW7Mx2.png" /></figure><p>In other words, while we see some correspondence between what we do in Gremlin and what we see in the Cassandra backend, there is not a correspondence as nice and clean as what we will see in DSE 6.8.</p><h3>Step 2: Send CSV data using DSE GraphLoader</h3><p>When loading data into our graph, we will use <a href="https://docs.datastax.com/en/dse/6.7/dse-dev/datastax_enterprise/graph/dgl/dglCSV.html#dglCSV">DSE GraphLoader</a>. In DSE 6.8 we can use <a href="https://docs.datastax.com/en/dse/6.8/dse-dev/datastax_enterprise/graph/using/dsbulkGraph.html">DSE Bulk Loader</a> instead, but this option isn’t available for DSE 6.7. DSE GraphLoader works well enough for our use case, though it is worth noting this difference as well since there are some shortcomings relative to the newer DSE Bulk Loader.</p><p>For each of our trials, we will create four supernodes, each with 1 million edges. DSE GraphLoader gives the following output:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*L3VdQHBbl29I5ARy" /></figure><p>The output shows 4,000,000 edges, which confirms that we ingested the correct amount of edges.</p><h3>Step 3: Confirm Edge Count in Gremlin</h3><p>We can take the ID of one of our supernodes to test whether there are indeed 1 million incident edges for this supernode:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*jRbmq1N2ykw0QbC0" /></figure><p>Looking good so far!</p><h3>Step 4: Confirm Wide-partitions in Cassandra</h3><p>Next, let’s check to make sure we really do have a wide partition as expected. Note that we will want to make sure we flush to disk using nodetool flush to ensure that everything is in sstables so that our tablestats will give us numbers that reflect all of our records. Then we can use tablestats to get partition sizes.</p><p>Vertices table (Table: person_p) partitions should not be large – each uuid is its own partition key, so those vertices should each basically have their own partition:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/680/0*_KcnvhrVdjkEiS_R" /></figure><p>The edges table (person_e) however should have large partitions, since each supernode should have all 1 million edges grouped together with it:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/660/0*olcnXmGQSAy6SchJ" /></figure><p>As you can see, the output reads “Compacted partition maximum bytes” of 89,970,660 and “Space used (total)” of 334,853,167. This matches our expectations: 80+ MB/partition and four times that for total disk space used since we created four supernodes.</p><h3>Step 5: Verify shape of graph in DSE Studio</h3><p>Before moving on to our next trial run where we try out intermediary vertices, it’s worth taking a moment to visualize our graph in DSE Studio. DSE Studio only shows 1000 elements at a time, so we shouldn’t rely on this too heavily for our experiment, but still, it can at least help us get a mental image of what’s going on here. Note also that some of the Gremlin traversals shown below are not written for performance but rather just to make sure it displays correctly in DSE Studio.</p><h4>Visualize a supernode</h4><p>Going out from one of our supernodes, we can see how there is one central node (the big one) to which all other nodes are connected.</p><p>1g.V().hasLabel(&quot;person&quot;).has(&quot;uuid&quot;, &quot;53eb72bd-7a7a-4ff3-b0de-451eab371b05&quot;).as(&quot;supernode&quot;).bothE()</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*FXYmntDZwasJLGmp" /></figure><h3>Trial #2: Try to Break Apart Supernodes Using Intermediate Vertices</h3><p>Next, we will try out intermediate vertices, the solution mentioned in <a href="https://blog.anant.us/partitioning-in-dse-graph">our previous post</a>. The idea is that by introducing a vertex in between our supernode and its adjacent vertices, we can keep partition sizes manageable, as suggested by a DSE Graph team member here in <a href="https://stackoverflow.com/questions/48092495/how-to-handle-supernodes-with-dse-graph">this StackOverflow post</a>.</p><h3>Step 1: Create schema</h3><p>Our schema for this will be the same as in the first trial: a simple vertex person with an edge called likes.</p><h3>Step 2: Send CSV data using DSE GraphLoader</h3><p>As in the previous step, we ingest the CSV data, but this time the data has a different shape. Each supernode still has 1 million other persons who “like” them as before, but for each supernode, we introduce 1000 intermediary vertices, each of which has 1000 terminal vertices.</p><p>Looking at our CSV with the edges that we will use for ingestion, there are indeed 4,004,000 edges: 4,000,000 from the intermediary vertices to the end vertices, and then 4000 from the supernodes to the intermediary vertices.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*kQ9ijNtuBqTR00Ja" /></figure><h4>Load intermediary vertices into DB using DSE GraphLoader</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*0sAeootrPiTleNS1" /></figure><h3>Step 3: Confirm Edge Count in Gremlin</h3><p>If our test worked, the “supernodes” should no longer have wide partitions. Incident edges should be down to 1000 per supernode, whereas before it was 1,000,000.</p><p>When we can use the same Gremlin traversal that we did in Trial #1. In trial #1, this traveral returned 1 million incident edges for this supernode. Now it should only return the intermediary vertices, so as expected there are only 1000:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*5z-zWY-bjZet1k21" /></figure><h4>Make sure this is true for all supernodes</h4><p>By assigning the supernode uuids to a variable sn_uuids, we can confirm that all supernodes are the same. As expected, there are four supernodes, each with 1000 (= 4000 edges).</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*3BeENuLbrb8wiROM" /></figure><h4>Go out two hops and make sure we’re getting some people</h4><p>Our previous traveral confirmed that each supernode has 1000 intermediary vertices. Let’s go out from one of these intermediary vertices, and make sure there are 1000 terminal vertices on the other side.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*KsQPiRhc7pSOZd1L" /></figure><h3>Step 4: Confirm Smaller Partition Size in Cassandra</h3><p>Finally, the moment of truth. We again flushed to disk and then used tablestats to check partition size. As we were hoping for,, the edges table (person_e) no longer has large partitions.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/868/0*dNVFUoE9qO8ml6AP" /></figure><p>“Compacted partition maximum bytes” comes out to 88148, which is roughly 89 KB. This is roughly 1000x smaller than the result from the first trial (roughly 89 MB).</p><p>And just for a sanity check, we also see that total disk space is roughly the same, though slightly higher (since we introduced 1000 new vertices and their edges). Now, “Space used (total)” comes out to around 370 MB, whereas before it was around 330 MB.</p><h3>Step 5: Verify shape of in DSE Studio</h3><p>As noted before, we have to be careful here, since DSE Studio shows a maximum of 1000 vertices anyways. This means that the original supernode will look more or less the same since it still has 1000 incoming edges:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*UhT5AkBj2dDP7E_h" /></figure><p>As expected, still has a lot of connections. Even still, the visualization can help us see what’s going on here a little bit.<br>What we can do is look at only the supernode with 20 of its intermediary vertices, so that we can visualize how this thing looks without hitting the 1000 element maximum. (We are using fold and union steps as well here in order to make sure it looks nice in DSE Studio). Before expanding, it looks like this:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1018/0*GiczXAH6oXV6ntKw" /></figure><h4>Using “Expand neighborhood” feature, we can get a better idea of how this graph looks</h4><p>The “Expand neighborhood” feature makes it easy to go out from nodes found in a traversal within DSE Studio. Using this feature, we go out another hop and see how the supernode (underlined in red below) is connected to intermediary vertices (due to the 1000 element limit, only 10 are shown now), which in turn are connected to several others.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*_orEzI2Uom4kXWpS" /></figure><h3>Conclusion</h3><p>Overall, our experiment was successful. We showed how supernodes create wide partitions in DSE Graph, and how to break those wide partitions up using intermediary vertices. While this means we use a little higher total disk space, the partition size can become much more manageable.</p><p>It bears repeating though that this solution is less than ideal for several reasons. As mentioned in the previous post, not only is there “edge cut” (i.e., traversals from one vertex to its adjacent vertex requires crossing partitions, adding network latency, etc), but there is also an extra hop involved in order to get from your source note to your destination node, since now there is this “intermediate vertex” in between. This also adds greater complexity to your applications’ business logic if they ever do run these traversals.</p><p>This brings us to our alternative solution for breaking up supernodes in DSE 6.7: you guessed it, upgrading to DSE 6.8. This will be the focus of <a href="https://medium.com/@RyanQuey/solving-wide-partitions-caused-by-supernodes-in-dse-6-8-part-three-12fa14e371d0">the final post of this series</a>.</p><h3>Series</h3><ol><li><a href="https://medium.com/@RyanQuey/partitioning-in-dse-graph-part-one-91f1cce6a0ba">Partioning in DSE Graph</a></li><li><a href="https://medium.com/@RyanQuey/solving-wide-partitions-caused-by-supernodes-in-dse-6-7-part-two-6a2609e86776">Solving Wide Partitions caused by Supernodes in DSE 6.7</a></li><li><a href="https://medium.com/@RyanQuey/solving-wide-partitions-caused-by-supernodes-in-dse-6-8-part-three-12fa14e371d0">Solving Wide Partitions caused by Supernodes in DSE 6.8</a></li></ol><p><a href="https://medium.com/@RyanQuey/solving-wide-partitions-caused-by-supernodes-in-dse-6-7-part-two-6a2609e86776"><em>Originally posted on the Anant blog</em></a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=6a2609e86776" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Partitioning in DSE Graph (Part One)]]></title>
            <link>https://medium.com/@Ryan-Kh/partitioning-in-dse-graph-part-one-91f1cce6a0ba?source=rss-50aa1c648e04------2</link>
            <guid isPermaLink="false">https://medium.com/p/91f1cce6a0ba</guid>
            <category><![CDATA[super-nodes]]></category>
            <category><![CDATA[cassandra]]></category>
            <category><![CDATA[graph-data-model]]></category>
            <category><![CDATA[graph-database]]></category>
            <category><![CDATA[datastax]]></category>
            <dc:creator><![CDATA[Ryan]]></dc:creator>
            <pubDate>Fri, 04 Mar 2022 04:24:28 GMT</pubDate>
            <atom:updated>2022-03-04T04:37:57.151Z</atom:updated>
            <content:encoded><![CDATA[<h3>Introduction</h3><p>In the graph world, supernodes are a common yet devastating problem. In the Cassandra world, wide-partitions can be paralyzing and have a ripple effect across your cluster. Put them together, and you’ve got yourself into a lot of trouble!</p><p>Supernodes can impact your cluster in many different ways, but it is not hard to see why it is particularly problematic due to the way it can cause wide-partitions in Cassandra. A supernode is a single node vertex that has a disproportionately high amount of edges (Justin Bieber’s Twitter account is a common example). Accordingly, since edges are generally stored on the same partition as the vertex (more on that later), a supernode can very easily create a wide partition.</p><p>Anyone who has used Cassandra before will tell you that the key to avoiding wide-partitions is to have the correct data model, and that applies here as well. DSE Graph is a Tinkerpop implementation that uses Datastax’s implementation of Cassandra as a backend. Accordingly, in order to avoid disaster down the line as you scale up your data, it is crucial to know what’s going on under the hood of DSE Graph so that you can model your data properly.</p><p>This issue has been addressed before by the <a href="https://www.experoinc.com/post/dse-graph-partitioning-part-1-custom-vertex-ids">excellent two-part blog-post</a> by Ted Wilmes of Expero, but that was in January 2017, and regarding DSE Graph 5.x. Changes made to DSE Graph since then mean that there are now different considerations involved in addressing this issue.</p><p>Accordingly, the goal for this series of blog posts is to bring us up to date for DSE 6.7 and 6.8 in particular. This first part will give an overview of the background information and investigate changes to the partitioning behavior made in DSE 6.0–6.7. <a href="https://medium.com/@RyanQuey/solving-wide-partitions-caused-by-supernodes-in-dse-6-7-part-two-6a2609e86776">The second part</a> will be to apply what we learned from the first part, getting hands-on with DSE Graph 6.7 and showing how to break apart wide partitions caused by supernodes in light of changes made since DSE 5.x. Then finally, since <a href="https://www.datastax.com/blog/whats-new-datastax-enterprise-68">substantial changes were made to DSE Graph 6.8</a> that calls for a totally different approach than what we do in 6.7, <a href="https://medium.com/@RyanQuey/solving-wide-partitions-caused-by-supernodes-in-dse-6-8-part-three-12fa14e371d0">part three </a>will focus on DSE Graph 6.8.</p><h3>How DSE Graph partitioned vertices and edges in 5.x</h3><p>Hopefully not many of you are using DSE 5.x still, but in order to understand what is going on in DSE 6.x, it will be helpful to first review the way that DSE Graph partitioned edges and vertices in DSE 5.x. That way we will know how our solution will differ from solutions offered in the past. For that, I will defer to the excellent <a href="https://www.experoinc.com/post/dse-graph-partitioning-part-1-custom-vertex-ids">blog post by Ted Wilmes of Expero</a>.</p><p>To quickly summarize, the idea is that in DSE 5.x, there was automatic partitioning available. For automatic partitioning, <strong>edges</strong> are duplicated and stored in partitions with both vertices. On the other hand, <strong>vertices</strong> are stored in the same partitions with other vertices that were created in the same transaction and with the same label.</p><h3>Custom Vertex IDs in DSE 5.x</h3><p>However, for more control, you could opt out of automatic partitioning and instead use “Custom Vertex Ids”, in which case the vertex’s partition is determined by its id instead (though note that the edge is still duplicated and stored in the same partition as both vertices). This way, you could avoid <strong>edge cuts</strong>, which is where two connected vertices live in different partitions. As is always true of Cassandra, when possible you want to keep data that is going to be queried together in the same partition. However, if two vertices are stored in different partitions, then traversals between these vertices will necessarily cross partitions, and possibly require a network hop to a different node in your Cassandra cluster.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/558/0*Qw7ebNdX4fv7RZmm.png" /><figcaption><em>(Image source: </em><a href="https://www.experoinc.com/post/dse-graph-partitioning-part-1-custom-vertex-ids"><em>https://www.experoinc.com/post/dse-graph-partitioning-part-1-custom-vertex-ids</em></a><em>)</em></figcaption></figure><p>Custom Vertex IDs would not necessarily solve the supernode issue, however. If you have a few larger nodes (maybe we could call them “semi-supernodes”), then of course maybe you would want to try to make sure that they are not located on the same partition to avoid wide partitions by specifying different custom vertex IDs. But if you have a single supernode that is big enough to be a supernode in itself, it does not matter how many other vertices are co-located with it. For example, if the Justin Bieber supernode has 114 million followers as edges since those 114 million edges are all stored on the same partition as the vertex, just that one node is enough to create a wide partition regardless of whether or not other vertices are in the same partition or not.</p><h3>Partitioned Vertices in DSE 5.x</h3><p>Hence Ted Wilmes’ second blog post, on <a href="https://www.experoinc.com/post/dse-graph-partitioning-part-2-taming-your-supernodes">Taming Your Supernodes</a>. He points out that if you cannot avoid creating supernodes in the first place by changing your data model, you can use what is called <strong>Partitioned Vertices</strong>. This allows you to store the edges of certain vertex labels apart from your vertex. So, for the Justin Bieber node, you could split up his 114 million “follower” edges across several partitions, and thereby avoid wide-partitions for that supernode.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*Qt_AaKU1HVkXb_oZ.png" /><figcaption><em>(image source: </em><a href="https://www.experoinc.com/post/dse-graph-partitioning-part-2-taming-your-supernodes"><em>https://www.experoinc.com/post/dse-graph-partitioning-part-2-taming-your-supernodes</em></a><em>)</em></figcaption></figure><p>However, all of this changed in DSE 6.0…</p><h3>How DSE Graph partitions vertices and edges in 6.0–6.7</h3><p>Two big differences stand out in regard to DSE Graph between 5.x and 6.0 — you guessed it, custom vertex IDs and partitioned vertices.</p><h3>All Vertex IDs are “Custom IDs”</h3><p>To quote the <a href="https://docs.datastax.com/en/dse/6.0/dse-dev/datastax_enterprise/releaseNotes/RNdse.html">release notes</a>:</p><blockquote><em>“Standard vertex IDs are deprecated. Use custom vertex IDs instead. (DSP-13485)”</em></blockquote><p>In other words, using the terminology used in the <a href="https://www.experoinc.com/post/dse-graph-partitioning-part-1-custom-vertex-ids">Expero blog post</a>, now there is no option besides implementing “User-Defined Partitioning” using “DSE Graph Custom Vertex Ids” — there is no longer any “DSE Graph Automatic Partitioning” available.</p><h3>Partitioned vertex tables are removed</h3><p>Again, quoting the <a href="https://docs.datastax.com/en/dse/6.0/dse-dev/datastax_enterprise/releaseNotes/RNdse.html">release notes</a> for DSE 6.0:</p><blockquote><em>Partitioned vertex tables (PVT) are removed. (DSP-13676)</em></blockquote><p>I personally was still unsure about the full implications of this comment, so <a href="https://community.datastax.com/questions/11493/partitioning-vertices-in-dse-graph-6x.html">asked for clarification on Datastax Community</a> and got my answer: the mechanism for partitioning vertices was removed.</p><h3>Solution: Intermediary Vertices</h3><p>Instead, the solution to breaking up supernodes is by creating “intermediary vertices”. The best explanation I could find for this is from <a href="https://stackoverflow.com/a/48193296/6952495">this StackOverflow post</a>, by a DSE team member. The idea is that a supernode’s edges would be split up into “buckets”. For example, a vertex with 1 million edges could have 1000 such intermediary vertices (AKA 1000 buckets), and the 1 million edges would then be divided up among them. The result that instead of having 1 million edges, the former supernode now has only 1000 edges (one to each intermediary vertex), and each intermediary vertex has 1000 edges each.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/312/0*wmq56Ko86jROphg5.png" /><figcaption><em>(Image sourced from: </em><a href="https://stackoverflow.com/a/48193296/6952495"><em>https://stackoverflow.com/a/48193296/6952495</em></a><em>. Original source unknown)</em></figcaption></figure><p>There is of course a downside to this approach: if you ever have to traverse from the supernode out to its edges, now there is not only the performance hit caused by “edge cuts”, but now there is an extra hop required (one from Justin Bieber to the intermediate vertex, one from the intermediate vertex to his followers). Additionally, from an application point of view, there is also additional complexity required to navigate through these intermediary vertices.</p><p>That said, being able to break up wide partitions means potentially solving all kinds of other (often worse) problems.</p><h3>Conclusion</h3><p>It is worth noting briefly that there are other ways to mitigate the effects of supernodes as well besides this, including proper <a href="https://docs.datastax.com/en/dse/6.7/dse-dev/datastax_enterprise/graph/graphAntiPatterns.html">indexing</a>, or general graph data modeling strategies such as moving some information to a <a href="http://www.kelvinlawrence.net/book/PracticalGremlin.html#_a_few_words_about_supernodes">property instead of on the edge</a>, or vice versa (depending on your query patterns). Furthermore, in an ideal world, you could avoid creating supernodes in the first place, but if you can’t, then you will want to know how to break it apart when needed.</p><p>In <a href="https://medium.com/@RyanQuey/solving-wide-partitions-caused-by-supernodes-in-dse-6-7-part-two-6a2609e86776">part two</a> we will demonstrate how this works in a more hands on format, showing how this works with code examples and the resulting in partition size. In the end we will see that although there is a solution to the wide-partitions issue in 6.7, it is less than ideal in many ways. From there, in <a href="https://medium.com/@RyanQuey/solving-wide-partitions-caused-by-supernodes-in-dse-6-8-part-three-12fa14e371d0">part three</a> we will go on to see how a better solution is possible due to changes made in DSE 6.8.</p><h3>Series</h3><ol><li><a href="https://medium.com/@RyanQuey/partitioning-in-dse-graph-part-one-91f1cce6a0ba">Partitioning in DSE Graph</a></li><li><a href="https://blog.anant.us/solving-wide-partitions-caused-by-supernodes-in-dse-6-7-part-two/">Solving Wide Partitions caused by Supernodes in DSE 6.7</a></li><li><a href="https://medium.com/@RyanQuey/solving-wide-partitions-caused-by-supernodes-in-dse-6-8-part-three-12fa14e371d0">Solving Wide Partitions caused by Supernodes in DSE 6.8</a></li></ol><p><a href="https://blog.anant.us/partitioning-in-dse-graph/"><em>Originally posted on the Anant blog</em></a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=91f1cce6a0ba" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[An Overview and Comparison of Datastax Dependencies for Cassandra, Spark and Graph]]></title>
            <link>https://medium.com/@Ryan-Kh/an-overview-and-comparison-of-datastax-dependencies-for-cassandra-spark-and-graph-4666bf3393b5?source=rss-50aa1c648e04------2</link>
            <guid isPermaLink="false">https://medium.com/p/4666bf3393b5</guid>
            <category><![CDATA[spark]]></category>
            <category><![CDATA[tinkerpop]]></category>
            <category><![CDATA[datastax]]></category>
            <category><![CDATA[cassandra]]></category>
            <category><![CDATA[dependencies]]></category>
            <dc:creator><![CDATA[Ryan]]></dc:creator>
            <pubDate>Wed, 06 Oct 2021 14:24:55 GMT</pubDate>
            <atom:updated>2022-09-05T09:15:43.054Z</atom:updated>
            <content:encoded><![CDATA[<p>If you like wrestling with dependencies and version incompatibility issues as much as I do, then this post is for you! This post arises out of a project requiring execution of Gremlin traversals using multiple query APIs, and from both a DSE Graph Analytics cluster and an external Spark cluster at the same time. What we found is that keeping all the different available DSE libraries straight wasn’t always easy. The goal of this blog post is to summarize what we learned from the project so that others can know which library to use and why, particularly when using Spark and Graph with Cassandra. We will look at seven libraries, including DSE Java Driver, OSS Unified Java Driver, dse-java-driver-graph, OSS Spark Cassandra Connector, DSE GraphFrames, BYOS, and dse-spark-dependencies.</p><h3>Introduction</h3><p>If all you are trying to do is just write to Cassandra from your Java app, this blog post is not for you. Allow me to just refer you to the <a href="https://github.com/datastax/java-driver">Datastax Java Driver for Apache Cassandra®</a> and you can be on your way.</p><p>However, if you want to integrate other related tools, it starts to get a little more complicated. For example, if you are connecting to Cassandra from Spark, you might wonder when you should use the <a href="https://github.com/datastax/spark-cassandra-connector">OSS Spark Cassandra Connector</a> and when you should use the <a href="https://www.datastax.com/blog/bring-your-own-spark">“BYOS” (Bring your own Spark) jar</a>. Add Graph on top of Spark, and it gets even more complex: should you use the <a href="https://docs.datastax.com/en/developer/java-driver/4.13/manual/core/dse/graph/">Java Driver’s graph functionality</a>, <a href="https://www.datastax.com/blog/datastax-enterprise-graphframes-best-practices">DSE GraphFrames</a>, the BYOS jar, or some combination?</p><p>Indeed, as will be described below, many of these libraries have overlapping functionality and even overlapping Java classes. There is good reason for this as well, but what it means is that if you get it wrong, you can introduce incompatibilities, for example by accidentally overriding the classes in one of your dependencies with the classes of another. Knowing the what each library is for will help you avoid this problem.</p><p>The goal of this post is to line up each of these libraries in a single place and show their specific purpose. It is outside of the scope of this post to give implementation instructions — how you add your libs, whether as some xml in your pom, a jar in your <a href="https://docs.databricks.com/libraries/index.html">Databricks cluster’s libraries</a>, an SBT dependency, or however you choose to do this, is documented elsewhere. But at the very least this will help you to know which dependency to add to your class path for your use case.</p><h3>Starting Point: Java Drivers</h3><p>First we will start with the more fundamental and straightforward libraries, and then work our way up to the more complex. Accordingly, the Java Drivers are the place to start. Note that we are focusing specifically on Datastax libraries here, since the goal is to work upwards towards the other Datastax libraries that depend on the Java Drivers in different ways. For non-Datastax Drivers that work on the JVM, see the lists on the Apache Cassandra page for <a href="https://cassandra.apache.org/doc/latest/cassandra/getting_started/drivers.html#java">Java</a> or <a href="https://cassandra.apache.org/doc/latest/cassandra/getting_started/drivers.html#scala">Scala</a> .</p><h3><a href="https://docs.datastax.com/en/developer/java-driver-dse/">1) DSE Java Driver</a></h3><h3>Description</h3><p>Previously, the DSE Java Driver was the Java driver to use with Datastax enterprise. However, as <a href="https://www.datastax.com/blog/better-drivers-for-cassandra">this Datastax blog post</a> explains, this library was merged into the unified OSS Java driver (see below) as of 4.4.0.</p><p>One might (mistakenly) think that this means we can ignore the DSE Java Driver. As it turns out, the DSE Java Driver is used as a dependency within other Datastax dependencies. Accordingly, when you are up late at night trying to figure out why your external Spark cluster throws some missing dependency error when connecting to your Datastax C* cluster, these are the docs you will need to look into. Just make sure you look into the docs for the right version!</p><h3>Debugging tips</h3><p>Note that by definition, the code for this library is not open source. Sometimes however you can get an idea for the code that is used under the hood by checking out the equivalent classes of the OSS Java driver.</p><p>However, this isn’t enterprise software for nothing — you’ll often just want to either ask <a href="https://community.datastax.com/">Datastax Community</a> or your friendly Datastax Support for help with this one.</p><h3>When to use</h3><p>For the most part, don’t!</p><p>Just use the OSS Java driver, or use the version that comes bundled in the BYOS jar if you’re using that (e.g., for DSE 6.7, it’s DSE Java Driver 1.7). However, sometimes edge cases come up where you have to use this anyways, especially if you’re working on a project that hasn’t migrated to the OSS Java driver yet.</p><p>To be honest here, I’m not sure when anyone should ever use DSE Java Driver 2.x at all (?). If you have any ideas, leave a comment!</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/875/0*bk8VJRA5d3HVex1w.png" /><figcaption><em>Decision tree for DSE Java Driver</em></figcaption></figure><h3>Included in:</h3><ul><li>BYOS jar</li><li>DSE Spark Dependencies</li></ul><h3>Includes:</h3><p>None.</p><p>However, note that technically the “DSE Java Driver” is not just one dependency, but several, including:</p><ul><li>com.datastax.dse:dse-java-driver-core</li><li>com.datastax.dse:dse-java-driver-query-builder</li><li>com.datastax.dse:dse-java-driver-mapper-runtime</li></ul><p>com.datastax.dse:dse-java-driver-graph is also mostly under the umbrella of DSE Java Driver, but I&#39;m discussing it separately below as well. Note that since DSE Java Driver 2.x is based on the OSS Unified Java Driver, it does not have a separate dse-java-driver-graph dependency — all graph functionality is put together under dse-java-driver-core.</p><h3>Helpful Links</h3><ul><li><a href="https://docs.datastax.com/en/developer/java-driver-dse/">DSE Java Driver documentation</a></li><li><a href="https://www.datastax.com/blog/better-drivers-for-cassandra">Explanation of how DSE Java Driver got unified with OSS Java Driver</a></li><li><a href="https://docs.datastax.com/en/developer/java-driver-dse/">DSE Java Driver Java docs for v.2.3</a> (latest as of time of writing)</li><li><a href="https://docs.datastax.com/en/developer/java-driver-dse/2.3/manual/core/graph/">Graph Docs for Java Driver v.2.3</a> (latest as of time of writing)</li><li><a href="https://docs.datastax.com/en/developer/java-driver-dse/1.7/manual/graph/">Graph Docs for Java Driver v.1.7</a> (what is used for BYOS jar for DSE 6.7, at least for now)</li><li><a href="https://docs.datastax.com/en/driver-matrix/doc/java-drivers.html">Java Driver compatibility Matrix</a></li></ul><h3><a href="https://github.com/datastax/java-driver">2) OSS Unified Cassandra Java Driver</a></h3><h3>Description</h3><p>As noted above, this is the library that overtook the DSE Java Driver. And that’s a good thing. However, it’s worth repeating that this is not the driver that gets included in even more recent updates to the BYOS jar, that domain still belongs to the DSE Java Driver.</p><h3>When to Use</h3><p>Unless you are executing your jar from a Spark Cluster, this is the library to use.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Qw8qphiV7BxQCRv_jjZaDw.png" /><figcaption>Decision tree for OSS Java Driver</figcaption></figure><h3>Included in:</h3><ul><li>OSS Spark Cassandra Connector (see below for separate section on this)</li></ul><h3>Includes:</h3><p>None. Though again, this OSS Java driver technically is an umbrella which includes:</p><ul><li>com.datastax.oss:java-driver-core</li><li>com.datastax.oss:java-driver-query-builder</li><li>com.datastax.oss:java-driver-mapper-runtime</li></ul><p>Graph functionality is included in com.datastax.oss:java-driver-core.</p><h3>Helpful Links</h3><ul><li><a href="https://docs.datastax.com/en/developer/java-driver/">OSS Driver Documentation</a></li><li><a href="https://docs.datastax.com/en/developer/java-driver/4.13/manual/core/dse/graph/">Docs for OSS Driver Graph API</a> (v. 4.13, the most recent version as of writing)</li><li><a href="https://github.com/datastax/java-driver">OSS Driver Github</a></li><li><a href="https://docs.datastax.com/en/drivers/java/4.13/">OSS Driver Java Docs</a> (v. 4.13)</li><li><a href="https://docs.datastax.com/en/driver-matrix/doc/java-drivers.html">Java Driver compatibility Matrix</a></li></ul><h3><a href="https://docs.datastax.com/en/developer/java-driver-dse/1.8/manual/graph/querying/fluent_api/">3) DSE Java Driver Graph (dse-java-driver-graph)</a></h3><h3>Description</h3><p>DSE Java Driver Graph is not technically a separate driver from the DSE Java Driver, and is documented under <a href="https://docs.datastax.com/en/developer/java-driver-dse/1.8/manual/graph/querying/fluent_api/">the same set of developer documentation</a>. Indeed, for OSS Driver 4.4.0+ or DSE Java Driver 2.x, dse-java-driver-graph is no more — everything is included in dse-java-driver-core.</p><p>However, for 1.x, it is a separate dependency that you might see in your project’s pom.xml file: com.datastax.dse:dse-java-driver-graph. You will need this on top of the DSE Java Driver Core <a href="https://docs.datastax.com/en/developer/java-driver-dse/1.7/manual/graph/querying/fluent_api/">when performing Graph queries using the Fluent API</a>.</p><h3>When to Use</h3><p>Use when you need to use DSE Java Driver for some reason (is there a reason?) and using the fluent API for graph queries with DSE Java Driver 1.x <em>or some other dependency that includes DSE Java Driver 1.x within it, such as BYOS</em> (see notes under “BYOS” for more on this). At the same time, note that OSS Java Driver also includes the fluent API, so in most (if not all?) use cases, just use that instead.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/634/0*xyXL22ENHOQaD9DR.png" /><figcaption><em>Decision tree for dse-java-driver-graph</em></figcaption></figure><h3>Included in:</h3><p>None.</p><p><strong><em>Note that this is not included in the BYOS jar</em></strong><em> </em><strong><em>or dse-spark-dependencies</em>.</strong></p><p>I mention this just to say, beware: if you do use BYOS jar or dse-spark-dependencies, you will not want to include the DSE Java driver core for example (dse-java-driver-core), but you will want to include DSE Java Driver Graph in your pom (or whatever you&#39;re using to get dependencies on to your class path).</p><h3>Includes:</h3><p>None.</p><h3>Helpful Links</h3><p>Opening up the jar (<a href="https://repo.datastax.com/public-repos/com/datastax/dse/dse-java-driver-graph/">found here</a>) reveals that it includes the namespace com.datastax.dse.graph only:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/708/0*NAbwFjjyfjQ6yHDv.png" /><figcaption><em>Some of the classes you find when you open up dse-java-driver-graph</em></figcaption></figure><p>These classes are not included in the DSE Java Driver API docs and I was unable to find API docs elsewhere for this either. However, <a href="https://docs.datastax.com/en/developer/java-driver-dse/1.8/manual/graph/querying/fluent_api/">this is where the dependency is mentioned</a> in DSE Java Driver docs (v.1.8).</p><h3><a href="https://github.com/datastax/spark-cassandra-connector">4) OSS Spark Cassandra Connector (SCC)</a></h3><h3>Description</h3><p>Having finished an overview of the Java drivers, we can now move on to libraries for integration with Spark. First, we have the <a href="https://github.com/datastax/spark-cassandra-connector">OSS Spark Cassandra Connector</a> (SCC).</p><p>Note that this is not for use with a DSE Analytics cluster, and believe it or not, also not really for using an external (i.e., non-DSE) Spark cluster with your DSE Cassandra cluster. Though there are some specific use cases where you might consider using SCC for connecting an external Spark cluster with your DSE Cassandra cluster, that domain is actually the specific use case for the BYOS jar (more on that later).</p><p>A comparison between SCC and BYOS is helpful here:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/718/0*WPqTACjUJoGO3UBE" /><figcaption><em>Difference between SCC and BYOS jar (</em><a href="https://www.datastax.com/blog/bring-your-own-spark"><em>source: Datastax blog</em></a><em>)</em></figcaption></figure><h3>When to Use</h3><p>In summary, Spark Cassandra Connector is for connecting non-DSE Spark with non-DSE Cassandra. For example, if you’re using some implementation of <a href="https://alexott.blogspot.com/2020/07/working-with-datastax-astra-from.html">OSS Cassandra (including Datastax Astra) with Databricks</a>, SCC is for you.</p><p>If you’re using non-DSE Spark with DSE Cassandra however, you’ll probably benefit from the extra features that come along with the BYOS jar.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/960/0*ijWkVOIRkREQNbtA.png" /><figcaption><em>Decision tree for SCC</em></figcaption></figure><h3>Special Use Case: Spark Cassandra Connector With Databricks</h3><p>Databricks Spark has its own runtime and accordingly comes with certain dependencies and classes predefined. This is part of why people use Databricks in the first place, since it means you have less to set up yourself. On the other hand, this can lead to dependency conflicts. For example, Datastax Java Driver requires a Guava version of <a href="https://docs.datastax.com/en/developer/java-driver-dse/1.8/faq/osgi/#how-to-override-guava-s-version">at least 16.0.1</a>, whereas Databricks runtimes use Guava 15 (as of the latest version at time of writing, <a href="https://docs.databricks.com/release-notes/runtime/9.1.html#installed-java-and-scala-libraries-scala-212-cluster-version">9.1 LTS</a>).</p><p>Such conflicts can cause exceptions with helpful error messages such as the following:</p><pre>java.lang.NoSuchMethodError: com.datastax.driver.dse.DseSession.executeGraphAsync(Lcom/datastax/driver/dse/graph/GraphStatement;)Lrepackaged/com/google/common/google/common/util/concurrent/ListenableFuture</pre><p>Accordingly, if using SCC with Databricks, you will want to use the spark-cassandra-connector-assembly artifact rather than spark-cassandra-connector. As noted in <a href="https://community.datastax.com/answers/9540/view.html">this Datastax community post</a>, spark-cassandra-connector-assembly &quot;is a fat jar with some of the dependencies shaded. It was created to avoid classpath conflicts when SCC is used in Databricks env.” Watch out, since there is not much in the way of documentation for spark-cassandra-connector-assembly, besides <a href="https://github.com/datastax/spark-cassandra-connector/blob/master/doc/12_building_and_artifacts.md#building-the-assembly-jar">this brief comment in the docs</a> and <a href="https://alexott.blogspot.com/2020/07/working-with-datastax-astra-from.html">this blog post by one of the maintainers</a>.</p><h4>Further reading regarding SCC with Databricks:</h4><ul><li><a href="https://github.com/datastax/spark-cassandra-connector/blob/master/doc/12_building_and_artifacts.md#building-the-assembly-jar">The only official comments I could find on </a><a href="https://github.com/datastax/spark-cassandra-connector/blob/master/doc/12_building_and_artifacts.md#building-the-assembly-jar">spark-cassandra-connector-assembly</a></li><li><a href="https://alexott.blogspot.com/2020/07/working-with-datastax-astra-from.html">Blog post by Alex Ott on using Astra with Databricks, demonstrating use of spark-cassandra-connector-assembly</a></li><li><a href="https://www.youtube.com/watch?v=fk6XBjjiEH0">Anant webinar</a> and <a href="https://blog.anant.us/connect-databricks-and-datastax-astra/">corresponding blog post</a> on Astra with Databricks</li><li><a href="https://docs.databricks.com/release-notes/runtime/releases.html">Databricks Release Notes</a>, with version compatibility matrix. For specific Java/Scala libraries and versions on the Databricks runtime classpath, see release notes for your specific Databricks runtime version (e.g., <a href="https://docs.databricks.com/release-notes/runtime/9.1.html#installed-java-and-scala-libraries-scala-212-cluster-version">see here for Databricks runtime v. 9.1</a>).</li></ul><h4>Some resources related to Guava issues with Datastax Libraries:</h4><ul><li><a href="https://docs.datastax.com/en/developer/java-driver-dse/1.8/faq/osgi/#how-to-override-guava-s-version">https://docs.datastax.com/en/developer/java-driver-dse/1.8/faq/osgi/#how-to-override-guava-s-version</a></li><li><a href="https://groups.google.com/a/lists.datastax.com/g/spark-connector-user/c/uB_DN_CcK2k">https://groups.google.com/a/lists.datastax.com/g/spark-connector-user/c/uB_DN_CcK2k</a></li><li><a href="https://stackoverflow.com/questions/35618126/dse-cassandra-has-guava-16-0-1-jar-conflict-issue-with-cdh-spark">https://stackoverflow.com/questions/35618126/dse-cassandra-has-guava-16-0-1-jar-conflict-issue-with-cdh-spark</a></li><li><a href="https://stackoverflow.com/questions/36877897/detected-guava-issue-1635-which-indicates-that-a-version-of-guava-less-than-16">https://stackoverflow.com/questions/36877897/detected-guava-issue-1635-which-indicates-that-a-version-of-guava-less-than-16</a></li></ul><h3>Included in:</h3><p>SCC is not included in these libraries directly, but what appears to be a closely related library com.datastax.dse:spark-connector is included in the following:</p><ul><li>BYOS</li><li>dse-spark-dependencies</li></ul><p>However, note that even though it is included as a dependency in these two libraries, all of its transitive dependencies are excluded, at least in dse-spark-dependencies:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/525/1*xhKuYmbDqXbQBtAHV_H-Fw.png" /><figcaption>The entry for SCC in the dse-spark-dependencies pom.xml file</figcaption></figure><h3>Includes:</h3><ul><li>OSS Java Driver</li></ul><p>According to this <a href="https://community.datastax.com/questions/9525/can-i-use-byos-jar-at-the-same-time-as-dse-java-dr.html">Datastax community post</a>: “Similarly to BYOS, SCC comes with a version of the driver that should not be overridden in user apps.”</p><p>You can find the OSS Java driver version used by SCC in their repo under <a href="https://github.com/datastax/spark-cassandra-connector/blob/master/project/Versions.scala">project/Versions.scala</a>. E.g,. for <a href="https://github.com/datastax/spark-cassandra-connector/blob/v2.5.1/project/Versions.scala#L8">SCC 2.5.1, it’s OSS Java driver 4.7.2</a>.</p><p>Note also that SCC does not include DSE GraphFrames. Accordingly, you can perform graph traversals on your DSE Graph-enabled cluster using the Graph functionality built into the OSS Java driver if you want to, but to take advantage of the <a href="https://docs.datastax.com/en/dse/6.7/dse-dev/datastax_enterprise/graph/graphAnalytics/dseGraphFrameOverview.html#ChoosingwhentouseDseGraphFrameorDSEGraphOLAPqueries">Spark-specific optimization provided by DSE GraphFrames</a>, you will have to add that separately.</p><p>As an aside, a separate alternative altogether is to use <a href="https://docs.datastax.com/en/dse/6.7/dse-dev/datastax_enterprise/graph/graphAnalytics/graphAnalyticsSparkGraphComputer.html">DSE Graph OLAP queries</a>, which also makes use of DSE Spark with Graph.</p><h3>Helpful Links</h3><ul><li><a href="https://github.com/datastax/spark-cassandra-connector">https://github.com/datastax/spark-cassandra-connector</a></li><li><a href="https://groups.google.com/a/lists.datastax.com/g/spark-connector-user">SCC google group</a></li><li><a href="https://www.datastax.com/blog/spark-application-dependency-management">Overview of which dependencies to use for connecting to C* from Spark</a>. It’s a little bit outdated though, from May 2017. Note also that it does not discuss when to use BYOS.</li></ul><h3><a href="https://docs.datastax.com/en/dse/6.7/dse-dev/datastax_enterprise/graph/graphAnalytics/dseGraphFrameOverview.html">5)</a> <a href="https://docs.datastax.com/en/dse/6.7/dse-dev/datastax_enterprise/graph/graphAnalytics/dseGraphFrameOverview.html">DSE GraphFrames</a></h3><h3>Description</h3><p>As described by <a href="https://www.datastax.com/blog/datastax-enterprise-graphframes-best-practices">the Datastax blog</a>:</p><blockquote>“The DseGraphFrame package provides the Spark base API for bulk operations and analytics on DSE Graph. It is inspired by Databricks’ <a href="https://databricks.com/blog/2016/03/03/introducing-graphframes.html"><strong>GraphFrame</strong></a> library and supports a subset of <a href="http://tinkerpop.apache.org/"><strong>Apache TinkerPop™ Gremlin</strong></a> graph traversal language. It supports reading of DSE Graph data into a GraphFrame and writing GraphFrames from any format supported by Spark into DSE Graph.</blockquote><blockquote>The package ties <a href="https://www.datastax.com/products/datastax-enterprise-analytics"><strong>DSE Analytics</strong></a> and <a href="https://www.datastax.com/products/datastax-enterprise-graph"><strong>DSE Graph</strong></a> components together even stronger than it was before! Spark users will have direct access to the Graph and Graph users will be able to perform bulk deletes, updates and have an advanced API for faster scanning operations.”</blockquote><h3>When to Use</h3><p>According to Datastax documentation, when there are more complex queries involved, it is better to use DSE Graph OLAP instead of DSE GraphFrame lib, at least as of DSE 6.7. However, simpler Gremlin queries can benefit from performance optimizations provided by DSE GraphFrame. As stated in the <a href="https://www.datastax.com/products/datastax-enterprise-graph">DSE GraphFrames docs</a>: “<a href="https://docs.datastax.com/en/dse/6.7/dse-dev/datastax_enterprise/graph/graphAnalytics/graphAnalyticsSparkGraphComputer.html">DSE Graph OLAP</a> has broader support for Gremlin than the DseGraphFrame API. While Graph OLAP is the best choice for deep queries, simple filtering and counts are much faster using the DseGraphFrame API.”</p><p>Between DSE GraphFrame and the Graph API provided by the OSS or DSE Java Drivers, in general DSE GraphFrame is going to be a better pick. The main exception is if you have a very specific use case which does not allow use of DSE GraphFrames, for example, if your Gremlin queries are not supported by the more limited DSE GraphFrame API.</p><p>However, note that unless I’m mistaken, you should almost never need to define this in your app jar’s dependencies, since DSE GraphFrames is only for DSE graph-enabled Clusters, which means you’ll always either be using BYOS or dse-spark-dependencies, both of which include DSE GraphFrames. The only exception is if there’s some edge case where you have a DSE Graph Cluster, but need to use OSS SCC for whatever reason and still want to use DSE GraphFrame API.</p><h3>Includes:</h3><p>None</p><h3>Included In:</h3><ul><li>BYOS</li><li>dse-spark-dependencies</li></ul><h3>Helpful Links</h3><ul><li><a href="https://www.datastax.com/blog/introducing-dse-graph-frames">https://www.datastax.com/blog/introducing-dse-graph-frames</a></li><li><a href="https://www.datastax.com/blog/datastax-enterprise-graphframes-best-practices">https://www.datastax.com/blog/datastax-enterprise-graphframes-best-practices</a></li><li><a href="https://docs.datastax.com/en/dse/6.7/dse-dev/datastax_enterprise/graph/graphAnalytics/dseGraphFrameOverview.html">DSE Graph Frame docs (for DSE 6.7)</a></li><li><a href="https://docs.datastax.com/en/dse/6.7/dse-dev/datastax_enterprise/graph/graphAnalytics/dseGraphFrameOverview.html#ChoosingwhentouseDseGraphFrameorDSEGraphOLAPqueries">When to use DSE Graph OLAP and when to use DSE GraphFrames</a></li></ul><h3><a href="https://docs.datastax.com/en/dse/6.7/dse-dev/datastax_enterprise/spark/byosOverview.html">6) BYOS</a></h3><h3>Description</h3><p>Finally, we have arrived at the BYOS library. If you have been able to follow up to this point, then hopefully this section won’t be too bad for you either. Be warned however, that it gets a little crazy in here.</p><p>The <a href="https://www.datastax.com/blog/bring-your-own-spark">announcement post for BYOS</a> says it well: “Bring Your Own Spark (BYOS) is a feature of DSE Analytics designed to connect from external Apache Spark™ systems to DataStax Enterprise with minimal configuration efforts.” Part of how it does this is by bundling together several other libraries into one, so you don’t have to include them in your pom yourself.</p><h3>When to Use</h3><p>Use BYOS when connecting from external Spark to DSE C*.</p><p><strong><em>One thing to watch out for</em></strong>: BYOS is only tested with the Spark version that is integrated in the corresponding DSE release, as well as a couple other Spark distributions (e.g., <a href="https://docs.datastax.com/en/dse/6.8/dse-dev/datastax_enterprise/spark/byosOverview.html">BYOS jar for DSE 6.8</a> is tested with Spark 2.4, Hortonworks Data Platform 2.5, and Cloudera CDH 5.10). Watch out for this if your external Spark cluster uses a different version (thanks to <a href="https://www.linkedin.com/in/adamfortuno/">Adam Fortuno</a> for pointing this out).</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/723/0*zfzCAF32lU8-LD6v.png" /></figure><h4>When to use instead of SCC:</h4><p>When you have an external Spark cluster that is connecting to an <strong><em>DSE C* </em></strong>cluster, use BYOS. When connecting to <strong><em>OSS C*</em></strong>, use SCC.</p><p>For more on SCC, see separate section above.</p><h4>When to use instead of DSE spark dependencies:</h4><p>DSE spark dependencies is for when running on Spark from a <strong><em>DSE Analytics</em></strong> (i.e., Spark-enabled) cluster, BYOS is for when running on an <strong><em>external Spark</em></strong> cluster.</p><p>For more on DSE spark dependencies, see separate section below.</p><h3>Included in:</h3><ul><li>None</li></ul><h3>Includes:</h3><ul><li>DSE GraphFrames (source: <a href="https://community.datastax.com/questions/734/in-a-byos-approach-what-is-the-minimum-config-requ.html">Datastax Community post</a>). NOTE: Differently from dse-spark-dependencies, these classes are included in the BYOS jar itself.</li><li>DSE Spark Cassandra connector (SCC) (though note that this not the same as OSS SCC, but is a closely related library com.datastax.dse:spark-connector)</li></ul><p><a href="https://www.datastax.com/blog/bring-your-own-spark#:~:text=BYOS%20extends%20the,Spark%20Cassandra%20Connector">BYOS is actually built on top of SCC</a>, but just has some extra features built in and extra dependencies. In other words, DSE is to C* as BYOS is to SCC. I am not sure what version it uses however.</p><ul><li>DSE Java Driver</li></ul><p>Note that <a href="https://community.datastax.com/questions/9525/can-i-use-byos-jar-at-the-same-time-as-dse-java-dr.html">according to this Datastax Community post</a>, the version of DSE Java Driver included is “the same DSE Java driver (not OSS) that ships with the particular version of DSE. For example, <a href="https://docs.datastax.com/en/dse/6.7/dse-admin/datastax_enterprise/releaseNotes/RNdse.html#RNdse677__677comp">DSE 6.7.7 includes DSE Java driver 1.7.1</a>.” However, also note that according to <a href="https://community.datastax.com/questions/9525/can-i-use-byos-jar-at-the-same-time-as-dse-java-dr.html">a comment by a maintainer</a>, as of December 2020, there is a “plan to upgrade to 1.8.3-dse (unreleased yet) in the near future”.</p><p><strong><em>Implication:</em></strong> What this means is that if you are using the BYOS library to execute Gremlin traversals, make sure not to also include DSE GraphFrames or SCC or a separate Java Driver, or else you might run into conflicts. However, since BYOS is including DSE Java Driver 1.x, sometimes you will have to add dse-java-driver-graph also, for example, when using the fluent API.</p><p><strong><em>One other takeaway from what’s not on this list:</em></strong> while BYOS includes DSE Java Driver (which has some Graph functionality baked in) and DSE GraphFrames, BYOS does not include DSE Java Driver graph (com.datastax.dse:dse-java-driver-graph).</p><h3>Helpful Links</h3><p>General overviews:</p><ul><li><a href="https://www.datastax.com/blog/bring-your-own-spark">https://www.datastax.com/blog/bring-your-own-spark</a></li><li><a href="https://docs.datastax.com/en/dse/6.7/dse-dev/datastax_enterprise/spark/byosOverview.html">https://docs.datastax.com/en/dse/6.7/dse-dev/datastax_enterprise/spark/byosOverview.html</a></li></ul><p>More specific posts:</p><ul><li><a href="https://community.datastax.com/questions/9525/can-i-use-byos-jar-at-the-same-time-as-dse-java-dr.html">https://community.datastax.com/questions/9525/can-i-use-byos-jar-at-the-same-time-as-dse-java-dr.html</a></li><li><a href="https://community.datastax.com/questions/734/in-a-byos-approach-what-is-the-minimum-config-requ.html">https://community.datastax.com/questions/734/in-a-byos-approach-what-is-the-minimum-config-requ.html</a></li></ul><h3>7) dse-spark-dependencies</h3><h3>Description</h3><p>One could be forgiven for thinking that we would be able to stop at six dependencies, but alas, there is yet one more: the dse-spark-dependencies dependency. According to <a href="https://www.datastax.com/blog/spark-application-dependency-management">the Datastax blog</a>:</p><blockquote>“[The dse-spark-dependencies library] instructs a build tool to include all dependency JAR files that are distributed with DSE and are available in the DSE cluster runtime classpath. These JAR files include Apache Spark JARs and their dependencies, Apache Cassandra JARs, Spark Cassandra Connector JAR, and many others. Everything that is needed to build your bootstrap Spark Application is supplied by the dse-spark-dependencies dependency. To view the list of all dse-spark-dependencies dependencies, visit our <a href="https://repo.datastax.com/public-repos/com/datastax/dse/dse-spark-dependencies/">public repo</a> and inspect the pom files that are relevant to your DSE cluster version.”</blockquote><p>As noted in the same blog post, this is specifically for use with a DSE Analytics-enabled (i.e., Spark-enabled) cluster.</p><h3>When to Use:</h3><p>DSE spark dependencies is for when executing your jar on Spark from a DSE analytics cluster, in contrast to BYOS, which is for when running on external Spark.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/655/0*8UBwveL5mFHJyhPo.png" /><figcaption><em>Decision tree for dse-spark-dependencies</em></figcaption></figure><h3>Included in:</h3><ul><li>None</li></ul><h3>Includes:</h3><p>According to <a href="https://www.datastax.com/blog/spark-application-dependency-management">the Datastax blog</a> and the <a href="https://repo.datastax.com/public-repos/com/datastax/dse/dse-spark-dependencies/6.8.9/">dse-spark-dependencies pom file</a> (as of v. 6.8.9):</p><ul><li>DSE Java Driver Core (as of <a href="https://repo.datastax.com/public-repos/com/datastax/dse/dse-spark-dependencies/6.7.7/">DSE 6.7.7</a>, that’s DSE Java Driver 1.7.1)</li><li>DSE Spark Cassandra Connector (note that this is not the same as the <strong><em>OSS</em></strong> SCC mentioned above, but is a closely related library com.datastax.dse:spark-connector)</li><li>DSE GraphFrames (note that differently from BYOS, the DSE GraphFrames classes are not included in the dse-spark-dependencies jar itself, but are given as a dependency in the dse-spark-dependencies pom.xml)</li><li>Apache Spark JARs and their dependencies</li></ul><h3>Helpful Links</h3><ul><li><a href="https://docs.datastax.com/en/dse/6.8/dse-dev/datastax_enterprise/spark/sparkJavaApi.html">https://docs.datastax.com/en/dse/6.8/dse-dev/datastax_enterprise/spark/sparkJavaApi.html</a></li><li><a href="https://www.datastax.com/blog/spark-application-dependency-management">Overview of which dependencies to use for connecting to C* from Spark</a>. It’s a little bit outdated though, from May 2017. Note also that it does not discuss when to use BYOS.</li><li><a href="https://community.datastax.com/questions/734/in-a-byos-approach-what-is-the-minimum-config-requ.html">https://community.datastax.com/questions/734/in-a-byos-approach-what-is-the-minimum-config-requ.html</a></li><li><a href="https://community.datastax.com/questions/9525/can-i-use-byos-jar-at-the-same-time-as-dse-java-dr.html">https://community.datastax.com/questions/9525/can-i-use-byos-jar-at-the-same-time-as-dse-java-dr.html</a></li><li><a href="https://github.com/DataStax-Examples/SparkBuildExamples">Example code repo provided by Datastax for Spark + Cassandra</a></li></ul><h3>Conclusion</h3><p>A chart to summarize what gets included into what might be helpful here:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*52Fs-5TrMv6j6aovNDq8Tw.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*cH00X0qlF-5zTHrTTx1d9Q.png" /></figure><p>If we gloss over some details, we can also give a rough decision tree as well:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/755/1*26ch5w-jWk0j8ejBChzXpA.png" /></figure><p>In summary, depending on your use case, Datastax has put out a number of very helpful libraries, and in general each individual library is fairly well documented. The problem is that there is not as much documentation describing how all of these libraries relate to each other, and when to use which library when. I can understand if this hasn’t been much of a page-turner, but hopefully this post will help to keep things straight somewhat.</p><p>P.S., I apologize in advance for broken links, which are bound to arise as time passes and pages move. If you find some, please let me know and we can keep this post updated for future readers.</p><p><a href="https://blog.anant.us/an-overview-and-comparison-of-datastax-dependencies-for-cassandra-spark-graph/"><em>Originally posted on the Anant blog</em></a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=4666bf3393b5" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Elassandra with NodeJS Demo — Part Two]]></title>
            <link>https://medium.com/@Ryan-Kh/elassandra-with-nodejs-demo-part-two-30d5e3886058?source=rss-50aa1c648e04------2</link>
            <guid isPermaLink="false">https://medium.com/p/30d5e3886058</guid>
            <category><![CDATA[nodejs]]></category>
            <category><![CDATA[cassandra]]></category>
            <category><![CDATA[react]]></category>
            <category><![CDATA[elassandra]]></category>
            <category><![CDATA[elasticsearch]]></category>
            <dc:creator><![CDATA[Ryan]]></dc:creator>
            <pubDate>Thu, 25 Jun 2020 05:26:38 GMT</pubDate>
            <atom:updated>2020-06-27T11:48:29.019Z</atom:updated>
            <content:encoded><![CDATA[<h3>Elassandra with NodeJS Demo — Part Two</h3><h4>Connecting Elassandra to NodeJS and React</h4><p>In <a href="https://medium.com/@rlquey2/elassandra-with-nodejs-demo-part-1-setting-up-elassandra-f94234aa4fc1">part one</a>, we set up Elassandra using Docker and looked at our data via Kibana and the command line. Now, let’s take a look to see what it looks like to connect Elassandra to a basic NodeJS Express app, React and <a href="https://github.com/searchkit/searchkit">Searchkit</a>. Searchkit provides an easy way to request and display Elasticsearch data in the a React app, which fits our use case perfectly.</p><h3>Installation</h3><h4>Install React</h4><p>First, let’s setup React. I’m using Node 10 and nvm, but you use what works for you :). We’re going to do it the easy way today, using create-react-app:</p><pre>npx create-react-app elassandra-demo<br>cd elassandra-demo<br>npm start</pre><h4>Setup Express</h4><p>First let’s install our package:</p><pre>npm install express — save</pre><p>Next we’ll add our express server. Create app.js and add the following code:</p><pre>touch ./app.js</pre><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/db2b5db015354b5b243d2da7993ee2e1/href">https://medium.com/media/db2b5db015354b5b243d2da7993ee2e1/href</a></iframe><p>Note that we set it up so that we have to whitelist the client url for our cors policy. If you don’t do this, your searches won’t be able to go through since Express won’t let them. Be careful for example, since the way this is written http://localhost:3000 will be fine but if you use http://127.0.0.1:3000 then Express will just block the request.</p><p>Next, we’ll use a basic routes direct reports with a single router:</p><pre>mkdir routes<br>touch routes/index.js</pre><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/db6606e0835e05c07507c5f88fd39c9e/href">https://medium.com/media/db6606e0835e05c07507c5f88fd39c9e/href</a></iframe><p>How this will work is that in production we will build the React code (using npm run build which was defined for us by create-react-app) and serve it from express (via the index router). But in development, in order to take advantage of the create-react-app hot reloader, we’re just going to hit the hot reloader server via localhost:3000 for React, and for everything we will use our express server at localhost:8080.</p><p>This is preferable to having to continually rebuild our React code for every change in development. Again, this is not a perfect development environment, but will do for our use case, since really we want to just get up and running and see how we can access Elassandra via express.</p><p>We are now ready to add React and Searchkit.</p><h3>Setup Searchkit</h3><p><a href="https://github.com/searchkit/searchkit">Searchkit</a> is a UI for search based on React. We will be basically following <a href="http://docs.searchkit.co/stable/setup/project-setup.html">their quickstart instructions</a> along with their <a href="https://github.com/searchkit/searchkit#quick-intro">sample App.js file</a> to make this simple.</p><p>First install the package:</p><pre>npm install searchkit —save</pre><p>Then, to get searchkit styles, add this link tag to your public/index.html file in the header, that create-react-app built for us before:</p><pre>&lt;link rel=&quot;stylesheet” type=&quot;text/css&quot; href=&quot;//cdn.jsdelivr.net/searchkit/2.0.0/theme.css&quot;&gt;</pre><p>(Note that even though I’m using searchkit 2.4.1, apparently the css from 2.0.0 is what they want us to use as of the time of this writing)</p><h3>Build our Searchkit Component</h3><p>We’re going to just make the search view our home page, so let’s go ahead and change the src/App.js file that create-react-app generated for us to more or less what they use as a <a href="https://github.com/searchkit/searchkit#quick-intro">sample App.js file</a>, but <a href="http://docs.searchkit.co/stable/setup/project-setup.html">with imports</a>, and adjusting their components to match our dataset:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/c8a1cd7673ea7efff926dc1390576aa5/href">https://medium.com/media/c8a1cd7673ea7efff926dc1390576aa5/href</a></iframe><h4>Some things to point out:</h4><ul><li>We are using our Express app as an endpoint instead of Elasticsearch directly. You can change the endpoint that Searchkit uses from http://localhost:8080/flight-search to http://localhost:9200/kibana_sample_data_flights if you want to, (kibana_sample_data_flights being the specific Elasticsearch index we want to search). Basically whatever you put here, Searchkit will hit that url and put the search query in a json body.</li><li>If you did you can skip using Express altogether. On the other hand, it will mean that you’re exposing your Elasticsearch server to the outside world if you ever go into production, and will need to <a href="http://docs.searchkit.co/v2.0.0/setup/elasticsearch.html">setup a CORS policy</a> on your Elasticsearch server as well.</li><li>Take a look at the <a href="https://www.elastic.co/guide/en/elasticsearch/reference/current/run-a-search.html#run-uri-search">Elasticsearch REST API docs</a> for more options. For example, you could also specify <a href="https://www.elastic.co/guide/en/elasticsearch/reference/current/run-a-search.html#search-multiple-indices">searching multiple indices</a>.</li></ul><p>We added a component for the search results as well, so let’s make that real quick, I called mine src/components/FlightHit.js:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/35f902b155bb5d908b7432a55557332f/href">https://medium.com/media/35f902b155bb5d908b7432a55557332f/href</a></iframe><p>Notice that Searchkit gives us direct access to the Elasticsearch data in the props here, with each hit found at props.result._source. If you want to change what you display, you can access other data from the Elasticsearch index through the props that way.</p><h4>Start the server</h4><p>In one terminal, start the Express server at localhost:8080:</p><pre>node app.js</pre><p>Then, while that is running in another terminal start the React development server:</p><pre>npm start</pre><p>Now take a look at localhost:3000 in your browser. It should show something like this:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*exSMNVJyhHj09W1k-R3ydA.png" /></figure><p>Again, not the best development set up I’ve ever seen, but just something simple to get us started. You can click around and filter by carrier, destination or origin.</p><p>To see all the code together in one place, check out the <a href="https://github.com/RyanQuey/node-elassandra-demo">Github repository here</a>.</p><h3>Conclusion</h3><p>Elassandra makes it easy to quickly and easily use Cassandra together with Elasticsearch, allowing us to take advantage of the strength of each. With a simple NodeJS server on top of that, and tools like React and Searchkit, we can access and display our data whether it originated in Cassandra or Elasticsearch. If you have a Cassandra cluster and want to add greater querying power, or on the other hand have Elasticsearch and want to pair it with the capabilities of Cassandra, it’s definitely worth giving Elassandra a look.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=30d5e3886058" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Elassandra with NodeJS Demo — Part 1: Setting up Elassandra]]></title>
            <link>https://medium.com/@Ryan-Kh/elassandra-with-nodejs-demo-part-1-setting-up-elassandra-f94234aa4fc1?source=rss-50aa1c648e04------2</link>
            <guid isPermaLink="false">https://medium.com/p/f94234aa4fc1</guid>
            <category><![CDATA[elassandra]]></category>
            <category><![CDATA[nodejs]]></category>
            <category><![CDATA[tutorial]]></category>
            <category><![CDATA[cassandra]]></category>
            <dc:creator><![CDATA[Ryan]]></dc:creator>
            <pubDate>Thu, 25 Jun 2020 03:42:44 GMT</pubDate>
            <atom:updated>2020-06-27T11:48:47.239Z</atom:updated>
            <content:encoded><![CDATA[<h3>Elassandra with NodeJS Demo — Part One</h3><h4>Setting up Elassandra</h4><h3>Why this tutorial</h3><p>I’ve used both Elasticsearch and Cassandra separately before, but have never had a chance to use Elassandra before, and wanted to give it a try. Accordingly, this is written not from the perspective of an expert, but from the perspective of someone who is just picking it up for the first time.</p><p>Hopefully this demonstrates something to you as it did to me, namely just how easy it is to get these tools up and running together.</p><p>In part one, we’ll setup Elassandra, and in <a href="https://medium.com/@rlquey2/elassandra-with-nodejs-demo-part-two-30d5e3886058">part two</a>, we’ll connect a simple NodeJS server with React and Searchkit to provide a nice user interface.</p><h3>What is Elassandra?</h3><p>In the words of the <a href="https://www.elassandra.io/">Elassandra home page</a>:</p><blockquote>Elassandra simplifies your data stack by integrating <a href="https://www.elastic.co/fr/products/elasticsearch">Elasticsearch</a>® into <a href="http://cassandra.apache.org/">Apache Cassandra</a>®.</blockquote><p>There are number of reasons why you might want to do this, but I’ll leave that discussion for <a href="https://dzone.com/articles/7-reasons-why-open-source-elassandra-cassandra-ela">someone else</a>. What I want to do is show how we can get it up and running and connected to a basic NodeJS app (built with Express), and visualized using React and <a href="https://github.com/searchkit/searchkit">SearchKit</a>.</p><h3>Installation</h3><p>For this tutorial, we will be using their quickstart for Docker, <a href="http://doc.elassandra.io/en/latest/quickstart.html#start-your-cluster">following these instructions</a>. First, we’ll setup a docker-compose file,</p><h4>Setup docker compose file for EC*</h4><pre>mkdir -p ci &amp;&amp; touch ci/docker-compose.yml</pre><h4>Add this to your file</h4><p>You’ll probably want to use vim, so run your command like so:</p><pre>vim ci/docker-compose.yml</pre><p>And then add the following code:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/03561b7f5e0358d1ef25cc8f89a9cba6/href">https://medium.com/media/03561b7f5e0358d1ef25cc8f89a9cba6/href</a></iframe><p><strong>This gives us three containers:</strong> seed_node, node, and kibana.</p><ul><li><a href="https://www.elastic.co/kibana">Kibana</a> is a visualization tool for elasticsearch. It has port 5601 opened up so we can access it from our browser.</li><li>seed_node has ports exposed for us to access, and is what we will use to access via Kibana. However, although only seed_node has ports exposed, both seed_mode and node have both Cassandra and Elasticsearch running on them.</li></ul><p>We are also doing a <a href="https://docs.docker.com/compose/compose-file/#links">link</a> between our node and seed_node containers. This is <a href="https://docs.docker.com/network/links/">deprecated</a>, but using it for now just for the tutorial.</p><h4>Start our Containers</h4><p>To start everything, we just run docker-compose:</p><pre>docker-compose — project-name test -f ./ci/docker-compose.yml up -d — scale node=0</pre><pre>docker-compose — project-name test -f ./ci/docker-compose.yml up -d — scale node=1</pre><p>Now let’s run nodetool to show all of the nodes in our Cassandra cluster:</p><pre>docker exec -i test_seed_node_1 nodetool status</pre><p>And we should get something like this:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*vWTI4_ZFaeUXyyK5vLrJDA.png" /></figure><p>Notice now that there are two nodes up and running.</p><ul><li>UN means it is up (U) and healthy (N for NORMAL)</li><li>You also see some details about token distribution and host IDs.</li></ul><h4>A couple notes/disclaimers:</h4><ul><li>If you are following their instructions closely, and put your compose file in a subdirectory ./ci/ then you have to make sure to specify the location of your docker compose file as above, (./ci/docker-compose.yml ).</li><li>Using scale in docker compose is <a href="https://docs.docker.com/compose/reference/scale/">also deprecated</a>. But again, this works fine for us just as a proof of concept.</li></ul><h3>Check Kibana</h3><p>We can now use Kibana to view our Elasticsearch data at <a href="http://localhost:5601/">http://localhost:5601</a>. If we scroll down, we can create some sample data to play around with.</p><h3>Try out the sample data</h3><p>I’m trying the sample flight data, sounds interesting enough! If you are following along in the tutorial, go ahead and use the same data set since it’s what will use as we continue to build out our app. Just click on the “Try our sample data” button.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/726/1*TrB8PN5lAZYNi6diRouz_A.png" /></figure><p>Then under “Sample flight data”, click the “Add” button to get started.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*y2g81pCF1eU3_0AN3zZyow.png" /></figure><p>If we then click on “View Data”, we have this nice dashboard to look at:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Hv-4P_peKLicMy8yHLKavg.png" /></figure><p>This Kibana dashboard makes it easy to dig deeper into our data. For example, to see only flights with an origin of Japan, I simply click on Japan and it filters it for me in moments:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*_BQU-sDU6O85J5-jcy1Q7g.png" /></figure><p>As you can see by the highlighted data in the table below, now data is filtered by OriginCountry, only returning records where the value is “JP” (for Japan).</p><p>That’s a pretty neat dashboard to have out of the box!</p><h3>Exploring Data over the Elasticsearch REST API</h3><p>Integration with Elasticsearch means that we automatically have a REST API. To get some information about our Elasticsearch cluster, we can use curl and take advantage of the ports we exposed in our docker containers before. First let’s <a href="https://www.elastic.co/guide/en/elasticsearch/reference/current/cat-indices.html#cat-indices">get our indices</a>:</p><pre>curl &quot;<a href="http://localhost:9200/_cat/indices?v">http://localhost:9200/_cat/indices?v</a>&quot;</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*bfa9zlga6OrGoD_cWeY6dQ.png" /></figure><p>We can use the returned indices list to find our sample data. First let’s take a look at the index itself, using <a href="https://www.elastic.co/guide/en/elasticsearch/reference/current/indices-get-index.html">Elasticsearch Get Index API</a>:</p><pre>curl &quot;<a href="http://localhost:9200/kibana_sample_data_flights?pretty">http://localhost:9200/kibana_sample_data_flights?pretty</a>&quot;</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/728/1*F_l1PzYGfgHjw8ooCDqC9g.png" /></figure><p>To actually get some records, we run a search on that endpoint using <a href="https://www.elastic.co/guide/en/elasticsearch/reference/current/search-search.html">Elasticsearch search API</a>. (Here we’re using q, but you can find <a href="https://www.elastic.co/guide/en/elasticsearch/reference/current/search-search.html#search-search-api-example">more examples online</a>). We’ll filter by OriginCountry, giving us data similar to what we saw when we filtered using the Kibana GUI before (unless you like looking at your data using maps and charts of course).</p><pre>curl &quot;<a href="http://localhost:9200/kibana_sample_data_flights/_search?q=OriginCountry:JP&amp;pretty">http://localhost:9200/kibana_sample_data_flights/_search?q=OriginCountry:JP&amp;pretty</a>&quot;</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/808/1*BgbeL0tXWKJRqiLKfSm47Q.png" /></figure><h3>Explore the data within Cassandra</h3><p>Since this Kibana dashboard is integrated with Cassandra via Elassandra, we should now be able to view this sample data that we just made in our Cassandra DB. An easy way to check this and play around with the data is cqlsh:</p><pre>docker exec -i -t test_seed_node_1 cqlsh</pre><p>To find out what key space they made for me with the sample data, I use the describe keyspaces command from within cqlsh:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/845/1*sPLCqql7p1VnV3FIhC218g.png" /></figure><p>From here, I can tell that we have a new `kibana_sample_data_flights` keyspace. Let’s dig deeper into this keyspace a little bit, by doing the following in cqlsh:</p><pre>describe kibana_sample_data_flights</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/608/1*F3RSgcjyFT0rmGBSH9QBzQ.png" /></figure><p>It looks like they start us off with one main table, _doc. This corresponds to the Elasticsearch type for our index (you can read more about that <a href="https://www.elastic.co/guide/en/elasticsearch/reference/current/removal-of-types.html">here</a>).</p><h4>Using vanilla CQL to query our Cassandra tables</h4><p>Since we are using Cassandra, we can run basic CQL statements on our sample data. However, our “_doc” table has a singular PRIMARY KEY of “_id”, which is TEXT. This doesn’t make it very easy to query using vanilla CQL, but we can at least do a basic SELECT, or search by id. Here’s some examples:</p><p><strong>Basic SELECT statement</strong></p><pre>SELECT &quot;_id&quot;, &quot;Cancelled&quot;, &quot;Carrier&quot;, &quot;DestCityName&quot;, &quot;OriginCityName&quot;, &quot;DestWeather&quot;, &quot;OriginWeather&quot; FROM kibana_sample_data_flights.&quot;_doc&quot;;</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*5G5A-rmDVezbe-Mw-OCjsw.png" /></figure><p><strong>Search by primary key (</strong><strong>_id)</strong></p><pre>SELECT &quot;_id&quot;, &quot;Cancelled&quot;, &quot;Carrier&quot;, &quot;DestCityName&quot;, &quot;OriginCityName&quot;, &quot;DestWeather&quot;, &quot;OriginWeather&quot; FROM kibana_sample_data_flights.&quot;_doc&quot; WHERE &quot;_id&quot; = &#39;VvLv3nIBSUNQoGiq90nw&#39;;</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*4OMnu8Iyv7SDU3mhs5PI6Q.png" /></figure><h3>Using CQL enhanced by Elassandra</h3><p>We can get a lot more mileage out of our queries by using CQL that takes advantage of Elasticsearch indexing. For one thing, we can query our tables without having to know a row’s primary key! First we have to <a href="http://doc.elassandra.io/en/latest/search_over_cql.html#configuration">configure our nodes</a> to accept Elasticsearch queries. Normally we would have to set cassandra.custom_query_handler_class in our cassandra-env.sh and reset our nodes, but we already did this in our docker-compose file. We do need to add some “dummy” tables though, since that is what Elassandra requires for this to work. Otherwise else we’ll get something like this when trying to run our Elasticsearch-powered query:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*iNVn_wl0gG2QfAQTpvpvwA.png" /></figure><p>We therefore need to run the following in our CQLSH:</p><pre>ALTER TABLE kibana_sample_data_flights.&quot;_doc&quot; ADD es_query text;</pre><pre>ALTER TABLE kibana_sample_data_flights.&quot;_doc&quot; ADD es_options text;</pre><p>Now it should work just fine, querying our tables for the word “Cloudy” (whether in the origin weather or the destination weather)</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*-VQEO2th-6rO46d4QClhpg.png" /></figure><h3>Some conclusions</h3><p>You can quickly see some advantages of adding Elasticsearch on top of Cassandra:</p><ul><li>Provides a REST API for Cassandra</li><li>Enables us to perform aggregations, complex searches without having to specify the partition key</li></ul><p>There are also clear advantages of Cassandra on top of Elasticsearch:</p><ul><li>Simple and fast replication across nodes, which is what Cassandra is known for</li><li>Allows us to use easy CQL (which is very similar to SQl) to query our data</li></ul><p>As someone who has never touched Elassandra before, I found getting something up and running to be extremely easy and straightforward, and with great visuals built into it like this, makes for a great learning project.</p><h3>What’s next</h3><p>Now we are ready to hook up our NodeJS app. Check out <a href="https://medium.com/@rlquey2/elassandra-with-nodejs-demo-part-two-30d5e3886058">Part Two</a> for hooking up Node, using React and SearchKit!</p><p>To see all the code together in one place, check out the <a href="https://github.com/RyanQuey/node-elassandra-demo">Github repository here</a>.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=f94234aa4fc1" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>