Selaa lähdekoodia

Merge pull request #12879 from ghalliday/issue22662

HPCC-22662 Report a WARNING for an alien type better expressed as DATA

Reviewed-By: Shamser Ahmed <shamser.ahmed@lexisnexis.co.uk>
Reviewed-By: Richard Chapman <rchapman@hpccsystems.com>
Richard Chapman 5 vuotta sitten
vanhempi
commit
d4dd91c715
3 muutettua tiedostoa jossa 38 lisäystä ja 0 poistoa
  1. 2 0
      ecl/hql/hqlerrors.hpp
  2. 1 0
      ecl/hql/hqlgram.hpp
  3. 35 0
      ecl/hql/hqlgram2.cpp

+ 2 - 0
ecl/hql/hqlerrors.hpp

@@ -514,6 +514,7 @@
 #define HQLERR_NoScalarOutputInLibrary          3156
 #define HQLERR_OnlyExtendOutputInLibrary        3157
 #define HQLERR_UnnamedOutputInLibrary           3158
+#define HQLERR_AlienUseData                     3159
 
 #define HQLERR_DedupFieldNotFound_Text          "Field removed from dedup could not be found"
 #define HQLERR_CycleWithModuleDefinition_Text   "Module definition contains an illegal cycle/recursive definition %s"
@@ -566,6 +567,7 @@
 #define HQLERR_NoScalarOutputInLibrary_Text     "Scalar outputs are not supported inside libraries"
 #define HQLERR_OnlyExtendOutputInLibrary_Text   "OUTPUT within a library must use EXTEND"
 #define HQLERR_UnnamedOutputInLibrary_Text      "OUTPUT within a library must be NAMED"
+#define HQLERR_AlienUseData_Text                "More efficient to use a DATA field than this custom alien type"
 
 /* parser error */
 #define ERR_PARSER_CANNOTRECOVER    3005  /* The parser can not recover from previous error(s) */

+ 1 - 0
ecl/hql/hqlgram.hpp

@@ -450,6 +450,7 @@ public:
     void checkType(attribute &a1, ITypeInfo *t2);
     ITypeInfo *checkType(attribute &e1, attribute &e2);
     bool checkAlienTypeDef(IHqlScope* scope, const attribute& errpos);
+    void checkAlienType(const attribute &errpos, IHqlAlienTypeInfo * alien);
     IHqlExpression* checkServiceDef(IHqlScope* serviceScope,IIdAtom * name, IHqlExpression* attrs, const attribute& errpos);
     void checkConstant(attribute & attr, bool callAllowed);
     IHqlExpression * checkConstant(const attribute & errpos, IHqlExpression * expr, bool callAllowed);

+ 35 - 0
ecl/hql/hqlgram2.cpp

@@ -2643,6 +2643,40 @@ void HqlGram::checkDefaultValueVirtualAttr(const attribute &errpos, IHqlExpressi
     }
 }
 
+void HqlGram::checkAlienType(const attribute &errpos, IHqlAlienTypeInfo * alien)
+{
+    IHqlExpression * store = alien->queryStoreFunction();
+    assertex(store->isFunction());
+    ITypeInfo * type = store->queryType()->queryChildType();
+    if (!isUnknownSize(type))
+        return;
+
+    IHqlExpression * size = alien->queryLengthFunction();
+    if (size->isConstant())
+        return;
+
+    if (size->getOperator() == no_funcdef)
+        size = size->queryChild(0);
+    size = queryStripCasts(size);
+    if (size->getOperator() == no_select)
+    {
+        if (size->queryChild(0)->getOperator() == no_selfref)
+        {
+            IHqlExpression & topRecord = activeRecords.tos();
+            if (topRecord.numChildren())
+            {
+                IHqlExpression * lastField = topRecord.queryChild(topRecord.numChildren()-1);
+                if (lastField == size->queryChild(1))
+                {
+                    if (lastField->queryType()->getSize() == 4)
+                        reportWarning(CategoryDeprecated, HQLERR_AlienUseData, errpos.pos, HQLERR_AlienUseData_Text);
+                    return;
+                }
+            }
+        }
+    }
+}
+
 /* In parms: type, value: linked */
 void HqlGram::addField(const attribute &errpos, IIdAtom * name, ITypeInfo *_type, IHqlExpression * _value, IHqlExpression *attrs)
 {
@@ -2652,6 +2686,7 @@ void HqlGram::addField(const attribute &errpos, IIdAtom * name, ITypeInfo *_type
     if (expectedType->getTypeCode() == type_alien)
     {
         IHqlAlienTypeInfo * alien = queryAlienType(fieldType);
+        checkAlienType(errpos, alien);
         expectedType.setown(alien->getLogicalType());
     }