forked from apache/spark
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[SPARK-19459] Support for nested char/varchar fields in ORC
## What changes were proposed in this pull request? This PR is a small follow-up on apache#16804. This PR also adds support for nested char/varchar fields in orc. ## How was this patch tested? I have added a regression test to the OrcSourceSuite. Author: Herman van Hovell <[email protected]> Closes apache#17030 from hvanhovell/SPARK-19459-follow-up. # Conflicts: # sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/parser/AstBuilder.scala # sql/hive/src/test/scala/org/apache/spark/sql/hive/orc/OrcSourceSuite.scala
- Loading branch information
1 parent
21afc45
commit c80f2f9
Showing
3 changed files
with
140 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
73 changes: 73 additions & 0 deletions
73
sql/catalyst/src/main/scala/org/apache/spark/sql/types/HiveStringType.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
/* | ||
* 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.types | ||
|
||
import scala.math.Ordering | ||
import scala.reflect.runtime.universe.typeTag | ||
|
||
import org.apache.spark.sql.catalyst.ScalaReflectionLock | ||
import org.apache.spark.unsafe.types.UTF8String | ||
|
||
/** | ||
* A hive string type for compatibility. These datatypes should only used for parsing, | ||
* and should NOT be used anywhere else. Any instance of these data types should be | ||
* replaced by a [[StringType]] before analysis. | ||
*/ | ||
sealed abstract class HiveStringType extends AtomicType { | ||
private[sql] type InternalType = UTF8String | ||
|
||
private[sql] val ordering = implicitly[Ordering[InternalType]] | ||
|
||
@transient private[sql] lazy val tag = ScalaReflectionLock.synchronized { | ||
typeTag[InternalType] | ||
} | ||
|
||
override def defaultSize: Int = length | ||
|
||
private[spark] override def asNullable: HiveStringType = this | ||
|
||
def length: Int | ||
} | ||
|
||
object HiveStringType { | ||
def replaceCharType(dt: DataType): DataType = dt match { | ||
case ArrayType(et, nullable) => | ||
ArrayType(replaceCharType(et), nullable) | ||
case MapType(kt, vt, nullable) => | ||
MapType(replaceCharType(kt), replaceCharType(vt), nullable) | ||
case StructType(fields) => | ||
StructType(fields.map { field => | ||
field.copy(dataType = replaceCharType(field.dataType)) | ||
}) | ||
case _: HiveStringType => StringType | ||
case _ => dt | ||
} | ||
} | ||
|
||
/** | ||
* Hive char type. | ||
*/ | ||
case class CharType(length: Int) extends HiveStringType { | ||
override def simpleString: String = s"char($length)" | ||
} | ||
|
||
/** | ||
* Hive varchar type. | ||
*/ | ||
case class VarcharType(length: Int) extends HiveStringType { | ||
override def simpleString: String = s"varchar($length)" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters