Comments (8)
Hi!
Parquet itself does not support fields of type Any. You need to specify a fixed type. So I suggest you change the model of DataMap. For example, you can have two maps: stringIds: Map[String, String]
and decimalIds: Map[String, BigDecimal]
.
from parquet4s.
Unfortunately, there’s way too much legacy code that depends on this. Can I dynamically generate the TypedSchemaDef via Ref[A] somehow? How is it that the SchemaDef I wrote actually works? I didn’t reason it out so much as I tried different things.
from parquet4s.
The schema is for the whole Parquet file - not for a single row. So, if you keep writing decimals to one file, and then all strings to another (with another schema) - then it will work.
However, you can expect later problems with reading files with conflicting schemas.
from parquet4s.
The thing is that I wrote the encoder to always write strings but it seems like the type of the input data is checked against the output schema as opposed to the encoder output being validated against the schema. So if I change that map to use stringSchema instead of decimalSchema, it fails to compile.
from parquet4s.
if the value of the Map[String,Any] can be of a finite set of possibilities (i.e either the value is a string or it is a long then I think the structure could feasibly be described as an Either.
Is there support for an Either structure? (ie a Map described as a Map[String, Either[String,Long]])
from parquet4s.
Of course, there is :)
As I said before - do not insist on saving heterogeneous values of a map to a single collection. Partition your map into two: one for strings and the second for decimals. E.g. you can encode Ref
directly as a RowParquetRecord
if creating an intermediary case class is such a problem:
implicit def myEncoder[T]: OptionalValueEncoder[Ref[T]] =
new OptionalValueCodec[CustomType] {
override def encodeNonNull(ref: Ref[T], configuration: ValueCodecConfiguration): Value =
RowParquetRecord("type" -> [type as string], "stringIds" -> MapParquetRecord(stringIds entries), "decimalIds" -> MapParquetRecord([decimalIds entries])
}
And define a corresponding groupSchema
.
from parquet4s.
There's another low-level option - you can implement a custom version of MapParquetRecord, which writes several types of map entries: https://github.com/mjakubowski84/parquet4s/blob/master/core/src/main/scala/com/github/mjakubowski84/parquet4s/ParquetRecord.scala#L814 (not strictly one type, as it is done now).
However, I do not recommend it because it would be a non-standard approach to a map and reading such a map would be a challenge using any existing application/framework.
from parquet4s.
my map seems to write okay however when I attempt to read it in parquet tools, I get a ArrowInvalid: Map keys must be provided. Is there something I need to explicitly do to add the annotation here?
implicit def refSchema[A <: MyObject[_]](implicit stringSchema: TypedSchemaDef[String]): TypedSchemaDef[Ref[A]] = { SchemaDef .group( stringSchema("type"), SchemaDef.map(stringSchema, stringSchema)("ids") ).typed[Ref[A]] }
from parquet4s.
Related Issues (20)
- Reading from gcs bucket HOT 1
- Do not publish a pekko/akko versions of scapapb module HOT 1
- missing tail records of large(~193M) parquet files HOT 4
- Protobuf enums deserialisation HOT 3
- compatible parquet-hadoop with spark3.1 HOT 3
- Unsure how to use for 'semiauto' approach HOT 2
- ParquetSchemaResolver test fails on recent JVMs HOT 1
- [akka/pekko] Too many paths created during record partitioning HOT 2
- [RFC] Refactor timestamp codecs HOT 2
- Feature request: Expose partitions as a `Stream[F, Stream[F, Record]]` for FS2 HOT 5
- Incorrect value after reading parquet HOT 7
- [Question] get a listing of parquet files? HOT 4
- [Question] Is there a mechanism to detect when the `rotatingWriter` finishes writing to a file and to be notified of the file that was written? HOT 1
- Support vectored io introduced in Parquet 1.14 HOT 1
- Efficent way to read big files? HOT 2
- Possiblity to write avro IndexedRecords to Parquet using ParquetStreams HOT 3
- feat(akkaPekko): Retry mechanism for ParquetPartitioningFlow HOT 4
- Partitions with nested directories return zero rows HOT 1
- partitioning incompatibility with spark HOT 2
- ProjectionSchema self-inconsistency with partitioned source HOT 3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from parquet4s.