spark-reviews mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From cloud-fan <...@git.apache.org>
Subject [GitHub] spark pull request #13967: [SPARK-16278][SPARK-16279][SQL] Implement map_key...
Date Wed, 29 Jun 2016 11:43:43 GMT
Github user cloud-fan commented on a diff in the pull request:

    https://github.com/apache/spark/pull/13967#discussion_r68931609
  
    --- Diff: sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/collectionOperations.scala
---
    @@ -44,6 +44,56 @@ case class Size(child: Expression) extends UnaryExpression with ExpectsInputType
     }
     
     /**
    + * Returns an unordered array containing the keys of the map.
    + */
    +@ExpressionDescription(
    +  usage = "_FUNC_(map) - Returns an unordered array containing the keys of the map.")
    +case class MapKeys(child: Expression)
    +  extends UnaryExpression with ExpectsInputTypes {
    +
    +  override def inputTypes: Seq[AbstractDataType] = Seq(MapType)
    +
    +  override def dataType: DataType = ArrayType(child.dataType.asInstanceOf[MapType].keyType)
    +
    +  override def foldable: Boolean = child.foldable
    +
    +  override def nullSafeEval(map: Any): Any = {
    +    map.asInstanceOf[MapData].keyArray().copy()
    +  }
    +
    +  override def doGenCode(ctx: CodegenContext, ev: ExprCode): ExprCode = {
    +    nullSafeCodeGen(ctx, ev, c => s"${ev.value} = ($c).keyArray().copy();")
    +  }
    +
    +  override def prettyName: String = "map_keys"
    +}
    +
    +/**
    + * Returns an unordered array containing the values of the map.
    + */
    +@ExpressionDescription(
    +  usage = "_FUNC_(map) - Returns an unordered array containing the values of the map.")
    +case class MapValues(child: Expression)
    +  extends UnaryExpression with ExpectsInputTypes {
    +
    +  override def inputTypes: Seq[AbstractDataType] = Seq(MapType)
    +
    +  override def dataType: DataType = ArrayType(child.dataType.asInstanceOf[MapType].valueType)
    +
    +  override def foldable: Boolean = child.foldable
    +
    +  override def nullSafeEval(map: Any): Any = {
    +    map.asInstanceOf[MapData].valueArray().copy()
    --- End diff --
    
    What if we don't call `copy` here? It looks reasonable to copy, I'm just curious :)


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


Mime
View raw message