瀏覽代碼

Merge pull request #4290 from ghalliday/issue8914

HPCC-8914 Implemennt NOXPATH flag on OUTPUT

Reviewed-By: Richard Chapman <rchapman@hpccsystems.com>
Richard Chapman 12 年之前
父節點
當前提交
c0aa2aef14

+ 2 - 0
ecl/hql/hqlatoms.cpp

@@ -256,6 +256,7 @@ _ATOM notMatchedAtom;
 _ATOM notMatchedOnlyAtom;
 _ATOM noTrimAtom;
 _ATOM noTypeAtom;
+_ATOM noXpathAtom;
 _ATOM oldSetFormatAtom;
 _ATOM omethodAtom;
 _ATOM _omitted_Atom;
@@ -668,6 +669,7 @@ MODULE_INIT(INIT_PRIORITY_HQLATOM)
     notMatchedOnlyAtom = createLowerCaseAtom("NOT MATCHED ONLY");
     MAKEATOM(noTrim);
     MAKEATOM(noType);
+    MAKEATOM(noXpath);
     MAKEATOM(oldSetFormat);
     MAKEATOM(omethod);
     MAKESYSATOM(omitted);

+ 1 - 0
ecl/hql/hqlatoms.hpp

@@ -260,6 +260,7 @@ extern HQL_API _ATOM notMatchedOnlyAtom;
 extern HQL_API _ATOM _noStreaming_Atom;
 extern HQL_API _ATOM noTrimAtom;
 extern HQL_API _ATOM noTypeAtom;
+extern HQL_API _ATOM noXpathAtom;
 extern HQL_API _ATOM oldSetFormatAtom;
 extern HQL_API _ATOM omethodAtom;
 extern HQL_API _ATOM _omitted_Atom;

+ 9 - 0
ecl/hql/hqlgram.y

@@ -316,6 +316,7 @@ static void eclsyntaxerror(HqlGram * parser, const char * s, short yystate, int
   NOTHOR
   NOTIFY
   NOTRIM
+  NOXPATH
   OF
   OMITTED
   ONCE
@@ -3172,6 +3173,10 @@ outputFlag
                             $$.setExpr(createAttribute(workunitAtom));              // need a better keyword, but WORKUNIT is no good
                             $$.setPosition($1);
                         }
+    | NOXPATH           {
+                            $$.setExpr(createAttribute(noXpathAtom));
+                            $$.setPosition($1);
+                        }
     ;
 
 soapFlags
@@ -3421,6 +3426,10 @@ outputWuFlag
                             $$.setExpr(createComma(createAttribute(updateAtom), createAttribute(overwriteAtom)));
                             $$.setPosition($1);
                         }
+    | NOXPATH           {
+                            $$.setExpr(createAttribute(noXpathAtom));
+                            $$.setPosition($1);
+                        }
     | commonAttribute
     ;
 

+ 1 - 0
ecl/hql/hqlgram2.cpp

@@ -10215,6 +10215,7 @@ static void getTokenText(StringBuffer & msg, int token)
     case NOTHOR: msg.append("NOTHOR"); break;
     case NOTIFY: msg.append("NOTIFY"); break;
     case NOTRIM: msg.append("NOTRIM"); break;
+    case NOXPATH: msg.append("NOXPATH"); break;
     case OF: msg.append("OF"); break;
     case OMITTED: msg.append("OMITTED"); break;
     case ONCE: msg.append("ONCE"); break;

+ 1 - 0
ecl/hql/hqllex.l

@@ -811,6 +811,7 @@ __NOSTREAMING__     { RETURNSYM(__NOSTREAMING__); }
 NOTHOR              { RETURNSYM(NOTHOR); }
 NOTIFY              { RETURNSYM(NOTIFY); }
 NOTRIM              { RETURNSYM(NOTRIM); }
+NOXPATH             { RETURNSYM(NOXPATH); }
 OF                  { RETURNSYM(OF); }
 OMITTED             { RETURNSYM(OMITTED); }
 ONCE                { RETURNSYM(ONCE); }

+ 15 - 10
ecl/hqlcpp/hqlhtcpp.cpp

@@ -1779,7 +1779,10 @@ ActivityInstance::ActivityInstance(HqlCppTranslator & _translator, BuildCtx & ct
     if ((op == no_setgraphresult) && translator.queryOptions().minimizeActivityClasses)
         outputDataset = dataset->queryChild(0);
 
-    IHqlExpression * record = queryRecord(outputDataset);
+    bool removeXpath = dataset->hasProperty(noXpathAtom) || (op == no_output && translator.queryOptions().removeXpathFromOutput);
+    LinkedHqlExpr record = queryRecord(outputDataset);
+    if (removeXpath)
+        record.setown(removePropertyFromFields(record, xpathAtom));
     meta.setMeta(translator, record, ::isGrouped(outputDataset));
 
     activityId = translator.nextActivityId();
@@ -10313,7 +10316,9 @@ ABoundActivity * HqlCppTranslator::doBuildActivityOutput(BuildCtx & ctx, IHqlExp
             }
         }
 
