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
Use Arrow 0.8 APIs and fix a test.
  • Loading branch information
ueshin committed Dec 22, 2017
commit 4a697b3048218df5ae8167ba88ff9a1e9bcba60b
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ object ArrowWriter {
case (LongType, vector: BigIntVector) => new LongWriter(vector)
case (FloatType, vector: Float4Vector) => new FloatWriter(vector)
case (DoubleType, vector: Float8Vector) => new DoubleWriter(vector)
case (DecimalType.Fixed(precision, scale), vector: NullableDecimalVector) =>
case (DecimalType.Fixed(precision, scale), vector: DecimalVector) =>
new DecimalWriter(vector, precision, scale)
case (StringType, vector: VarCharVector) => new StringWriter(vector)
case (BinaryType, vector: VarBinaryVector) => new BinaryWriter(vector)
Expand Down Expand Up @@ -217,21 +217,18 @@ private[arrow] class DoubleWriter(val valueVector: Float8Vector) extends ArrowFi
}

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

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

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

override def setValue(input: SpecializedGetters, ordinal: Int): Unit = {
valueMutator.setIndexDefined(count)
val decimal = input.getDecimal(ordinal, precision, scale)
decimal.changePrecision(precision, scale)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it necessary to call changePrecision even though getDecimal already takes the precision/scale as input - is it not guaranteed to return a decimal with that scale?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unfortunately, it depends on the implementation of getDecimal for now.
Btw, I guess we need to check the return value of changePrecision() and set null if the value is false, which means overflow.

DecimalUtility.writeBigDecimalToArrowBuf(decimal.toJavaBigDecimal, valueVector.getBuffer, count)
valueVector.setSafe(count, decimal.toJavaBigDecimal)
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -311,40 +311,22 @@ class ArrowConvertersSuite extends SharedSQLContext with BeforeAndAfterAll {
| "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
| } ]
| }
| "nullable" : true,
| "children" : [ ]
| }, {
| "name" : "b_d",
| "nullable" : true,
| "type" : {
| "name" : "decimal",
| "precision" : 38,
| "scale" : 18
| },
| "children" : [ ],
| "typeLayout" : {
| "vectors" : [ {
| "type" : "VALIDITY",
| "typeBitWidth" : 1
| }, {
| "type" : "DATA",
| "typeBitWidth" : 64
| } ]
| }
| "nullable" : true,
| "children" : [ ]
| } ]
| },
| "batches" : [ {
Expand All @@ -354,23 +336,23 @@ class ArrowConvertersSuite extends SharedSQLContext with BeforeAndAfterAll {
| "count" : 6,
| "VALIDITY" : [ 1, 1, 1, 1, 1, 1 ],
| "DATA" : [
| 1.000000000000000000,
| 2.000000000000000000,
| 0.010000000000000000,
| 200.000000000000000000,
| 0.000100000000000000,
| 20000.000000000000000000 ]
| "1000000000000000000",
| "2000000000000000000",
| "10000000000000000",
| "200000000000000000000",
| "100000000000000",
| "20000000000000000000000" ]
| }, {
| "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 ]
| "1100000000000000000",
| "0",
| "0",
| "2200000000000000000",
| "0",
| "3300000000000000000" ]
| } ]
| } ]
|}
Expand Down