-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
56 additions
and
0 deletions.
There are no files selected for viewing
40 changes: 40 additions & 0 deletions
40
...cala-3/me/mnedokushev/zio/apache/parquet/core/filter/internal/CompilePredicateMacro.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
package me.mnedokushev.zio.apache.parquet.core.filter.internal | ||
|
||
import scala.quoted._ | ||
import me.mnedokushev.zio.apache.parquet.core.filter.Predicate | ||
import org.apache.parquet.filter2.predicate.FilterPredicate | ||
|
||
object CompilePredicateMacro { | ||
|
||
inline def compileImpl[A](predicate: Predicate[A]): Either[String, FilterPredicate] = ${ compileImplImpl[A]('predicate) } | ||
|
||
def compileImplImpl[A: Type](predicate: Expr[Predicate[A]])(using Quotes): Expr[Either[String, FilterPredicate]] = { | ||
import quotes.reflect._ | ||
|
||
val containsOptionalValue = predicate.asTerm match { | ||
case Inlined(_, _, Block(stats, _)) => | ||
stats.exists { | ||
case Apply(TypeApply(Select(Ident("scala"), "Some"), _), _) => | ||
true | ||
case Select(Ident("scala"), "None") => | ||
true | ||
case _ => | ||
false | ||
} | ||
case _ => | ||
false | ||
} | ||
|
||
if (containsOptionalValue) | ||
report.errorAndAbort( | ||
s""" | ||
| The use of optional columns in filter predicate is prohibited. Please, use .nullable: | ||
| column.nullable > 3 | ||
| Predicate: ${predicate.show} | ||
""".stripMargin | ||
) | ||
else | ||
'{ _root_.me.mnedokushev.zio.apache.parquet.core.filter.Filter.compile[A]($predicate) } | ||
} | ||
|
||
} |
16 changes: 16 additions & 0 deletions
16
modules/core/src/main/scala-3/me/mnedokushev/zio/apache/parquet/core/filter/package.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
package me.mnedokushev.zio.apache.parquet.core | ||
|
||
import me.mnedokushev.zio.apache.parquet.core.filter.internal.CompilePredicateMacro | ||
import org.apache.parquet.filter2.predicate.FilterPredicate | ||
|
||
package object filter { | ||
|
||
extension[F, S, A](column: Lens[F, S, Option[A]]) { | ||
def nullable(implicit typeTag: TypeTag[A]): Column.Named[A, column.Identity] = | ||
Column.Named(column.path) | ||
} | ||
|
||
def compile[A](predicate: Predicate[A]): Either[String, FilterPredicate] = | ||
CompilePredicateMacro.compileImpl[A](predicate) | ||
|
||
} |