We use Kafka in Docker container. We create topics automatically if the topic does not exist when producing or consuming messages. We want 3 partitions for the topics, so set
num.partitions=3
Run Code Online (Sandbox Code Playgroud)
in file /etc/kafka/server.properties in the Kafka container. However, it does not take effect. After doing the setting and restarting the container, then try subscribing or publishing on some non-existential topics, the topics are created, but only with one partition.
We tried this on containers created from image confluentinc/cp-kafka:5.1.0 and …
看来选项.contains()并不总是按预期工作。我有以下代码:
case class Person (name: String, nickName: Option[String])
val people = Seq(Person("Ned", Some("d")), Person("Alex", None))
val suspects = Map("c" -> 1, "d" -> 2)
val result1 = people.filter(_.nickName.contains(suspects.contains(_)))
val result2 = people.filter{ p =>
p.nickName.contains{ n =>
suspects.contains(n)
}
}
println(result1)
println(result2)
Run Code Online (Sandbox Code Playgroud)
你可能期望result1并result2包含一个人,但他们实际上是空的。为什么?
事实证明以下代码有效:
val result3 = people.filter{ _.nickName match {
case Some(n) => suspects.contains(n)
case None => false
}
}
val result4 = people.filter( _.nickName.map(suspects.contains).getOrElse(false))
val result5 = people.filter( _.nickName.fold(false)(suspects.contains))
println(result3)
println(result4)
println(result5) …Run Code Online (Sandbox Code Playgroud)