Skip to content

Commit 5e1bb87

Browse files
committed
Support for all primitive types
1 parent f8fa508 commit 5e1bb87

File tree

4 files changed

+245
-22
lines changed

4 files changed

+245
-22
lines changed
Lines changed: 71 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,26 @@
11
package me.mnedokushev.zio.apache.parquet.core.filter
22

3+
import zio.{ Chunk, Duration }
4+
5+
import java.time.{
6+
DayOfWeek,
7+
Instant,
8+
LocalDate,
9+
LocalDateTime,
10+
LocalTime,
11+
Month,
12+
MonthDay,
13+
OffsetDateTime,
14+
OffsetTime,
15+
Period,
16+
Year,
17+
YearMonth,
18+
ZoneId,
19+
ZonedDateTime
20+
}
21+
import java.util.UUID
322
import scala.annotation.implicitNotFound
23+
import java.time.ZoneOffset
424

525
sealed trait OperatorSupport[A]
626

@@ -12,9 +32,28 @@ object OperatorSupport {
1232
}
1333

1434
object LtGt {
15-
implicit case object SByte extends LtGt[Byte]
16-
implicit case object SShort extends LtGt[Short]
17-
implicit case object SInt extends LtGt[Int]
35+
implicit case object byte extends LtGt[Byte]
36+
implicit case object short extends LtGt[Short]
37+
implicit case object int extends LtGt[Int]
38+
implicit case object long extends LtGt[Long]
39+
implicit case object float extends LtGt[Float]
40+
implicit case object double extends LtGt[Double]
41+
implicit case object bigDecimal extends LtGt[java.math.BigDecimal]
42+
implicit case object bigInteger extends LtGt[java.math.BigInteger]
43+
implicit case object dayOfWeek extends LtGt[DayOfWeek]
44+
implicit case object month extends LtGt[Month]
45+
implicit case object monthDay extends LtGt[MonthDay]
46+
implicit case object period extends LtGt[Period]
47+
implicit case object year extends LtGt[Year]
48+
implicit case object yearMonth extends LtGt[YearMonth]
49+
implicit case object duration extends LtGt[Duration]
50+
implicit case object instant extends LtGt[Instant]
51+
implicit case object localDate extends LtGt[LocalDate]
52+
implicit case object localTime extends LtGt[LocalTime]
53+
implicit case object localDateTime extends LtGt[LocalDateTime]
54+
implicit case object offsetTime extends LtGt[OffsetTime]
55+
implicit case object offsetDateTime extends LtGt[OffsetDateTime]
56+
implicit case object zonedDateTime extends LtGt[ZonedDateTime]
1857
}
1958

2059
@implicitNotFound("You can't use this operator for the type ${A}")
@@ -23,11 +62,35 @@ object OperatorSupport {
2362
}
2463

2564
object EqNotEq {
26-
implicit case object SString extends EqNotEq[String]
27-
implicit case object SBoolean extends EqNotEq[Boolean]
28-
implicit case object SByte extends EqNotEq[Byte]
29-
implicit case object SShort extends EqNotEq[Short]
30-
implicit case object SInt extends EqNotEq[Int]
65+
implicit case object string extends EqNotEq[String]
66+
implicit case object boolean extends EqNotEq[Boolean]
67+
implicit case object byte extends EqNotEq[Byte]
68+
implicit case object short extends EqNotEq[Short]
69+
implicit case object int extends EqNotEq[Int]
70+
implicit case object long extends EqNotEq[Long]
71+
implicit case object float extends EqNotEq[Float]
72+
implicit case object double extends EqNotEq[Double]
73+
implicit case object binary extends EqNotEq[Chunk[Byte]]
74+
implicit case object char extends EqNotEq[Char]
75+
implicit case object uuid extends EqNotEq[UUID]
76+
implicit case object bigDecimal extends EqNotEq[java.math.BigDecimal]
77+
implicit case object bigInteger extends EqNotEq[java.math.BigInteger]
78+
implicit case object dayOfWeek extends EqNotEq[DayOfWeek]
79+
implicit case object month extends EqNotEq[Month]
80+
implicit case object monthDay extends EqNotEq[MonthDay]
81+
implicit case object period extends EqNotEq[Period]
82+
implicit case object year extends EqNotEq[Year]
83+
implicit case object yearMonth extends EqNotEq[YearMonth]
84+
implicit case object zoneId extends EqNotEq[ZoneId]
85+
implicit case object zoneOffset extends EqNotEq[ZoneOffset]
86+
implicit case object duration extends EqNotEq[Duration]
87+
implicit case object instant extends EqNotEq[Instant]
88+
implicit case object localDate extends EqNotEq[LocalDate]
89+
implicit case object localTime extends EqNotEq[LocalTime]
90+
implicit case object localDateTime extends EqNotEq[LocalDateTime]
91+
implicit case object offsetTime extends EqNotEq[OffsetTime]
92+
implicit case object offsetDateTime extends EqNotEq[OffsetDateTime]
93+
implicit case object zonedDateTime extends EqNotEq[ZonedDateTime]
3194
}
3295

