Это часть моего кода :
Код: Выделить всё
bucket_name = 'julio-s3'
json_source = 'source/'
file_2 = "tmp.json"
json_s3_path = f"s3://{bucket_name}/{json_source}/{file_2}"
print(json_s3_path)
df = spark.read.json(json_s3_path)
df.printSchema()
df.show()
Код: Выделить всё
AnalysisException: 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).csv(file).filter($"_corrupt_record".isNotNull).count()
and
spark.read.schema(schema).csv(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).csv(file).cache() and then
df.filter($"_corrupt_record".isNotNull).count().
Код: Выделить всё
multiline_df = spark.read.option("multiline","true").json(json_s3_path)
multiline_df.show(truncate=False)
print(type(multiline_df))
Код: Выделить всё
+----------------------------------------------------------------------------------------------------------------------------------------------------+
|mySchema |
+----------------------------------------------------------------------------------------------------------------------------------------------------+
|{{{NVARCHAR2, NUMBER, NVARCHAR2, NVARCHAR2}, Delta}, {{NVARCHAR2, NVARCHAR2, NVARCHAR2}, Delta}, {{NVARCHAR2, NVARCHAR2, NUMBER, NVARCHAR2}, Delta}}|
+----------------------------------------------------------------------------------------------------------------------------------------------------+
Код: Выделить всё
{
"myschema": {
"accounts": {
"load_type": "daily",
"fields": {
"id": "nvarchar2",
"isdeleted": "number",
"master": "nvarchar2",
"name": "nvarchar2"
}
},
"customer": {
"load_type": "daily",
"fields": {
"id": "nvarchar2",
"accountid": "nvarchar2",
"usergroupid": "nvarchar2"
}
},
"resources": {
"load_type": "daily",
"fields": {
"id": "nvarchar2",
"isdeleted": "number",
"name": "nvarchar2",
"currency": "nvarchar2"
}
}
}
}
Код: Выделить всё
TABLE |COLUMN |COLUMN_TYPE |
+——————-———-+----------———----+---------------+
| accounts |id |NVARCHAR2 |
| accounts |master |NVARCHAR2 |
| accounts |name |NVARCHAR2 |
| customer |id |NVARCHAR2 |
| customer |accountid |NVARCHAR2 |
| customer |usergroupid |NVARCHAR2 |
| resources |id |NVARCHAR2 |
| resources |name |NVARCHAR2 |
| resources |currency |NVARCHAR2 |
+-----------+-----------------+--------------+
С уважением
Подробнее здесь: https://stackoverflow.com/questions/790 ... with-spark