-
-
Notifications
You must be signed in to change notification settings - Fork 67
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Bugfix: support reading decimals encoded as long values
- Loading branch information
1 parent
2727a58
commit 76f91fd
Showing
5 changed files
with
66 additions
and
11 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
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
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
60 changes: 60 additions & 0 deletions
60
core/src/test/scala/com/github/mjakubowski84/parquet4s/DecimalValueSpec.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,60 @@ | ||
package com.github.mjakubowski84.parquet4s | ||
|
||
import org.scalatest.flatspec.AnyFlatSpec | ||
import org.scalatest.matchers.should.Matchers | ||
import org.apache.parquet.schema.PrimitiveType | ||
import org.apache.parquet.schema.LogicalTypeAnnotation | ||
|
||
import scala.util.Using | ||
|
||
class DecimalValueSpec extends AnyFlatSpec with Matchers { | ||
|
||
case class Data(decimal: BigDecimal) | ||
val data = Seq(Data(BigDecimal.decimal(1.2f))) | ||
|
||
"Decimal value" should "read from binary" in { | ||
|
||
val outputFile = InMemoryOutputFile(initBufferSize = 1024) | ||
|
||
// write | ||
ParquetWriter | ||
.generic(Message(Some("binary-dec"), TypedSchemaDef.decimalSchema("decimal"))) | ||
.writeAndClose( | ||
outputFile, | ||
Seq(RowParquetRecord("decimal" -> BinaryValue(Decimals.binaryFromDecimal(BigDecimal.decimal(1.2f))))) | ||
) | ||
|
||
val inputFile = outputFile.toInputFile | ||
|
||
// read | ||
Using(ParquetReader.as[Data].read(inputFile)) { readData => | ||
readData.toSeq shouldBe data | ||
} | ||
} | ||
|
||
it should "read from long" in { | ||
|
||
val outputFile = InMemoryOutputFile(initBufferSize = 1024) | ||
|
||
// write | ||
ParquetWriter | ||
.generic( | ||
Message( | ||
Some("long-dec"), | ||
SchemaDef.primitive( | ||
primitiveType = PrimitiveType.PrimitiveTypeName.INT64, | ||
logicalTypeAnnotation = Some(LogicalTypeAnnotation.decimalType(4, 8)) | ||
)("decimal") | ||
) | ||
) | ||
.writeAndClose(outputFile, Seq(RowParquetRecord("decimal" -> LongValue(12000L)))) | ||
|
||
val inputFile = outputFile.toInputFile | ||
|
||
// read | ||
Using(ParquetReader.as[Data].read(inputFile)) { readData => | ||
readData.toSeq shouldBe data | ||
} | ||
} | ||
|
||
} |
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