我有如下所示的DataFrame。
select t1.*
from t1
where not exists (select 1 from t2 where t2.day = t1.day and t2.month = t1.month);
我有如下替换地图。
WebView
现在,我要迭代此替换图,并希望将其应用于我的数据框。
预期的DataFrame。
ionic3
答案 0 :(得分:0)
通过fn main() {
let cfg = read_ini("demo.ini");
let addr = "127.0.0.1:3000".parse().unwrap();
let server = Server::bind(&addr)
.serve(move || {
let cfg = cfg.clone();
service_fn_ok(move |req| request_handler(req, &cfg))
})
.map_err(|e| println!("server error: {}", e));
rt::run(server);
}
函数直接退出。
regexp_replace
输出
import spark.implicits._
import org.apache.spark.sql.functions._
val df = Seq("12 https://jhafi.com xyza@gmail.com",
"12 https://jhafi.com xyza@gmail.com",
"12 https://jhafi.com xyza@gmail.com",
"12 https://jhafi.com xyza@gmail.com").toDF("mycol")
val email = """(?i)\b[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,4}\b"""
val url ="(https?:\\/\\/(?:www\\.|(?!www))[a-zA-Z0-9][a-zA-Z0-9-]+[a-zA-Z0-9]\\.[^\\s]{2,}|www\\.[a-zA-Z0-9][a-zA-Z0-9-]+[a-zA-Z0-9]\\.[^\\s]{2,}|https?:\\/\\/(?:www\\.|(?!www))[a-zA-Z0-9]+\\.[^\\s]{2,}|www\\.[a-zA-Z0-9]+\\.[^\\s]{2,})"
val urlRegexExpression = regexp_replace($"mycol", url, "PHTEXTURL")
val emailRegexExpression = regexp_replace($"mycol", email, "PHTEXTEMAIL")
df.withColumn("mycol", emailRegexExpression).withColumn("mycol", urlRegexExpression).show(false)
注意:
我对您的网址正则表达式进行了更改,因为它不起作用。
希望这可以解决您的问题。
答案 1 :(得分:0)
你可以试试这个:)
import sparkSession.implicits._
import org.apache.spark.sql.functions.{udf, col}
def patterns_replace(patterns: Map[String, String]) = udf((text: String) =>
patterns.foldLeft(text) { case (text, (replacement, pattern)) =>
text.replaceAll(pattern, replacement)
}
)
val df = Seq(
"12 https://jhafi.com xyza@gmail.com",
"12 https://jhafi.com xyza@gmail.com",
"12 https://jhafi.com xyza@gmail.com",
"12 https://jhafi.com xyza@gmail.com"
).toDF("input")
val patterns = Map(
"EMAIL" -> "[a-z]+@gmail.com",
"URL" -> "https://[a-z]+\\.com"
)
df.withColumn("output", patterns_replace(patterns)(col("input")))
输出
+-----------------------------------+------------+
|input |output |
+-----------------------------------+------------+
|12 https://jhafi.com xyza@gmail.com|12 URL EMAIL|
|12 https://jhafi.com xyza@gmail.com|12 URL EMAIL|
|12 https://jhafi.com xyza@gmail.com|12 URL EMAIL|
|12 https://jhafi.com xyza@gmail.com|12 URL EMAIL|
+-----------------------------------+------------+