Browse Source

HPCC-8808 Fix issues with truncation of lookup values

Minor changes following code review.

Signed-off-by: Richard Chapman <rchapman@hpccsystems.com>
Richard Chapman 12 years ago
parent
commit
072db90b67
4 changed files with 36 additions and 12 deletions
  1. 1 1
      common/deftype/deftype.cpp
  2. 23 11
      ecl/hql/hqlutil.cpp
  3. 6 0
      testing/ecl/dict_field.ecl
  4. 6 0
      testing/ecl/key/dict_field.xml

+ 1 - 1
common/deftype/deftype.cpp

@@ -3176,7 +3176,7 @@ ITypeInfo * getMaxLengthType(ITypeInfo * type)
     case type_data:
         return getStretchedType(UNKNOWN_LENGTH, type);
     default:
-        throw MakeStringException(99, "Internal error: getMaxLengthType");
+        return LINK(type);
     }
     return NULL;
 }

+ 23 - 11
ecl/hql/hqlutil.cpp

@@ -5413,31 +5413,43 @@ IHqlExpression *getDictionaryKeyRecord(IHqlExpression *record)
     return newrec->closeExpr();
 }
 
-IHqlExpression *getDictionarySearchRecord(IHqlExpression *record)
+IHqlExpression *recursiveStretchFields(IHqlExpression *record)
 {
-    // MORE - should probably use an attr to cache this?
-    IHqlExpression * payload = record->queryProperty(_payload_Atom);
-    unsigned payloadSize = payload ? getIntValue(payload->queryChild(0)) : 0;
-    unsigned max = record->numChildren() - payloadSize;
     IHqlExpression *newrec = createRecord();
-    for (unsigned idx = 0; idx < max; idx++)
+    ForEachChild (idx, record)
     {
         IHqlExpression *child = record->queryChild(idx);
-        if (!child->isAttribute() || child->queryName()!=_payload_Atom)  // Strip off the payload attribute
+        if (child->getOperator()==no_field)
         {
-            if (child->getOperator()==no_field)
+            ITypeInfo *fieldType = child->queryType();
+            switch (fieldType->getTypeCode())
+            {
+            case type_row:
+            {
+                OwnedHqlExpr childType = recursiveStretchFields(child->queryRecord());
+                newrec->addOperand(createField(child->queryName(), makeRowType(childType->getType()), NULL, NULL));
+                break;
+            }
+            default:
             {
-                ITypeInfo *fieldType = child->queryType();
                 Owned<ITypeInfo> stretched = getMaxLengthType(fieldType);
                 newrec->addOperand(createField(child->queryName(), stretched.getClear(), NULL, NULL));
+                break;
+            }
             }
-            else
-                newrec->addOperand(LINK(child));
         }
+        else
+            newrec->addOperand(LINK(child));
     }
     return newrec->closeExpr();
 }
 
+IHqlExpression *getDictionarySearchRecord(IHqlExpression *record)
+{
+    OwnedHqlExpr keyrec = getDictionaryKeyRecord(record);
+    return recursiveStretchFields(keyrec);
+}
+
 IHqlExpression * createSelectMapRow(IErrorReceiver * errors, ECLlocation & location, IHqlExpression * dict, IHqlExpression *values)
 {
     OwnedHqlExpr record = getDictionarySearchRecord(dict->queryRecord());

+ 6 - 0
testing/ecl/dict_field.ecl

@@ -74,3 +74,9 @@ u1 in ucoloru2code;
 u2 in ucoloru2code;
 u3 not in ucoloru2code;
 u4 not in ucoloru2code;
+
+'---';
+
+stringrecord := { string fcolor; };
+colorx2code := DICTIONARY(resistorCodes, { stringrecord s := row(transform(stringrecord, SELF.fcolor := color))  => value});
+ROW({ {c1} }, { stringrecord s } ) IN colorx2code;

+ 6 - 0
testing/ecl/key/dict_field.xml

@@ -103,3 +103,9 @@
 <Dataset name='Result 35'>
  <Row><Result_35>true</Result_35></Row>
 </Dataset>
+<Dataset name='Result 36'>
+ <Row><Result_36>---</Result_36></Row>
+</Dataset>
+<Dataset name='Result 37'>
+ <Row><Result_37>true</Result_37></Row>
+</Dataset>