-        Owned<IWUResult> result = createDatasetResultSchema(seq, queryResultName(expr), dataset->queryRecord(), (kind != TAKcsvwrite) && (kind != TAKxmlwrite), true);
+        IHqlExpression * outputRecord = instance->meta.queryRecord();
+        OwnedHqlExpr outputDs = createDataset(no_null, LINK(outputRecord));
+        Owned<IWUResult> result = createDatasetResultSchema(seq, queryResultName(expr), outputRecord, (kind != TAKcsvwrite) && (kind != TAKxmlwrite), true);
         if (expr->hasProperty(resultAtom))
             result->setResultRowLimit(-1);
 
@@ -10327,9 +10332,9 @@ ABoundActivity * HqlCppTranslator::doBuildActivityOutput(BuildCtx & ctx, IHqlExp
 
         //Both csv write and pipe with csv/xml format
         if (csvAttr)
-            buildCsvWriteMembers(instance, dataset, csvAttr);
+            buildCsvWriteMembers(instance, outputDs, csvAttr);
         if (xmlAttr)
-            buildXmlWriteMembers(instance, dataset, xmlAttr);
+            buildXmlWriteMembers(instance, outputDs, xmlAttr);
 
         buildEncryptHelper(instance->startctx, expr->queryProperty(encryptAtom));
     }
@@ -10891,17 +10896,17 @@ ABoundActivity * HqlCppTranslator::doBuildActivityOutputWorkunit(BuildCtx & ctx,
             buildReturn(namectx, name, constUnknownVarStringType);
         }
 
-        LinkedHqlExpr cleanedRecord = record;
-        if (options.removeXpathFromOutput)
-            cleanedRecord.setown(removePropertyFromFields(cleanedRecord, xpathAtom));
-
-        Owned<IWUResult> result = createDatasetResultSchema(seq, name, cleanedRecord, true, false);
+        IHqlExpression * outputRecord = instance->meta.queryRecord();
+        Owned<IWUResult> result = createDatasetResultSchema(seq, name, outputRecord, true, false);
         if (result)
         {
             result->setResultRowLimit(-1);
 
             if (sequence >= 0)
-                buildXmlSerialize(instance->startctx, dataset, "serializeXml", false);
+            {
+                OwnedHqlExpr outputDs = createDataset(no_null, LINK(outputRecord));
+                buildXmlSerialize(instance->startctx, outputDs, "serializeXml", false);
+            }
         }
 
         if (flags.length())

+ 37 - 0
ecl/regress/issue8914.ecl

@@ -0,0 +1,37 @@
+/*##############################################################################
+
+    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.
+############################################################################## */
+
+namesRecord :=
+            RECORD
+string20        surname{xpath('SURnamE')};
+string10        forename{xpath('fOrEnAmE')};
+integer2        age{xpath('_age_')} := 25;
+            END;
+
+namesTable := dataset([
+        {'Hawthorn','Gavin',31},
+        {'Hawthorn','Mia',30},
+        {'Smithe','Pru',10},
+        {'X','Z'}], namesRecord);
+
+output(namesTable,,XML,NOXPATH);
+
+output(namesTable,,'out.xml',XML,NOXPATH);
+
+output(namesTable,,'out.raw',NOXPATH);
+
+output(namesTable,,'out.csv',CSV,NOXPATH);

+ 39 - 0
ecl/regress/issue8914b.ecl

@@ -0,0 +1,39 @@
+/*##############################################################################
+
+    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.
+############################################################################## */
+
+#option ('removeXpathFromOutput', true);
+
+namesRecord :=
+            RECORD
+string20        surname{xpath('SURnamE')};
+string10        forename{xpath('fOrEnAmE')};
+integer2        age{xpath('_age_')} := 25;
+            END;
+
+namesTable := dataset([
+        {'Hawthorn','Gavin',31},
+        {'Hawthorn','Mia',30},
+        {'Smithe','Pru',10},
+        {'X','Z'}], namesRecord);
+
+output(namesTable,,XML);
+
+output(namesTable,,'out.xml',XML);
+
+output(namesTable,,'out.raw');
+
+output(namesTable,,'out.csv',CSV);

+ 32 - 0
testing/ecl/issue8914.ecl

@@ -0,0 +1,32 @@
+/*##############################################################################
+
+    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.
+############################################################################## */
+
+namesRecord :=
+            RECORD
+string20        surname{xpath('SURnamE')};
+string10        forename{xpath('fOrEnAmE')};
+integer2        age{xpath('_age_')} := 25;
+            END;
+
+namesTable := dataset([
+        {'Hawthorn','Gavin',31},
+        {'Hawthorn','Mia',30},
+        {'Smithe','Pru',10},
+        {'X','Z'}], namesRecord);
+
+output(namesTable,,XML,NOXPATH);
+

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

@@ -0,0 +1,6 @@
+<Dataset name='Result 1'>
+ <Row><surname>Hawthorn            </surname><forename>Gavin     </forename><age>31</age></Row>
+ <Row><surname>Hawthorn            </surname><forename>Mia       </forename><age>30</age></Row>
+ <Row><surname>Smithe              </surname><forename>Pru       </forename><age>10</age></Row>
+ <Row><surname>X                   </surname><forename>Z         </forename><age>25</age></Row>
+</Dataset>