Repository: storm Updated Branches: refs/heads/asf-site 1ec78daa5 -> 3e6f1e7c8
STORM-1366. Add documentation for StormSQL into the website. Project: http://git-wip-us.apache.org/repos/asf/storm/repo Commit: http://git-wip-us.apache.org/repos/asf/storm/commit/3e6f1e7c Tree: http://git-wip-us.apache.org/repos/asf/storm/tree/3e6f1e7c Diff: http://git-wip-us.apache.org/repos/asf/storm/diff/3e6f1e7c Branch: refs/heads/asf-site Commit: 3e6f1e7c85df328f091a8b534f564ef74578280f Parents: 1ec78da Author: Haohui Mai <[email protected]> Authored: Thu Dec 3 23:12:58 2015 -0800 Committer: Haohui Mai <[email protected]> Committed: Tue Jan 5 14:53:44 2016 -0800 ---------------------------------------------------------------------- documentation.html | 5 +- .../images/storm-sql-internal-example.png | Bin 0 -> 28377 bytes .../images/storm-sql-internal-workflow.png | Bin 0 -> 20020 bytes documentation/storm-sql-internal.md | 55 ++++++++++++ documentation/storm-sql.md | 87 +++++++++++++++++++ 5 files changed, 145 insertions(+), 2 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/storm/blob/3e6f1e7c/documentation.html ---------------------------------------------------------------------- diff --git a/documentation.html b/documentation.html index 348edd8..a2fc2f9 100644 --- a/documentation.html +++ b/documentation.html @@ -49,8 +49,8 @@ title: Documentation </ul> </div> <div role="tabpanel" class="tab-pane" id="integration"> - <p>The following modules are included in the Apache Storm distribution and are not required for storm to operate, - but are useful for extending Storm in order to provide additional functionality such as integration with other + <p>The following modules are included in the Apache Storm distribution and are not required for storm to operate, + but are useful for extending Storm in order to provide additional functionality such as integration with other technologies frequently used in combination with Storm.</p> <ul> <li><a href="documentation/storm-kafka.html">Kafka</a></li> @@ -62,6 +62,7 @@ title: Documentation <li><a href="documentation/storm-solr.html">Solr</a></li> <li><a href="documentation/storm-eventhubs.html">Azure EventHubs</a></li> <li><a href="documentation/flux.html">Flux</a> (declarative wiring/configuration of Topologies)</li> + <li><a href="documentation/storm-sql.html">SQL</a> (writing topologies in SQL)</li> </ul> </div> <div role="tabpanel" class="tab-pane" id="intermediate"> http://git-wip-us.apache.org/repos/asf/storm/blob/3e6f1e7c/documentation/images/storm-sql-internal-example.png ---------------------------------------------------------------------- diff --git a/documentation/images/storm-sql-internal-example.png b/documentation/images/storm-sql-internal-example.png new file mode 100644 index 0000000..74828d5 Binary files /dev/null and b/documentation/images/storm-sql-internal-example.png differ http://git-wip-us.apache.org/repos/asf/storm/blob/3e6f1e7c/documentation/images/storm-sql-internal-workflow.png ---------------------------------------------------------------------- diff --git a/documentation/images/storm-sql-internal-workflow.png b/documentation/images/storm-sql-internal-workflow.png new file mode 100644 index 0000000..655c1c4 Binary files /dev/null and b/documentation/images/storm-sql-internal-workflow.png differ http://git-wip-us.apache.org/repos/asf/storm/blob/3e6f1e7c/documentation/storm-sql-internal.md ---------------------------------------------------------------------- diff --git a/documentation/storm-sql-internal.md b/documentation/storm-sql-internal.md new file mode 100644 index 0000000..05ca1a9 --- /dev/null +++ b/documentation/storm-sql-internal.md @@ -0,0 +1,55 @@ +--- +title: The Internals of Storm SQL +layout: documentation +documentation: true +--- + +This page describes the design and the implementation of the Storm SQL integration. + +## Overview + +SQL is a well-adopted yet complicated standard. Several projects including Drill, Hive, Phoenix and Spark have invested significantly in their SQL layers. One of the main design goal of StormSQL is to leverage the existing investments for these projects. StormSQL leverages [Apache Calcite](///calcite.apache.org) to implement the SQL standard. StormSQL focuses on compiling the SQL statements to Storm / Trident topologies so that they can be executed in Storm clusters. + +Figure 1 describes the workflow of executing a SQL query in StormSQL. First, users provide a sequence of SQL statements. StormSQL parses the SQL statements and translates them to a Calcite logical plan. A logical plan consists of a sequence of SQL logical operators that describe how the query should be executed irrespective to the underlying execution engines. Some examples of logical operators include `TableScan`, `Filter`, `Projection` and `GroupBy`. + +<div align="center"> +<img title="Workflow of StormSQL" src="images/storm-sql-internal-workflow.png" style="max-width: 80rem"/> + +<p>Figure 1: Workflow of StormSQL.</p> +</div> + +The next step is to compile the logical execution plan down to a physical execution plan. A physical plan consists of physical operators that describes how to execute the SQL query in *StormSQL*. Physical operators such as `Filter`, `Projection`, and `GroupBy` are directly mapped to operations in Trident topologies. StormSQL also compiles expressions in the SQL statements into Java byte codes and plugs them into the Trident topologies. + +Finally, StormSQL packages both the Java byte codes and the topology into a JAR and submits it to the Storm cluster. Storm schedules and executes the JAR in the same way of it executes other Storm topologies. + +The follow code blocks show an example query that filters and projects results from a Kafka stream. + +``` +CREATE EXTERNAL TABLE ORDERS (ID INT PRIMARY KEY, UNIT_PRICE INT, QUANTITY INT) LOCATION 'kafka://localhost:2181/brokers?topic=orders' ... + +CREATE EXTERNAL TABLE LARGE_ORDERS (ID INT PRIMARY KEY, TOTAL INT) LOCATION 'kafka://localhost:2181/brokers?topic=large_orders' ... + +INSERT INTO LARGE_ORDERS SELECT ID, UNIT_PRICE * QUANTITY AS TOTAL FROM ORDERS WHERE UNIT_PRICE * QUANTITY > 50 +``` + +The first two SQL statements define the inputs and outputs of external data. Figure 2 describes the processes of how StormSQL takes the last `SELECT` query and compiles it down to Trident topology. + +<div align="center"> +<img title="Compiling the example query to Trident topology" src="images/storm-sql-internal-example.png" style="max-width: 80rem"/> + +<p>Figure 2: Compiling the example query to Trident topology.</p> +</div> + + +## Constraints of querying streaming tables + +There are several constraints when querying tables that represent a real-time data stream: + +* The `ORDER BY` clause cannot be applied to a stream. +* There is at least one monotonic field in the `GROUP BY` clauses to allow StormSQL bounds the size of the buffer. + +For more information please refer to https://calcite.incubator.apache.org/docs/stream.html. + +## Dependency + +StormSQL does not ship the dependency of the external data sources in the packaged JAR. The users have to provide the dependency in the `extlib` directory of the worker node. http://git-wip-us.apache.org/repos/asf/storm/blob/3e6f1e7c/documentation/storm-sql.md ---------------------------------------------------------------------- diff --git a/documentation/storm-sql.md b/documentation/storm-sql.md new file mode 100644 index 0000000..a5a8a4a --- /dev/null +++ b/documentation/storm-sql.md @@ -0,0 +1,87 @@ +--- +title: Storm SQL integration +layout: documentation +documentation: true +--- + +The Storm SQL integration allows users to run SQL queries over streaming data in Storm. Not only the SQL interface allows faster development cycles on streaming analytics, but also opens up the opportunities to unify batch data processing like [Apache Hive](///hive.apache.org) and real-time streaming data analytics. + +At a very high level StormSQL compiles the SQL queries to [Trident](Trident-API-Overview.html) topologies and executes them in Storm clusters. This document provides information of how to use StormSQL as end users. For people that are interested in more details in the design and the implementation of StormSQL please refer to the [this](storm-sql-internal.html) page. + +## Usage + +Run the ``storm sql`` command to compile SQL statements into Trident topology, and submit it to the Storm cluster + +``` +$ bin/storm sql <sql-file> <topo-name> +``` + +In which `sql-file` contains a list of SQL statements to be executed, and `topo-name` is the name of the topology. + + +## Supported Features + +The following features are supported in the current repository: + +* Streaming from and to external data sources +* Filtering tuples +* Projections + +## Specifying External Data Sources + +In StormSQL data is represented by external tables. Users can specify data sources using the `CREATE EXTERNAL TABLE` statement. For example, the following statement specifies a Kafka spouts and sink: + +``` +CREATE EXTERNAL TABLE FOO (ID INT PRIMARY KEY) LOCATION 'kafka://localhost:2181/brokers?topic=test' TBLPROPERTIES '{"producer":{"bootstrap.servers":"localhost:9092","acks":"1","key.serializer":"storm.kafka.IntSerializer","value.serializer":"storm.kafka.ByteBufferSerializer"}}' +``` + +The syntax of `CREATE EXTERNAL TABLE` closely follows the one defined in [Hive Data Definition Language](https://cwiki.apache.org/confluence/display/Hive/LanguageManual+DDL). + +## Plugging in External Data Sources + +Users plug in external data sources through implementing the `ISqlTridentDataSource` interface and registers them using the mechanisms of Java's service loader. The external data source will be chosen based on the scheme of the URI of the tables. Please refer to the implementation of `storm-sql-kafka` for more details. + +## Example: Filtering Kafka Stream + +Let's say there is a Kafka stream that represents the transactions of orders. Each message in the stream contains the id of the order, the unit price of the product and the quantity of the orders. The goal is to filter orders where the transactions are significant and to insert these orders into another Kafka stream for further analysis. + +The user can specify the following SQL statements in the SQL file: + +``` +CREATE EXTERNAL TABLE ORDERS (ID INT PRIMARY KEY, UNIT_PRICE INT, QUANTITY INT) LOCATION 'kafka://localhost:2181/brokers?topic=orders' TBLPROPERTIES '{"producer":{"bootstrap.servers":"localhost:9092","acks":"1","key.serializer":"storm.kafka.IntSerializer","value.serializer":"storm.kafka.ByteBufferSerializer"}}' + +CREATE EXTERNAL TABLE LARGE_ORDERS (ID INT PRIMARY KEY, TOTAL INT) LOCATION 'kafka://localhost:2181/brokers?topic=large_orders' TBLPROPERTIES '{"producer":{"bootstrap.servers":"localhost:9092","acks":"1","key.serializer":"storm.kafka.IntSerializer","value.serializer":"storm.kafka.ByteBufferSerializer"}}' + +INSERT INTO LARGE_ORDERS SELECT ID, UNIT_PRICE * QUANTITY AS TOTAL FROM ORDERS WHERE UNIT_PRICE * QUANTITY > 50 +``` + +The first statement defines the table `ORDER` which represents the input stream. The `LOCATION` clause specifies the ZkHost (`localhost:2181`), the path of the brokers in ZooKeeper (`/brokers`) and the topic (`orders`). The `TBLPROPERTIES` clause specifies the configuration of [KafkaProducer](http://kafka.apache.org/documentation.html#newproducerconfigs). +Current implementation of `storm-sql-kafka` requires specifying both `LOCATION` and `TBLPROPERTIES` clauses even though the table is read-only or write-only. + +Similarly, the second statement specifies the table `LARGE_ORDERS` which represents the output stream. The third statement is a `SELECT` statement which defines the topology: it instructs StormSQL to filter all orders in the external table `ORDERS`, calculates the total price and inserts matching records into the Kafka stream specified by `LARGE_ORDER`. + +To run this example, users need to include the data sources (`storm-sql-kafka` in this case) and its dependency in the class path. One approach is to put the required jars into the `extlib` directory: + +``` +$ cp curator-client-2.5.0.jar curator-framework-2.5.0.jar zookeeper-3.4.6.jar + extlib/ +$ cp scala-library-2.10.4.jar kafka-clients-0.8.2.1.jar kafka_2.10-0.8.2.1.jar metrics-core-2.2.0.jar extlib/ +$ cp json-simple-1.1.1.jar extlib/ +$ cp storm-kafka-*.jar storm-sql-kafka-*.jar storm-sql-runtime-*.jar extlib/ +``` + +The next step is to submit the SQL statements to StormSQL: + +``` +$ bin/storm sql order_filtering order_filtering.sql +``` + +By now you should be able to see the `order_filtering` topology in the Storm UI. + +## Current Limitations + +Aggregation, windowing and joining tables are yet to be implemented. Specifying parallelism hints in the topology is not yet supported. + +Users also need to provide the dependency of the external data sources in the `extlib` directory. Otherwise the topology will fail to run because of `ClassNotFoundException`. + +The current implementation of the Kafka connector in StormSQL assumes both the int=put and the output are in JSON formats. The connector has not yet recognized the `INPUTFORMAT` and `OUTPUTFORMAT` clauses yet.
