scala

Enforcing that dependent return type must implement typeclass

巧了我就是萌 提交于 2020-11-29 10:13:43
问题 I am trying to enforce a rule that the (dependent) return type of a typeclass, must itself implement a typeclass. So when the user implements the IsVec typeclass below, they must also ensure that the return value of the getElem method implements another typeclass ( IsVecElem ). My attempts to make this work look something like this: // A typeclass for an vector element abstract class IsVecElem[A, T: Numeric] { def dataOnly(self: A): T } // A typeclass for a vector abstract class IsVec[A, T:

How to create an instances for typeclass with dependent type using shapeless

旧城冷巷雨未停 提交于 2020-11-29 09:32:58
问题 I'm trying to derive a tuple instance for a type class with dependent type. I'm using shapeless to create summon the type class for the tuple elements. I'm having trouble matching tuple instance types: import shapeless.the import simulacrum.typeclass @typeclass trait Identifiable[M] { type K def identify(id: M): K } object Identifiable{ implicit def identifiableTuple[K1: Identifiable, K2: Identifiable]: Identifiable[(K1,K2)] = new Identifiable[(K1,K2)]{ val b = the[Identifiable[K2]] val a =

Gatling: Understanding rampUsersPerSec(minTPS) to maxTPS during seconds

孤者浪人 提交于 2020-11-29 04:35:27
问题 I am checking a scala code for gatling where they inject transactions for the period of 20 seconds. /*TPS = Transaction Per Second */ val minTps = Integer.parseInt(System.getProperty("minTps", "1")) val maxTps = Integer.parseInt(System.getProperty("maxTps", "5")) var rampUsersDurationInMinutes =Integer.parseInt(System.getProperty("rampUsersDurationInMinutes", "20")) setUp(scn.inject( rampUsersPerSec(minTps) to maxTps during (rampUsersDurationInMinutes seconds)).protocols(tcilProtocol)) The

Spark dataframe checkpoint cleanup

若如初见. 提交于 2020-11-28 09:24:15
问题 I have a dataframe in spark where an entire partition from Hive has been loaded and i need to break the lineage to overwrite the same partition after some modifications to the data. However, when the spark job is done i am left with the data from the checkpoint on the HDFS. Why do Spark not clean this up by itself or is there something i am missing? spark.sparkContext.setCheckpointDir("/home/user/checkpoint/") spark.conf.set("spark.sql.sources.partitionOverwriteMode", "dynamic") val df =

Spark dataframe checkpoint cleanup

做~自己de王妃 提交于 2020-11-28 09:22:56
问题 I have a dataframe in spark where an entire partition from Hive has been loaded and i need to break the lineage to overwrite the same partition after some modifications to the data. However, when the spark job is done i am left with the data from the checkpoint on the HDFS. Why do Spark not clean this up by itself or is there something i am missing? spark.sparkContext.setCheckpointDir("/home/user/checkpoint/") spark.conf.set("spark.sql.sources.partitionOverwriteMode", "dynamic") val df =

在local模式下的spark程序打包到集群上运行

