Skip to content

Improve Parquet documentation for AvroCompat, @doc annotation#885

Merged
clairemcginty merged 4 commits intomainfrom
avro-compat-doc
Jan 12, 2024
Merged

Improve Parquet documentation for AvroCompat, @doc annotation#885
clairemcginty merged 4 commits intomainfrom
avro-compat-doc

Conversation

@clairemcginty
Copy link
Contributor

No description provided.


However, the parquet-avro API encodes array types differently: as a nested array inside a required group.

```scala mdoc
Copy link
Contributor Author

Choose a reason for hiding this comment

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

after running sbt site/mdoc this evaluates to:

import org.apache.avro.Schema
val avroSchema = new Schema.Parser().parse("{\"type\":\"record\",\"name\":\"MyRecord\",\"fields\":[{\"name\": \"listField\", \"type\": {\"type\": \"array\", \"items\": \"string\"}}]}")
// avroSchema: Schema = {"type":"record","name":"MyRecord","fields":[{"name":"listField","type":{"type":"array","items":"string"}}]}

import org.apache.parquet.avro.AvroSchemaConverter
new AvroSchemaConverter().convert(avroSchema)
// res4: org.apache.parquet.schema.MessageType = message MyRecord {
//   required group listField (LIST) {
//     repeated binary array (STRING);
//   }
// }
//

writer.write(MyRecord(List(1,2,3)))
writer.close()

ParquetFileReader.open(HadoopInputFile.fromPath(path, new Configuration())).getFileMetaData
Copy link
Contributor Author

Choose a reason for hiding this comment

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

after running sbt site/mdoc this block evaluates to:

import magnolify.parquet._
import magnolify.parquet.ParquetArray.AvroCompat._
import magnolify.shared._

@doc("Top level annotation")
case class MyRecord(@doc("field annotation") listField: List[Int])

val writer = ParquetType[MyRecord]
  .writeBuilder(HadoopOutputFile.fromPath(path, new Configuration()))
  .build()
// writer: org.apache.parquet.hadoop.ParquetWriter[MyRecord] = org.apache.parquet.hadoop.ParquetWriter@432302e5
writer.write(MyRecord(List(1,2,3)))
writer.close()

ParquetFileReader.open(HadoopInputFile.fromPath(path, new Configuration())).getFileMetaData
// res12: org.apache.parquet.hadoop.metadata.FileMetaData = FileMetaData{schema: message repl.MdocSession.MdocApp9.MyRecord {
//   required group listField (LIST) {
//     repeated int32 array (INTEGER(32,true));
//   }
// }
// , metadata: {writer.model.name=magnolify, parquet.avro.schema={"type":"record","name":"MyRecord","namespace":"repl.MdocSession.MdocApp9","doc":"Top level annotation","fields":[{"name":"listField","type":{"type":"array","items":"int"},"doc":"field annotation"}]}}}

@codecov
Copy link

codecov bot commented Jan 12, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Comparison is base (e57d06d) 95.17% compared to head (ac2f81c) 95.17%.

Additional details and impacted files
@@           Coverage Diff           @@
##             main     #885   +/-   ##
=======================================
  Coverage   95.17%   95.17%           
=======================================
  Files          51       51           
  Lines        1825     1825           
  Branches      157      157           
=======================================
  Hits         1737     1737           
  Misses         88       88           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@clairemcginty clairemcginty merged commit 8153389 into main Jan 12, 2024
@clairemcginty clairemcginty deleted the avro-compat-doc branch January 12, 2024 14:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants