Skip to content

Commit 8195056

Browse files
committed
Added support for the "add jar" command
1 parent 7c6e71f commit 8195056

File tree

3 files changed

+28
-3
lines changed

3 files changed

+28
-3
lines changed

sql/hive/src/main/scala/org/apache/spark/sql/hive/HiveQl.scala

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,8 @@ private[hive] case class SourceCommand(filePath: String) extends Command
4444

4545
private[hive] case class AddFile(filePath: String) extends Command
4646

47+
private[hive] case class AddJar(path: String) extends Command
48+
4749
private[hive] case class DropTable(tableName: String, ifExists: Boolean) extends Command
4850

4951
private[hive] case class AnalyzeTable(tableName: String) extends Command
@@ -231,7 +233,7 @@ private[hive] object HiveQl {
231233
} else if (sql.trim.toLowerCase.startsWith("uncache table")) {
232234
CacheCommand(sql.trim.drop(14).trim, false)
233235
} else if (sql.trim.toLowerCase.startsWith("add jar")) {
234-
NativeCommand(sql)
236+
AddJar(sql.trim.drop(8))
235237
} else if (sql.trim.toLowerCase.startsWith("add file")) {
236238
AddFile(sql.trim.drop(9))
237239
} else if (sql.trim.toLowerCase.startsWith("dfs")) {
@@ -1018,9 +1020,9 @@ private[hive] object HiveQl {
10181020

10191021
/* Other functions */
10201022
case Token("TOK_FUNCTION", Token(RAND(), Nil) :: Nil) => Rand
1021-
case Token("TOK_FUNCTION", Token(SUBSTR(), Nil) :: string :: pos :: Nil) =>
1023+
case Token("TOK_FUNCTION", Token(SUBSTR(), Nil) :: string :: pos :: Nil) =>
10221024
Substring(nodeToExpr(string), nodeToExpr(pos), Literal(Integer.MAX_VALUE, IntegerType))
1023-
case Token("TOK_FUNCTION", Token(SUBSTR(), Nil) :: string :: pos :: length :: Nil) =>
1025+
case Token("TOK_FUNCTION", Token(SUBSTR(), Nil) :: string :: pos :: length :: Nil) =>
10241026
Substring(nodeToExpr(string), nodeToExpr(pos), nodeToExpr(length))
10251027

10261028
/* UDFs - Must be last otherwise will preempt built in functions */

sql/hive/src/main/scala/org/apache/spark/sql/hive/HiveStrategies.scala

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -200,6 +200,8 @@ private[hive] trait HiveStrategies {
200200

201201
case hive.DropTable(tableName, ifExists) => execution.DropTable(tableName, ifExists) :: Nil
202202

203+
case hive.AddJar(path) => execution.AddJar(path) :: Nil
204+
203205
case hive.AnalyzeTable(tableName) => execution.AnalyzeTable(tableName) :: Nil
204206

205207
case describe: logical.DescribeCommand =>

sql/hive/src/main/scala/org/apache/spark/sql/hive/execution/commands.scala

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,3 +60,24 @@ case class DropTable(tableName: String, ifExists: Boolean) extends LeafNode with
6060
Seq.empty[Row]
6161
}
6262
}
63+
64+
/**
65+
* :: DeveloperApi ::
66+
*/
67+
@DeveloperApi
68+
case class AddJar(path: String) extends LeafNode with Command {
69+
70+
def hiveContext = sqlContext.asInstanceOf[HiveContext]
71+
72+
override def output = Seq.empty
73+
74+
override protected[sql] lazy val sideEffectResult: Seq[Any] = {
75+
hiveContext.sparkContext.addJar(path)
76+
Seq.empty[Any]
77+
}
78+
79+
override def execute(): RDD[Row] = {
80+
sideEffectResult
81+
hiveContext.emptyResult
82+
}
83+
}

0 commit comments

Comments
 (0)