1/*
2 * Licensed to the Apache Software Foundation (ASF) under one or more
3 * contributor license agreements.  See the NOTICE file distributed with
4 * this work for additional information regarding copyright ownership.
5 * The ASF licenses this file to You under the Apache License, Version 2.0
6 * (the "License"); you may not use this file except in compliance with
7 * the License.  You may obtain a copy of the License at
8 *
9 *    http://www.apache.org/licenses/LICENSE-2.0
10 *
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
16 */
17
18package org.apache.spark.sql.catalyst.catalog
19
20import org.apache.spark.sql.AnalysisException
21
22/** A trait that represents the type of a resourced needed by a function. */
23abstract class FunctionResourceType(val resourceType: String)
24
25object JarResource extends FunctionResourceType("jar")
26
27object FileResource extends FunctionResourceType("file")
28
29// We do not allow users to specify an archive because it is YARN specific.
30// When loading resources, we will throw an exception and ask users to
31// use --archive with spark submit.
32object ArchiveResource extends FunctionResourceType("archive")
33
34object FunctionResourceType {
35  def fromString(resourceType: String): FunctionResourceType = {
36    resourceType.toLowerCase match {
37      case "jar" => JarResource
38      case "file" => FileResource
39      case "archive" => ArchiveResource
40      case other =>
41        throw new AnalysisException(s"Resource Type '$resourceType' is not supported.")
42    }
43  }
44}
45
46case class FunctionResource(resourceType: FunctionResourceType, uri: String)
47
48/**
49 * A simple trait representing a class that can be used to load resources used by
50 * a function. Because only a SQLContext can load resources, we create this trait
51 * to avoid of explicitly passing SQLContext around.
52 */
53trait FunctionResourceLoader {
54  def loadResource(resource: FunctionResource): Unit
55}
56
57object DummyFunctionResourceLoader extends FunctionResourceLoader {
58  override def loadResource(resource: FunctionResource): Unit = {
59    throw new UnsupportedOperationException
60  }
61}
62