Skip to content

Commit

Permalink
[opt-tech#73] Make the 'AS' in the 'IGNOREHEADER' option as optional,…
Browse files Browse the repository at this point in the history
… as per official the Redshift spec
  • Loading branch information
Danijel Schiavuzzi committed Jul 11, 2022
1 parent a5236fa commit e144663
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ class CopyCommandParser extends BaseParser {
s"$any*(?i)BZIP2".r
}

private[this] val ignoreHeaderParser = s"$any*(?i)IGNOREHEADER$space+AS".r ~> "'" ~> """[^']*""".r <~ "'" <~ s"$any*".r
private[this] val ignoreHeaderParser = s"$any*(?i)IGNOREHEADER".r ~> "(?i)AS".r.? ~> "'" ~> """[^']*""".r <~ "'" <~ s"$any*".r

def parse(query: String): Option[CopyCommand] = {
val result = parse(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,19 @@ class CopyCommandParserTest extends FlatSpec {
assert(new CopyCommandParser().parse(command).map(_.ignoreHeader) == Some(1))
}

it should "parse 'IGNOREHEADER' (without the optional 'AS') from COPY command" in {
val command =
s"""
|COPY "public"."mytable"
|FROM '${Global.s3Scheme}some-bucket/path/to/unloaded_manifest.json'
|CREDENTIALS 'aws_access_key_id=AKIAXXXXXXXXXXXXXXX;aws_secret_access_key=YYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYY'
|IGNOREHEADER '1'
|MANIFEST
|""".stripMargin

assert(new CopyCommandParser().parse(command).map(_.ignoreHeader) == Some(1))
}

it should "set default 'IGNOREHEADER AS' correctly" in {
val command =
s"""
Expand Down

0 comments on commit e144663

Please sign in to comment.