Skip to content

Commit

Permalink
[SPARK-13157] [SQL] Support any kind of input for SQL commands.
Browse files Browse the repository at this point in the history
The ```SparkSqlLexer``` currently swallows characters which have not been defined in the grammar. This causes problems with SQL commands, such as: ```add jar file:///tmp/ab/TestUDTF.jar```. In this example the `````` is swallowed.

This PR adds an extra Lexer rule to handle such input, and makes a tiny modification to the ```ASTNode```.

cc davies liancheng

Author: Herman van Hovell <hvanhovell@questtec.nl>

Closes apache#11052 from hvanhovell/SPARK-13157.
  • Loading branch information
hvanhovell authored and davies committed Feb 3, 2016
1 parent c4feec2 commit 9dd2741
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -483,3 +483,7 @@ COMMENT
{ $channel=HIDDEN; }
;

/* Prevent that the lexer swallows unknown characters. */
ANY
:.
;
Original file line number Diff line number Diff line change
Expand Up @@ -58,12 +58,12 @@ case class ASTNode(
override val origin: Origin = Origin(Some(line), Some(positionInLine))

/** Source text. */
lazy val source: String = stream.toString(startIndex, stopIndex)
lazy val source: String = stream.toOriginalString(startIndex, stopIndex)

/** Get the source text that remains after this token. */
lazy val remainder: String = {
stream.fill()
stream.toString(stopIndex + 1, stream.size() - 1).trim()
stream.toOriginalString(stopIndex + 1, stream.size() - 1).trim()
}

def text: String = token.getText
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.spark.sql.catalyst.parser

import org.apache.spark.SparkFunSuite

class ASTNodeSuite extends SparkFunSuite {
test("SPARK-13157 - remainder must return all input chars") {
val inputs = Seq(
("add jar", "file:///tmp/ab/TestUDTF.jar"),
("add jar", "file:///tmp/a@b/TestUDTF.jar"),
("add jar", "c:\\windows32\\TestUDTF.jar"),
("add jar", "some \nbad\t\tfile\r\n.\njar"),
("ADD JAR", "@*#&@(!#@$^*!@^@#(*!@#"),
("SET", "foo=bar"),
("SET", "foo*)(@#^*@&!#^=bar")
)
inputs.foreach {
case (command, arguments) =>
val node = ParseDriver.parsePlan(s"$command $arguments", null)
assert(node.remainder === arguments)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -488,8 +488,7 @@ class HiveThriftBinaryServerSuite extends HiveThriftJdbcTest {
}
}

// TODO: enable this
ignore("SPARK-11595 ADD JAR with input path having URL scheme") {
test("SPARK-11595 ADD JAR with input path having URL scheme") {
withJdbcStatement { statement =>
val jarPath = "../hive/src/test/resources/TestUDTF.jar"
val jarURL = s"file://${System.getProperty("user.dir")}/$jarPath"
Expand Down Expand Up @@ -547,8 +546,7 @@ class SingleSessionSuite extends HiveThriftJdbcTest {
override protected def extraConf: Seq[String] =
"--conf spark.sql.hive.thriftServer.singleSession=true" :: Nil

// TODO: enable this
ignore("test single session") {
test("test single session") {
withMultipleConnectionJdbcStatement(
{ statement =>
val jarPath = "../hive/src/test/resources/TestUDTF.jar"
Expand Down

0 comments on commit 9dd2741

Please sign in to comment.