Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unable to decode BigDecimal via ByteBuffer #654

Open
sergiimk opened this issue May 19, 2021 · 0 comments
Open

Unable to decode BigDecimal via ByteBuffer #654

sergiimk opened this issue May 19, 2021 · 0 comments

Comments

@sergiimk
Copy link

When upgrading avro4s from version 2.0.4 to latest I get following exception when reading file containing DECIMAL type:

com.sksamuel.avro4s.Avro4sDecodingException: Unable to decode '[1, 31, 113, -5, 4, -53]' to BigDecimal via ByteBuffer

Sample file attached: example.zip

parquet-tools utility seems to have no problem reading this file.

I'm using the following DTO when reading:

case class Foo(
  // These columns are present in the file but we can skip them when reading
  // system_time: Timestamp,
  // event_time: Timestamp,
  decimal_13_4: Option[BigDecimal],
  decimal_38_18: Option[BigDecimal]
)

Read using following bit of code:

def read[T: Encoder: Decoder](path: Path)(
    implicit schemaFor: SchemaFor[T]
  ): List[T] = {
    val format = RecordFormat[T]

    val reader =
      AvroParquetReader
        .builder[GenericRecord](new org.apache.hadoop.fs.Path(path.toUri))
        .withDataModel(GenericData.get)
        .build()

    val records = Stream
      .continually(reader.read)
      .takeWhile(_ != null)
      .map(format.from)
      .toList

    reader.close()
    records
  }

Reproducible in hello-world project using the following dependencies:

scalaVersion := "2.12.13"
libraryDependencies += "com.sksamuel.avro4s" %% "avro4s-core" % "4.0.9"
libraryDependencies += "org.apache.parquet" % "parquet-avro" % "1.12.0"
libraryDependencies += "org.apache.hadoop" % "hadoop-client" % "3.3.0"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants