William Candillon has proposed merging lp:~zorba-coders/zorba/compile_queryplan 
into lp:zorba.

Requested reviews:
  Matthias Brantner (matthias-brantner)

For more details, see:
https://code.launchpad.net/~zorba-coders/zorba/compile_queryplan/+merge/93694

Add --compile-plan and --execute-plan option to zorba command line.
Example:
zorba -q 1+1 --compile-plan > test.xqc
zorba -q test.xqc -f --execute-plan
-- 
https://code.launchpad.net/~zorba-coders/zorba/compile_queryplan/+merge/93694
Your team Zorba Coders is subscribed to branch lp:zorba.
=== modified file 'bin/zorbacmd.cpp'
--- bin/zorbacmd.cpp	2012-01-12 14:21:09 +0000
+++ bin/zorbacmd.cpp	2012-02-18 14:47:20 +0000
@@ -38,6 +38,7 @@
 #include <zorba/iterator.h>
 #include <zorba/xquery_functions.h>
 #include <zorba/uri_resolvers.h>
+#include <zorba/serialization_callback.h>
 
 #include <zorba/store_manager.h>
 
@@ -72,6 +73,24 @@
 OneToOneURIMapper theStopWordsMapper(EntityData::STOP_WORDS);
 OneToOneURIMapper theThesaurusMapper(EntityData::THESAURUS);
 #endif
+class URIMapperSerializationCallback : public SerializationCallback
+{
+  private:
+    std::vector<URIMapper*> theURIMappers;
+
+  public:
+    void addURIMapper(URIMapper* lURIMapper)
+    {
+      theURIMappers.push_back(lURIMapper);
+    }
+
+    virtual URIMapper*
+    getURIMapper(size_t i) const
+    {   
+      return theURIMappers[i];
+    }   
+};
+URIMapperSerializationCallback theSerializationCallback;
 
 bool
 populateStaticContext(
@@ -149,7 +168,11 @@
     for (; lIter != end; ++lIter) {
       theStopWordsMapper.addMapping(lIter->uri, lIter->value);
     }
-    aStaticContext->registerURIMapper(&theStopWordsMapper);
+    if(aProperties.executePlan()) {
+      theSerializationCallback.addURIMapper(&theStopWordsMapper);
+    } else {
+      aStaticContext->registerURIMapper(&theStopWordsMapper);
+    }
   }
   {
     ZorbaCMDProperties::FullText_t::const_iterator lIter = aProperties.thesaurusBegin();
@@ -157,7 +180,11 @@
     for (; lIter != end; ++lIter) {
       theThesaurusMapper.addMapping(lIter->uri, lIter->value);
     }
-    aStaticContext->registerURIMapper(&theThesaurusMapper);
+    if(aProperties.executePlan()) {
+      theSerializationCallback.addURIMapper(&theStopWordsMapper);
+    } else {
+      aStaticContext->registerURIMapper(&theThesaurusMapper);
+    }
   }
 #endif
   return true;
@@ -503,7 +530,9 @@
   unsigned long lNumExecutions = properties.multiple();
   bool lIndent = properties.indent();
   bool doTiming = properties.timing();
-
+  bool compilePlan = properties.compilePlan();
+  bool executePlan = properties.executePlan();
+  std::ostringstream lOut;
   Zorba_CompilerHints lHints;
 
   // default is O1 in the Zorba_CompilerHints constructor
@@ -568,7 +597,11 @@
         query->registerDiagnosticHandler(&diagnosticHandler);
         query->setFileName(qfilepath);
 
