Apache Spark Machine Learning with Dremio Data Lake Engine
Define data lake!
According to Wikipedia:
A data lake is a system or repository of data stored in its natural/raw format, usually object blobs or files. A data lake is usually a single store of all enterprise data including raw copies of source system data and transformed data used for tasks such as reporting, visualization, advanced analytics and machine learning. A data lake can include structured data from relational databases (rows and columns), semi-structured data (CSV, logs, XML, JSON), unstructured data (emails, documents, PDFs) and binary data (images, audio, video).
In simple term, data lake is like a giant melting pot (like the United States) of data of all formats, structured such as RDBMS tables, non-structured such as NoSQL entities, of any kind, you grab whatever you want to see from the pot.
I have explored a software product, "data lake engine", called Dremio:
Dremio’s query engine is built on Apache Arrow, which is an in memory columnar data structure. Its SQL engine allows you to use SQL to query structured data such as relational database tables or non-structure such as key value pairs entities such as JSON, it is a distributed/clustered and in memory columnar query engine, that can run on one node or many nodes.
While there is commercial version available, there is also an open source version of Dremio that can be gotten from GitHub:
My experiments on Dremio starts from cloning from Dremio’s GitHub repo, the open source version on a CentOS7 Linux VM.
Dremio is written in Java, so JDK 8 and Maven 3.3.9 or better are pre-requisites. After git clone the Dremio, simply run below mvn command to build, make sure your mvn version must be 3.3.9 or better to build successfully. If you do not have mvn 3.3.9 or better, there is a mvnw that comes from GitHub repo.
mvn clean install -DskipTests
or
mvnw clean install -DskipTests
Additionally, it is better to build and run Dremio in its own OS user account, not to share user account that run other software, to avoid any issue down the road.
I initially build Dremio using existing Linux user that owns and run Hadoop, HIVE and Spark, but I run into issue when starting Dremio, got messages resulted from
SLF4J: Class path contains multiple SLF4J bindings. SLF4J: Found binding in [jar:file:/opt/hadoop/hive/lib/log4j-slf4j-impl-2.4.1.jar!/org/slf4j/impl/StaticLoggerBinder.class] SLF4J: Found binding in [jar:file:/opt/hadoop/share/hadoop/common/lib/slf4j-log4j12–1.7.10.jar!/org/slf4j/impl/StaticLoggerBinder.class]
Dremio instance did not start. While it is fixable by excluding unwanted SLF4J from classpath, but it would be easier and cleaner to build and run Dremio from OS user called dremio, instead of hadoop OS user.
Dremio has its own zookeeper service, but can use external one if there is one already running and listening to port 2181. Because I have Kafka running on the same VM, which has zookeeper, therefore, need to enable using external zookeeper, disable embedded zookeeper in Dremio configuration.
services.coordinator.master.embedded-zookeeper.enabled: false zookeeper: “10.0.2.15:2181,localhost:2181”
By default, Dremio server listens to address localhost, I made it to listen to all network interfaces including localhost by specifying IP address 0.0.0.0
registration.publish-host: 0.0.0.0
Once Dremio is built and started, I can log into Dremio UI by
http://<hostname>:9047
I can also add variety of data sources from Dremio to catalog them:
I can query, using SQL against JSON (nested) records:
After download JDBC driver from Dremio, I can connect JDBC client, I use SQLWorkbench, which is open source client to connect to Dremio and run queries
Once Dremio is up and running, JDBC connectivity is setup, my next task is to integrate Apache Spark with Dremio, using Dremio as repository, which can connect to hundreds of enterprise data sources in the data lake.
First task I want to play with is to run Apache Spark Machine Learning model on dataset stored on Hadoop, that is connected to Dremio as data source, that Dremio is going to supply to Apache Spark via JDBC connectivity.
To start, I need a dataset. Found one on Kaggle, called creditcardfraud
Here is the description from Kaggle:
Context
It is important that credit card companies are able to recognize fraudulent credit card transactions so that customers are not charged for items that they did not purchase.
Content
The datasets contain transactions made by credit cards in September 2013 by European cardholders.
This dataset presents transactions that occurred in two days, where we have 492 frauds out of 284,807 transactions. The dataset is highly unbalanced, the positive class (frauds) account for 0.172% of all transactions.
It contains only numerical input variables which are the result of a PCA transformation. Unfortunately, due to confidentiality issues, we cannot provide the original features and more background information about the data. Features V1, V2, … V28 are the principal components obtained with PCA, the only features which have not been transformed with PCA are 'Time' and 'Amount'. Feature 'Time' contains the seconds elapsed between each transaction and the first transaction in the dataset. The feature 'Amount' is the transaction Amount, this feature can be used for example-dependent cost-sensitive learning. Feature 'Class' is the response variable and it takes value 1 in case of fraud and 0 otherwise.
I downloaded the data file creditcard.csv and place it in an HDFS file system:
hdfs dfs -ls /dremio/
Found 2 items -rw-r — r — 3 hadoop supergroup 150828753 2020–03–14 16:20 /dremio/creditcard.csv
Load the Hadoop HDFS source /dremio/creditcard.csv into Dremio:
Once the link in Dremio that points to HDFS /dremio/creditcard.csv, I can start the work on Apache Spark:
I use logistic regression for the modeling, given this is binary classifier (fraud or no fraud).
Launch jupyter-notebook and start a Jupyter-Scala kernel, following is the code:
As the provider of this dataset said:
The dataset is highly unbalanced, the positive class (frauds) account for 0.172% of all transactions.
I am not surprised the 0.999 prediction accuracy, which is too good to be true. But my goal in this exercise is to demonstrate that data scientists and data engineers can leverage Dremio as an end point access to vast data lake to supply data sources to applications running on Apache Spark, including, but not limiting to, machine learning with Apache Spark.
This, has served my purpose for this exercise.
As always, code used in this writing is in my GitHub repo:
Last updated