3396
}

modules/core/src/main/scala/me/mnedokushev/zio/apache/parquet/core/filter/TypeTag.scala

Lines changed: 143 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,39 @@
11
package me.mnedokushev.zio.apache.parquet.core.filter
22

3+
import _root_.java.time.Instant
34
import me.mnedokushev.zio.apache.parquet.core.Value
45
import org.apache.parquet.filter2.predicate.FilterApi
56
import org.apache.parquet.filter2.predicate.Operators.{
67
BinaryColumn,
78
BooleanColumn,
89
Column,
10+
DoubleColumn,
11+
FloatColumn,
912
IntColumn,
1013
LongColumn,
1114
SupportsEqNotEq,
1215
SupportsLtGt
1316
}
1417
import org.apache.parquet.io.api.Binary
18+
import zio.{ Chunk, Duration }
1519

20+
import java.time.{
21+
DayOfWeek,
22+
LocalDate,
23+
LocalDateTime,
24+
LocalTime,
25+
Month,
26+
MonthDay,
27+
OffsetDateTime,
28+
OffsetTime,
29+
Period,
30+
Year,
31+
YearMonth,
32+
ZoneId,
33+
ZoneOffset,
34+
ZonedDateTime
35+
}
36+
import java.util.UUID
1637
import scala.jdk.CollectionConverters._
1738

1839
trait TypeTag[+A]
@@ -93,35 +114,151 @@ object TypeTag {
93114

94115
}
95116

