瀏覽代碼

Merge pull request #4497 from RussWhitehead/hthorTOPN

HPCC-9473 TOPN activity crashes if LIMIT depends on context

Reviewed-By: Richard Chapman <rchapman@hpccsystems.com>
Richard Chapman 12 年之前
父節點
當前提交
ad46a361a9
共有 3 個文件被更改,包括 27 次插入3 次删除
  1. 7 3
      ecl/hthor/hthor.cpp
  2. 5 0
      testing/ecl/key/topn.xml
  3. 15 0
      testing/ecl/topn.ecl

+ 7 - 3
ecl/hthor/hthor.cpp

@@ -6918,13 +6918,12 @@ const void * CHThorEnthActivity::nextInGroup()
 CHThorTopNActivity::CHThorTopNActivity(IAgentContext & _agent, unsigned _activityId, unsigned _subgraphId, IHThorTopNArg & _arg, ThorActivityKind _kind)
     : CHThorSimpleActivityBase(_agent, _activityId, _subgraphId, _arg, _kind), helper(_arg), compare(*helper.queryCompare())
 {
-    limit = helper.getLimit();
-    assertex(limit == (size_t)limit);
-    sorted = (const void * *)checked_calloc((size_t)(limit+1), sizeof(void *), "topn");
     hasBest = helper.hasBest();
     grouped = outputMeta.isGrouped();
     curIndex = 0;
     sortedCount = 0;
+    limit = 0;
+    sorted = NULL;
 }
 
 CHThorTopNActivity::~CHThorTopNActivity()
@@ -6937,6 +6936,9 @@ CHThorTopNActivity::~CHThorTopNActivity()
 void CHThorTopNActivity::ready()
 {
     CHThorSimpleActivityBase::ready();
+    limit = helper.getLimit();
+    assertex(limit == (size_t)limit);
+    sorted = (const void * *)checked_calloc((size_t)(limit+1), sizeof(void *), "topn");
     sortedCount = 0;
     curIndex = 0;
     eof = false;
@@ -6948,6 +6950,8 @@ void CHThorTopNActivity::done()
     CHThorSimpleActivityBase::done();
     while(curIndex < sortedCount)
         ReleaseRoxieRow(sorted[curIndex++]);
+    free(sorted);
+    sorted = NULL;
 }
 
 const void * CHThorTopNActivity::nextInGroup()

+ 5 - 0
testing/ecl/key/topn.xml

@@ -148,3 +148,8 @@
  <Row><_unnamed_cnt_1>2</_unnamed_cnt_1></Row>
  <Row><_unnamed_cnt_1>1</_unnamed_cnt_1></Row>
 </Dataset>
+<Dataset name='Result 29'>
+ <Row><i>1</i><num>1</num><children><Row><i>1</i></Row></children></Row>
+ <Row><i>2</i><num>3</num><children><Row><i>3</i></Row><Row><i>20</i></Row><Row><i>100</i></Row></children></Row>
+ <Row><i>4</i><num>2</num><children><Row><i>12</i></Row><Row><i>50</i></Row></children></Row>
+</Dataset>

+ 15 - 0
testing/ecl/topn.ecl

@@ -66,3 +66,18 @@ output(topn(i3, 1, -l, best('d'), local));      // expect {'d',4}
 b1 := topn(g3, 2, l, best('a'));
 output(sort(b1, l, d));     // expect {'a',1},{'a',9'},{'a',6},{'a',8},{'d',11}
 output(table(b1, { count(group) }));        // expect {2,2,1}
+
+
+
+r1 := { unsigned i; };
+r2 := { unsigned i, unsigned num, dataset(r1) children; };
+ds := dataset([
+    { 1, 1, [{1},{2},{3}] },
+    { 2, 3, [{100},{20},{3}] },
+    { 4, 2, [{50},{12},{76}] }], r2);
+r2 t(r2 l) := TRANSFORM
+    SELF.children := TOPN(l.children, l.num, i);
+    SELF := l;
+END;
+p := PROJECT(ds, t(LEFT));
+output(p);					// expect {1,1,{1}} {2,3,{3,20,100}} {4,2,{50}}