Skip to content

Commit

Permalink
[MINOR] Removed RecordLevelIndexSupport::fetchQueryWithAttribute, w…
Browse files Browse the repository at this point in the history
…hich duplicates `filterQueryWithRecordKey` (#12701)
  • Loading branch information
geserdugarov authored Jan 27, 2025
1 parent d1fe927 commit a7456c6
Showing 1 changed file with 0 additions and 74 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -229,80 +229,6 @@ object RecordLevelIndexSupport {
}
}

def fetchQueryWithAttribute(queryFilter: Expression, recordKeyOpt: Option[String], literalGenerator: Function2[AttributeReference, Literal, String],
attributeFetcher: Function1[Expression, Expression]): (Option[(Expression, List[String])], Boolean) = {
queryFilter match {
case equalToQuery: EqualTo =>
val attributeLiteralTuple = getAttributeLiteralTuple(attributeFetcher.apply(equalToQuery.left), attributeFetcher.apply(equalToQuery.right)).orNull
if (attributeLiteralTuple != null) {
val attribute = attributeLiteralTuple._1
val literal = attributeLiteralTuple._2
if (attribute != null && attribute.name != null && attributeMatchesRecordKey(attribute.name, recordKeyOpt)) {
val recordKeyLiteral = literalGenerator.apply(attribute, literal)
(Option.apply(EqualTo(attribute, literal), List.apply(recordKeyLiteral)), true)
} else {
(Option.empty, true)
}
} else {
(Option.empty, true)
}

case inQuery: In =>
var validINQuery = true
val attributeOpt = Option.apply(
attributeFetcher.apply(inQuery.value) match {
case attribute: AttributeReference =>
if (!attributeMatchesRecordKey(attribute.name, recordKeyOpt)) {
validINQuery = false
null
} else {
attribute
}
case _ =>
validINQuery = false
null
})
var literals: List[String] = List.empty
inQuery.list.foreach {
case literal: Literal if attributeOpt.isDefined =>
val recordKeyLiteral = literalGenerator.apply(attributeOpt.get, literal)
literals = literals :+ recordKeyLiteral
case _ => validINQuery = false
}
if (validINQuery) {
(Option.apply(In(attributeOpt.get, inQuery.list), literals), true)
} else {
(Option.empty, true)
}

// Handle And expression (composite filter)
case andQuery: And =>
val leftResult = filterQueryWithRecordKey(andQuery.left, recordKeyOpt, literalGenerator, attributeFetcher)
val rightResult = filterQueryWithRecordKey(andQuery.right, recordKeyOpt, literalGenerator, attributeFetcher)

val isSupported = leftResult._2 && rightResult._2
if (!isSupported) {
(Option.empty, false)
} else {
// If both left and right filters are valid, concatenate their results
(leftResult._1, rightResult._1) match {
case (Some((leftExp, leftKeys)), Some((rightExp, rightKeys))) =>
// Return concatenated expressions and record keys
(Option.apply(And(leftExp, rightExp), leftKeys ++ rightKeys), true)
case (Some((leftExp, leftKeys)), None) =>
// Return concatenated expressions and record keys
(Option.apply(leftExp, leftKeys), true)
case (None, Some((rightExp, rightKeys))) =>
// Return concatenated expressions and record keys
(Option.apply(rightExp, rightKeys), true)
case _ => (Option.empty, true)
}
}

case _ => (Option.empty, false)
}
}

/**
* Returns the list of storage paths from the pruned partitions and file slices.
*
Expand Down

0 comments on commit a7456c6

Please sign in to comment.