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

Fix summoned test cases #7

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -88,14 +88,14 @@ object ParquetReader {

}

def configured[A <: Product: ValueDecoder](
def configured[A <: Product: ValueDecoder: Tag](
hadoopConf: Configuration = new Configuration()
)(implicit tag: Tag[A]): ULayer[ParquetReader[A]] =
): ULayer[ParquetReader[A]] =
ZLayer.succeed(new ParquetReaderLive[A](hadoopConf))

def projected[A <: Product: ValueDecoder](
def projected[A <: Product: ValueDecoder: Tag](
hadoopConf: Configuration = new Configuration()
)(implicit schema: Schema[A], schemaEncoder: SchemaEncoder[A], tag: Tag[A]): ULayer[ParquetReader[A]] =
)(implicit schema: Schema[A], schemaEncoder: SchemaEncoder[A]): ULayer[ParquetReader[A]] =
ZLayer.succeed(new ParquetReaderLive[A](hadoopConf, Some(schema), Some(schemaEncoder)))

}
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,13 @@ package me.mnedokushev.zio.apache.parquet.core.codec

import me.mnedokushev.zio.apache.parquet.core.Schemas
import me.mnedokushev.zio.apache.parquet.core.Schemas.PrimitiveDef
import org.apache.parquet.schema.Type
import zio._
import zio.schema._
import zio.test._

import java.util.UUID
//import scala.annotation.nowarn
import scala.annotation.nowarn

object SchemaEncoderDeriverSpec extends ZIOSpecDefault {

Expand All @@ -25,6 +26,11 @@ object SchemaEncoderDeriverSpec extends ZIOSpecDefault {
implicit val schema: Schema[Record] = DeriveSchema.gen[Record]
}

case class Record1(a: String, b: Long)
object Record1 {
implicit val schema: Schema[Record1] = DeriveSchema.gen[Record1]
}

// Helper for being able to extract type parameter A from a given schema in order to cast the type of encoder<
private def encode[A](encoder: SchemaEncoder[_], schema: Schema[A], name: String, optional: Boolean) =
encoder.asInstanceOf[SchemaEncoder[A]].encode(schema, name, optional)
Expand Down Expand Up @@ -192,26 +198,26 @@ object SchemaEncoderDeriverSpec extends ZIOSpecDefault {
val tpe = encoder.encode(Schema[MyEnum], name, optional = true)

assertTrue(tpe == Schemas.enum0.optional.named(name))
},
test("summoned") {
// @nowarn annotation is needed to avoid having 'variable is not used' compiler error
@nowarn
implicit val intEncoder: SchemaEncoder[Long] = new SchemaEncoder[Long] {
override def encode(schema: Schema[Long], name: String, optional: Boolean): Type =
Schemas.uuid.optionality(optional).named(name)
}

val name = "myrecord1"
val encoder = Derive.derive[SchemaEncoder, Record1](SchemaEncoderDeriver.summoned)
val tpe = encoder.encode(Record1.schema, name, optional = true)

assertTrue(
tpe == Schemas
.record(Chunk(Schemas.string.required.named("a"), Schemas.uuid.required.named("b")))
.optional
.named(name)
)
}
// test("summoned") {
// // @nowarn annotation is needed to avoid having 'variable is not used' compiler error
// @nowarn
// implicit val intEncoder: SchemaEncoder[Int] = new SchemaEncoder[Int] {
// override def encode(schema: Schema[Int], name: String, optional: Boolean): Type =
// Schemas.uuid.optionality(optional).named(name)
// }
//
// val name = "myrecord"
// val encoder = Derive.derive[SchemaEncoder, Record](SchemaEncoderDeriver.summoned)
// val tpe = encoder.encode(Record.schema, name, optional = true)
//
// assertTrue(
// tpe == Schemas
// .record(Chunk(Schemas.uuid.required.named("a"), Schemas.string.optional.named("b")))
// .optional
// .named(name)
// )
// }
)

}