0
スパークデータフレーム/データセットで厳密なデータ型チェックを有効にするにはどうすればよいですか? 私たちは、変換のために上流システムから多くのシステム生成フィードと手動フィードを受け取ります。 変換を開始する前に、フィードを抽出し、スキーマに対して厳密なデータ型チェックを実行することをお勧めします。 Spark 2.0で効率的に行う方法を提案できますか?
私たちは、私はあなたがスカラ座を使用しているので、私の提案は、あなたのschema.Youのような何かを行うことができます定義するケースクラスを使用する場合と仮定していますSpark Dataframe/Datasetでの厳密なデータ型チェックの適用方法?
1. User infereSchema = true, while reading file and get generated dataframes schema to validate against expected schema. Normally infereSchema= true is two phase operation, prove costly for give file
2. Enforcing schema while creating data frame from csv file
val df:DataFrame = spark.read.format("csv")
.schema(readSchemaFromAvroSchemaFile)
.option("header","true")
.option("inferSchema","false")
.csv("CSVFileUri")
strict data type check not imposed while writing,
it applied only while reading dataframe
Is it possible to validate without making read call as it could be expensive operation?
Also in case of double type show some strange behavior
if we have avro schema
{
"namespace":"com.test.schema.validation",
"name" : "example",
"type" : "record",
"fields" [
{"name":"item_id","type":["null","string"],"default":null},
{"name":"item_price","type":["null","double"],"default":null}
]
}
CSV file
item_id|item_price
1|234.90
2|634.90
3|534.90
4|233A40.90
5|233E12
df.show(10)- gives me following
item_id|item_price
1|234.90
2|634.90
3|534.90
4|233.90
5|2.3E13
Value is Row#4 truncated without any failure so it's hard catch
Please suggest if you have any efficient way to validate schema
Have you come across double type value truncation?
ありがとう@Akhilanand私はケースクラスとしてスキーマを適用しています – user1876321