Integrate Tableau Data Visualization with Hive Data Warehouse and Apache Spark SQL
Components relevant to the subject:
Hive Warehouse
The Apache Hive data warehouse software facilitates reading, writing, and managing large datasets residing in distributed storage typically on Hadoop cluster using SQL. Structure can be projected onto data already in storage. A command line tool and JDBC driver are provided to connect users to Hive
SPARK SQL
Spark SQL is a Spark module for structured data processing. Unlike the basic Spark RDD API, the interfaces provided by Spark SQL provide Spark with more information about the structure of both the data and the computation being performed. Internally, Spark SQL uses this extra information to perform extra optimizations.
Apache Thrift Framework
The Apache Thrift software framework, for scalable cross-language services development, combines a software stack with a code generation engine to build services that work efficiently and seamlessly between C++, Java, Python, PHP, Ruby, Erlang, Perl, Haskell, C#, Cocoa, JavaScript, Node.js, Smalltalk, OCaml and Delphi and other languages.
Spark thrift server
Spark Thrift Server is Spark SQL’s implementation of Apache Hive’s HiveServer2 that allows JDBC/ODBC clients to execute SQL queries over JDBC and ODBC protocols on Apache Spark, default port is 10000 Spark thrift server is like hiveserver2 thrift, that allows running SQL queries against HIVE warehouse, however, SQL (HQL) queries on hive will be run as MR job, running SQL queries on Hive warehouse through Spark SQL will on spark cluster.
Tableau
A data visualization tool used in the Business Intelligence for analytics by visualizing data from rows into pictures.
Running query on Hive
A query runs on Hive is processed by Map Reduce jobs executing on Hadoop, as below demonstrates
Query response time seems high, at 37.414 seconds. Run same query again, repeat the same MR jobs again, with similar query response time, 30.073 seconds
Running same query on same Hive table on Spark
Spark SQL both use Spark Core as its processing engine to perform the task. Spark supports in-memory processing which is usually 50–100 times faster than regular processing.
By the way, in any possible benchmark Spark SQL is way faster than Hive using same query on the same data persistently on hive warehouse.
It took about 4.35 seconds, that includes fetching the rows from HIVE table economydata into Spark dataframe and caching into Spark memory
Run it again, it only takes 0.379 seconds, because it queries from cache.
Need to mention, if the HIVE table is changed, as result of insert for example, Spark SQL will update its cache incrementally to reflect the change.
spark-sql client
spark-sql is client of Hive thriftserver, basically executes below on the Linux command line:
Source code for org.apache.spark.sql.hive.thriftserver.SparkSQLCLIDriver is available if interested in:
hive-site.xml
The hive-site.xml is the global hive configuration file. The file hive-default.xml.template contains the default values. You will need to copy hive-default.xml.template to hive-site.xml and edit it to set the right parameters. I have a working copy of hive-site.xml in my GitHub in case it might be helpful, you still need to modify to fit your environment.
https://github.com/geyungjen/jentekllc/blob/master/hive/hive-site.xml
Integrate with Spark
If hive and spark runs on the same machine, to integrate Hive with Spark, simply to copy $HIVE_HOME/conf/hive-site.xml to $SPARK_HOME/conf, so Spark and Spark SQL will know where is the hive metastore , which is the data dictionary of Hive database is located and access the same metastore in the query.
You can simply create a soft link in $SPARK_HOME/conf/hive-site.xml pointing to $HIVE_HOME/conf/hive-site.xml
Connect tableau to visualize business intelligence
Tableau can connect to Hive and Spark SQL, which one you want to connect? Spark SQL is a better option because query with Spark SQL on the same table client on Hive runs many times faster than with Hive, as demonstrated earlier.
Start spark thrift server on spark cluster master node
Which runs
CLASS is "org.apache.spark.sql.hive.thriftserver.HiveThriftServer2"
which as consequence, starts up a 'SparkSQLContext' and a 'HiveThriftServer2' thrift server, that listens to port 10000
Choose your OS, and make sure download 64 bit ODBC driver
Download Tableau to Spark SQL ODBC driver
The first time you choose to connect to Spark SQL from Tableau, sign in button is grey out, but you are provided with a download link in the sign in screen:
If your Spark runs on a Virtualbox VM with NAT network adapter, to connect through port forwarding, see below:
Before you attempt to connect to Spark SQL from Tableau, you must download and install Tableau driver for Spark SQL:
https://www.tableau.com/support/drivers
After installation of ODBC driver in prior step, relaunch tableau desktop, choose connect to Spark SQL
Enter host name or IP address of the spark master node, leave port 10000 as is
Leave type field as is. For simplicity, I choose no authentication in field Authentication, transport is binary.
Do NOT check require SSL checkbox
Hive authentication is defined in $HIVE_HOME/conf/hive-site.xml (that has been copied to $SPARK_HOME/conf/)
It is important to note that for “no authentication”, hive.server2.authentication needs to be set to NOSASL, not NONE, which is password authentication.
Transport is “binary” because in hive-site.xml, transport mode is set to binary
Now just click sign in, specify schemas and you will see your tables such as economydata in schema jentekllc
You can do fancy things to visualize your query
Summary
Apache Spark is one of the greatest open source all in one enterprise big data/analytic engine. It combines distributed/clustered computing, high availability, disruption resilience and fault tolerance. It is in memory computing. It encapsulates sophisticated query capability on structure data like relational database tables and non-structure data like NoSQL key value pairs, along with robust streaming, rich machine learning and statistics features, paired with a graph computing engine for applications such as social network and internet advertisement revenue driven search engines.
Page Rank with Apache Spark Graphx
https://medium.com/@jentekllc8888/page-rank-with-apache-spark-graphx-a51964467c56
Dremio Data Lake Engine Apache Arrow Flight Connector with Spark Machine Learning
Because it’s in memory, distributed computing, Spark and Spark SQL is fast, and because it is in memory computing, Spark SQL does not keep data persistently, which needs a database or file system to hold data when Spark is shutdown. In additional to HIVE, Spark can easily connect to any database as long as there is JDBC driver available and use that database as "file server" to hold data and computing result, such as below Spark streaming use case.
My YouTube presentation “Develop Spark Streaming get Twitter tweets save to Hive, sbt assembly build needed twitter util jar” https://www.youtube.com/watch?v=XBfL6Jx4U2I&t=532s
Last updated