萝らか妹 提交于 2020-11-28 08:26:38
一、前期准备   前期的环境准备,在Linux系统下要有Hadoop系统,spark伪分布式或者分布式,具体的教程可以查阅我的这两篇博客: Hadoop2.0伪分布式平台环境搭建 Spark2.4.0伪分布式环境搭建   然后在spark伪分布式的环境下必须出现如下八个节点才算spark环境搭建好。      然后再在本地windows系统下有一个简单的词频统计程序。 import org.apache.spark.SparkConf import org.apache.spark.SparkContext import org.apache.spark.rdd.RDD object ScalaSparkDemo { def main(args: Array[String]) { /** * 第一步:创建Spark的配置对象SparkConf,设置Spark程序的运行时的配置信息, * 例如说通过setMaster来设置程序要连接的Spark集群的Master的URL, * 如果设置为local,则代表Spark程序在本地运行,特别适合于机器配置条件非常差 * (例如只有1G的内存)的初学者 */ val conf = new SparkConf() //创建SparkConf对象,由于全局只有一个SparkConf所以不需要工厂方法 conf.setAppName("wow,my

从普通JAVA程序员到阿里架构师,他用了六年

帅比萌擦擦* 提交于 2020-11-27 05:49:38
工作年限:8 年服务公司:4 家(含四大门户中的两家)最近职业:Java 架构师职场关键词:社交平台、高并发系统架构设计、技术团队管理、多款从零到一的产品城市! 六年间,这位职人呆过四大门户中的两家,完成了工程师到架构师的蜕变。经手多款从零到一产品的开发和增长,也经历国内最大社交平台亿级流量和用户的架构设计及优化工作。工作上思路清晰、认真负责,是同事们心目中优秀 Problem Solver。 问:介绍一下你自己? 答 :我 2008 年硕士毕业后,前 2 年在一家传统 IT 公司,最近 6 年在互联网公司,历任 Java 开发工程师、高级工程师、架构师等职位。工作内容上,经历过多款产品从零到一的诞生开发过程,也经手过国内用户、内容和流量最大的社交/社区产品的架构改造优化工作,有丰富的社交产品的研发经验,目前在一家创业公司担任技术合伙人。 问:你擅长的技术领域是什么? 答 :擅长的编程语言是 Java、Golang、Scala,熟悉程度依次递减。专注于高性能、高并发系统架构设计和实现。 问:平时怎么向家人解释你的工作是做什么的? 答 :一般不详细解释,即使解释了也是徒劳。所以他们会按照自己的理解来描述我的工作,比如修电脑的,比如卖手机的。 问:你觉得程序员可以当一辈子吗?有没有想象过自己 40 岁时在做什么? 答 :应该还是会从事开发方面的工作吧,外企中有很多上了年岁的程序员啊。

Gatling脚本编写技巧篇(二)

偶尔善良 提交于 2020-11-27 02:30:44
脚本示例: import io.gatling.core.Predef._ import io.gatling.http.Predef._ import scala.concurrent.duration._ class BaiduSimulation extends Simulation { //读取配置文件 val conf = ConfigFactory.load() //实例化请求方法 val httpProtocol = http.baseUrl(conf.getString("baseUrl")) //包装请求接口 val rootEndPointUsers = scenario("信贷重构") .exec(http("信贷重构-授信申请") .post("/apply") .header("Content-Type", "application/json") .header("Accept-Encoding", "gzip") .body(RawFileBody("computerdatabase/recordedsimulation/0001_request.json")) .check(status.is(200) .saveAs("myresponse") ) .check(bodyString.saveAs("Get_bodys"))) .exec{

案例说明flink的udf

旧城冷巷雨未停 提交于 2020-11-21 05:50:45
本文会主要讲三种udf: 用户自定义函数是非常重要的一个特征,因为他极大地扩展了查询的表达能力。本文除了介绍这三种udf之外,最后会介绍一个redis作为交互数据源的udf案例。 注册用户自定义函数 在大多数场景下,用户自定义函数在使用之前是必须要注册的。对于Scala的Table API,udf是不需要注册的。 调用TableEnvironment的registerFunction()方法来实现注册。Udf注册成功之后,会被插入TableEnvironment的function catalog,这样table API和sql就能解析他了。 Scalar Functions 标量函数 标量函数,是指返回一个值的函数。标量函数是实现将0,1,或者多个标量值转化为一个新值。 实现一个标量函数需要继承ScalarFunction,并且实现一个或者多个evaluation方法。标量函数的行为就是通过evaluation方法来实现的。evaluation方法必须定义为public,命名为eval。evaluation方法的输入参数类型和返回值类型决定着标量函数的输入参数类型和返回值类型。evaluation方法也可以被重载实现多个eval。同时evaluation方法支持变参数,例如:eval(String... strs)。 下面给出一个标量函数的例子。例子实现的是一个hashcode方法

Scala 基础语法

一笑奈何 提交于 2020-11-21 02:23:39
Scala 解释器的使用 · REPL : Read (取值) -> Evaluation (求值) -> Print (打印) -> Loop (循环)。 scala 解释器也被称为 REPL ,会快速编译 scala 代码为字节码,然后交给 JVM 来执行。 ·计算表达式:在 scala> 命令行内,键入 scala 代码,解释器会直接返回结果给你。如果你没有指定变量来存放这个值,那么值默认的名称为 res ,而且会显示结果的数据类型,比如 Int 、 Double 、 String 等等。 ·例如,输入 1 + 1 ,会看到 res0: Int = 2 ·内置变量:在后面可以继续使用 res 这个变量,以及它存放的值。 ·例如, 2.0 * res0 ,返回 res1: Double = 4.0 ·例如, "Hi, " + res0 ,返回 res2: String = Hi, 2 ·自动补全:在 scala> 命令行内,可以使用 Tab 键进行自动补全。 ·例如,输入 res2.to ,敲击 Tab 键,解释器会显示出以下选项, toCharArray , toLowerCase , toString , toUpperCase 。因为此时无法判定你需要补全的是哪一个,因此会提供给你所有的选项。 ·例如,输入 res2.toU ,敲击 Tab 键,直接会给你补全为 res2