Spark 之 Row
来源:互联网 发布:阿依莲正品淘宝折扣店 编辑:程序博客网 时间:2024/06/06 02:21
hkl曰:直接搞过来官方的API文档,看不懂英文没关系,看它的实例就可以了。
http://spark.apache.org/docs/1.3.1/api/scala/index.html#org.apache.spark.sql.Row
注意:import org.apache.spark.sql._ 要先导入这个包 。
Represents one row of output from a relational operator. Allows both generic access by ordinal, which will incur boxing overhead for primitives, as well as native primitive access.
It is invalid to use the native primitive interface to retrieve a value that is null, instead a user must check isNullAt
before attempting to retrieve a value that might be null.
To create a new Row, use RowFactory.create() in Java or Row.apply() in Scala.
A Row object can be constructed by providing field values. Example:
import org.apache.spark.sql._// Create a Row from values.Row(value1, value2, value3, ...)// Create a Row from a Seq of values.Row.fromSeq(Seq(value1, value2, ...))
A value of a row can be accessed through both generic access by ordinal, which will incur boxing overhead for primitives, as well as native primitive access. An example of generic access by ordinal:
import org.apache.spark.sql._val row = Row(1, true, "a string", null)// row: Row = [1,true,a string,null]val firstValue = row(0)// firstValue: Any = 1val fourthValue = row(3)// fourthValue: Any = null
For native primitive access, it is invalid to use the native primitive interface to retrieve a value that is null, instead a user must check isNullAt
before attempting to retrieve a value that might be null. An example of native primitive access:
// using the row from the previous example.val firstValue = row.getInt(0)// firstValue: Int = 1val isNull = row.isNullAt(3)// isNull: Boolean = true
In Scala, fields in a Row object can be extracted in a pattern match. Example:
import org.apache.spark.sql._val pairs = sql("SELECT key, value FROM src").rdd.map { case Row(key: Int, value: String) => key -> value}
实在想看懂的,就直接用翻译插件吧。
这个都是它的具体的API,
还有一个要注意的是他的一个API isNullAt()这个索引第一位的元素是 0 。
size 方法是显示row里元素的个数。
row的api很丰富,自己需要的话就查看文章顶部的链接。
- Spark 之 Row
- Spark-sql-row
- Spark-Sql源码解析之七 Execute: executed Plan -> RDD[Row]
- Spark基本操作SparkSession,Dataset<Row>,JavaRDD<Row>
- LeetCode之Keyboard Row
- LeetCode之Keyboard Row
- QML之Row水平定位器
- spark 之 spark是什么?
- Spark 之 spark submit
- Row
- Spark 入门篇之spark&spark sql
- 初识Spark之 Spark API
- 【spark】spark之shuffle调优
- 白鳝说WAIT EVENT之ROW CACHE LOCK
- MySQL触发器 trigger之for each row
- LeetCode之路:500. Keyboard Row
- spark2.2错误 java.lang.UnsupportedOperationException: No Encoder found for org.apache.spark.sql.Row解决
- spark 之 SparkContext
- 过滤器与拦截器
- Hello World
- Android 实现音乐剪切功能 可以选择起始点和结束点 也可以同时拖动块级元素
- idea快捷键
- Java创建和解析Json数据方法(三)——json-lib包的使用
- Spark 之 Row
- 2017.8.11 OSU 失败总结
- 【Spring】Spring Framework Reference Documentation中文版38
- 对SpringMVC上下文容器配置的理解
- Git--将服务器代码更新到本地
- 百度地图前端插件的获取
- C++知识点(4)
- Model
- MySql 批量更新语句