Skip to content

Commit

Permalink
Add "compile summoned" TypeTag test case
Browse files Browse the repository at this point in the history
  • Loading branch information
grouzen committed Jan 14, 2024
1 parent ad64538 commit f8fa508
Show file tree
Hide file tree
Showing 10 changed files with 225 additions and 156 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,9 @@ object Expr {

def compile[A](predicate: Predicate[A]): Either[String, FilterPredicate] = {

def error(op: Operator) =
Left(s"Operator $op is not supported by $predicate")

def binarySet[T <: Comparable[T], C <: Operators.Column[T] with Operators.SupportsEqNotEq](
column: C,
values: java.util.Set[T],
Expand Down Expand Up @@ -105,7 +108,7 @@ object Expr {
case Operator.Binary.NotEq() =>
Right(FilterApi.notEq(column0, value0))
case _ =>
Left("missing eqnoteq")
error(op)
}
case typeTag: TypeTag.LtGt[_] =>
val typeTag0 = typeTag.cast[A]
Expand All @@ -126,10 +129,10 @@ object Expr {
case Operator.Binary.GreaterEq() =>
Right(FilterApi.gtEq(column0, value0))
case _ =>
Left("missing ltgt")
error(op)
}
case _ =>
Left("missing binaryset")
error(op)
}
case Predicate.BinarySet(column, values, op) =>
column.typeTag match {
Expand All @@ -146,7 +149,7 @@ object Expr {

binarySet(column0, values0, op)
case _ =>
Left("missing binaryset")
error(op)
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,25 +15,25 @@ import org.apache.parquet.io.api.Binary

import scala.jdk.CollectionConverters._

sealed trait TypeTag[+A]
trait TypeTag[+A]

object TypeTag {

trait Dummy[A] extends TypeTag[A]
trait Dummy[+A] extends TypeTag[A]

def dummy[A]: TypeTag.Dummy[A] =
new Dummy[A] {}

final case class Optional[A: TypeTag]() extends TypeTag[Option[A]] {
final case class Optional[+A: TypeTag]() extends TypeTag[Option[A]] {
val typeTag: TypeTag[A] = implicitly[TypeTag[A]]
}

implicit def optional[A: TypeTag]: TypeTag[Option[A]] =
Optional[A]()

final case class Record[A](columns: Map[String, TypeTag[_]]) extends TypeTag[A]
final case class Record[+A](columns: Map[String, TypeTag[_]]) extends TypeTag[A]

sealed trait EqNotEq[A] extends TypeTag[A] { self =>
trait EqNotEq[A] extends TypeTag[A] { self =>
type T <: Comparable[T]
type C <: Column[T] with SupportsEqNotEq

Expand All @@ -45,7 +45,7 @@ object TypeTag {
vs.map(value).asJava
}

sealed trait LtGt[A] extends TypeTag[A] { self =>
trait LtGt[A] extends TypeTag[A] { self =>
type T <: Comparable[T]
type C <: Column[T] with SupportsLtGt

Expand All @@ -57,75 +57,71 @@ object TypeTag {
vs.map(value).asJava
}

implicit case object TString extends TypeTag.EqNotEq[String] {
override type T = Binary
override type C = BinaryColumn

override def column(path: String): C =
FilterApi.binaryColumn(path)

override def value(v: String): T =
Value.string(v).value

}

implicit case object TBoolean extends TypeTag.EqNotEq[Boolean] {
override type T = java.lang.Boolean
override type C = BooleanColumn

override def column(path: String): C =
FilterApi.booleanColumn(path)

override def value(v: Boolean): T =
Value.boolean(v).value

}

implicit case object TByte extends TypeTag.LtGt[Byte] {
override type T = java.lang.Integer
override type C = IntColumn

override def column(path: String): C =
FilterApi.intColumn(path)

override def value(v: Byte): T =
Value.byte(v).value

}

implicit case object TShort extends TypeTag.LtGt[Short] {
override type T = java.lang.Integer
override type C = IntColumn

override def column(path: String): C =
FilterApi.intColumn(path)

override def value(v: Short): T =
Value.short(v).value

}
implicit case object TInt extends TypeTag.LtGt[Int] {
override type T = java.lang.Integer
override type C = IntColumn

override def column(path: String): C =
FilterApi.intColumn(path)

override def value(v: Int): T =
Value.int(v).value

}

implicit case object TLong extends TypeTag.LtGt[Long] {
override type T = java.lang.Long
override type C = LongColumn

override def column(path: String): C =
FilterApi.longColumn(path)

override def value(v: Long): T =
Value.long(v).value

}
def eqnoteq[A, T0 <: Comparable[T0], C0 <: Column[T0] with SupportsEqNotEq](
column0: String => C0,
value0: A => T0
): TypeTag.EqNotEq[A] =
new TypeTag.EqNotEq[A] {

override type T = T0

override type C = C0

override def column(path: String): C =
column0(path)

override def value(v: A): T =
value0(v)

}

def ltgt[A, T0 <: Comparable[T0], C0 <: Column[T0] with SupportsLtGt](
column0: String => C0,
value0: A => T0
): TypeTag.LtGt[A] =
new TypeTag.LtGt[A] {

override type T = T0

override type C = C0

override def column(path: String): C =
column0(path)

override def value(v: A): T =
value0(v)

}

implicit val string: TypeTag.EqNotEq[String] =
eqnoteq[String, Binary, BinaryColumn](
FilterApi.binaryColumn,
Value.string(_).value
)
implicit val boolean: TypeTag.EqNotEq[Boolean] =
eqnoteq[Boolean, java.lang.Boolean, BooleanColumn](
FilterApi.booleanColumn,
Value.boolean(_).value
)
implicit val byte: TypeTag.LtGt[Byte] =
ltgt[Byte, java.lang.Integer, IntColumn](
FilterApi.intColumn,
Value.byte(_).value
)
implicit val short: TypeTag.LtGt[Short] =
ltgt[Short, java.lang.Integer, IntColumn](
FilterApi.intColumn,
Value.short(_).value
)
implicit val int: TypeTag.LtGt[Int] =
ltgt[Int, java.lang.Integer, IntColumn](
FilterApi.intColumn,
Value.int(_).value
)
implicit val long: TypeTag.LtGt[Long] =
ltgt[Long, java.lang.Long, LongColumn](
FilterApi.longColumn,
Value.long(_).value
)

}
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,12 @@ object TypeTagDeriver {
summoned: => Option[TypeTag[A]]
): TypeTag[A] =
st match {
case StandardType.StringType => TypeTag.TString
case StandardType.BoolType => TypeTag.TBoolean
case StandardType.ByteType => TypeTag.TByte
case StandardType.ShortType => TypeTag.TShort
case StandardType.IntType => TypeTag.TInt
case StandardType.LongType => TypeTag.TLong
case StandardType.StringType => TypeTag.string
case StandardType.BoolType => TypeTag.boolean
case StandardType.ByteType => TypeTag.byte
case StandardType.ShortType => TypeTag.short
case StandardType.IntType => TypeTag.int
case StandardType.LongType => TypeTag.long
case _ => TypeTag.dummy[A]
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
package me.mnedokushev.zio.apache.parquet.core.filter

import me.mnedokushev.zio.apache.parquet.core.Value
import org.apache.parquet.filter2.predicate.FilterApi
import org.apache.parquet.filter2.predicate.Operators.BinaryColumn
import org.apache.parquet.io.api.Binary
import zio.schema._

object Fixtures {

case class MyRecord(a: String, b: Int, child: MyRecord.Child)

object MyRecord {
implicit val schema = DeriveSchema.gen[MyRecord]
implicit val typeTag: TypeTag[MyRecord] = Derive.derive[TypeTag, MyRecord](TypeTagDeriver.default)

case class Child(c: Int, d: Option[Long])
object Child {
implicit val schema = DeriveSchema.gen[Child]
implicit val typeTag: TypeTag[Child] = Derive.derive[TypeTag, Child](TypeTagDeriver.default)
}

}

case class MyRecordSummoned(a: Int, b: String)

object MyRecordSummoned {
implicit val schema = DeriveSchema.gen[MyRecordSummoned]

implicit val intTypeTag: TypeTag.EqNotEq[Int] =
TypeTag.eqnoteq[Int, Binary, BinaryColumn](
FilterApi.binaryColumn,
v => Value.string(v.toString).value
)
implicit val typeTag: TypeTag[MyRecordSummoned] = Derive.derive[TypeTag, MyRecordSummoned](TypeTagDeriver.summoned)
}

}

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
package me.mnedokushev.zio.apache.parquet.core.filter

import me.mnedokushev.zio.apache.parquet.core.Value
import org.apache.parquet.filter2.predicate.FilterApi
import org.apache.parquet.filter2.predicate.Operators.BinaryColumn
import org.apache.parquet.io.api.Binary
import zio.schema._
object Fixtures {

case class MyRecord(a: String, b: Int, child: MyRecord.Child)

object MyRecord {
implicit val schema: Schema.CaseClass3.WithFields["a", "b", "child", String, Int, MyRecord.Child, MyRecord] =
DeriveSchema.gen[MyRecord]
implicit val typeTag: TypeTag[MyRecord] =
Derive.derive[TypeTag, MyRecord](TypeTagDeriver.default)

case class Child(c: Int, d: Option[Long])
object Child {
implicit val schema: Schema.CaseClass2.WithFields["c", "d", Int, Option[Long], MyRecord.Child] =
DeriveSchema.gen[Child]
implicit val typeTag: TypeTag[Child] =
Derive.derive[TypeTag, Child](TypeTagDeriver.default)

}
}

case class MyRecordSummoned(a: Int, b: String)

object MyRecordSummoned {
implicit val schema: zio.schema.Schema.CaseClass2.WithFields["a", "b", Int, String, MyRecordSummoned] =
DeriveSchema.gen[MyRecordSummoned]

implicit val intTypeTag: TypeTag.EqNotEq[Int] =
TypeTag.eqnoteq[Int, Binary, BinaryColumn](
FilterApi.binaryColumn,
v => Value.string(v.toString).value
)
implicit val typeTag: TypeTag[MyRecordSummoned] = Derive.derive[TypeTag, MyRecordSummoned](TypeTagDeriver.summoned)
}

}

This file was deleted.

Loading

0 comments on commit f8fa508

Please sign in to comment.