Github user HyukjinKwon commented on a diff in the pull request:
https://github.com/apache/spark/pull/17377#discussion_r107169934
--- Diff:
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/util/ParseMode.scala
---
@@ -17,25 +17,35 @@
package org.apache.spark.sql.catalyst.util
-object ParseModes {
- val PERMISSIVE_MODE = "PERMISSIVE"
- val DROP_MALFORMED_MODE = "DROPMALFORMED"
- val FAIL_FAST_MODE = "FAILFAST"
+import org.apache.spark.internal.Logging
- val DEFAULT = PERMISSIVE_MODE
+object ParseMode extends Enumeration with Logging {
+ type ParseMode = Value
- def isValidMode(mode: String): Boolean = {
- mode.toUpperCase match {
- case PERMISSIVE_MODE | DROP_MALFORMED_MODE | FAIL_FAST_MODE => true
- case _ => false
- }
- }
+ /**
+ * This mode permissively parses the records.
+ */
+ val Permissive = Value("PERMISSIVE")
+
+ /**
+ * This mode ignores the whole corrupted records.
+ */
+ val DropMalformed = Value("DROPMALFORMED")
+
+ /**
+ * This mode throws an exception when it meets corrupted records.
+ */
+ val FailFast = Value("FAILFAST")
- def isDropMalformedMode(mode: String): Boolean = mode.toUpperCase ==
DROP_MALFORMED_MODE
- def isFailFastMode(mode: String): Boolean = mode.toUpperCase ==
FAIL_FAST_MODE
- def isPermissiveMode(mode: String): Boolean = if (isValidMode(mode)) {
- mode.toUpperCase == PERMISSIVE_MODE
- } else {
- true // We default to permissive is the mode string is not valid
+ /**
+ * Returns `ParseMode` enum from the given string.
+ */
+ def fromString(mode: String): ParseMode = mode.toUpperCase match {
+ case "PERMISSIVE" => ParseMode.Permissive
--- End diff --
We can use `Permissive.toString`.
```
Error:(34, 33) stable identifier required, but
ParseMode.Permissive.toString found.
case ParseMode.Permissive.toString => ParseMode.Permissive
^
```
---
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 [email protected] or file a JIRA ticket
with INFRA.
---
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]