@@ -27,42 +27,29 @@ import org.apache.spark.unsafe.types.UTF8String
2727
2828object ExprUtils {
2929
30- def evalSchemaExpr (exp : Expression ): StructType = {
31- val dataType = if (exp.foldable) {
30+ def evalTypeExpr (exp : Expression ): DataType = {
31+ if (exp.foldable) {
3232 exp.eval() match {
33- case s : UTF8String if s != null =>
34- // Use `DataType.fromDDL` since the type string can be struct<...>.
35- DataType .fromDDL(s.toString)
33+ case s : UTF8String if s != null => DataType .fromDDL(s.toString)
3634 case _ => throw new AnalysisException (
3735 s " The expression ' ${exp.sql}' must be evaluated to a valid string. " )
3836 }
3937 } else {
4038 throw new AnalysisException (
4139 " Schema should be specified in DDL format as a string literal or output of " +
42- s " the schema_of_csv function instead of ${exp.sql}" )
40+ s " the schema_of_json/ schema_of_csv functions instead of ${exp.sql}" )
4341 }
42+ }
4443
44+ def evalSchemaExpr (exp : Expression ): StructType = {
45+ val dataType = evalTypeExpr(exp)
4546 if (! dataType.isInstanceOf [StructType ]) {
4647 throw new AnalysisException (
4748 s " Schema should be struct type but got ${dataType.sql}. " )
4849 }
4950 dataType.asInstanceOf [StructType ]
5051 }
5152
52- def evalTypeExpr (exp : Expression ): DataType = {
53- if (exp.foldable) {
54- exp.eval() match {
55- case s : UTF8String if s != null => DataType .fromDDL(s.toString)
56- case _ => throw new AnalysisException (
57- s " The expression ' ${exp.sql}' must be evaluated to a valid string. " )
58- }
59- } else {
60- throw new AnalysisException (
61- " Schema should be specified in DDL format as a string literal or output of " +
62- s " the schema_of_json function instead of ${exp.sql}" )
63- }
64- }
65-
6653 def convertToMapData (exp : Expression ): Map [String , String ] = exp match {
6754 case m : CreateMap
6855 if m.dataType.acceptsType(MapType (StringType , StringType , valueContainsNull = false )) =>
0 commit comments