Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ import org.apache.hadoop.{io => hadoopIo}

import org.apache.spark.sql.catalyst.expressions._
import org.apache.spark.sql.catalyst.util.DateTimeUtils
import org.apache.spark.sql.types
import org.apache.spark.sql.types._
import org.apache.spark.sql.{AnalysisException, types}
import org.apache.spark.unsafe.types.UTF8String

/* Implicit conversions */
Expand Down Expand Up @@ -218,6 +218,14 @@ private[hive] trait HiveInspectors {

// Hive seems to return this for struct types?
case c: Class[_] if c == classOf[java.lang.Object] => NullType

// java list type unsupported
case c: Class[_] if c == classOf[java.util.List[_]] =>
throw new AnalysisException(
"List type in java is unsupported because " +
"JVM type erasure makes spark fail to catch a component type in List<>")

case c => throw new AnalysisException(s"Unsupported java type $c")
}

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
/*
* 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.hive.execution;

import org.apache.hadoop.hive.ql.exec.UDF;

import java.util.Arrays;
import java.util.List;

public class UDFToListInt extends UDF {
public List<Integer> evaluate(Object o) {
return Arrays.asList(1, 2, 3);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
/*
* 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.hive.execution;

import org.apache.hadoop.hive.ql.exec.UDF;

import java.util.Arrays;
import java.util.List;

public class UDFToListString extends UDF {
public List<String> evaluate(Object o) {
return Arrays.asList("data1", "data2", "data3");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ import org.apache.hadoop.hive.serde2.objectinspector.primitive.PrimitiveObjectIn
import org.apache.hadoop.hive.serde2.objectinspector.{ObjectInspector, ObjectInspectorFactory}
import org.apache.hadoop.hive.serde2.{AbstractSerDe, SerDeStats}
import org.apache.hadoop.io.Writable
import org.apache.spark.sql.{QueryTest, Row}
import org.apache.spark.sql.{AnalysisException, QueryTest, Row}
import org.apache.spark.sql.hive.test.TestHive

import org.apache.spark.util.Utils
Expand Down Expand Up @@ -133,6 +133,36 @@ class HiveUDFSuite extends QueryTest {
TestHive.reset()
}

test("UDFToListString") {
val testData = TestHive.sparkContext.parallelize(StringCaseClass("") :: Nil).toDF()
testData.registerTempTable("inputTable")

sql(s"CREATE TEMPORARY FUNCTION testUDFToListString AS '${classOf[UDFToListString].getName}'")
val errMsg = intercept[AnalysisException] {
sql("SELECT testUDFToListString(s) FROM inputTable")
}
assert(errMsg.getMessage === "List type in java is unsupported because " +
"JVM type erasure makes spark fail to catch a component type in List<>;")

sql("DROP TEMPORARY FUNCTION IF EXISTS testUDFToListString")
TestHive.reset()
}

test("UDFToListInt") {
val testData = TestHive.sparkContext.parallelize(StringCaseClass("") :: Nil).toDF()
testData.registerTempTable("inputTable")

sql(s"CREATE TEMPORARY FUNCTION testUDFToListInt AS '${classOf[UDFToListInt].getName}'")
val errMsg = intercept[AnalysisException] {
sql("SELECT testUDFToListInt(s) FROM inputTable")
}
assert(errMsg.getMessage === "List type in java is unsupported because " +
"JVM type erasure makes spark fail to catch a component type in List<>;")

sql("DROP TEMPORARY FUNCTION IF EXISTS testUDFToListInt")
TestHive.reset()
}

test("UDFListListInt") {
val testData = TestHive.sparkContext.parallelize(
ListListIntCaseClass(Nil) ::
Expand Down