Github user yhuai commented on a diff in the pull request: https://github.com/apache/spark/pull/13068#discussion_r63101198 --- Diff: sql/core/src/main/scala/org/apache/spark/sql/execution/SparkSqlParser.scala --- @@ -941,6 +944,43 @@ class SparkSqlAstBuilder(conf: SQLConf) extends AstBuilder { } /** + * Throw a [[ParseException]] if the user specified incompatible SerDes through ROW FORMAT + * and STORED AS. + */ + private def validateRowFormatFileFormat( + rowFormatCtx: RowFormatContext, + createFileFormatCtx: CreateFileFormatContext, + parentCtx: ParserRuleContext): Unit = { + if (rowFormatCtx == null || createFileFormatCtx == null) { + return + } + val cff = (0 until createFileFormatCtx.getChildCount) + .map { i => createFileFormatCtx.getChild(i).getText } + .mkString(" ") + (rowFormatCtx, createFileFormatCtx.fileFormat) match { + case (_, ffTable: TableFileFormatContext) => + if (visitTableFileFormat(ffTable).serde.isDefined) { + throw operationNotAllowed(s"ROW FORMAT is not compatible with $cff", parentCtx) + } + case (rfSerde: RowFormatSerdeContext, ffGeneric: GenericFileFormatContext) => + ffGeneric.identifier.getText.toLowerCase match { + case ("sequencefile" | "textfile" | "rcfile") => // OK + case _ => throw operationNotAllowed( + s"ROW FORMAT SERDE is not compatible with $cff", parentCtx) + } + case (rfDelimited: RowFormatDelimitedContext, ffGeneric: GenericFileFormatContext) => + ffGeneric.identifier.getText.toLowerCase match { + case "textfile" => // OK + case _ => throw operationNotAllowed( + s"ROW FORMAT SERDE is not compatible with $cff", parentCtx) + } + case (rf, ff) => + // should never happen + throw operationNotAllowed(s"Unexpected combination of ROW FORMAT and $cff", parentCtx) --- End diff -- Should we also print out `rf`? Is `ff` the same as `cff`? (Maybe it is good to add a few examples at here?)
--- 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 infrastruct...@apache.org or file a JIRA ticket with INFRA. --- --------------------------------------------------------------------- To unsubscribe, e-mail: reviews-unsubscr...@spark.apache.org For additional commands, e-mail: reviews-h...@spark.apache.org