diff --git a/src/main/scala/com/databricks/spark/xml/util/TypeCast.scala b/src/main/scala/com/databricks/spark/xml/util/TypeCast.scala index 6a888e0b..d570d0bf 100644 --- a/src/main/scala/com/databricks/spark/xml/util/TypeCast.scala +++ b/src/main/scala/com/databricks/spark/xml/util/TypeCast.scala @@ -59,9 +59,7 @@ object TypeCast { .getOrElse(NumberFormat.getInstance(Locale.getDefault).parse(datum).doubleValue()) case _: BooleanType => datum.toBoolean case _: DecimalType => new BigDecimal(datum.replaceAll(",", "")) - // TODO(hossein): would be good to support other common timestamp formats case _: TimestampType => Timestamp.valueOf(datum) - // TODO(hossein): would be good to support other common date formats case _: DateType => Date.valueOf(datum) case _: StringType => datum case _ => throw new RuntimeException(s"Unsupported type: ${castType.typeName}") @@ -69,34 +67,6 @@ object TypeCast { } } - /** - * Helper method that converts string representation of a character to actual character. - * It handles some Java escaped strings and throws exception if given string is longer than one - * character. - * - */ - @throws[IllegalArgumentException] - private[xml] def toChar(str: String): Char = { - if (str.charAt(0) == '\\') { - str.charAt(1) - match { - case 't' => '\t' - case 'r' => '\r' - case 'b' => '\b' - case 'f' => '\f' - case '\"' => '\"' // In case user changes quote char and uses \" as delimiter in options - case '\'' => '\'' - case 'u' if str == """\u0000""" => '\u0000' - case _ => - throw new IllegalArgumentException(s"Unsupported special character for delimiter: $str") - } - } else if (str.length == 1) { - str.charAt(0) - } else { - throw new IllegalArgumentException(s"Delimiter cannot be more than one character: $str") - } - } - /** * Helper method that checks and cast string representation of a numeric types. */ diff --git a/src/test/scala/com/databricks/spark/xml/util/TypeCastSuite.scala b/src/test/scala/com/databricks/spark/xml/util/TypeCastSuite.scala index f2d3a992..f2bc420f 100644 --- a/src/test/scala/com/databricks/spark/xml/util/TypeCastSuite.scala +++ b/src/test/scala/com/databricks/spark/xml/util/TypeCastSuite.scala @@ -35,30 +35,6 @@ class TypeCastSuite extends FunSuite { } } - test("Can parse escaped characters") { - assert(TypeCast.toChar("""\t""") === '\t') - assert(TypeCast.toChar("""\r""") === '\r') - assert(TypeCast.toChar("""\b""") === '\b') - assert(TypeCast.toChar("""\f""") === '\f') - assert(TypeCast.toChar("""\"""") === '\"') - assert(TypeCast.toChar("""\'""") === '\'') - assert(TypeCast.toChar("""\u0000""") === '\u0000') - } - - test("Does not accept delimiter larger than one character") { - val exception = intercept[IllegalArgumentException]{ - TypeCast.toChar("ab") - } - assert(exception.getMessage.contains("cannot be more than one character")) - } - - test("Throws exception for unsupported escaped characters") { - val exception = intercept[IllegalArgumentException]{ - TypeCast.toChar("""\1""") - } - assert(exception.getMessage.contains("Unsupported special character for delimiter")) - } - test("Nullable types are handled") { assert(TypeCast.castTo("", IntegerType, nullable = true) == null) }