1
某一特定日期戳
我有以下數據框(數據框的名稱是:df
)比較與Spark和斯卡拉
+---------------+-----------+-------------+------+----+-----+--------------------+-------------------+------+------+------+-----+--------------------+--------------------+------------------+------------------+------+
| time_stamp_0|sender_ip_1|receiver_ip_2| count|rank| xi| pi| r| ip5| ip4| ip3| ip2| variance| entropy| pre_chi_square| total_chi_square|attack|
+---------------+-----------+-------------+------+----+-----+--------------------+-------------------+------+------+------+-----+--------------------+--------------------+------------------+------------------+------+
|07:19:00.005763| 10.0.0.2| 10.0.0.1|509286| 1|92055|1.963533260289896E-6|0.18075305427598637|111891|115199|190028|92055|1.317855896447428...|2.580232918985576E-5|3.7131630265751565|14.852652106300626| 1|
|07:19:00.005788| 10.0.0.2| 10.0.0.1|509286| 2|92055|3.927066520579792E-6|0.18075305427598637|111891|115199|190028|92055|6.498626409377348E-6|4.888262329310028E-5|18.310392943472664|14.852652106300626| 1|
|07:19:00.005807| 10.0.0.2| 10.0.0.1|509286| 3|92055|5.890599780869688E-6|0.18075305427598637|111891|115199|190028|92055|1.560646344288706E-5|7.093550226267817E-5| 43.9724428049685|14.852652106300626| 1|
我需要把零值attack
場如果,無論是時間戳大於「07:19:00.005788」和等於10.0.0.3。
但是,我不知道如何處理時間戳與scala條件下的特定數據進行比較。這裏是我的代碼:
val df_attack = df
.withColumn("attack",
when($"sender_ip_1" === "10.0.0.3"
and ($"time_stamp_0").cast(TimestampType) > "07:19:00.005788", 0)
.otherwise(1))
任何機構可以幫助我嗎?
完全無關:http://wiki.c2.com/?BadVariableNames – philantrovert
@philantrovert:謝謝,我改變了它。 – Queen
我不是說你應該改變它。我發佈它作爲輕鬆的幽默。 – philantrovert