Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix for xml expression to not parse arbitrary strings #679

Merged
merged 1 commit into from
Apr 8, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 3 additions & 5 deletions src/main/scala/com/databricks/spark/xml/functions.scala
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
package com.databricks.spark.xml

import org.apache.spark.sql.Column
import org.apache.spark.sql.catalyst.parser.CatalystSqlParser
import org.apache.spark.sql.types.DataType

/**
Expand All @@ -28,14 +27,13 @@ object functions {
/**
* Parses a column containing a XML string into a `StructType` with the specified schema.
*
* @param e a string column containing XML data
* @param col a string column containing XML data
* @param schema the schema to use when parsing the XML string. Must be a StructType if
* column is string-valued, or ArrayType[StructType] if column is an array of strings
* @param options key-value pairs that correspond to those supported by [[XmlOptions]]
*/
def from_xml(e: Column, schema: DataType, options: Map[String, String] = Map.empty): Column = {
val expr = CatalystSqlParser.parseExpression(e.toString())
new Column(XmlDataToCatalyst(expr, schema, XmlOptions(options)))
def from_xml(col: Column, schema: DataType, options: Map[String, String] = Map.empty): Column = {
new Column(XmlDataToCatalyst(col.expr, schema, XmlOptions(options)))
}

}
Loading