Github user HyukjinKwon commented on a diff in the pull request:

    https://github.com/apache/spark/pull/17785#discussion_r113855222
  
    --- Diff: sql/core/src/main/scala/org/apache/spark/sql/api/r/SQLUtils.scala 
---
    @@ -92,48 +93,8 @@ private[sql] object SQLUtils extends Logging {
         def r: Regex = new Regex(sc.parts.mkString, sc.parts.tail.map(_ => 
"x"): _*)
       }
     
    -  def getSQLDataType(dataType: String): DataType = {
    -    dataType match {
    -      case "byte" => org.apache.spark.sql.types.ByteType
    -      case "integer" => org.apache.spark.sql.types.IntegerType
    -      case "float" => org.apache.spark.sql.types.FloatType
    -      case "double" => org.apache.spark.sql.types.DoubleType
    -      case "numeric" => org.apache.spark.sql.types.DoubleType
    -      case "character" => org.apache.spark.sql.types.StringType
    -      case "string" => org.apache.spark.sql.types.StringType
    -      case "binary" => org.apache.spark.sql.types.BinaryType
    -      case "raw" => org.apache.spark.sql.types.BinaryType
    -      case "logical" => org.apache.spark.sql.types.BooleanType
    -      case "boolean" => org.apache.spark.sql.types.BooleanType
    -      case "timestamp" => org.apache.spark.sql.types.TimestampType
    -      case "date" => org.apache.spark.sql.types.DateType
    -      case r"\Aarray<(.+)${elemType}>\Z" =>
    -        org.apache.spark.sql.types.ArrayType(getSQLDataType(elemType))
    -      case r"\Amap<(.+)${keyType},(.+)${valueType}>\Z" =>
    -        if (keyType != "string" && keyType != "character") {
    -          throw new IllegalArgumentException("Key type of a map must be 
string or character")
    -        }
    -        org.apache.spark.sql.types.MapType(getSQLDataType(keyType), 
getSQLDataType(valueType))
    -      case r"\Astruct<(.+)${fieldsStr}>\Z" =>
    -        if (fieldsStr(fieldsStr.length - 1) == ',') {
    -          throw new IllegalArgumentException(s"Invalid type $dataType")
    -        }
    -        val fields = fieldsStr.split(",")
    -        val structFields = fields.map { field =>
    -          field match {
    -            case r"\A(.+)${fieldName}:(.+)${fieldType}\Z" =>
    -              createStructField(fieldName, fieldType, true)
    -
    -            case _ => throw new IllegalArgumentException(s"Invalid type 
$dataType")
    -          }
    -        }
    -        createStructType(structFields)
    -      case _ => throw new IllegalArgumentException(s"Invalid type 
$dataType")
    -    }
    -  }
    -
       def createStructField(name: String, dataType: String, nullable: 
Boolean): StructField = {
    -    val dtObj = getSQLDataType(dataType)
    +    val dtObj = CatalystSqlParser.parseDataType(dataType)
    --- End diff --
    
    Yea, however, for those types, we can't create that field because the check 
via 
[checkType](https://github.com/apache/spark/blob/39e2bad6a866d27c3ca594d15e574a1da3ee84cc/R/pkg/R/schema.R#L129-L187)
 fails as it is not in 
[`PREMISITVE_TYPES`](https://github.com/apache/spark/blob/bc0a0e6392c4e729d8f0e4caffc0bd05adb0d950/R/pkg/R/types.R#L21-L39)
 as below:
    
    ```r
    > structField("_col", "character")
    Error in checkType(type) : Unsupported type for SparkDataframe: character
    > structField("_col", "logical")
    Error in checkType(type) : Unsupported type for SparkDataframe: logical
    > structField("_col", "numeric")
    Error in checkType(type) : Unsupported type for SparkDataframe: numeric
    > structField("_col", "raw")
    Error in checkType(type) : Unsupported type for SparkDataframe: raw
    ```
    
    I double-checked this is the only place where we called `getSQLDataType` 
and therefore they look unreachable (I hope you could double-check this when 
you have some time for this one just in case I missed something about this).



---
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 infrastruct...@apache.org or file a JIRA ticket
with INFRA.
---

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

Reply via email to