scala

“Insecure HTTP request is unsupported” Error in Scala

半世苍凉 提交于 2021-01-05 08:56:14
问题 I am getting the following error when attempting to run sbt run to run my Scala code: insecure HTTP request is unsupported 'http://repo.typesafe.com/typesafe/releases'; switch to HTTPS or opt-in as ("typesafe-releases" at "http://repo.typesafe.com/typesafe/releases").withAllowInsecureProtocol(true), or by using allowInsecureProtocol in repositories file This is strange because it was working perfectly fine last week and I have changed nothing in the code. I have tried adding ("typesafe

Extend Java abstract class in Scala

三世轮回 提交于 2021-01-05 07:31:22
问题 Given a Java class, something like public abstract class A { public A(URI u) { } } I can extend it in Scala like this class B(u: URI) extends A(u) { } However, what I would like to do is alter the constructor of B, something like case class Settings() class B(settings: Settings) extends A { // Handle settings // Call A's constructor } What's the correct syntax for doing this in Scala? 回答1: Blocks are expressions in Scala, so you can run code before calling the superclass constructor. Here's a

Spark Structured Streaming dynamic lookup with Redis

三世轮回 提交于 2021-01-05 07:31:09
问题 i am new to spark. We are currently building a pipeline : Read the events from Kafka topic Enrich this data with the help of Redis-Lookup Write events to the new Kafka topic So, my problem is when i want to use spark-redis library it performs very well, but data stays static in my streaming job. Although data is refreshed at Redis, it does not reflect to my dataframe. Spark reads data at first then never updates it. Also i am reading from REDIS data at first,total data about 1mio key-val

Extend Java abstract class in Scala

空扰寡人 提交于 2021-01-05 07:29:53
问题 Given a Java class, something like public abstract class A { public A(URI u) { } } I can extend it in Scala like this class B(u: URI) extends A(u) { } However, what I would like to do is alter the constructor of B, something like case class Settings() class B(settings: Settings) extends A { // Handle settings // Call A's constructor } What's the correct syntax for doing this in Scala? 回答1: Blocks are expressions in Scala, so you can run code before calling the superclass constructor. Here's a

Extend Java abstract class in Scala

浪子不回头ぞ 提交于 2021-01-05 07:29:46
问题 Given a Java class, something like public abstract class A { public A(URI u) { } } I can extend it in Scala like this class B(u: URI) extends A(u) { } However, what I would like to do is alter the constructor of B, something like case class Settings() class B(settings: Settings) extends A { // Handle settings // Call A's constructor } What's the correct syntax for doing this in Scala? 回答1: Blocks are expressions in Scala, so you can run code before calling the superclass constructor. Here's a

kafka的分区和主题

只谈情不闲聊 提交于 2021-01-04 07:34:04
分区 设置分区数 我们无法通过Producer相关的API设定分区数和复制因子的,因为Producer相关API创建topic的是通过读取 server.properties 文件中的 num.partitions 和 default.replication.factor 的。 kafka分区分配策略 当以下事件发生时,Kafka 将会进行一次分区分配: 同一个 Consumer Group 内新增消费者 消费者离开当前所属的Consumer Group,包括shuts down 或 crashes 订阅的主题新增分区 每个分区只能由同一个消费组内的一个consumer来消费。那么问题来了,同一个 Consumer Group 里面的 Consumer 是如何知道该消费哪些分区里面的数据呢? 在 Kafka 内部存在两种默认的分区分配策略:Range 和 RoundRobin。具体策略可通过参数配置: partition.assignment.strategy 。 Range策略 range分区的对象是topic,会对同一个topic里面的partition进行排序,然后除以consumer数量,得到的步长就是每个consumer消费的数量,对consumer也进行了排序,每个consumer消费对应步长里面的partition。如果不能均分,则那么前几个消费者线程将多消费一个分区

MapView(<not computed>) in Scala

北城余情 提交于 2021-01-03 07:08:43
问题 I started learning Scala but I found a confusing problem about map . My code is like this: val mymap = Map(1 -> "james",2 -> "justin") println(mymap.view.mapValues(x => "hi" + x)) println(mymap.view.mapValues(x => x.toUpperCase)) but the result is MapView(<not computed>) MapView(<not computed>) I am using view.mapValues because .map is deprecated. Any suggestion or doc I need to read about this? 回答1: Try the following: val mymap = Map(1 -> "james",2 -> "justin") println(mymap.view.mapValues(x

MapView(<not computed>) in Scala

青春壹個敷衍的年華 提交于 2021-01-03 07:04:01
问题 I started learning Scala but I found a confusing problem about map . My code is like this: val mymap = Map(1 -> "james",2 -> "justin") println(mymap.view.mapValues(x => "hi" + x)) println(mymap.view.mapValues(x => x.toUpperCase)) but the result is MapView(<not computed>) MapView(<not computed>) I am using view.mapValues because .map is deprecated. Any suggestion or doc I need to read about this? 回答1: Try the following: val mymap = Map(1 -> "james",2 -> "justin") println(mymap.view.mapValues(x

成功入职字节跳动,分享我的八面面经心得!

余生颓废 提交于 2021-01-02 22:58:52
今天正式入职了字节跳动。办公环境也很好,这边一栋楼都是办公区域。公司内部配备各种小零食、饮料,还有免费的咖啡。15楼还有健身房。而且公司包三餐来着。下午三点半左右还会有阿姨推着小车给大家送下午茶。听说入职以后很容易长胖来着。不过如果想要保持身材的话,公司二楼还提供专门的健身餐。周二周四还可以预约专业的按摩服务,有效调理颈椎和腰椎。生活服务得这么贴心,感觉在这里就只需要好好工作就好了吧,哈哈 为什么想去字节跳动 实际上,这次的工作变动并不在我计划中。只是在四月份的时候偶然得知字节跳动上海要搬到合川路地铁站附近,我就忽然心动了。为什么呢,因为我家距离合川路地铁站步行只要十分钟。本身宇宙条待遇高名声在外,也就是说,只要我能来这里的话,人生最美满的钱多事少离家近的不可能三角我能拿俩。所以在五月份的时候我就开始悄摸摸地准备面试头条了。为的就是以后可以过上早上八点半起床,然后慢慢悠悠走到公司还不迟到(可能还是很早来的人之一)的生活。 当然,这是我为什么想去字节跳动的原因。换算到你们自己的时候,你们也要想一想是因为什么想要换一份工作、想要去某个公司。为了薪资?环境?平台?还是大公司的名头?记住,不管是为了哪一个,都OK的。谈钱不伤感情,目标明确,心智坚定以后,才好围绕着这个目标做一系列的准备。面试的过程中每次面试官问我为什么想来字节跳动,我都是直截了当地说离家近,还说假如这次面不上,准备准备

Why is scalatest MockitoSugar deprecated?

谁都会走 提交于 2021-01-02 14:02:33
问题 I'm new to writing junit tests in Scala and I'm using Mockito to mock objects. I'm also using scalatest_2.12-3.0.4 . The ScalaTest documentation (like here) shows the syntax to create the mock using MockitoSugar, i.e. val mockCollaborator = mock[Collaborator] Eclipse shows org.scalatest.mock.MockitoSugar crossed out in the import statement, indicating it is deprecated. The only alternative I've found is, don't use MockitoSugar and instead do: val mockCollaborator = mock(classOf[Collaborator])