Explorar o código

Merge pull request #8157 from ghalliday/issue14812

HPCC-14812 Fix ROWDIFF with nested records

Reviewed-By: Jamie Noss <james.noss@lexisnexis.com>
Reviewed-By: Richard Chapman <rchapman@hpccsystems.com>
Richard Chapman %!s(int64=9) %!d(string=hai) anos
pai
achega
7cc3dfaa28

+ 1 - 1
ecl/hqlcpp/hqlhtcpp.cpp

@@ -8023,7 +8023,7 @@ void HqlCppTranslator::doBuildExprSizeof(BuildCtx & ctx, IHqlExpression * expr,
 
 }
 
-void HqlCppTranslator::doBuildExprRowDiff(BuildCtx & ctx, const CHqlBoundTarget & target, IHqlExpression * expr, IHqlExpression * rightRecord, IHqlExpression * leftSelector, IHqlExpression * rightSelector, StringBuffer & selectorText, bool isCount)
+void HqlCppTranslator::doBuildExprRowDiff(BuildCtx & ctx, const CHqlBoundTarget & target, IHqlExpression * expr, IHqlExpression * leftSelector, IHqlExpression * rightRecord, IHqlExpression * rightSelector, StringBuffer & selectorText, bool isCount)
 {
     switch (expr->getOperator())
     {

+ 5 - 3
ecl/regress/rowdiff.ecl

@@ -26,16 +26,18 @@ string20            middle;
                 end;
             end;
 
-
-in1rec :=   record
+idRec := record
 unsigned    id;
+END;
+
+in1rec :=   record(idRec)
 complexName name;
 unsigned    age;
 string      title;
         end;
 
 in2rec := record
-unsigned    id;
+idRec;
 complexName name;
 real8       age;
 boolean     dead;

+ 10 - 0
testing/regress/ecl/key/rowdiff.xml

@@ -0,0 +1,10 @@
+<Dataset name='Result 1'>
+ <Row><id>1</id><diff1>                                   </diff1><diff2>                                   </diff2></Row>
+ <Row><id>2</id><diff1>name.surname,name.middle           </diff1><diff2>surname,middle                     </diff2></Row>
+ <Row><id>3</id><diff1>age                                </diff1><diff2>                                   </diff2></Row>
+</Dataset>
+<Dataset name='Result 2'>
+ <Row><id>1</id><diff1>0,0,0,0,0                          </diff1><diff2>0,0,0                              </diff2></Row>
+ <Row><id>2</id><diff1>0,0,1,1,0                          </diff1><diff2>0,1,1                              </diff2></Row>
+ <Row><id>3</id><diff1>0,0,0,0,1                          </diff1><diff2>0,0,0                              </diff2></Row>
+</Dataset>

+ 83 - 0
testing/regress/ecl/rowdiff.ecl

@@ -0,0 +1,83 @@
+/*##############################################################################
+
+    HPCC SYSTEMS software Copyright (C) 2012 HPCC Systems®.
+
+    Licensed under the Apache License, Version 2.0 (the "License");
+    you may not use this file except in compliance with the License.
+    You may obtain a copy of the License at
+
+       http://www.apache.org/licenses/LICENSE-2.0
+
+    Unless required by applicable law or agreed to in writing, software
+    distributed under the License is distributed on an "AS IS" BASIS,
+    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+    See the License for the specific language governing permissions and
+    limitations under the License.
+############################################################################## */
+
+
+
+complexName :=
+            record
+string30        forename;
+string20        surname;
+                ifblock(self.surname <> 'Windsor')
+string20            middle;
+                end;
+            end;
+
+idRec := record
+unsigned    id;
+END;
+
+in1rec :=   record(idRec)
+complexName name;
+unsigned    age;
+string      title;
+        end;
+
+in2rec := record
+idRec;
+complexName name;
+real8       age;
+boolean     dead;
+        end;
+
+
+in1 := dataset([
+        {1,'Gavin','Hawthorn','',33,'Mr'},
+        {2,'Mia','Hawthorn','',33,'Dr'},
+        {3,'Elizabeth','Windsor',99,'Queen'}
+        ], in1rec);
+
+
+in2 := dataset([
+        {1,'Gavin','Hawthorn','',33,false},
+        {2,'Mia','','Jean',33,false},
+        {3,'Elizabeth','Windsor',99.1,false}
+        ], in2rec);
+
+outrec :=
+        record
+unsigned        id;
+string35        diff1;
+string35        diff2;
+        end;
+
+outrec t1(in1 l, in2 r) := transform
+//      self.id := if(l = r, SKIP, l.id);
+        self.id := l.id;
+        self.diff1 := rowdiff(l, r);
+        self.diff2 := rowdiff(l.name, r.name);
+    end;
+
+output(join(in1, in2, left.id = right.id, t1(left, right)));
+
+
+outrec t2(in1 l, in2 r) := transform
+        self.id := l.id;
+        self.diff1 := rowdiff(l, r, count);
+        self.diff2 := rowdiff(l.name, r.name, count);
+    end;
+
+output(join(in1, in2, left.id = right.id, t2(left, right)));