scala

Scala : How to split words using multiple delimeters

霸气de小男生 提交于 2020-08-07 05:41:45
问题 Suppose I have the text file like this: Apple#mango&banana@grapes The data needs to be split on multiple delimiters before performing the word count. How to do that? 回答1: Use split method: scala> "Apple#mango&banana@grapes".split("[#&@]") res0: Array[String] = Array(Apple, mango, banana, grapes) 回答2: If you just want to count words, you don't need to split. Something like this will do: val numWords = """\b\w""".r.findAllIn(string).length This is a regex that matches start of a word ( \b is a

Scala : How to split words using multiple delimeters

為{幸葍}努か 提交于 2020-08-07 05:41:40
问题 Suppose I have the text file like this: Apple#mango&banana@grapes The data needs to be split on multiple delimiters before performing the word count. How to do that? 回答1: Use split method: scala> "Apple#mango&banana@grapes".split("[#&@]") res0: Array[String] = Array(Apple, mango, banana, grapes) 回答2: If you just want to count words, you don't need to split. Something like this will do: val numWords = """\b\w""".r.findAllIn(string).length This is a regex that matches start of a word ( \b is a

Scala : How to split words using multiple delimeters

一世执手 提交于 2020-08-07 05:41:04
问题 Suppose I have the text file like this: Apple#mango&banana@grapes The data needs to be split on multiple delimiters before performing the word count. How to do that? 回答1: Use split method: scala> "Apple#mango&banana@grapes".split("[#&@]") res0: Array[String] = Array(Apple, mango, banana, grapes) 回答2: If you just want to count words, you don't need to split. Something like this will do: val numWords = """\b\w""".r.findAllIn(string).length This is a regex that matches start of a word ( \b is a

How to avoid writing confusing DSLs in Scala

穿精又带淫゛_ 提交于 2020-08-07 05:23:07
问题 I've read comments stating that Scala's flexibility makes it easy for developers to write DSLs that are difficult to understand and reason about. DSLs are possible because we can sometimes omit . and parentheses (e.g. List(1) map println ) we can sometimes interchange () and {} we have implicit values, parameters, and classes (also conversions, which are now discouraged) there is a relatively small number of reserved symbols in the language (e.g. I can define + for my class) and possibly

How to avoid writing confusing DSLs in Scala

萝らか妹 提交于 2020-08-07 05:22:19
问题 I've read comments stating that Scala's flexibility makes it easy for developers to write DSLs that are difficult to understand and reason about. DSLs are possible because we can sometimes omit . and parentheses (e.g. List(1) map println ) we can sometimes interchange () and {} we have implicit values, parameters, and classes (also conversions, which are now discouraged) there is a relatively small number of reserved symbols in the language (e.g. I can define + for my class) and possibly

redis介绍

纵饮孤独 提交于 2020-08-07 05:08:25
Ø 开源的( BSD 协议),使用 ANSI C 编写,基于内存的且 支持持久化 ,高性能的 Key-Value 的 NoSQL 数据库 Ø 支持数据结构 类型丰富 ,有如 字符串( strings ), 散列( hashes ), 列表( lists ), 集合( sets ), 有序集合( sorted sets ) 与范围查询, bitmaps , hyperloglogs 和 地理空间( geospatial ) 索引半径查询。 Ø 丰富的支持主流语言的客户端 , C 、 C++ 、 Python 、 Erlang 、 R 、 C# 、 Java 、 PHP 、 Objective-C 、 Perl 、 Ruby 、 Scala 、 Go 、 JavaScript Ø Ø 用途:缓存( StackOverFlow )、数据库(微博)、消息中间件(微博) Ø Ø 官方网站: http://www.redis.io 来源: oschina 链接: https://my.oschina.net/u/3095186/blog/4367251

Plink v0.1.0 发布——基于Flink的流处理平台

