1

Why does a combinator choke when broken into multiple lines, as shown below:

Compiles (since all on one honkin big line):

  protected lazy val create: Parser[LogicalPlan] =
    CREATE ~> TABLE ~> opt(IF ~ NOT ~ EXISTS ^^^ { var notExists = true }) ~ ident ~ "(" ~> tableCols <~ ")"  ~ (MAPPED ~> BY ~> "(" ~> ident <~ "," ~ colFamilies <~ ")") <~ opt(";") ^^ {

Does not compile:

  protected lazy val create: Parser[LogicalPlan] =
    CREATE ~> TABLE ~> opt(IF ~ NOT ~ EXISTS ^^^ { var notExists = true }) ~ ident ~ "(" ~> tableCols <~ ")"
  ~ (MAPPED ~> BY ~> "(" ~> ident <~ "," ~ colFamilies <~ ")") <~ opt(";") ^^ {


[error] /shared/hwspark/sql/hbase/src/main/scala/org/apache/spark/sql/hbase/HBaseSQLParser.scala:37: type mismatch;
[error]  found   : HBaseSQLParser.this.Parser[Seq[org.apache.spark.sql.catalyst.expressions.Expression]]
[error]  required: HBaseSQLParser.this.Parser[org.apache.spark.sql.catalyst.plans.logical.LogicalPlan]
[error]     CREATE ~> TABLE ~> opt(IF ~ NOT ~ EXISTS ^^^ { var notExists = true }) ~ ident ~ "(" ~> tableCols <~ ")"
[error]

1 Answer 1

3

It looks like you are running foul of the Scala rule for semicolon insertion. To continue an expression on a second line you need to ensure that a semicolon is not inserted at the end of the first line. The easiest way to do that is to end the first line with an operator (whose right operand will then be on the next line). In other words, try moving the ~ from in the front of (MAPPED ... back on to the end of the previous line.

Sign up to request clarification or add additional context in comments.

1 Comment

that was it. had me well confused. Thanks.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.