Recursive Binary Search Example

Binary Search is a classic algorithm used to find an item in an ordered list/array of items. This list/array of items must be ordered for binary search to work. The basic idea of Binary Search is to: Take the midpoint between the smallest and largest elements. Determine if item being searched for is smaller or

read more

Iterative Binary Search Example

Binary Search is a classic algorithm used to find an item in an ordered list/array of items. This list/array of items must be ordered for binary search to work. The basic idea of Binary Search is to: Take the midpoint between the smallest and largest elements. Determine if item being searched for is smaller or

read more

How to Extract Nested JSON Data in Spark

JSON is a very common way to store data. But JSON can get messy and parsing it can get tricky. Here are a few examples of parsing nested data structures in JSON using Spark DataFrames (examples here done with Spark 1.6.0). Our sample.json file:

Assuming you already have a SQLContext object created, the examples

read more

How to Read / Write JSON in Spark

Needing to read and write JSON data is a common big data task. Thankfully this is very easy to do in Spark using Spark SQL DataFrames. Spark SQL can automatically infer the schema of a JSON dataset, and use it to load data into a DataFrame object. A DataFrame’s schema is used when writing JSON

read more

How to Exclude Fields using Gson

There are a lot of great Java libraries for working with JSON. One of these is Google’s Gson, which has the goal of providing simple toJson() and fromJson() methods to convert Java objects to JSON and vice-versa. Often when serializing objects into JSON you will want to exclude certain object fields. There a couple of

read more

Creating JSON with Gson

There are a lot of great Java libraries for working with JSON. One of these is Google’s Gson, which has the goal of providing simple toJson() and fromJson() methods to convert Java objects to JSON and vice-versa. By default, the toJson() method will serialize all fields in the current class (and all super classes). Below

read more

Java Binary Search Tree Implementation

The Binary Search Tree is commonly used data structure in Computer Science. Below is a complete binary search tree implementation, including the standard methods used to find, insert, and delete nodes from the tree. In addition are methods to print tree structure as well as track of the number nodes (so the tree size can

read more

Simple Apache Avro Example using Java

Apache Avro is a popular data serialization system that relies on schemas. The official Avro documentation can be found here: http://avro.apache.org/docs/current/. This post walks through an example of serializing and deserializing data using Avro in Java. Maven is not necessary for working with Avro in Java, but we will be using Maven in this post.

read more

How to Break from Nested Loop in Java

In Java, we can break/exit from the current loop with the break statement. But what if we want to break an outer loop from a nested loop? In Java we can name our loops using labels. By using labels we can specify which loop we would like to break out of (also called “breaking to

read more