Spark-sql-row

Spark-sql-row

@(spark)[sql|row]

Row

row就是关系数据库中的一行。

/**                                                                                                                                                                     
 * 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 = 1                                                                                                                                               
 * val 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 = 1                                                                                                                                               
 * val 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                                                                                                                                                     
 * }                                                                                                                                                                    
 * }}}                                                                                                                                                                  
 *                         
 *   *                                                                                                                                                                      
 * @group row                                                                                                                                                           
 */                                                                                                                                                                     
trait Row extends Serializable {   
  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值