Skip to content

Commit

Permalink
add splitOnPipes
Browse files Browse the repository at this point in the history
  • Loading branch information
alextheimer committed Sep 13, 2023
1 parent 6561d21 commit ccc4e2c
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -428,7 +428,7 @@ object LogicalPlanUtils extends StrictLogging {
filter.filter match {
// Take care of pipe-joined values here -- create one Equals filter per value.
case EqualsRegex(values: String) if QueryUtils.isPipeOnlyRegex(values) =>
values.split('|').map(value => ColumnFilter(filter.column, Equals(value))).toSeq
QueryUtils.splitOnPipes(values).map(value => ColumnFilter(filter.column, Equals(value)))
case _ => Seq(filter)
}}
QueryUtils.combinations(resolvedFilters)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ abstract class PartitionLocationPlanner(dataset: Dataset,
case Equals(value) => Seq(value.toString)
// Split '|'-joined values if pipes are the only regex chars used.
case EqualsRegex(value: String) if QueryUtils.isPipeOnlyRegex(value) =>
value.split('|').toSeq
QueryUtils.splitOnPipes(value)
case _ => throw new IllegalArgumentException(
s"""shard keys must be filtered by equality or "|"-only regex. filter=${filter}""")
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -269,7 +269,7 @@ class SingleClusterPlanner(val dataset: Dataset,
case Some(ColumnFilter(_, Filter.Equals(filtVal: String))) =>
Seq(filtVal)
case Some(ColumnFilter(_, Filter.EqualsRegex(filtVal: String)))
if QueryUtils.isPipeOnlyRegex(filtVal) => filtVal.split('|').toSeq
if QueryUtils.isPipeOnlyRegex(filtVal) => QueryUtils.splitOnPipes(filtVal)
case Some(ColumnFilter(_, filter)) =>
throw new BadQueryException(s"Found filter for shard column $shardCol but " +
s"$filter cannot be used for shard key routing")
Expand Down
7 changes: 7 additions & 0 deletions core/src/main/scala/filodb.core/query/QueryUtils.scala
Original file line number Diff line number Diff line change
Expand Up @@ -48,4 +48,11 @@ object QueryUtils {
def isPipeOnlyRegex(str: String): Boolean = {
getUnescapedSpecialRegexChars(str).diff(Set('|')).isEmpty
}

/**
* Splits a string on unescaped pipe characters.
*/
def splitOnPipes(str: String): Seq[String] = {
str.split("(^|[^\\\\])(\\\\\\\\)*\\|")
}
}

0 comments on commit ccc4e2c

Please sign in to comment.