فهرست منبع

HPCC-23906 Add an option (-ftimeRegex) to time regular expressions

Signed-off-by: Gavin Halliday <gavin.halliday@lexisnexis.com>
Gavin Halliday 5 سال پیش
والد
کامیت
1f9f8f92a8
4فایلهای تغییر یافته به همراه24 افزوده شده و 1 حذف شده
  1. 1 0
      ecl/hqlcpp/hqlcpp.cpp
  2. 1 0
      ecl/hqlcpp/hqlcpp.ipp
  3. 21 0
      ecl/hqlcpp/hqlhtcpp.cpp
  4. 1 1
      testing/regress/ecl/aaalibrary2.ecl

+ 1 - 0
ecl/hqlcpp/hqlcpp.cpp

@@ -1860,6 +1860,7 @@ void HqlCppTranslator::cacheOptions()
         DebugOption(options.generateDiskFormats, "generateDiskFormats", false),
         DebugOption(options.maxOptimizeSize, "maxOptimizeSize", 5),             // Remove the overhead from very small functions e.g. function prolog
         DebugOption(options.minNoOptimizeSize, "minNoOptimizeSize", 10000),     // functions larger than this will take a long time to optimize, better to not try
+        DebugOption(options.timeRegex, "timeRegex", false),
     };
 
     //get options values from workunit

+ 1 - 0
ecl/hqlcpp/hqlcpp.ipp

@@ -831,6 +831,7 @@ struct HqlCppOptions
     bool                genericDiskReads;
     bool                generateActivityFormats;
     bool                generateDiskFormats;
+    bool                timeRegex;
 };
 
 //Any information gathered while processing the query should be moved into here, rather than cluttering up the translator class

+ 21 - 0
ecl/hqlcpp/hqlhtcpp.cpp

@@ -18337,6 +18337,25 @@ void HqlCppTranslator::doBuildNewRegexFindReplace(BuildCtx & ctx, const CHqlBoun
     // Because the search instance is created locally, the search parameter is always going to be valid
     // as long as the find instance.  Only exception could be if call created a temporary class instance.
     bool cloneSearch = false;
+    CHqlBoundExpr boundTimer, boundStart;
+    if (options.timeRegex)
+    {
+        StringBuffer regexName;
+        regexName.append(getOpString(expr->getOperator()));
+
+        if (pattern->queryId())
+            regexName.append("(").append(str(pattern->queryId())).append(")");
+        else if (pattern->isConstant())
+        {
+            StringBuffer patternText;
+            getUTF8Value(patternText, pattern);
+            // Replace colons in the pattern to avoid issues with scopes, and single quotes to avoid xpath quoting issues
+            patternText.replace(':', '_').replace('\'', '_');
+            regexName.append("(").append(patternText).append(")");
+        }
+
+        buildStartTimer(ctx, boundTimer, boundStart, regexName);
+    }
     IHqlExpression * findInstance = doBuildRegexFindInstance(ctx, compiled, search, cloneSearch);
     if(expr->queryType() == queryBoolType())
     {
@@ -18355,6 +18374,8 @@ void HqlCppTranslator::doBuildNewRegexFindReplace(BuildCtx & ctx, const CHqlBoun
         OwnedHqlExpr call = bindFunctionCall(func, args);
         buildExprOrAssign(ctx, target, call, bound);
     }
+    if (options.timeRegex)
+        buildStopTimer(ctx, boundTimer, boundStart);
 }
 
 void HqlCppTranslator::doBuildExprRegexFindReplace(BuildCtx & ctx, IHqlExpression * expr, CHqlBoundExpr & bound)

+ 1 - 1
testing/regress/ecl/aaalibrary2.ecl

@@ -37,7 +37,7 @@ end;
 
 filterDatasetLibrary(dataset(namesRecord) ds, dataset(namesRecord) unused, string search, boolean onlyOldies) := module,library(FilterDatasetInterface)
     f := ds;
-    shared g := if (onlyOldies, f(age >= 65), f);
+    shared g := if (onlyOldies, f(age >= 65, not regexfind('boris', forename)), f);
     export matches := g(surname = search);
     export others := g(surname != search);
 end;