scala

Flink实战-订单支付和对账情况监控(分别使用CEP和ProcessFunction来实现)

十年热恋 提交于 2021-02-02 14:48:49
在电商网站中,订单的支付作为直接与钱挂钩的一环,在业务流程中非常重要。对于订单而言,为了正确控制业务流程,也为了增加用户的支付意愿,网站一般会设置一个支付失效时间,超过一段时间没支付的订单就会被取消。另外,对于订单的支付,还应该保证最终支付的正确性,可以通过第三方支付平台的交易数据来做一个实时对账 第一个实现的效果,实时获取订单数据,分析订单的支付情况,分别实时统计支付成功的和15分钟后支付超时的情况 新建一个maven项目,这是基础依赖,如果之前引入了,就不用加了 <properties> <maven.compiler.source>8</maven.compiler.source> <maven.compiler.target>8</maven.compiler.target> <flink.version>1.10.1</flink.version> <scala.binary.version>2.12</scala.binary.version> <kafka.version>2.2.0</kafka.version> </properties> <dependencies> <dependency> <groupId>org.apache.flink</groupId> <artifactId>flink-scala_${scala.binary.version}<

Scala打印菱形*

吃可爱长大的小学妹 提交于 2021-01-30 08:49:23
object TestStar { def main(args: Array[String]) { var len = 5 //上半部分 1,3,5,7,9 Range(1, 10, 2).map("*"*_) .map(s=>{len-=1;val s1 = ((" ")*len)+s;s1}).foreach(println _); //下半部分 7,5,3,1 Range(7, 0, -2).map("*"*_) .map(s=>{len+=1;val s1 = ((" ")*len)+s;s1}).foreach(println _); } } So easy! 来源: oschina 链接: https://my.oschina.net/u/925404/blog/689073

Use mapN to apply values

我的未来我决定 提交于 2021-01-29 22:32:29
问题 I have the following code snippet: final case class Configuration(env: Env, user: String, password: String, address: String) trait DbSetup[F[_]] { type EnvT[A] = OptionT[F, A] def system: EnvT[Env] def user: EnvT[String] def password: EnvT[String] def address: EnvT[String] } object DbSetup { def get[F[_] : Monad](s: DbSetup[F]): s.EnvT[Configuration] = ??? } How to use Applicative function mapN in the implementation of get function to get Configuration filled? 回答1: Try import cats.syntax

In Spark, how to do One Hot Encoding for top N frequent values only?

◇◆丶佛笑我妖孽 提交于 2021-01-29 22:22:16
问题 Let, in my dataframe df, I have a column my_category in which I have different values, and I can view the value counts using: df.groupBy("my_category").count().show() value count a 197 b 166 c 210 d 5 e 2 f 9 g 3 Now, I'd like to apply One Hot Encoding (OHE) on this column, but for the top N frequent values only (say N = 3 ), and put all the rest infrequent values in a dummy column (say, "default"). E.g., the output should be something like: a b c default 0 0 1 0 1 0 0 0 0 1 0 0 1 0 0 0 ... 0

In a scala macro, how to get the full name that a class will have at runtime?

隐身守侯 提交于 2021-01-29 22:08:03
问题 The intention is to get at run-time some info of particular classes that is available only at compile-time. My approach was to generate the info at compile time with a macro that expands to a map that contains the info indexed by the runtime class name. Something like this: object macros { def subClassesOf[T]: Map[String, Info] = macro subClassesOfImpl[T]; def subClassesOfImpl[T: ctx.WeakTypeTag](ctx: blackbox.Context): ctx.Expr[Map[String, Info]] = { import ctx.universe._ val classSymbol =

Composing functions via map and flatmap

若如初见. 提交于 2021-01-29 22:02:12
问题 I learn scala in university and I cannot understand how to use map, flatmap and Option. Here's couple functions from my lab. I know how to implement first but I have no idea how to deal with second? So, the question: how to implement second function without changing it's signature (using map and flatmap)? def testCompose[A, B, C, D](f: A => B) (g: B => C) (h: C => D): A => D = h compose g compose f def testMapFlatMap[A, B, C, D](f: A => Option[B]) (g: B => Option[C]) (h: C => D): Option[A] =>

Difference between [A: C] and [A[_]: C] context bounds

眉间皱痕 提交于 2021-01-29 22:00:38
问题 I'm a newbie, according to my lectures : class Test [T: Comparing] means that it requires an implicit value of type Comparing[T] that can be used in the methods of that class. With this Higher kinded type notation Question : What does this expression def notation[F[_]: Sync] : F[Unit] = ??? refer to ? 回答1: Consider the difference between concrete type and type constructor Int // concrete type List[Int] // concrete type List // type constructor We represent the shape of the type constructor

Understanding type arguments do not conform to class type parameter bounds error when using Higher kinded type parameter

你。 提交于 2021-01-29 21:55:54
问题 I am trying to understand why the following piece of code won't compile when I use a higher kinded type parameter for T in MyModel abstract class Model[M <: Model[M]] class MyModel[T] extends Model[MyModel[T]] class Bar[TModel <: Model[TModel]] object Foo extends App { new Bar[MyModel[_]] } But if i change it to new Bar[MyModel[Any]] it will compile. Why is this ? 回答1: Bar[MyModel[_]] is Bar[MyModel[X] forSome {type X}] . (It should not be confused neither with Bar[MyModel[X]] forSome {type X

In Spark, how to do One Hot Encoding for top N frequent values only?

二次信任 提交于 2021-01-29 21:47:51
问题 Let, in my dataframe df, I have a column my_category in which I have different values, and I can view the value counts using: df.groupBy("my_category").count().show() value count a 197 b 166 c 210 d 5 e 2 f 9 g 3 Now, I'd like to apply One Hot Encoding (OHE) on this column, but for the top N frequent values only (say N = 3 ), and put all the rest infrequent values in a dummy column (say, "default"). E.g., the output should be something like: a b c default 0 0 1 0 1 0 0 0 0 1 0 0 1 0 0 0 ... 0

How to resolve implicit lookup by bounded generic?

◇◆丶佛笑我妖孽 提交于 2021-01-29 20:39:34
问题 I have a series of class Foo: trait Foo class Foo1 extends Foo class Foo2 extends Foo //... and I have a type class and instances for all of the Foos: trait CanBar[T] { def bar: Unit } implicit val foo1: CanBar[Foo1] = null implicit val foo2: CanBar[Foo2] = null and I try to get the type class instance from a method: def bar[T <: Foo](foo: T) = { val canBar = implicitly[CanBar[T]] //... } The compiler complains No implicits found for parameter e: CanBar[T] , even though I imported all the