96-
implicit val string: TypeTag.EqNotEq[String] =
117+
implicit val string: TypeTag.EqNotEq[String] =
97118
eqnoteq[String, Binary, BinaryColumn](
98119
FilterApi.binaryColumn,
99120
Value.string(_).value
100121
)
101-
implicit val boolean: TypeTag.EqNotEq[Boolean] =
122+
implicit val boolean: TypeTag.EqNotEq[Boolean] =
102123
eqnoteq[Boolean, java.lang.Boolean, BooleanColumn](
103124
FilterApi.booleanColumn,
104125
Value.boolean(_).value
105126
)
106-
implicit val byte: TypeTag.LtGt[Byte] =
127+
implicit val byte: TypeTag.LtGt[Byte] =
107128
ltgt[Byte, java.lang.Integer, IntColumn](
108129
FilterApi.intColumn,
109130
Value.byte(_).value
110131
)
111-
implicit val short: TypeTag.LtGt[Short] =
132+
implicit val short: TypeTag.LtGt[Short] =
112133
ltgt[Short, java.lang.Integer, IntColumn](
113134
FilterApi.intColumn,
114135
Value.short(_).value
115136
)
116-
implicit val int: TypeTag.LtGt[Int] =
137+
implicit val int: TypeTag.LtGt[Int] =
117138
ltgt[Int, java.lang.Integer, IntColumn](
118139
FilterApi.intColumn,
119140
Value.int(_).value
120141
)
121-
implicit val long: TypeTag.LtGt[Long] =
142+
implicit val long: TypeTag.LtGt[Long] =
122143
ltgt[Long, java.lang.Long, LongColumn](
123144
FilterApi.longColumn,
124145
Value.long(_).value
125146
)
147+
implicit val float: TypeTag.LtGt[Float] =
148+
ltgt[Float, java.lang.Float, FloatColumn](
149+
FilterApi.floatColumn,
150+
Value.float(_).value
151+
)
152+
implicit val double: TypeTag.LtGt[Double] =
153+
ltgt[Double, java.lang.Double, DoubleColumn](
154+
FilterApi.doubleColumn,
155+
Value.double(_).value
156+
)
157+
implicit val binary: TypeTag.EqNotEq[Chunk[Byte]] =
158+
eqnoteq[Chunk[Byte], Binary, BinaryColumn](
159+
FilterApi.binaryColumn,
160+
Value.binary(_).value
161+
)
162+
implicit val char: TypeTag.EqNotEq[Char] =
163+
eqnoteq[Char, java.lang.Integer, IntColumn](
164+
FilterApi.intColumn,
165+
Value.char(_).value
166+
)
167+
implicit val uuid: TypeTag.EqNotEq[UUID] =
168+
eqnoteq[UUID, Binary, BinaryColumn](
169+
FilterApi.binaryColumn,
170+
Value.uuid(_).value
171+
)
172+
implicit val bigDecimal: TypeTag.LtGt[java.math.BigDecimal] =
173+
ltgt[java.math.BigDecimal, java.lang.Long, LongColumn](
174+
FilterApi.longColumn,
175+
Value.bigDecimal(_).value
176+
)
177+
implicit val bigInteger: TypeTag.LtGt[java.math.BigInteger] =
178+
ltgt[java.math.BigInteger, Binary, BinaryColumn](
179+
FilterApi.binaryColumn,
180+
Value.bigInteger(_).value
181+
)
182+
implicit val dayOfWeek: TypeTag.LtGt[DayOfWeek] =
183+
ltgt[DayOfWeek, java.lang.Integer, IntColumn](
184+
FilterApi.intColumn,
185+
Value.dayOfWeek(_).value
186+
)
187+
implicit val month: TypeTag.LtGt[Month] =
188+
ltgt[Month, java.lang.Integer, IntColumn](
189+
FilterApi.intColumn,
190+
Value.month(_).value
191+
)
192+
implicit val monthDay: TypeTag.LtGt[MonthDay] =
193+
ltgt[MonthDay, Binary, BinaryColumn](
194+
FilterApi.binaryColumn,
195+
Value.monthDay(_).value
196+
)
197+
implicit val period: TypeTag.LtGt[Period] =
198+
ltgt[Period, Binary, BinaryColumn](
199+
FilterApi.binaryColumn,
200+
Value.period(_).value
201+
)
202+
implicit val year: TypeTag.LtGt[Year] =
203+
ltgt[Year, java.lang.Integer, IntColumn](
204+
FilterApi.intColumn,
205+
Value.year(_).value
206+
)
207+
implicit val yearMonth: TypeTag.LtGt[YearMonth] =
208+
ltgt[YearMonth, Binary, BinaryColumn](
209+
FilterApi.binaryColumn,
210+
Value.yearMonth(_).value
211+
)
212+
// NOTE: it is not implicit to make scalac happy since ZoneOffset is a subtype of ZoneId
213+
val zoneId: TypeTag.EqNotEq[ZoneId] =
214+
eqnoteq[ZoneId, Binary, BinaryColumn](
215+
FilterApi.binaryColumn,
216+
Value.zoneId(_).value
217+
)
218+
implicit val zoneOffset: TypeTag.EqNotEq[ZoneOffset] =
219+
eqnoteq[ZoneOffset, Binary, BinaryColumn](
220+
FilterApi.binaryColumn,
221+
Value.zoneOffset(_).value
222+
)
223+
implicit val duration: TypeTag.LtGt[Duration] =
224+
ltgt[Duration, java.lang.Long, LongColumn](
225+
FilterApi.longColumn,
226+
Value.duration(_).value
227+
)
228+
implicit val instant: TypeTag.LtGt[Instant] =
229+
ltgt[Instant, java.lang.Long, LongColumn](
230+
FilterApi.longColumn,
231+
Value.instant(_).value
232+
)
233+
implicit val localDate: TypeTag.LtGt[LocalDate] =
234+
ltgt[LocalDate, java.lang.Integer, IntColumn](
235+
FilterApi.intColumn,
236+
Value.localDate(_).value
237+
)
238+
implicit val localTime: TypeTag.LtGt[LocalTime] =
239+
ltgt[LocalTime, java.lang.Integer, IntColumn](
240+
FilterApi.intColumn,
241+
Value.localTime(_).value
242+
)
243+
implicit val localDateTime: TypeTag.LtGt[LocalDateTime] =
244+
ltgt[LocalDateTime, java.lang.Long, LongColumn](
245+
FilterApi.longColumn,
246+
Value.localDateTime(_).value
247+
)
248+
implicit val offsetTime: TypeTag.LtGt[OffsetTime] =
249+
ltgt[OffsetTime, java.lang.Integer, IntColumn](
250+
FilterApi.intColumn,
251+
Value.offsetTime(_).value
252+
)
253+
implicit val offsetDateTime: TypeTag.LtGt[OffsetDateTime] =
254+
ltgt[OffsetDateTime, java.lang.Long, LongColumn](
255+
FilterApi.longColumn,
256+
Value.offsetDateTime(_).value
257+
)
258+
implicit val zonedDateTime: TypeTag.LtGt[ZonedDateTime] =
259+
ltgt[ZonedDateTime, java.lang.Long, LongColumn](
260+
FilterApi.longColumn,
261+
Value.zonedDateTime(_).value
262+
)
126263

