Github user ueshin commented on a diff in the pull request:

    https://github.com/apache/spark/pull/18680#discussion_r128425605
  
    --- Diff: 
sql/core/src/main/scala/org/apache/spark/sql/execution/arrow/ArrowUtils.scala 
---
    @@ -0,0 +1,109 @@
    +/*
    + * 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.execution.arrow
    +
    +import scala.collection.JavaConverters._
    +
    +import org.apache.arrow.memory.RootAllocator
    +import org.apache.arrow.vector.types.FloatingPointPrecision
    +import org.apache.arrow.vector.types.pojo.{ArrowType, Field, FieldType, 
Schema}
    +
    +import org.apache.spark.sql.types._
    +
    +object ArrowUtils {
    +
    +  val rootAllocator = new RootAllocator(Long.MaxValue)
    +
    +  // todo: support more types.
    +
    +  def toArrowType(dt: DataType): ArrowType = dt match {
    +    case BooleanType => ArrowType.Bool.INSTANCE
    +    case ByteType => new ArrowType.Int(8, true)
    +    case ShortType => new ArrowType.Int(8 * 2, true)
    +    case IntegerType => new ArrowType.Int(8 * 4, true)
    +    case LongType => new ArrowType.Int(8 * 8, true)
    +    case FloatType => new 
ArrowType.FloatingPoint(FloatingPointPrecision.SINGLE)
    +    case DoubleType => new 
ArrowType.FloatingPoint(FloatingPointPrecision.DOUBLE)
    +    case StringType => ArrowType.Utf8.INSTANCE
    +    case BinaryType => ArrowType.Binary.INSTANCE
    +    case DecimalType.Fixed(precision, scale) => new 
ArrowType.Decimal(precision, scale)
    +    case _ => throw new UnsupportedOperationException(s"Unsupported data 
type: ${dt.simpleString}")
    +  }
    +
    +  def fromArrowType(dt: ArrowType): DataType = dt match {
    +    case ArrowType.Bool.INSTANCE => BooleanType
    +    case int: ArrowType.Int if int.getIsSigned && int.getBitWidth == 8 => 
ByteType
    +    case int: ArrowType.Int if int.getIsSigned && int.getBitWidth == 8 * 2 
=> ShortType
    +    case int: ArrowType.Int if int.getIsSigned && int.getBitWidth == 8 * 4 
=> IntegerType
    +    case int: ArrowType.Int if int.getIsSigned && int.getBitWidth == 8 * 8 
=> LongType
    +    case float: ArrowType.FloatingPoint
    +      if float.getPrecision() == FloatingPointPrecision.SINGLE => FloatType
    +    case float: ArrowType.FloatingPoint
    +      if float.getPrecision() == FloatingPointPrecision.DOUBLE => 
DoubleType
    +    case ArrowType.Utf8.INSTANCE => StringType
    +    case ArrowType.Binary.INSTANCE => BinaryType
    +    case d: ArrowType.Decimal => DecimalType(d.getPrecision, d.getScale)
    +    case _ => throw new UnsupportedOperationException(s"Unsupported data 
type: $dt")
    +  }
    +
    +  def toArrowField(name: String, dt: DataType, nullable: Boolean): Field = 
{
    --- End diff --
    
    No, this is used to create an Arrow schema from `StructType` in `ArrowUtils 
.toArrowSchema()`, too.


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastruct...@apache.org or file a JIRA ticket
with INFRA.
---

---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscr...@spark.apache.org
For additional commands, e-mail: reviews-h...@spark.apache.org

Reply via email to