English 中文(简体)
自Pecur2.3起,来自JSON/CSV原始档案的查询不公开。
原标题:Since Spark 2.3, the queries from raw JSON/CSV files are disallowed

Hi i 正在学习pysstart 现在和现在,它正在为v数据工作,但如果将其转换成json <>/code>数据,则正在出现错误。

*Since Spark 2.3, the queries from raw JSON/CSV files are disallowed when the referenced columns only include the internal corrupt record column (named _corrupt_record by default). For example:

spark.read.schema(schema).json(file).filter($"_corrupt_record".isNotNull).count()

and spark.read.schema(schema).json(file).select("_corrupt_record").show(). Instead, you can cache or save the parsed results and then send the same query. For example, val df = spark.read.schema(schema).json(file).cache() and then

df.filter($"_corrupt_record".isNotNull).count().*

样本json数据为

[
  {
    "student_id": 1,
    "name": "John Doe",
    "age": 18,
    "grade": "A"
  },
  {
    "student_id": 2,
    "name": "Jane Smith",
    "age": 17,
    "grade": "B"
  },
  {
    "student_id": 3,
    "name": "Bob Johnson",
    "age": 19,
    "grade": "C"
  },
  {
    "student_id": 4,
    "name": "Alice Williams",
    "age": 18,
    "grade": "A"
  },
  {
    "student_id": 5,
    "name": "Charlie Brown",
    "age": 17,
    "grade": "B"
  },
  {
    "student_id": 6,
    "name": "Emma Davis",
    "age": 19,
    "grade": "C"
  },
  {
    "student_id": 7,
    "name": "James Miller",
    "age": 18,
    "grade": "A"
  },
  {
    "student_id": 8,
    "name": "Sophie Taylor",
    "age": 17,
    "grade": "B"
  },
  {
    "student_id": 9,
    "name": "David White",
    "age": 19,
    "grade": "C"
  }
]

以及i 已经使用的假冒代码

mydata = spark.read.json("/original.csv")
mydata.show()
问题回答

在处理json数据时,每条新线都被视为完全的json,因此该线已经失效。

Try using this:

mydata = spark.read.option("multiline","true").json("/或iginal.csv")
mydata.show()

spark.read.json("/或iginal.csv", multiLine=true)

https://spark.apache.或g/docs/latest/sql-data-sources-json.html#:~:text=read-,multiLine,-false





相关问题
Can Django models use MySQL functions?

Is there a way to force Django models to pass a field to a MySQL function every time the model data is read or loaded? To clarify what I mean in SQL, I want the Django model to produce something like ...

An enterprise scheduler for python (like quartz)

I am looking for an enterprise tasks scheduler for python, like quartz is for Java. Requirements: Persistent: if the process restarts or the machine restarts, then all the jobs must stay there and ...

How to remove unique, then duplicate dictionaries in a list?

Given the following list that contains some duplicate and some unique dictionaries, what is the best method to remove unique dictionaries first, then reduce the duplicate dictionaries to single ...

What is suggested seed value to use with random.seed()?

Simple enough question: I m using python random module to generate random integers. I want to know what is the suggested value to use with the random.seed() function? Currently I am letting this ...

How can I make the PyDev editor selectively ignore errors?

I m using PyDev under Eclipse to write some Jython code. I ve got numerous instances where I need to do something like this: import com.work.project.component.client.Interface.ISubInterface as ...

How do I profile `paster serve` s startup time?

Python s paster serve app.ini is taking longer than I would like to be ready for the first request. I know how to profile requests with middleware, but how do I profile the initialization time? I ...

Pragmatically adding give-aways/freebies to an online store

Our business currently has an online store and recently we ve been offering free specials to our customers. Right now, we simply display the special and give the buyer a notice stating we will add the ...

Converting Dictionary to List? [duplicate]

I m trying to convert a Python dictionary into a Python list, in order to perform some calculations. #My dictionary dict = {} dict[ Capital ]="London" dict[ Food ]="Fish&Chips" dict[ 2012 ]="...