Skip to content

Commit

Permalink
[SPARK-2779] [SQL] asInstanceOf[Map[...]] should use scala.collection…
Browse files Browse the repository at this point in the history
….Map instead of scala.collection.immutable.Map

Since we let users create Rows. It makes sense to accept mutable Maps as values of MapType columns.

JIRA: https://issues.apache.org/jira/browse/SPARK-2779

Author: Yin Huai <[email protected]>

Closes #1705 from yhuai/SPARK-2779 and squashes the following commits:

00d72fd [Yin Huai] Use scala.collection.Map.
  • Loading branch information
yhuai authored and marmbrus committed Aug 1, 2014
1 parent b124de5 commit 9632719
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@

package org.apache.spark.sql.catalyst.expressions

import scala.collection.Map

import org.apache.spark.sql.catalyst.types._

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@

package org.apache.spark.sql.catalyst.expressions

import scala.collection.Map

import org.apache.spark.sql.catalyst.trees
import org.apache.spark.sql.catalyst.types._

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

package org.apache.spark.sql.json

import scala.collection.Map
import scala.collection.convert.Wrappers.{JMapWrapper, JListWrapper}
import scala.math.BigDecimal

Expand Down
19 changes: 19 additions & 0 deletions sql/core/src/test/scala/org/apache/spark/sql/SQLQuerySuite.scala
Original file line number Diff line number Diff line change
Expand Up @@ -505,5 +505,24 @@ class SQLQuerySuite extends QueryTest {
(2, null) ::
(3, null) ::
(4, 2147483644) :: Nil)

// The value of a MapType column can be a mutable map.
val rowRDD3 = unparsedStrings.map { r =>
val values = r.split(",").map(_.trim)
val v4 = try values(3).toInt catch {
case _: NumberFormatException => null
}
Row(Row(values(0).toInt, values(2).toBoolean), scala.collection.mutable.Map(values(1) -> v4))
}

val schemaRDD3 = applySchema(rowRDD3, schema2)
schemaRDD3.registerAsTable("applySchema3")

checkAnswer(
sql("SELECT f1.f11, f2['D4'] FROM applySchema3"),
(1, null) ::
(2, null) ::
(3, null) ::
(4, 2147483644) :: Nil)
}
}

0 comments on commit 9632719

Please sign in to comment.