简体   繁体   English

使用Spark Local从GCS加载数据

[英]Loading data from GCS using Spark Local

I am trying to read data from GCS buckets on my local machine, for testing purposes. 我正在尝试从本地计算机上的GCS存储桶读取数据,以进行测试。 I would like to sample some of the data in the cloud I have downloaded the GCS Hadoop Connector JAR . 我想在我下载了GCS Hadoop Connector JAR的云中采样一些数据。

And setup the sparkConf as follow: 并设置sparkConf ,如下所示:

conf = SparkConf() \
    .setMaster("local[8]") \
    .setAppName("Test") \
    .set("spark.jars", "path/gcs-connector-hadoop2-latest.jar") \
    .set("spark.hadoop.google.cloud.auth.service.account.enable", "true") \
    .set("spark.hadoop.google.cloud.auth.service.account.json.keyfile", "path/to/keyfile")

sc = SparkContext(conf=conf)

spark = SparkSession.builder \
    .config(conf=sc.getConf()) \
    .getOrCreate()

spark.read.json("gs://gcs-bucket")

I have also tried to set the conf like so: 我也试图像这样设置conf:

sc._jsc.hadoopConfiguration().set("fs.AbstractFileSystem.gs.impl",  "com.google.cloud.hadoop.fs.gcs.GoogleHadoopFS")
sc._jsc.hadoopConfiguration().set("fs.gs.auth.service.account.json.keyfile", "path/to/keyfile")
sc._jsc.hadoopConfiguration().set("fs.gs.auth.service.account.enable", "true")

I am using PySpark install via PIP and running the code using the unit test module from IntelliJ 我正在通过PIP使用PySpark安装并使用IntelliJ中的单元测试模块运行代码

py4j.protocol.Py4JJavaError: An error occurred while calling o128.json.
: java.io.IOException: No FileSystem for scheme: gs

What should I do? 我该怎么办?

Thanks! 谢谢!

要解决此问题,除了已经配置的属性外,还需要为fs.gs.impl属性添加配置:

sc._jsc.hadoopConfiguration().set("fs.gs.impl", "com.google.cloud.hadoop.fs.gcs.GoogleHadoopFileSystem")

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 将数据从 GCS 中的文件加载到 GCP firestore - Loading data from a file in GCS to GCP firestore 加载本地数据google colab - Loading local data google colab 使用 python 从 AWS redshift 加载数据 - Loading data from AWS redshift using python 如何将 API 调用返回的数据直接加载到 BigQuery 中而不存储在 GCS 上? - How to load data returned from API call directly into BigQuery without storing on GCS? 无法使用python从GCS加载到Bigquery。 客户端没有属性问题 - Unable to load to Bigquery from GCS using python. Client has no attribute issue 如何使用 GAE 和 Python 3 从 GCS 提供大于 32 MB 的文件 - How to serve files larger than 32 MB from GCS using GAE and Python 3 优化 BigQuery 资源的使用,使用 Google Dataflow 从 GCS 加载 200 万个 JSON 文件 - Optimize the use of BigQuery resources to load 2 million JSON files from GCS using Google Dataflow 使用 pandas dataframe 将数据从 csv 加载到表时出错 - Error while loading data from csv to table using pandas dataframe 将存储桶从 S3 传输到 GCS 并在不先下载存储桶的情况下使用 python3 进行反向传输? - Transfer buckets from S3 to GCS and reverse as well using python3 without downloading the buckets first? 使用 python 将文件上传到 gcs 存储桶中的文件夹 - upload file to a folder in gcs bucket using python
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM