Sfoglia il codice sorgente

Merge pull request #1620 from ghalliday/assertfold

Fix gh-1592 Constant fold assert(condition or true)

Reviewed-By: Richard Chapman <rchapman@hpccsystems.com>
Richard Chapman 13 anni fa
parent
commit
c9d8919eba
4 ha cambiato i file con 65 aggiunte e 0 eliminazioni
  1. 25 0
      ecl/hql/hqlfold.cpp
  2. 10 0
      ecl/hql/hqlthql.cpp
  3. 1 0
      ecl/hqlcpp/hqlhtcpp.cpp
  4. 29 0
      ecl/regress/assertfold.ecl

+ 25 - 0
ecl/hql/hqlfold.cpp

@@ -3584,6 +3584,27 @@ IHqlExpression * NullFolderMixin::foldNullDataset(IHqlExpression * expr)
                 return removeParentNode(expr);
             break;
         }
+    case no_assert_ds:
+        {
+            if (isNull(child))
+                return removeParentNode(expr);
+
+            bool hasAssert = false;
+            ForEachChildFrom(i, expr, 1)
+            {
+                IHqlExpression * cur = queryRealChild(expr, i);
+                if (cur && (cur->getOperator() != no_null))
+                {
+                    hasAssert = true;
+                    break;
+                }
+            }
+            //All asserts have constant folded away...
+            if (!hasAssert)
+                return removeParentNode(expr);
+            break;
+        }
+
     case no_choosen:
         {
             if (isNull(child) || isFail(child))
@@ -4582,6 +4603,10 @@ IHqlExpression * CExprFolderTransformer::doFoldTransformed(IHqlExpression * unfo
             }
             break;
         }
+    case no_assert:
+        if (getBoolValue(expr->queryChild(0), false))
+            return createValue(no_null, makeVoidType());
+        break;
     }
 
     return LINK(expr);

+ 10 - 0
ecl/hql/hqlthql.cpp

@@ -2579,6 +2579,16 @@ void HqltHql::toECL(IHqlExpression *expr, StringBuffer &s, bool paren, bool inTy
             else
                 defaultToECL(expr, s, inType);
             break;
+        case no_assert_ds:
+            if (xgmmlGraphText)
+            {
+                pushScope(child0);
+                childrenToECL(expr, s, inType, false, 1);
+                popScope();
+            }
+            else
+                defaultToECL(expr, s, inType);
+            break;
         //case no_table:
         //case no_count:
         //case no_if:

+ 1 - 0
ecl/hqlcpp/hqlhtcpp.cpp

@@ -14529,6 +14529,7 @@ ABoundActivity * HqlCppTranslator::doBuildActivityAssert(BuildCtx & ctx, IHqlExp
 
     //MORE: Change this when ThroughApply activities are supported in engines.
     Owned<ActivityInstance> instance = new ActivityInstance(*this, ctx, TAKfilter, expr,"Filter");
+    instance->graphLabel.set("Assert");
 
     buildActivityFramework(instance);
     buildInstancePrefix(instance);

+ 29 - 0
ecl/regress/assertfold.ecl

@@ -0,0 +1,29 @@
+/*##############################################################################
+
+    Copyright (C) 2011 HPCC Systems.
+
+    All rights reserved. This program is free software: you can redistribute it and/or modify
+    it under the terms of the GNU Affero General Public License as
+    published by the Free Software Foundation, either version 3 of the
+    License, or (at your option) any later version.
+
+    This program is distributed in the hope that it will be useful,
+    but WITHOUT ANY WARRANTY; without even the implied warranty of
+    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+    GNU Affero General Public License for more details.
+
+    You should have received a copy of the GNU Affero General Public License
+    along with this program.  If not, see <http://www.gnu.org/licenses/>.
+############################################################################## */
+
+ds1 := DATASET('ds1', { unsigned i }, thor);
+f1 := assert(ds1, i != 10);
+output(f1);
+
+ds2 := DATASET('ds2', { unsigned i }, thor);
+f2 := assert(ds2, i != 10 or true);
+output(f2);
+
+ds3 := DATASET('ds3', { unsigned i }, thor);
+f3 := assert(ds3, i != 10 and false);
+output(f3);