Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
Remove DecimalType support for now.
  • Loading branch information
ueshin committed Jul 26, 2017
commit 5bbb46f55a90bae3008ee374ef2c0349a3489c09
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,6 @@ object ArrowWriter {
new FloatWriter(vector.asInstanceOf[NullableFloat4Vector])
case DoubleType =>
new DoubleWriter(vector.asInstanceOf[NullableFloat8Vector])
case DecimalType.Fixed(precision, scale) =>
new DecimalWriter(vector.asInstanceOf[NullableDecimalVector], precision, scale)
case StringType =>
new StringWriter(vector.asInstanceOf[NullableVarCharVector])
case BinaryType =>
Expand All @@ -76,6 +74,8 @@ object ArrowWriter {
createFieldWriter(v.getChildByOrdinal(ordinal))
}
new StructWriter(v, children.toArray)
case dt =>
throw new UnsupportedOperationException(s"Unsupported data type: ${dt.simpleString}")
}
}
}
Expand Down Expand Up @@ -269,29 +269,6 @@ private[arrow] class DoubleWriter(val valueVector: NullableFloat8Vector) extends
}
}

private[arrow] class DecimalWriter(
val valueVector: NullableDecimalVector,
precision: Int,
scale: Int) extends ArrowFieldWriter {

override def valueMutator: NullableDecimalVector#Mutator = valueVector.getMutator()

override def setNull(): Unit = {
valueMutator.setNull(count)
}

override def setValue(input: SpecializedGetters, ordinal: Int): Unit = {
valueMutator.setIndexDefined(count)
val decimal = input.getDecimal(ordinal, precision, scale)
decimal.changePrecision(precision, scale)
DecimalUtility.writeBigDecimalToArrowBuf(decimal.toJavaBigDecimal, valueVector.getBuffer, count)
}

override def skip(): Unit = {
valueMutator.setIndexDefined(count)
}
}

private[arrow] class StringWriter(val valueVector: NullableVarCharVector) extends ArrowFieldWriter {

override def valueMutator: NullableVarCharVector#Mutator = valueVector.getMutator()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ import org.scalatest.BeforeAndAfterAll
import org.apache.spark.SparkException
import org.apache.spark.sql.{DataFrame, Row}
import org.apache.spark.sql.test.SharedSQLContext
import org.apache.spark.sql.types.{BinaryType, Decimal, IntegerType, StructField, StructType}
import org.apache.spark.sql.types.{BinaryType, IntegerType, StructField, StructType}
import org.apache.spark.util.Utils


Expand Down Expand Up @@ -391,85 +391,6 @@ class ArrowConvertersSuite extends SharedSQLContext with BeforeAndAfterAll {
collectAndValidate(df, json, "floating_point-double_precision.json")
}

ignore("decimal conversion") {
val json =
s"""
|{
| "schema" : {
| "fields" : [ {
| "name" : "a_d",
| "nullable" : true,
| "type" : {
| "name" : "decimal",
| "precision" : 38,
| "scale" : 18
| },
| "children" : [ ],
| "typeLayout" : {
| "vectors" : [ {
| "type" : "VALIDITY",
| "typeBitWidth" : 1
| }, {
| "type" : "DATA",
| "typeBitWidth" : 64
| } ]
| }
| }, {
| "name" : "b_d",
| "nullable" : true,
| "type" : {
| "name" : "decimal",
| "precision" : 38,
| "scale" : 18
| },
| "children" : [ ],
| "typeLayout" : {
| "vectors" : [ {
| "type" : "VALIDITY",
| "typeBitWidth" : 1
| }, {
| "type" : "DATA",
| "typeBitWidth" : 64
| } ]
| }
| } ]
| },
| "batches" : [ {
| "count" : 6,
| "columns" : [ {
| "name" : "a_d",
| "count" : 6,
| "VALIDITY" : [ 1, 1, 1, 1, 1, 1 ],
| "DATA" : [
| 1.000000000000000000,
| 2.000000000000000000,
| 0.010000000000000000,
| 200.000000000000000000,
| 0.000100000000000000,
| 20000.000000000000000000 ]
| }, {
| "name" : "b_d",
| "count" : 6,
| "VALIDITY" : [ 1, 0, 0, 1, 0, 1 ],
| "DATA" : [
| 1.100000000000000000,
| 0E-18,
| 0E-18,
| 2.200000000000000000,
| 0E-18,
| 3.300000000000000000 ]
| } ]
| } ]
|}
""".stripMargin

val a_d = List(1.0, 2.0, 0.01, 200.0, 0.0001, 20000.0).map(Decimal(_))
val b_d = List(Some(Decimal(1.1)), None, None, Some(Decimal(2.2)), None, Some(Decimal(3.3)))
val df = a_d.zip(b_d).toDF("a_d", "b_d")

collectAndValidate(df, json, "decimalData.json")
}

test("index conversion") {
val data = List[Int](1, 2, 3, 4, 5, 6)
val json =
Expand Down Expand Up @@ -1561,6 +1482,7 @@ class ArrowConvertersSuite extends SharedSQLContext with BeforeAndAfterAll {
assert(msg.getCause.getClass === classOf[UnsupportedOperationException])
}

runUnsupported { decimalData.toArrowPayload.collect() }
runUnsupported { mapData.toDF().toArrowPayload.collect() }
runUnsupported { complexData.toArrowPayload.collect() }

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,10 +55,6 @@ class ArrowWriterSuite extends SparkFunSuite {
check(FloatType, Seq(1.0f, 2.0f, null, 4.0f), (reader, rowId) => reader.getFloat(rowId))
check(DoubleType, Seq(1.0d, 2.0d, null, 4.0d), (reader, rowId) => reader.getDouble(rowId))

check(DecimalType.SYSTEM_DEFAULT, Seq(Decimal(1), Decimal(2), null, Decimal(4)),
(reader, rowId) => reader.getDecimal(
rowId, DecimalType.SYSTEM_DEFAULT.precision, DecimalType.SYSTEM_DEFAULT.scale))

check(StringType,
Seq("a", "b", null, "d").map(UTF8String.fromString),
(reader, rowId) => reader.getUTF8String(rowId))
Expand Down