127264
}

modules/core/src/main/scala/me/mnedokushev/zio/apache/parquet/core/filter/TypeTagDeriver.scala

Lines changed: 30 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -31,13 +31,36 @@ object TypeTagDeriver {
3131
summoned: => Option[TypeTag[A]]
3232
): TypeTag[A] =
3333
st match {
34-
case StandardType.StringType => TypeTag.string
35-
case StandardType.BoolType => TypeTag.boolean
36-
case StandardType.ByteType => TypeTag.byte
37-
case StandardType.ShortType => TypeTag.short
38-
case StandardType.IntType => TypeTag.int
39-
case StandardType.LongType => TypeTag.long
40-
case _ => TypeTag.dummy[A]
34+
case StandardType.StringType => TypeTag.string
35+
case StandardType.BoolType => TypeTag.boolean
36+
case StandardType.ByteType => TypeTag.byte
37+
case StandardType.ShortType => TypeTag.short
38+
case StandardType.IntType => TypeTag.int
39+
case StandardType.LongType => TypeTag.long
40+
case StandardType.FloatType => TypeTag.float
41+
case StandardType.DoubleType => TypeTag.double
42+
case StandardType.BinaryType => TypeTag.binary
43+
case StandardType.CharType => TypeTag.char
44+
case StandardType.UUIDType => TypeTag.uuid
45+
case StandardType.BigDecimalType => TypeTag.bigDecimal
46+
case StandardType.BigIntegerType => TypeTag.bigInteger
47+
case StandardType.DayOfWeekType => TypeTag.dayOfWeek
48+
case StandardType.MonthType => TypeTag.month
49+
case StandardType.MonthDayType => TypeTag.monthDay
50+
case StandardType.PeriodType => TypeTag.period
51+
case StandardType.YearType => TypeTag.year
52+
case StandardType.YearMonthType => TypeTag.yearMonth
53+
case StandardType.ZoneIdType => TypeTag.zoneId
54+
case StandardType.ZoneOffsetType => TypeTag.zoneOffset
55+
case StandardType.DurationType => TypeTag.duration
56+
case StandardType.InstantType => TypeTag.instant
57+
case StandardType.LocalDateType => TypeTag.localDate
58+
case StandardType.LocalTimeType => TypeTag.localTime
59+
case StandardType.LocalDateTimeType => TypeTag.localDateTime
60+
case StandardType.OffsetTimeType => TypeTag.offsetTime
61+
case StandardType.OffsetDateTimeType => TypeTag.offsetDateTime
62+
case StandardType.ZonedDateTimeType => TypeTag.zonedDateTime
63+
case _ => TypeTag.dummy[A]
4164
}
4265

4366
override def deriveOption[A](

modules/core/src/test/scala/me/mnedokushev/zio/apache/parquet/core/filter/ExprSpec.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ object ExprSpec extends ZIOSpecDefault {
1515

1616
override def spec: Spec[TestEnvironment with Scope, Any] =
1717
suite("ExprSpec")(
18-
test("compile") {
18+
test("compile all operators") {
1919
val (a, b, _) = Filter.columns[MyRecord]
2020

2121
val result = Expr.compile(

0 commit comments

Comments
 (0)