你。 提交于 2020-08-06 20:18:16
Plink是一个基于Flink的流处理平台,旨在基于 [Apache Flink]封装构建上层平台。 提供常见的作业管理功能。如作业的创建,删除,编辑,更新,保存,启动,停止,重启,管理,多作业模板配置等。 Flink SQL 编辑提交功能。如 SQL 的在线开发,智能提示,格式化,语法校验,保存,采样,运行,测试,集成 Kafka 等。 由于项目刚刚启动,未来还有很长的路要走,让我们拭目以待。 在 Windows 上部署 Plink Plink 进行独立单机部署,可以在 Windows 上进行部署,以下是部署的操作详情。 环境需求 操作系统 Windows 编译环境 Java 1.8 + Maven 3.3 + (编译代码) 运行环境 Apache Flink 1.9 + (Standalone 模式) MySQL 5.7 + Java 1.8 + 安装 Java 版本: java 1.8+ JAVA_HOME 配置 安装详情: 略 。。。 安装 Maven 版本: maven 3.3 + MAVEN_HOME 配置 安装详情: 略 。。。 安装 Mysql 版本: mysql 5.7+ 安装建议: 建议 Docker 安装,命令如下: docker run -p 3306:3306 --name plink-mysql -e MYSQL_ROOT_PASSWORD=123456

小师妹学JavaIO之:文件编码和字符集Unicode

僤鯓⒐⒋嵵緔 提交于 2020-08-06 09:43:18
文章目录 简介 使用Properties读取文件 乱码初现 字符集和文件编码 解决Properties中的乱码 真.终极解决办法 总结 简介 小师妹一时兴起,使用了一项从来都没用过的新技能,没想却出现了一个无法解决的问题。把大象装进冰箱到底有几步?乱码的问题又是怎么解决的?快来跟F师兄一起看看吧。 更多精彩内容且看: 区块链从入门到放弃系列教程-涵盖密码学,超级账本,以太坊,Libra,比特币等持续更新 Spring Boot 2.X系列教程:七天从无到有掌握Spring Boot-持续更新 Spring 5.X系列教程:满足你对Spring5的一切想象-持续更新 java程序员从小工到专家成神之路(2020版)-持续更新中,附详细文章教程 使用Properties读取文件 这天,小师妹心情很愉悦,吹着口哨唱着歌,标准的45度俯视让人好不自在。 小师妹呀,什么事情这么高兴,说出来让师兄也沾点喜庆? 小师妹:F师兄,最新我发现了一种新型的读取文件的方法,很好用的,就跟map一样: public void usePropertiesFile ( ) throws IOException { Properties configProp = new Properties ( ) ; InputStream in = this . getClass ( ) . getClassLoader

How to efficiently map over DF and use combination of outputs?

ⅰ亾dé卋堺 提交于 2020-08-06 06:56:21
问题 Given a DF, let's say I have 3 classes each with a method addCol that will use the columns in the DF to create and append a new column to the DF (based on different calculations). What is the best way to get a resulting df that will contain the original df A and the 3 added columns? val df = Seq((1, 2), (2,5), (3, 7)).toDF("num1", "num2") def addCol(df: DataFrame): DataFrame = { df.withColumn("method1", col("num1")/col("num2")) } def addCol(df: DataFrame): DataFrame = { df.withColumn("method2

关于Java8的精心总结

前提是你 提交于 2020-08-06 03:53:23
前言 ​ 最近公司里比较新的项目里面,看到了很多关于java8新特性的用法,由于之前自己对java8的新特性不是很了解也没有去做深入研究,所以最近就系统的去学习了一下,然后总结了一篇文章第一时间和大家分享一下。 ​ ​ 在了解一项新技术之前,我们需要了解我们为什么要去学习它以及它的优点,以下是我总结的: Java8(又称jdk1.8)是java语言开发的一个主要版本,Java8是oracal公司于2014年3月发布,可以看成是自java5以来最具有革命性的版本。 新特性的优点: 速度更快、代码更少、便于并行、最大化减少空指针异常 函数式编程提供了一种更高层次的抽象化 排序: List<RoleEntity> rolesListSort = rolesList.stream().sorted(Comparator.comparing(RoleEntity::getCreateDate)).collect(Collectors.toList()); Consumer是一个函数式接口 参数是Consumer类型的,Consumer里面的泛型表示泛型的类型要么是Integer,要么是Integer的父类,super表示它及它上面的,也就是父类。 下面这段代码是在Iterable接口里面的默认方法,jdk8之后的新方法,默认方法(默认方法的引入很大程度上是为了保证向后兼容) default