forked from GoogleCloudPlatform/magic-modules
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add support for Stored Procedure for Apache Spark (GoogleCloudPlatfor…
…m#9793) * impl for hashicorp/terraform-provider-google#16953 * modified format in example * modified tab to space * added test for update and test for coverage * mofify all resource in the spark option section * modified connection id to avoid conflict
- Loading branch information
1 parent
12e2773
commit ec8f642
Showing
5 changed files
with
269 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
41 changes: 41 additions & 0 deletions
41
mmv1/templates/terraform/examples/big_query_routine_pyspark.tf.erb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
resource "google_bigquery_dataset" "test" { | ||
dataset_id = "<%= ctx[:vars]['dataset_id'] %>" | ||
} | ||
|
||
resource "google_bigquery_connection" "test" { | ||
connection_id = "<%= ctx[:vars]['connection_id'] %>" | ||
location = "US" | ||
spark { } | ||
} | ||
|
||
resource "google_bigquery_routine" "<%= ctx[:primary_resource_id] %>" { | ||
dataset_id = google_bigquery_dataset.test.dataset_id | ||
routine_id = "<%= ctx[:vars]['routine_id'] %>" | ||
routine_type = "PROCEDURE" | ||
language = "PYTHON" | ||
definition_body = <<-EOS | ||
from pyspark.sql import SparkSession | ||
|
||
spark = SparkSession.builder.appName("spark-bigquery-demo").getOrCreate() | ||
|
||
# Load data from BigQuery. | ||
words = spark.read.format("bigquery") \ | ||
.option("table", "bigquery-public-data:samples.shakespeare") \ | ||
.load() | ||
words.createOrReplaceTempView("words") | ||
|
||
# Perform word count. | ||
word_count = words.select('word', 'word_count').groupBy('word').sum('word_count').withColumnRenamed("sum(word_count)", "sum_word_count") | ||
word_count.show() | ||
word_count.printSchema() | ||
|
||
# Saving the data to BigQuery | ||
word_count.write.format("bigquery") \ | ||
.option("writeMethod", "direct") \ | ||
.save("wordcount_dataset.wordcount_output") | ||
EOS | ||
spark_options { | ||
connection = google_bigquery_connection.test.name | ||
runtime_version = "2.1" | ||
} | ||
} |
25 changes: 25 additions & 0 deletions
25
mmv1/templates/terraform/examples/big_query_routine_pyspark_mainfile.tf.erb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
resource "google_bigquery_dataset" "test" { | ||
dataset_id = "<%= ctx[:vars]['dataset_id'] %>" | ||
} | ||
|
||
resource "google_bigquery_connection" "test" { | ||
connection_id = "<%= ctx[:vars]['connection_id'] %>" | ||
location = "US" | ||
spark { } | ||
} | ||
|
||
resource "google_bigquery_routine" "<%= ctx[:primary_resource_id] %>" { | ||
dataset_id = google_bigquery_dataset.test.dataset_id | ||
routine_id = "<%= ctx[:vars]['routine_id'] %>" | ||
routine_type = "PROCEDURE" | ||
language = "PYTHON" | ||
definition_body = "" | ||
spark_options { | ||
connection = google_bigquery_connection.test.name | ||
runtime_version = "2.1" | ||
main_file_uri = "gs://test-bucket/main.py" | ||
py_file_uris = ["gs://test-bucket/lib.py"] | ||
file_uris = ["gs://test-bucket/distribute_in_executor.json"] | ||
archive_uris = ["gs://test-bucket/distribute_in_executor.tar.gz"] | ||
} | ||
} |
28 changes: 28 additions & 0 deletions
28
mmv1/templates/terraform/examples/big_query_routine_spark_jar.tf.erb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
resource "google_bigquery_dataset" "test" { | ||
dataset_id = "<%= ctx[:vars]['dataset_id'] %>" | ||
} | ||
|
||
resource "google_bigquery_connection" "test" { | ||
connection_id = "<%= ctx[:vars]['connection_id'] %>" | ||
location = "US" | ||
spark { } | ||
} | ||
|
||
resource "google_bigquery_routine" "<%= ctx[:primary_resource_id] %>" { | ||
dataset_id = google_bigquery_dataset.test.dataset_id | ||
routine_id = "<%= ctx[:vars]['routine_id'] %>" | ||
routine_type = "PROCEDURE" | ||
language = "SCALA" | ||
definition_body = "" | ||
spark_options { | ||
connection = google_bigquery_connection.test.name | ||
runtime_version = "2.1" | ||
container_image = "gcr.io/my-project-id/my-spark-image:latest" | ||
main_class = "com.google.test.jar.MainClass" | ||
jar_uris = [ "gs://test-bucket/uberjar_spark_spark3.jar" ] | ||
properties = { | ||
"spark.dataproc.scaling.version" : "2", | ||
"spark.reducer.fetchMigratedShuffle.enabled" : "true", | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters