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

Read Schema of parquet file #276

Open
ChrisMuki opened this issue Sep 30, 2022 · 2 comments
Open

Read Schema of parquet file #276

ChrisMuki opened this issue Sep 30, 2022 · 2 comments

Comments

@ChrisMuki
Copy link

ChrisMuki commented Sep 30, 2022

First i want to thank you for this great library!

I need to merge hundreds of small parquet files into bigger ones. Sadly they are not all the same schema (e.g. missing columns), nor is the schema known at compile time.

I am just wondering what would be the most eficient way to get only the schema of a parquet file.
Currently i am looking into the first RowParquetRecord but as there might be NullValues....

Further, i am interested if there is a complete list of how to map scala types properly to fields, like this
Types.primitive(INT32, OPTIONAL).as(LogicalTypeAnnotation.dateType()).named(Birthday)

Thanks

@mjakubowski84
Copy link
Owner

Hi Chris!

Parquet4s doesn't expose file schema in its own API (it is a thing that could be added). However, you can easily access it by calling the original Java API that Parquet4s is using under the hood. Check org.apache.parquet.hadoop.ParquetFileReader, e.g.:

val reader = ParquetFileReader.open(inputFile, readerOptions)
try {
  val schema: MessageType = reader.getFileMetaData.getSchema
  ...
} finally reader.close()

@mjakubowski84
Copy link
Owner

mjakubowski84 commented Oct 2, 2022

Regarding

a complete list of how to map scala types properly to fields

check the content of TypedSchemaDef

I mean... use this type class implicitly or explicitly to obtain type mapping. Check also a quite rich API of RowParquetRecord

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

No branches or pull requests

2 participants