-
Notifications
You must be signed in to change notification settings - Fork 15
Expand file tree
/
Copy pathMetadataFilter.scala
More file actions
54 lines (46 loc) · 1.59 KB
/
Copy pathMetadataFilter.scala
File metadata and controls
54 lines (46 loc) · 1.59 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
/*
* Copyright 2021 IBM Corp.
* SPDX-License-Identifier: Apache-2.0
*/
package io.xskipper.search.filters
import io.xskipper.search.clause._
import io.xskipper.search.expressions.MetadataWrappedExpression
import org.apache.spark.sql.catalyst.expressions._
/**
* represents a meta data filter that can process a wrapped expression and add the relevant clauses
*/
trait MetadataFilter{
/**
* Process a wrapped expression by traversing the expression tree and adding the relevant
* clauses according to the filter
*
* @param wrappedExpr the wrapped expression to be processed
*/
def processWrappedExpression(wrappedExpr : MetadataWrappedExpression) : Unit
}
abstract class BaseMetadataFilter extends MetadataFilter {
/**
* Process a wrapped expression by traversing the expression tree and adding the relevant
* clauses according to the filter
*
* @param wrappedExpr the wrapped expression to be processed
*/
override def processWrappedExpression(wrappedExpr: MetadataWrappedExpression): Unit = {
wrappedExpr.expr match {
case _@(_: And | _: Or) =>
wrappedExpr.children.foreach(processWrappedExpression(_))
case _ =>
val query = getQueryContent(wrappedExpr)
query match {
case Some(queryInstance) => wrappedExpr.addClause(queryInstance)
case _ =>
}
}
}
/**
* Returns a clause representing the query contents associated with the expression
*
* @param wrappedExpr the expression to be
*/
protected def getQueryContent(wrappedExpr: MetadataWrappedExpression): Option[Clause]
}