← Back to team overview

zorba-coders team mailing list archive

[Merge] lp:~zorba-coders/zorba/markos-scratch into lp:zorba

 

Markos Zaharioudakis has proposed merging lp:~zorba-coders/zorba/markos-scratch into lp:zorba.

Requested reviews:
  Markos Zaharioudakis (markos-za)

For more details, see:
https://code.launchpad.net/~zorba-coders/zorba/markos-scratch/+merge/103438

put back --compile-plan and --execute-plan options
-- 
https://code.launchpad.net/~zorba-coders/zorba/markos-scratch/+merge/103438
Your team Zorba Coders is subscribed to branch lp:zorba.
=== modified file 'bin/zorbacmd.cpp'
--- bin/zorbacmd.cpp	2012-04-24 12:39:38 +0000
+++ bin/zorbacmd.cpp	2012-04-25 10:13:21 +0000
@@ -177,7 +177,7 @@
       theStopWordsMapper.addMapping(lIter->uri, lIter->value);
     }
 
-    if (props.serializePlan()) 
+    if (props.serializePlan() || props.loadPlan()) 
     {
       theSerializationCallback.addURIMapper(&theStopWordsMapper);
     }
@@ -195,7 +195,7 @@
       theThesaurusMapper.addMapping(lIter->uri, lIter->value);
     }
 
-    if (props.serializePlan()) 
+    if (props.serializePlan() || props.loadPlan())
     {
       theSerializationCallback.addURIMapper(&theStopWordsMapper);
     }
@@ -551,6 +551,8 @@
   bool lIndent = properties.indent();
   bool doTiming = properties.timing();
   bool serializePlan = properties.serializePlan();
+  bool savePlan = properties.savePlan();
+  bool loadPlan = properties.loadPlan();
   std::ostringstream lOut;
   Zorba_CompilerHints lHints;
 
@@ -559,6 +561,12 @@
 
   if (serializePlan)
   {
+    if (savePlan || loadPlan)
+    {
+      std::cerr << "The --serialize-plan option cannot be used together with the --compile-plan or --execute-plan options" << std::endl;
+      exit(1);
+    }
+
     std::string planFilePath = qfilepath;
     planFilePath += ".plan";
     planFile.reset(new std::fstream(planFilePath.c_str(), 
@@ -570,6 +578,12 @@
     assert(planFilep->good());
   }
 
+  if (savePlan && loadPlan)
+  {
+    std::cerr << "The --compile-plan and --execute-plan options cannot be used together" << std::endl;
+    exit(1);
+  }
+
   // default is O1 in the Zorba_CompilerHints constructor
   if (properties.optimizationLevel() == "O0") 
   {
@@ -629,17 +643,24 @@
         query->registerDiagnosticHandler(&diagnosticHandler);
         query->setFileName(qfilepath);
 
-        query->compile(qfile, staticContext, lHints);
-
-        // Serialize the execution plan, if requested
-        if (serializePlan) 
-        {
-          planFilep->clear();
-          planFilep->seekp(0);
-
-          query->saveExecutionPlan(*planFilep, ZORBA_USE_BINARY_ARCHIVE);
-
-          planFilep->flush();
+        if (loadPlan) 
+        {
+          query->loadExecutionPlan(qfile, &theSerializationCallback);
+        }
+        else
+        {
+          query->compile(qfile, staticContext, lHints);
+
+          // Serialize the execution plan, if requested
+          if (serializePlan) 
+          {
+            planFilep->clear();
+            planFilep->seekp(0);
+
+            query->saveExecutionPlan(*planFilep, ZORBA_USE_BINARY_ARCHIVE);
+
+            planFilep->flush();
+          }
         }
 
         // stop the compilation timer
@@ -705,6 +726,12 @@
         {
           query->executeSAX();
         }
+        else if (savePlan)
+        {
+          query->saveExecutionPlan(outputStream,
+                                   ZORBA_USE_BINARY_ARCHIVE,
+                                   SAVE_UNUSED_FUNCTIONS);
+        }
         else
         {
           query->execute(outputStream, &lSerOptions);

=== modified file 'bin/zorbacmdproperties_base.h'
--- bin/zorbacmdproperties_base.h	2012-04-24 12:39:38 +0000
+++ bin/zorbacmdproperties_base.h	2012-04-25 10:13:21 +0000
@@ -29,9 +29,9 @@
 class ZorbaCMDPropertiesBase : public ::zorba::PropertiesBase
 {
 protected:
-  const char **get_all_options () const
+  const char** get_all_options () const
   {
-    static const char *result [] = {
+    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",
@@ -42,7 +42,7 @@
       "--no-serializer", "--debug", "--debug-host", "--debug-port", "--no-logo",
       "--timeout", "--uri-path", "--lib-path", "--module-path", "--classpath",
       "--option", "--trailing-nl", "--stop-words", "--thesaurus",
-      "--compile-plan", "--execute-plan", NULL };
+      "--compile-plan", "--execute-plan --serialize-plan", NULL };
     return result;
   }
 
@@ -85,6 +85,8 @@
   std::vector<std::string> theStopWords;
   std::vector<std::string> theThesaurus;
   bool theSerializePlan;
+  bool theSavePlan;
+  bool theLoadPlan;
 
   void initialize () 
   {
@@ -110,6 +112,8 @@
     theTimeout = -1;
     theTrailingNl = false;
     theSerializePlan = false;
+    theSavePlan = false;
+    theLoadPlan = false;
   }
 
 public:
@@ -152,6 +156,8 @@
   const std::vector<std::string> &stopWords () const { return theStopWords; }
   const std::vector<std::string> &thesaurus () const { return theThesaurus; }
   const bool& serializePlan () const { return theSerializePlan; }
+  const bool& loadPlan () const { return theLoadPlan; }
+  const bool& savePlan () const { return theSavePlan; }
 
   std::string load_argv (int argc, const char **argv) 
   {
@@ -412,6 +418,14 @@
       {
         theSerializePlan = true;
       }
+      else if (strcmp (*argv, "--compile-plan") == 0)
+      {
+        theSavePlan = true;
+      }
+      else if (strcmp (*argv, "--execute-plan") == 0)
+      {
+        theLoadPlan = true;
+      }
       else if (strcmp (*argv, "--") == 0)
       {
         copy_args (++argv);
@@ -472,7 +486,9 @@
         "--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"
-        "--serialize-plan, -cs\nSerialize and then load the query execution plan.\n\n"
+        "--serialize-plan, -s\nSerialize and then load the query execution plan.\n\n"
+        "--compile-plan,\nDo not execute the query; just compile it and save the execution plan in the file specified with the -o option.\n\n"
+        "--execute-plan\nDo not compile the query; instead load the execution plan from the file specified by the -f -q options, and execute the loaded plan.\n\n"
         ;
   }
 


Follow ups