-        query->compile(qfile, staticContext, lHints);
+        if(executePlan) {
+          query->loadExecutionPlan(qfile, &theSerializationCallback);
+        } else {
+          query->compile(qfile, staticContext, lHints);
+        }
 
         if (doTiming)
         {
@@ -631,7 +664,11 @@
         }
         else
         {
-          query->execute(outputStream, &lSerOptions);
+          if (compilePlan) {
+            query->saveExecutionPlan(outputStream, ZORBA_USE_BINARY_ARCHIVE, SAVE_UNUSED_FUNCTIONS);
+          } else {
+            query->execute(outputStream, &lSerOptions);
+          }
           if (properties.trailingNl()) {
             outputStream << std::endl;
           }

=== modified file 'bin/zorbacmdproperties.txt'
--- bin/zorbacmdproperties.txt	2011-10-21 08:07:43 +0000
+++ bin/zorbacmdproperties.txt	2012-02-18 14:47:20 +0000
@@ -35,3 +35,5 @@
 ("trailing-nl", "Output a trailing newline after the result of the query.")
 ("stop-words", po::value<std::vector<std::string> >(), "Mapping specifying a stop-words URI to another.")
 ("thesaurus", po::value<std::vector<std::string> >(), "Mapping specifying a thesaurus URI to another.")
+("compile-plan,c", "Compile query plan.")
+("execute-plan,e", "Execute query plan.")

=== modified file 'bin/zorbacmdproperties_base.h'
--- bin/zorbacmdproperties_base.h	2011-10-21 08:07:43 +0000
+++ bin/zorbacmdproperties_base.h	2012-02-18 14:47:20 +0000
@@ -34,7 +34,7 @@
 class ZorbaCMDPropertiesBase : public ::zorba::PropertiesBase {
 protected:
   const char **get_all_options () const {
-    static const char *result [] = { "--timing", "--output-file", "--serialization-parameter", "--serialize-html", "--serialize-text", "--indent", "--print-query", "--print-errors-as-xml", "--byte-order-mark", "--omit-xml-declaration", "--base-uri", "--boundary-space", "--default-collation", "--construction-mode", "--ordering-mode", "--multiple", "--query", "--as-files", "--external-variable", "--context-item", "--optimization-level", "--lib-module", "--parse-only", "--compile-only", "--no-serializer", "--debug", "--debug-host", "--debug-port", "--no-logo", "--timeout", "--uri-path", "--lib-path", "--module-path", "--option", "--trailing-nl", "--stop-words", "--thesaurus", NULL };
+    static const char *result [] = { "--timing", "--output-file", "--serialization-parameter", "--serialize-html", "--serialize-text", "--indent", "--print-query", "--print-errors-as-xml", "--byte-order-mark", "--omit-xml-declaration", "--base-uri", "--boundary-space", "--default-collation", "--construction-mode", "--ordering-mode", "--multiple", "--query", "--as-files", "--external-variable", "--context-item", "--optimization-level", "--lib-module", "--parse-only", "--compile-only", "--no-serializer", "--debug", "--debug-host", "--debug-port", "--no-logo", "--timeout", "--uri-path", "--lib-path", "--module-path", "--option", "--trailing-nl", "--stop-words", "--thesaurus", "--compile-plan", "--execute-plan", NULL };
     return result;
   }
   bool theTiming;
@@ -74,6 +74,8 @@
   bool theTrailingNl;
   std::vector<std::string> theStopWords;
   std::vector<std::string> theThesaurus;
+  bool theCompilePlan;
+  bool theExecutePlan;
 
   void initialize () {
     theTiming = false;
@@ -97,6 +99,8 @@
     theNoLogo = false;
     theTimeout = -1;
     theTrailingNl = false;
+    theCompilePlan = false;
+    theExecutePlan = false;
   }
 public:
   const bool &timing () const { return theTiming; }
@@ -136,6 +140,8 @@
   const bool &trailingNl () const { return theTrailingNl; }
   const std::vector<std::string> &stopWords () const { return theStopWords; }
   const std::vector<std::string> &thesaurus () const { return theThesaurus; }
+  const bool &compilePlan () const { return theCompilePlan; }
+  const bool &executePlan () const { return theExecutePlan; }
 
   std::string load_argv (int argc, const char **argv) {
     if (argv == NULL) return "";
@@ -299,6 +305,12 @@
         if ((*argv) [1] == '-' || (*argv) [2] == '\0') { d = 0; ++argv; }
         if (*argv == NULL) { result = "No value given for --thesaurus option"; break; }        init_val (*argv, theThesaurus, d);
       }
+      else if (strcmp (*argv, "--compile-plan") == 0 || strncmp (*argv, "-c", 2) == 0) {
+        theCompilePlan = true;
+      }
+      else if (strcmp (*argv, "--execute-plan") == 0 || strncmp (*argv, "-e", 2) == 0) {
+        theExecutePlan = true;
+      }
       else if (strcmp (*argv, "--") == 0) {
         copy_args (++argv);
         break;
@@ -352,6 +364,8 @@
 "--trailing-nl\nOutput a trailing newline after the result of the query.\n\n"
 "--stop-words\nMapping specifying a stop-words URI to another.\n\n"
 "--thesaurus\nMapping specifying a thesaurus URI to another.\n\n"
+"--compile-plan, -c\nCompile query plan.\n\n"
+"--execute-plan, -e\nExecute query plan.\n\n"
 ;
   }
 

=== modified file 'src/store/naive/store_properties.h'
--- src/store/naive/store_properties.h	2012-01-14 22:52:27 +0000
+++ src/store/naive/store_properties.h	2012-02-18 14:47:20 +0000
@@ -30,65 +30,47 @@
 
 #ifndef ZORBA_STORE_STOREPROPERTIES
 #define ZORBA_STORE_STOREPROPERTIES
-namespace zorba 
-{ 
-namespace store 
-{
-
- 
-class StoreProperties : public ::zorba::PropertiesBase 
-{
+namespace zorba { namespace store { 
+class StoreProperties : public ::zorba::PropertiesBase {
 protected:
-  const char** get_all_options() const 
-  {
+  const char **get_all_options () const {
     static const char *result [] = { "--build-dataguide", "--store-trace-level", NULL };
     return result;
   }
-
   bool theBuildDataguide;
   long theStoreTraceLevel;
 
-  void initialize () 
-  {
+  void initialize () {
     theBuildDataguide = false;
     theStoreTraceLevel = 0;
   }
 public:
-  const bool& buildDataguide() const { return theBuildDataguide; }
-  const long& storeTraceLevel() const { return theStoreTraceLevel; }
+  const bool &buildDataguide () const { return theBuildDataguide; }
+  const long &storeTraceLevel () const { return theStoreTraceLevel; }
 
-  std::string load_argv(int argc, const char **argv) 
-  {
+  std::string load_argv (int argc, const char **argv) {
     if (argv == NULL) return "";
 
     std::string result;
-    for (++argv; *argv != NULL; ++argv) 
-    {
+    for (++argv; *argv != NULL; ++argv) {
       if (strcmp (*argv, "--help") == 0 || strcmp (*argv, "-h") == 0)
         return "!HELP";
       else if (strcmp (*argv, "--version") == 0)
         return "!VER";
-      else if (strcmp (*argv, "--build-dataguide") == 0) 
-      {
+      else if (strcmp (*argv, "--build-dataguide") == 0) {
         theBuildDataguide = true;
       }
-      else if (strcmp (*argv, "--store-trace-level") == 0) 
-      {
+      else if (strcmp (*argv, "--store-trace-level") == 0) {
         int d = 2;
         if ((*argv) [1] == '-' || (*argv) [2] == '\0') { d = 0; ++argv; }
         if (*argv == NULL) { result = "No value given for --store-trace-level option"; break; }        init_val (*argv, theStoreTraceLevel, d);
       }
-      else if (strcmp (*argv, "--") == 0) 
-      {
+      else if (strcmp (*argv, "--") == 0) {
         copy_args (++argv);
         break;
-      }
-      else if ((*argv) [0] == '-') 
-      {
+      } else if ((*argv) [0] == '-') {
         result = "unknown command line option "; result += *argv; break; 
-      }
-      else
-      {
+      } else {
         copy_args (argv);
         break;
       }
@@ -97,21 +79,20 @@
     return result;
   }
 
-  const char* get_help_msg () const 
-  {
+  const char *get_help_msg () const {
     return
 "--build-dataguide\nbuild-dataguide (true/false)\n\n"
 "--store-trace-level\nstore trace level (<= 0 : no tracing)\n\n"
 ;
   }
 
-  static const StoreProperties* instance() 
-  {
+  static const StoreProperties *instance () {
     static StoreProperties result;
     return &result;
   }
 
-  StoreProperties() { initialize(); }
+  StoreProperties () { initialize (); }
+  
 };
 
 } }   // namespaces

=== modified file 'src/system/zorba_properties.h'
--- src/system/zorba_properties.h	2012-01-11 17:30:25 +0000
+++ src/system/zorba_properties.h	2012-02-18 14:47:20 +0000
@@ -30,20 +30,13 @@
 
 #ifndef ZORBA_ZORBAPROPERTIES
 #define ZORBA_ZORBAPROPERTIES
-namespace zorba 
-{ 
-
-class ZORBA_DLL_PUBLIC ZorbaProperties : public ::zorba::PropertiesBase 
-{
+namespace zorba { 
+class ZORBA_DLL_PUBLIC ZorbaProperties : public ::zorba::PropertiesBase {
 protected:
-  const char** get_all_options() const 
-  {
-    static const char* result [] = 
-      { "--trace-parsing", "--trace-scanning", "--use-serializer", "--optimizer", "--result-file", "--debug-file", "--abort", "--query", "--print-query", "--print-time", "--print-ast", "--print-xqdoc", "--print-translated", "--print-normalized", "--print-optimized", "--print-iterator-tree", "--print-item-flow", "--print-static-types", "--dump-lib", "--stable-iterator-ids", "--no-tree-ids", "--print-intermediate-opt", "--print-locations", "--force-gflwor", "--reorder-globals", "--specialize-num", "--specialize-cmp", "--inline-udf", "--loop-hoisting", "--infer-joins", "--no-copy-optim", "--serialize-only-query", "--trace-translator", "--trace-codegen", "--trace-fulltext", "--debug", "--compile-only", "--tz", "--external-var", "--serializer-param", "--iter-plan-test", "--dot-plan-file", "--max-udf-call-depth", NULL };
-
+  const char **get_all_options () const {
+    static const char *result [] = { "--trace-parsing", "--trace-scanning", "--use-serializer", "--optimizer", "--result-file", "--debug-file", "--abort", "--query", "--print-query", "--print-time", "--print-ast", "--print-xqdoc", "--print-translated", "--print-normalized", "--print-optimized", "--print-iterator-tree", "--print-item-flow", "--print-static-types", "--dump-lib", "--stable-iterator-ids", "--no-tree-ids", "--print-intermediate-opt", "--print-locations", "--force-gflwor", "--reorder-globals", "--specialize-num", "--specialize-cmp", "--inline-udf", "--loop-hoisting", "--infer-joins", "--no-copy-optim", "--serialize-only-query", "--trace-translator", "--trace-codegen", "--trace-fulltext", "--debug", "--compile-only", "--tz", "--external-var", "--serializer-param", "--iter-plan-test", "--dot-plan-file", "--max-udf-call-depth", NULL };
     return result;
   }
-
   bool theTraceParsing;
   bool theTraceScanning;
   bool theUseSerializer;
@@ -75,7 +68,7 @@
   bool theLoopHoisting;
   bool theInferJoins;
   bool theNoCopyOptim;
-  int theSerializeOnlyQuery;
+  bool theSerializeOnlyQuery;
   bool theTraceTranslator;
   bool theTraceCodegen;
   bool theTraceFulltext;
@@ -88,8 +81,7 @@
   std::string theDotPlanFile;
   uint32_t theMaxUdfCallDepth;
 
-  void initialize() 
-  {
+  void initialize () {
     theTraceParsing = false;
     theTraceScanning = false;
     theUseSerializer = false;
@@ -118,7 +110,7 @@
     theLoopHoisting = true;
     theInferJoins = true;
     theNoCopyOptim = true;
-    theSerializeOnlyQuery = -1;
+    theSerializeOnlyQuery = false;
     theTraceTranslator = false;
     theTraceCodegen = false;
     theTraceFulltext = false;
@@ -127,7 +119,6 @@
     theIterPlanTest = false;
     theMaxUdfCallDepth = 1024;
   }
-
 public:
   const bool &traceParsing () const { return theTraceParsing; }
   const bool &traceScanning () const { return theTraceScanning; }
@@ -159,8 +150,8 @@
   const bool &inlineUdf () const { return theInlineUdf; }
   const bool &loopHoisting () const { return theLoopHoisting; }
   const bool &inferJoins () const { return theInferJoins; }
-  const bool &noCopyOptim() const { return theNoCopyOptim; }
-  const int& serializeOnlyQuery() const { return theSerializeOnlyQuery; }
+  const bool &noCopyOptim () const { return theNoCopyOptim; }
+  const bool &serializeOnlyQuery () const { return theSerializeOnlyQuery; }
   const bool &traceTranslator () const { return theTraceTranslator; }
   const bool &traceCodegen () const { return theTraceCodegen; }
   const bool &traceFulltext () const { return theTraceFulltext; }
@@ -173,8 +164,7 @@
   const std::string &dotPlanFile () const { return theDotPlanFile; }
   const uint32_t &maxUdfCallDepth () const { return theMaxUdfCallDepth; }
 
-  std::string load_argv (int argc, const char **argv) 
-  {
+  std::string load_argv (int argc, const char **argv) {
     if (argv == NULL) return "";
 
     std::string result;
@@ -195,14 +185,12 @@
       else if (strcmp (*argv, "--optimizer") == 0 || strncmp (*argv, "-O", 2) == 0) {
         int d = 2;
         if ((*argv) [1] == '-' || (*argv) [2] == '\0') { d = 0; ++argv; }
-        if (*argv == NULL) { result = "No value given for --optimizer option"; break; }
-        init_val (*argv, theOptimizer, d);
+        if (*argv == NULL) { result = "No value given for --optimizer option"; break; }        init_val (*argv, theOptimizer, d);
       }
       else if (strcmp (*argv, "--result-file") == 0 || strncmp (*argv, "-o", 2) == 0) {
         int d = 2;
         if ((*argv) [1] == '-' || (*argv) [2] == '\0') { d = 0; ++argv; }
-        if (*argv == NULL) { result = "No value given for --result-file option"; break; }
-        init_val (*argv, theResultFile, d);
+        if (*argv == NULL) { result = "No value given for --result-file option"; break; }        init_val (*argv, theResultFile, d);
       }
       else if (strcmp (*argv, "--debug-file") == 0) {
         int d = 2;
@@ -297,20 +285,15 @@
         if ((*argv) [1] == '-' || (*argv) [2] == '\0') { d = 0; ++argv; }
         if (*argv == NULL) { result = "No value given for --infer-joins option"; break; }        init_val (*argv, theInferJoins, d);
       }
-      else if (strcmp (*argv, "--no-copy-optim") == 0)
-      {
+      else if (strcmp (*argv, "--no-copy-optim") == 0) {
         int d = 2;
         if ((*argv) [1] == '-' || (*argv) [2] == '\0') { d = 0; ++argv; }
-        if (*argv == NULL) { result = "No value given for --no-copy-optim option"; break; }
-        init_val (*argv, theNoCopyOptim, d);
+        if (*argv == NULL) { result = "No value given for --no-copy-optim option"; break; }        init_val (*argv, theNoCopyOptim, d);
       }
-      else if (strcmp (*argv, "--serialize-only-query") == 0)
-      {
+      else if (strcmp (*argv, "--serialize-only-query") == 0) {
         int d = 2;
         if ((*argv) [1] == '-' || (*argv) [2] == '\0') { d = 0; ++argv; }
-        if (*argv == NULL)
-        { result = "No value given for --serialize-only-query option"; break; }
-        init_val(*argv, theSerializeOnlyQuery, d);
+        if (*argv == NULL) { result = "No value given for --serialize-only-query option"; break; }        init_val (*argv, theSerializeOnlyQuery, d);
       }
 #ifndef NDEBUG
       else if (strcmp (*argv, "--trace-translator") == 0 || strncmp (*argv, "-l", 2) == 0) {
@@ -371,9 +354,7 @@
     return result;
   }
 
-
-  const char* get_help_msg() const 
-  {
+  const char *get_help_msg () const {
     return
 "--trace-parsing, -p\ntrace parsing\n\n"
 "--trace-scanning, -s\ntrace scanning\n\n"
@@ -405,8 +386,8 @@
 "--inline-udf\ninline functions (1=enabled (default), 0=off)\n\n"
 "--loop-hoisting\nhoist expressions out of loops (1=enabled (default), 0=off)\n\n"
 "--infer-joins\ninfer joins (1=enabled (default), 0=off)\n\n"
-"--no-copy-optim\napply the no-copy optimization (1=enabled (default), 0=off)\n\n"
-"--serialize-only-query\nserialize-only-query (<0=unknown (default), 1=enabled, 0=off)\n\n"
+"--no-copy-optim\nno copy optim (1=enabled (default), 0=off)\n\n"
+"--serialize-only-query\nserialize-only query (1=true, 0=false (default))\n\n"
 #ifndef NDEBUG
 "--trace-translator, -l\ntrace the translator\n\n"
 "--trace-codegen, -c\ntrace the codegenerator\n\n"
@@ -423,16 +404,15 @@
 ;
   }
 
-  static const ZorbaProperties* instance() 
-  {
+  static const ZorbaProperties *instance () {
     static ZorbaProperties result;
     return &result;
   }
 
-  ZorbaProperties() { initialize (); }
+  ZorbaProperties () { initialize (); }
+  
 };
 
-
 }   // namespaces
 
 #endif // ZORBA_ZORBAPROPERTIES

-- 
Mailing list: https://launchpad.net/~zorba-coders
Post to     : zorba-coders@lists.launchpad.net
Unsubscribe : https://launchpad.net/~zorba-coders
More help   : https://help.launchpad.net/ListHelp

Reply via email to