rdblue commented on code in PR #75:
URL: https://github.com/apache/iceberg-docs/pull/75#discussion_r880924703


##########
landing-page/content/common/quickstarts.md:
##########
@@ -0,0 +1,335 @@
+---
+url: quickstarts
+toc: true
+aliases:
+    - "quickstarts"
+    - "getting-started"
+---
+<!--
+ - Licensed to the Apache Software Foundation (ASF) under one or more
+ - contributor license agreements.  See the NOTICE file distributed with
+ - this work for additional information regarding copyright ownership.
+ - The ASF licenses this file to You under the Apache License, Version 2.0
+ - (the "License"); you may not use this file except in compliance with
+ - the License.  You may obtain a copy of the License at
+ -
+ -   http://www.apache.org/licenses/LICENSE-2.0
+ -
+ - Unless required by applicable law or agreed to in writing, software
+ - distributed under the License is distributed on an "AS IS" BASIS,
+ - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ - See the License for the specific language governing permissions and
+ - limitations under the License.
+ -->
+
+## <img src="../img/spark-menu-logo.png"> Spark and Iceberg Quickstart
+
+This quickstart will get you up and running with an Iceberg and Spark 
environment, including sample code to
+highlight some powerful features. You can learn more about Iceberg's Spark 
runtime by checking out the [Spark](../docs/latest/spark-ddl/) section.
+
+- [Docker-Compose](#docker-compose)
+- [Creating a table](#creating-a-table)
+- [Writing Data to a Table](#writing-data-to-a-table)
+- [Reading Data from a Table](#reading-data-from-a-table)
+- [Adding Iceberg to your Existing Spark 
Environment](#adding-iceberg-to-your-existing-spark-environment)
+- [Adding A Catalog to Your Existing Spark 
Environment](#adding-a-catalog-to-your-existing-spark-environment)
+- [Next Steps](#next-steps)
+
+#### Docker-Compose
+
+The fastest way to get started is to use a docker-compose file that uses the 
the [tabulario/spark-iceberg](https://hub.docker.com/r/tabulario/spark-iceberg) 
image
+which contains a local Spark cluster with a configured Iceberg catalog. To use 
this, you'll need to install the [Docker 
CLI](https://docs.docker.com/get-docker/) as well as the [Docker Compose 
CLI](https://github.com/docker/compose-cli/blob/main/INSTALL.md).
+
+Once you have those, save the following into a file named `docker-compose.yml`.
+
+```yaml
+version: "3"
+
+services:
+  spark-iceberg:
+    image: tabulario/spark-iceberg
+    depends_on:
+      - postgres
+    container_name: spark-iceberg
+    environment:
+      - SPARK_HOME=/opt/spark
+      - PYSPARK_PYTON=/usr/bin/python3.9
+      - 
PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/opt/spark/bin
+    volumes:
+      - ./warehouse:/home/iceberg/warehouse
+      - ./notebooks:/home/iceberg/notebooks/notebooks
+    ports:
+      - 8888:8888
+      - 8080:8080
+      - 18080:18080
+  postgres:
+    image: postgres:13.4-bullseye
+    container_name: postgres
+    environment:
+      - POSTGRES_USER=admin
+      - POSTGRES_PASSWORD=password
+      - POSTGRES_DB=demo_catalog
+    volumes:
+      - ./postgres/data:/var/lib/postgresql/data
+```
+
+Next, run the following to start up the docker containers.
+```sh
+docker-compose up
+```
+
+You can then run any of the following to start a Spark session.
+
+{{% codetabs "LaunchSparkClient" %}}
+{{% addtab "SparkSQL" checked %}}
+{{% addtab "SparkShell" %}}
+{{% addtab "PySpark" %}}
+{{% addtab "Notebook" %}}
+{{% tabcontent "SparkSQL"  %}}
+```sh
+docker exec -it spark-iceberg spark-sql
+```
+{{% /tabcontent %}}
+{{% tabcontent "SparkShell" %}}
+```sh
+docker exec -it spark-iceberg spark-shell
+```
+{{% /tabcontent %}}
+{{% tabcontent "PySpark" %}}
+```sh
+docker exec -it spark-iceberg pyspark
+```
+{{% /tabcontent %}}
+{{% tabcontent "Notebook" %}}
+```sh
+docker exec -it spark-iceberg notebook
+```
+{{< hint warning >}}
+The notebook server will be available at 
[http://localhost:8888](http://localhost:8888)
+{{< /hint >}}
+{{% /tabcontent %}}
+{{% /codetabs %}}
+
+
+#### Creating a table
+
+To create your first Iceberg table in Spark, run a [`CREATE 
TABLE`](../spark-ddl#create-table) command. In the following example, we'll 
create a table
+using `demo.nyc.taxis` where `demo` is the catalog name, `nyc` is the schema 
name, and `taxis` is the table name.
+
+
+{{% codetabs "CreateATable" %}}
+{{% addtab "SparkSQL" checked %}}
+{{% addtab "SparkShell" %}}
+{{% addtab "PySpark" %}}
+{{% tabcontent "SparkSQL"  %}}
+```sql
+CREATE TABLE demo.nyc.taxis
+(
+  vendor_id bigint,
+  trip_id bigint,
+  Trip_distance float,
+  fare_amount double,
+  Store_and_fwd_flag string
+)
+PARTITIONED BY (vendor_id);
+```
+{{% /tabcontent %}}
+{{% tabcontent "SparkShell" %}}
+```scala
+import org.apache.spark.sql.types.{DoubleType, FloatType, LongType, 
StringType, StructField, StructType}
+import org.apache.spark.sql.Row
+val schema = StructType( Array(
+    StructField("vendor_id", LongType,true),
+    StructField("trip_id", LongType,true),
+    StructField("Trip_distance", FloatType,true),
+    StructField("fare_amount", DoubleType,true),
+    StructField("Store_and_fwd_flag", StringType,true)
+))
+val df = spark.createDataFrame(spark.sparkContext.emptyRDD[Row],schema)
+df.writeTo("demo.nyc.taxis").create()
+```
+{{% /tabcontent %}}
+{{% tabcontent "PySpark" %}}
+```py
+from pyspark.sql.types import DoubleType, FloatType, LongType, 
StructType,StructField, StringType
+schema = StructType([
+  StructField("vendor_id", LongType(), True),
+  StructField("trip_id", LongType(), True),
+  StructField("Trip_distance", FloatType(), True),
+  StructField("fare_amount', DoubleType(), True),
+  StructField("Store_and_fwd_flag', StringType(), True)
+])
+
+df = spark.createDataFrame([], schema)
+df.writeTo("demo.nyc.taxis").create()
+```
+{{% /tabcontent %}}
+{{% /codetabs %}}
+
+Iceberg catalogs support the full range of SQL DDL commands, including:
+
+* [`CREATE TABLE ... PARTITIONED BY`](../spark-ddl#create-table)
+* [`CREATE TABLE ... AS SELECT`](../spark-ddl#create-table--as-select)
+* [`ALTER TABLE`](../spark-ddl#alter-table)
+* [`DROP TABLE`](../spark-ddl#drop-table)
+
+#### Writing Data to a Table
+
+Once your table is created, you can insert records.
+
+{{% codetabs "InsertData" %}}
+{{% addtab "SparkSQL" checked %}}
+{{% addtab "SparkShell" %}}
+{{% addtab "PySpark" %}}
+{{% tabcontent "SparkSQL"  %}}
+```sql
+INSERT INTO demo.nyc.taxis
+VALUES (1, 1000371, 1.8, 15.32, 'N'), (2, 1000372, 2.5, 22.15, 'N'), (2, 
1000373, 0.9, 9.01, 'N'), (1, 1000374, 8.4, 42.13, 'Y');
+```
+{{% /tabcontent %}}
+{{% tabcontent "SparkShell" %}}
+```scala
+import org.apache.spark.sql.Row
+
+val schema = spark.table("demo.nyc.taxis").schema
+val data = Seq(
+    Row(1: Long, 1000371: Long, 1.8f: Float, 15.32: Double, "N": String),
+    Row(2: Long, 1000372: Long, 2.5f: Float, 22.15: Double, "N": String),
+    Row(2: Long, 1000373: Long, 0.9f: Float, 9.01: Double, "N": String),
+    Row(1: Long, 1000374: Long, 8.4f: Float, 42.13: Double, "Y": String)
+)
+val df = spark.createDataFrame(spark.sparkContext.parallelize(data), schema)
+df.writeTo("demo.nyc.taxis").append()
+```
+{{% /tabcontent %}}
+{{% tabcontent "PySpark" %}}
+```py
+schema = spark.table("demo.nyc.taxis").schema
+data = [
+    (1, 1000371, 1.8, 15.32, "N"),
+    (2, 1000372, 2.5, 22.15, "N"),
+    (2, 1000373, 0.9, 9.01, "N"),
+    (1, 1000374, 8.4, 42.13, "Y")
+  ]
+df = spark.createDataFrame(data, schema)
+df.writeTo("demo.nyc.taxis").append()
+```
+{{% /tabcontent %}}
+{{% /codetabs %}}
+
+#### Reading Data from a Table
+
+To read a table, simply use the Iceberg table's name.
+
+{{% codetabs "SelectData" %}}
+{{% addtab "SparkSQL" checked %}}
+{{% addtab "SparkShell" %}}
+{{% addtab "PySpark" %}}
+{{% tabcontent "SparkSQL"  %}}
+```sql
+SELECT * FROM demo.nyc.taxis;
+```
+{{% /tabcontent %}}
+{{% tabcontent "SparkShell" %}}
+```scala
+val df = spark.table("demo.nyc.taxis").show()
+```
+{{% /tabcontent %}}
+{{% tabcontent "PySpark" %}}
+```py
+df = spark.table("demo.nyc.taxis").show()
+```
+{{% /tabcontent %}}
+{{% /codetabs %}}
+
+#### Adding Iceberg to your Existing Spark Environment
+
+To add Iceberg, use the `--packages` option.
+
+{{% codetabs "AddIcebergToSpark" %}}
+{{% addtab "SparkSQL" checked %}}
+{{% addtab "SparkShell" %}}
+{{% addtab "PySpark" %}}
+{{% tabcontent "SparkSQL"  %}}
+```sh
+spark-sql --packages org.apache.iceberg:iceberg-spark-runtime-3.2_2.12:{{% 
icebergVersion %}}
+```
+{{% /tabcontent %}}
+{{% tabcontent "SparkShell" %}}
+```sh
+spark-shell --packages org.apache.iceberg:iceberg-spark-runtime-3.2_2.12:{{% 
icebergVersion %}}
+```
+{{% /tabcontent %}}
+{{% tabcontent "PySpark" %}}
+```sh
+pyspark --packages org.apache.iceberg:iceberg-spark-runtime-3.2_2.12:{{% 
icebergVersion %}}
+```
+{{% /tabcontent %}}
+{{% /codetabs %}}
+
+{{< hint info >}}
+If you want to include Iceberg in your Spark installation, add the 
[`iceberg-spark-runtime-3.2_2.12` Jar](spark-runtime-jar) to Spark's `jars` 
folder.
+{{< /hint >}}
+
+[spark-runtime-jar]: 
https://search.maven.org/remotecontent?filepath=org/apache/iceberg/iceberg-spark-runtime-3.2_2.12/{{%
 icebergVersion %}}/iceberg-spark-runtime-3.2_2.12-{{% icebergVersion %}}.jar
+
+#### Adding A Catalog to Your Existing Spark Environment
+
+Iceberg has several catalog back-ends that can be used to track tables, like 
JDBC, Hive MetaStore and Glue.
+Catalogs are configured using properties under 
`spark.sql.catalog.(catalog_name)`. In this quickstart guide,
+we use JDBC, but you can follow these instructions to configure other catalog 
types. To learn more, check out
+the [Catalog](../docs/latest/spark-configuration/#catalogs) page in the Spark 
section.
+
+This configuration creates a path-based catalog named `local` for tables under 
`$PWD/warehouse` and adds support for Iceberg tables to Spark's built-in 
catalog.
+
+
+{{% codetabs "AddingACatalog" %}}
+{{% addtab "SparkSQL" checked %}}
+{{% addtab "SparkShell" %}}
+{{% addtab "PySpark" %}}
+{{% tabcontent "SparkSQL"  %}}
+```sh
+spark-sql --packages org.apache.iceberg:iceberg-spark-runtime-3.2_2.12:{{% 
icebergVersion %}}\
+    --conf 
spark.sql.extensions=org.apache.iceberg.spark.extensions.IcebergSparkSessionExtensions
 \
+    --conf 
spark.sql.catalog.spark_catalog=org.apache.iceberg.spark.SparkSessionCatalog \
+    --conf spark.sql.catalog.spark_catalog.type=hive \
+    --conf spark.sql.catalog.demo=org.apache.iceberg.spark.SparkCatalog \
+    --conf spark.sql.catalog.demo.type=hadoop \
+    --conf spark.sql.catalog.demo.warehouse=$PWD/warehouse \
+    --conf spark.sql.defaultCatalog=demo

Review Comment:
   I'd probably make this one `spark-defaults.properties` file. Maybe have CLI 
options and properties in separate tabs?



-- 
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]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to