Skip to content

Commit 748fb07

Browse files
author
Sun Rui
committed
Check if key type of a map is string when creating structField in R.
1 parent 74558eb commit 748fb07

File tree

2 files changed

+5
-2
lines changed

2 files changed

+5
-2
lines changed

R/pkg/R/schema.R

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ checkType <- function(type) {
131131
if (type %in% primtiveTypes) {
132132
return()
133133
} else {
134-
# Array type
134+
# Check complex types
135135
firstChar <- substr(type, 1, 1)
136136
switch (firstChar,
137137
a = {
@@ -150,8 +150,8 @@ checkType <- function(type) {
150150
matchedStrings <- regmatches(type, m)
151151
if (length(matchedStrings[[1]]) >= 3) {
152152
keyType <- matchedStrings[[1]][2]
153+
stopifnot (keyType == "string" || keyType == "character")
153154
valueType <- matchedStrings[[1]][3]
154-
checkType(keyType)
155155
checkType(valueType)
156156
return()
157157
}

sql/core/src/main/scala/org/apache/spark/sql/api/r/SQLUtils.scala

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,9 @@ private[r] object SQLUtils {
6565
org.apache.spark.sql.types.ArrayType(getSQLDataType(elemType))
6666
}
6767
case r"\Amap<(.*)${keyType},(.*)${valueType}>\Z" => {
68+
if (keyType != "string" && keyType != "character") {
69+
throw new IllegalArgumentException("Key type of a map must be string or character")
70+
}
6871
org.apache.spark.sql.types.MapType(getSQLDataType(keyType), getSQLDataType(valueType))
6972
}
7073
case _ => throw new IllegalArgumentException(s"Invaid type $dataType")

0 commit comments

Comments
 (0)