KevinGG commented on a change in pull request #15518:
URL: https://github.com/apache/beam/pull/15518#discussion_r713265671



##########
File path: sdks/python/apache_beam/runners/interactive/examples/Run Beam SQL 
with beam_sql magic.ipynb
##########
@@ -0,0 +1,548 @@
+{
+ "cells": [
+  {
+   "cell_type": "markdown",
+   "id": "a999c0fd",
+   "metadata": {},
+   "source": [
+    "Licensed under the Apache License, Version 2.0 (the \"License\");\n",
+    "<!--\n",
+    "    Licensed to the Apache Software Foundation (ASF) under one\n",
+    "    or more contributor license agreements.  See the NOTICE file\n",
+    "    distributed with this work for additional information\n",
+    "    regarding copyright ownership.  The ASF licenses this file\n",
+    "    to you under the Apache License, Version 2.0 (the\n",
+    "    \"License\"); you may not use this file except in compliance\n",
+    "    with the License.  You may obtain a copy of the License at\n",
+    "\n",
+    "      http://www.apache.org/licenses/LICENSE-2.0\n";,
+    "\n",
+    "    Unless required by applicable law or agreed to in writing,\n",
+    "    software distributed under the License is distributed on an\n",
+    "    \"AS IS\" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY\n",
+    "    KIND, either express or implied.  See the License for the\n",
+    "    specific language governing permissions and limitations\n",
+    "    under the License.\n",
+    "-->\n"
+   ]
+  },
+  {
+   "cell_type": "markdown",
+   "id": "5562c11a",
+   "metadata": {},
+   "source": [
+    "# Run Beam SQL in notebooks\n",
+    "\n",
+    "[Beam SQL](https://beam.apache.org/documentation/dsls/sql/overview/) 
allows a Beam user to query PCollections with SQL statements. Currently, 
`InteractiveRunner` does not support `SqlTransform` due to 
[BEAM-10708](https://issues.apache.org/jira/browse/BEAM-10708). However, a user 
could use the `beam_sql` magic to run Beam SQL in the notebook and introspect 
the result. It's a convenient way to validate your queries locally against 
known/test data sources when prototyping a Beam pipeline with SQL, before 
productionizing it on remote cluster/services. \n",
+    "\n",
+    "First, let's load the `beam_sql` magic:"
+   ]
+  },
+  {
+   "cell_type": "code",
+   "execution_count": null,
+   "id": "8928343a",
+   "metadata": {},
+   "outputs": [],
+   "source": [
+    "%load_ext apache_beam.runners.interactive.sql.beam_sql_magics"
+   ]
+  },
+  {
+   "cell_type": "markdown",
+   "id": "dec39a04",
+   "metadata": {},
+   "source": [
+    "Since SQL support in Beam Python SDK is implemented through xLang 
external transform, make sure you have below prerequisites:\n",
+    "- Have `docker` installed;\n",
+    "- Have jdk8 or jdk11 installed and $JAVA_HOME set;"
+   ]
+  },
+  {
+   "cell_type": "code",
+   "execution_count": null,
+   "id": "fa9cede3",
+   "metadata": {},
+   "outputs": [],
+   "source": [
+    "!docker image list\n",
+    "!java --version\n",
+    "!echo $JAVA_HOME"
+   ]
+  },
+  {
+   "cell_type": "code",
+   "execution_count": null,
+   "id": "640a427e",
+   "metadata": {},
+   "outputs": [],
+   "source": [
+    "# Optionally sets the logging level to reduce distraction.\n",
+    "import logging\n",
+    "\n",
+    "logging.root.setLevel(logging.ERROR)"
+   ]
+  },
+  {
+   "cell_type": "markdown",
+   "id": "3ab6438a",
+   "metadata": {},
+   "source": [
+    "**Important**: if you're using Beam built from your local source code, 
additionally:\n",
+    "\n",
+    "- Have the Java expansion service shadowjar built. Go to the root 
directory of your local beam repo and then execute:\n",
+    "  `./gradlew :sdks:java:extensions:sql:expansion-service:shadowJar`;\n",
+    "- Based on your jdk version, pull the docker image `docker pull 
apache/beam_java11_sdk` or `docker pull apache/beam_java8_sdk`.\n",
+    "- Then tag the image with your current Beam dev version.  You can check 
the dev version under `apache_beam.version.__version__`. For example, if you're 
using jdk11 and dev version is `x.x.x.dev`, execute `docker image tag 
apache/beam_java11_sdk:latest apache/beam_java11_sdk:x.x.x.dev`."
+   ]
+  },
+  {
+   "cell_type": "markdown",
+   "id": "bcf28852",
+   "metadata": {},
+   "source": [
+    "## Query#1 - A simple static query\n",
+    "`beam_sql` is an IPython [custom 
magic](https://ipython.readthedocs.io/en/stable/config/custommagics.html). If 
you're not familiar with magics, here are some [built-in 
examples](https://ipython.readthedocs.io/en/stable/interactive/magics.html).\n",

Review comment:
       I'll move the explanation to the very beginning, immediately after 
mentioning the `beam_sql` magic.
   
   > `beam_sql` is an IPython [custom 
magic](https://ipython.readthedocs.io/en/stable/config/custommagics.html) ...




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


Reply via email to