Skip to content
Closed
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
Original file line number Diff line number Diff line change
Expand Up @@ -49,53 +49,4 @@ case class ScriptInputOutputSchema(
outputSerdeProps: Seq[(String, String)],
recordReaderClass: Option[String],
recordWriterClass: Option[String],
schemaLess: Boolean) {

def inputRowFormatSQL: Option[String] =
getRowFormatSQL(inputRowFormat, inputSerdeClass, inputSerdeProps)

def outputRowFormatSQL: Option[String] =
getRowFormatSQL(outputRowFormat, outputSerdeClass, outputSerdeProps)

/**
* Get the row format specification
* Note:
* 1. Changes are needed when readerClause and writerClause are supported.
* 2. Changes are needed when "ESCAPED BY" is supported.
*/
private def getRowFormatSQL(
rowFormat: Seq[(String, String)],
serdeClass: Option[String],
serdeProps: Seq[(String, String)]): Option[String] = {
if (schemaLess) return Some("")

val rowFormatDelimited =
rowFormat.map {
case ("TOK_TABLEROWFORMATFIELD", value) =>
"FIELDS TERMINATED BY " + value
case ("TOK_TABLEROWFORMATCOLLITEMS", value) =>
"COLLECTION ITEMS TERMINATED BY " + value
case ("TOK_TABLEROWFORMATMAPKEYS", value) =>
"MAP KEYS TERMINATED BY " + value
case ("TOK_TABLEROWFORMATLINES", value) =>
"LINES TERMINATED BY " + value
case ("TOK_TABLEROWFORMATNULL", value) =>
"NULL DEFINED AS " + value
case o => return None
}

val serdeClassSQL = serdeClass.map("'" + _ + "'").getOrElse("")
val serdePropsSQL =
if (serdeClass.nonEmpty) {
val props = serdeProps.map{p => s"'${p._1}' = '${p._2}'"}.mkString(", ")
if (props.nonEmpty) " WITH SERDEPROPERTIES(" + props + ")" else ""
} else {
""
}
if (rowFormat.nonEmpty) {
Some("ROW FORMAT DELIMITED " + rowFormatDelimited.mkString(" "))
} else {
Some("ROW FORMAT SERDE " + serdeClassSQL + serdePropsSQL)
}
}
}
schemaLess: Boolean)