title: Downloading a public dataset from Google BigQuery using Spark to PC
body: <p>I would like to ask for your help. I have solved a lot of problems for this task myself but unfortunately I am not able to solve the following one. I need to download a public dataset (for example bigquery-public-data:samples.shakespeare) from Google BigQuery using Spark (namely PySpark) to my PC. It should be something like "HelloWorld" example for me. I have installed Spark locally in VirtualBox 6.0.10 (Ubuntu 18.04 LTS). First, I want to show some data from the above-mentioned table for beginning. I have created the following piece of code for that (the code is in the file called <code>spark_download_data_from_bq.py</code>). </p>
  
  <pre><code>#!/usr/bin/python
  """BigQuery I/O PySpark example."""
  from pyspark.sql import SparkSession
  from google.cloud import bigquery
  
  spark = SparkSession \
  .builder \
  .master('local') \
  .appName('spark-bigquery-demo') \
  .getOrCreate()
  
  bucket = "gs://my-test-bucket-xxxx"
  spark.conf.set('temporaryGcsBucket', bucket)
  
  # Load data from BigQuery.
  df_data = spark.read.format('bigquery') \
  .option("credentialsFile", "/home/user/Downloads/test-project-xxxxxx-xxxxxxxxxxxx.json")\
  .option("parentProject", "test-project-i-xxxxxx")\
  .option("project", "test-project-i-xxxxxx")\
  .option('table', 'bigquery-public-data:samples.shakespeare') \
  .load()
  df_data.createOrReplaceTempView('data')
  df_data.show() 
  </code></pre>
  
  <p>I run it using the following command: <code>/home/user/Downloads/spark-2.4.0-bin-hadoop2.7/bin/spark-submit --jars /home/user/Downloads/spark-bigquery-with-dependencies_2.11-0.13.1-beta.jar /home/user/Downloads/spark_download_data_from_bq.py</code></p>
  
  <p>Unfortunately, I have the following error and I do not know how to solve:</p>
  
  <pre><code>    py4j.protocol.Py4JJavaError: An error occurred while calling o40.showString.
      : 
  com.google.cloud.spark.bigquery.repackaged.com.google.api.gax.rpc.PermissionDeniedException: com.google.cloud.spark.bigquery.repackaged.io.grpc.StatusRuntimeException: PERMISSION_DENIED: request failed: the user does not have 'bigquery.readsessions.create' permission for 'projects/test-project-i-xxxxxx ...'
  </code></pre>
  
  <p>I don't know how/where to change the <code>bigquery.readsessions.create</code> property. Could you help me? Should the code work after fixing this problem? Do you have a better idea how to download data from BigQuery?</p>
  
  <p>Thanks a lot.</p>
  
  <p>A.</p>