Uploaded image for project: 'Spark'
  1. Spark
  2. SPARK-30759

The cache in StringRegexExpression is not initialized for foldable patterns

    XMLWordPrintableJSON

    Details

    • Type: Bug
    • Status: Resolved
    • Priority: Minor
    • Resolution: Fixed
    • Affects Version/s: 1.6.3, 2.0.2, 2.1.3, 2.2.3, 2.3.4, 2.4.5
    • Fix Version/s: 2.4.6, 3.0.0
    • Component/s: SQL
    • Labels:
      None

      Description

      In the case of foldable patterns, the cache in StringRegexExpression should be evaluated once but in fact it is compiled every time. Here is the example:

      SELECT '%SystemDrive%\Users\John' _FUNC_ '%SystemDrive%\\Users.*';
      

      the code https://github.com/apache/spark/blob/8aebc80e0e67bcb1aa300b8c8b1a209159237632/sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/regexpExpressions.scala#L45-L48:

        // try cache the pattern for Literal
        private lazy val cache: Pattern = pattern match {
          case Literal(value: String, StringType) => compile(value)
          case _ => null
        }
      

      The attached screenshot shows that foldable expression doesn't fall to the first case.

        Attachments

          Activity

            People

            • Assignee:
              maxgekk Max Gekk
              Reporter:
              maxgekk Max Gekk
            • Votes:
              0 Vote for this issue
              Watchers:
              3 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved: