summaryrefslogtreecommitdiffstats
path: root/qlparser/test
diff options
context:
space:
mode:
Diffstat (limited to 'qlparser/test')
-rw-r--r--qlparser/test/Makefile89
-rw-r--r--qlparser/test/insertbin.cpp316
-rw-r--r--qlparser/test/template_inst.hh152
-rw-r--r--qlparser/test/test_evaluate.cc338
-rw-r--r--qlparser/test/test_qlparser.cc205
5 files changed, 1100 insertions, 0 deletions
diff --git a/qlparser/test/Makefile b/qlparser/test/Makefile
new file mode 100644
index 0000000..fbf0bff
--- /dev/null
+++ b/qlparser/test/Makefile
@@ -0,0 +1,89 @@
+# -*-Makefile-*-
+#
+# This file is part of rasdaman community.
+#
+# Rasdaman community is free software: you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation, either version 3 of the License, or
+# (at your option) any later version.
+#
+# Rasdaman community is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with rasdaman community. If not, see <http://www.gnu.org/licenses/>.
+#
+# Copyright 2003, 2004, 2005, 2006, 2007, 2008, 2009 Peter Baumann /
+# rasdaman GmbH.
+#
+# For more information please see <http://www.rasdaman.org>
+# or contact Peter Baumann via <baumann@rasdaman.com>. # Top Level makefile. This points to the various modules that have to be build
+# and/or deployed
+#
+# MAKEFILE FOR:
+# test programs of module qlparser
+#
+# COMMENTS:
+#
+##################################################################
+#
+# This is just an example Makefile for a test program.
+# The dependency of the test program on the lib of the
+# corresponding module is in the Makefile of the module.
+#
+
+######################### Definitions ############################
+
+# all test programs
+SRCCXX = test_qlparser.cc test_evaluate.cc
+OBJS = ${SRCCXX:%.cc=%.o}
+ALLTESTS = ${SRCCXX:%.cc=%}
+MISCCLEAN := core
+
+# add compile and link options for STL
+CXXFLAGS += $(STLCXXFLAGS)
+LDFLAGS += $(STLLDFLAGS)
+
+########################### Targets ##############################
+
+# test target for qlparser
+.PHONY : qlparser
+qlparser: test_module test_qlparser
+
+.PHONY : evaluate
+evaluate: test_module test_evaluate
+
+.PHONY : test_module
+test_module:
+ cd $(RMANBASE)/qlparser; $(MAKE)
+
+test_evaluate: test_evaluate.o $(QLPARSER) \
+ $(RASLIB) \
+ $(CACHETAMGR) \
+ $(MDDIF) \
+ $(CATALOGIF) \
+ $(INDEXIF) \
+ $(INDEXMGR) \
+ $(BLOBIF) \
+ $(ADMINIF) \
+ $(CONVERSION)
+ $(PURIFY) $(CXX) $(LDFLAGS) $(BASEDBLDFLAGS) -o $@ $^
+
+
+test_qlparser: $(QLPARSER) test_qlparser.o $(RMANHOME)/qlparser/*.o \
+ $(QLPARSER) \
+ $(RMANHOME)/lib/librasodmg.a \
+ $(RASLIB) \
+ $(CACHETAMGR) \
+ $(MDDIF) \
+ $(CATALOGIF) \
+ $(INDEXIF) \
+ $(INDEXMGR) \
+ $(BLOBIF) \
+ $(ADMINIF) \
+ $(CONVERSION) \
+ $(RMANHOME)/rasdl/symbtbl.o
+ $(PURIFY) $(CXX) $(LDFLAGS) $(BASEDBLDFLAGS) -o $@ $^
+
diff --git a/qlparser/test/insertbin.cpp b/qlparser/test/insertbin.cpp
new file mode 100644
index 0000000..7779472
--- /dev/null
+++ b/qlparser/test/insertbin.cpp
@@ -0,0 +1,316 @@
+/*
+* This file is part of rasdaman community.
+*
+* Rasdaman community is free software: you can redistribute it and/or modify
+* it under the terms of the GNU General Public License as published by
+* the Free Software Foundation, either version 3 of the License, or
+* (at your option) any later version.
+*
+* Rasdaman community is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+* GNU General Public License for more details.
+*
+* You should have received a copy of the GNU General Public License
+* along with rasdaman community. If not, see <http://www.gnu.org/licenses/>.
+*
+* Copyright 2003, 2004, 2005, 2006, 2007, 2008, 2009 Peter Baumann /
+rasdaman GmbH.
+*
+* For more information please see <http://www.rasdaman.org>
+* or contact Peter Baumann via <baumann@rasdaman.com>.
+*/
+/*************************************************************
+ *
+ *
+ * COMMENTS:
+ *
+ *
+ *
+ ************************************************************/
+
+#define FASTCONNECT
+#define DEBUG_MAIN
+#define DEBUG
+#define __EXECUTABLE__
+#include "debug.hh"
+#include "template_inst.hh"
+
+#define RMANVERSION 6100
+#define RASARCHITECTURE X86
+
+extern unsigned long maxTransferBufferSize = 4000000;
+bool udfEnabled = true;
+extern char* dbSchema = 0;
+extern int noTimeOut= 0;
+
+#include <iostream> // cout
+#include <vector>
+#include <stdio.h> // fopen, perror
+#include <stdlib.h>
+#include <string.h>
+#include <time.h>
+
+
+#include "qlparser/querytree.hh"
+#include "raslib/rminit.hh"
+#include "raslib/rmdebug.hh"
+
+
+#include "adminif.hh"
+#include "databaseif.hh"
+#include "transactionif.hh"
+
+#include "mddmgr/mddobj.hh"
+#include "mddmgr/mddcoll.hh"
+#include "mddmgr/mddcolliter.hh"
+
+char globalConnectId[256]="RASBASE";
+
+// init globals for server initialization
+
+extern int yyparse(void *);
+extern char* myExecArgv0 = "";
+extern int globalOptimizationLevel = 4;
+extern char* beginParseString;
+extern char* iterParseString;
+
+extern int RManDebug;
+extern int RManInfo = 0;
+extern int rewrite = 0;
+extern int loadopt = 0;
+
+extern QueryTree* parseQueryTree;
+
+
+int checkArguments( int argc, char** argv, const char* searchText, int& optionValueIndex )
+{
+ int found = 0;
+ int i=1;
+
+ while( !found && i<argc )
+ found = !strcmp( searchText, argv[i++] );
+
+ if( found && i<argc && !strchr(argv[i],'-') )
+ optionValueIndex = i;
+ else
+ optionValueIndex = 0;
+
+ return found;
+}
+
+
+int main( int argc, char** argv )
+{
+ FILE* inFile;
+ char baseName[255];
+ char query[4096];
+ struct timezone tzp;
+ struct timeval startTime, stopTime, deltaTime;
+ int timeTest;
+ int optionValueIndex;
+ int noOutput;
+
+ if( checkArguments( argc, argv, "-h", optionValueIndex ) )
+ {
+ cout << "Usage: test_evaluate basename queryfile [options]" << endl;
+ cout << "Options: -h ... this help" << endl;
+ cout << " -l <file> ... log is printed to <file> (default: server.log)" << endl;
+ cout << " -l log is printed to standard out" << endl;
+ cout << " -d <file> ... debug output is printed to <file> (default: server.dbg)" << endl;
+ cout << " -d debug output is printed to standard out" << endl;
+ cout << " -dl n ... debug level is set to n (0-4, default: 0)" << endl;
+ cout << " - 0 = no / 4 = maximal debug information" << endl;
+ cout << " -opt n ... maximal optimization level (0-4, default: 4)" << endl;
+ cout << " - 0 = no / 4 = maximal optimization" << endl;
+ cout << " -t time test is enabled" << endl;
+ cout << " -nooutput ... no output of result" << endl;
+ cout << endl;
+ return 0;
+ }
+
+ strcpy( baseName, "RASBASE" );
+
+ inFile = fopen( "query", "r" );
+
+ if( inFile == NULL )
+ {
+ cout << "Error opening query file " << argv[2] << endl;
+ return -1;
+ }
+
+ fread( &query, 1, 4095, inFile );
+ fclose( inFile );
+
+ cout << endl << "Query:" << endl << endl << query << endl;
+
+ //
+ // open database, start transaction
+ //
+
+ // variables representing O2 database, ta and session
+ DatabaseIf db;
+ TransactionIf ta;
+
+ // don't forget to initialize before using AdminIf!
+ cout << "Connecting to O2 ..." << flush;
+ myExecArgv0 = argv[0];
+ AdminIf* myAdmin = AdminIf::instance();
+ cout << "OK" << endl;
+
+ // connect to the database
+ cout << "Opening database " << baseName << "... " << flush;
+ db.open( baseName );
+ cout << "OK" << endl;
+
+ cout << "Starting transaction ... " << flush;
+ ta.begin(&db);
+ cout << "OK" << endl;
+
+ //
+ // body of test program
+ //
+
+ beginParseString = query;
+ iterParseString = query;
+
+ parseQueryTree = new QueryTree(); // create a query tree object...
+
+ if( timeTest )
+ gettimeofday (&startTime, &tzp);
+
+ RMInit::logOut << "Parsing..." << flush;
+
+ if( yyparse(NULL) == 0 )
+ {
+ RMInit::logOut << "OK" << endl << endl;
+
+ parseQueryTree->printTree( 2, RMInit::logOut );
+ RMInit::logOut << endl;
+
+ parseQueryTree->getRoot()->printAlgebraicExpression();
+ cout << endl << endl;
+
+ unsigned int localOptimizationLevel = globalOptimizationLevel < parseQueryTree->getOptimizationLevel() ?
+ globalOptimizationLevel : parseQueryTree->getOptimizationLevel();
+
+ RMInit::logOut << "Optimizing query on level " << localOptimizationLevel << endl;
+ try
+ {
+ parseQueryTree->optimize( localOptimizationLevel );
+ }
+ catch( ParseInfo& info )
+ {
+ RMInit::logOut << endl << "Optimization Error" << endl;
+ info.printStatus();
+ cout << endl;
+
+ return 0;
+ }
+
+ RMInit::logOut << endl;
+ parseQueryTree->printTree( 2, RMInit::logOut );
+ RMInit::logOut << endl;
+ parseQueryTree->getRoot()->printAlgebraicExpression( RMInit::logOut );
+ RMInit::logOut << endl << endl;
+
+ RMInit::logOut << "Evaluating... " << flush;
+
+ vector<QtData*>* transColl = 0;
+
+ try
+ {
+ transColl = parseQueryTree->evaluateRetrieval();
+ }
+ catch( ParseInfo& info )
+ {
+ RMInit::logOut << endl << "Query Execution Error" << endl;
+ info.printStatus();
+ cout << endl;
+
+ return 0;
+ }
+
+ RMInit::logOut << "OK" << endl << endl;
+
+ if( timeTest )
+ {
+ gettimeofday(&stopTime, &tzp);
+
+ if(startTime.tv_usec > stopTime.tv_usec) {
+ stopTime.tv_usec += 1000000;
+ stopTime.tv_sec--;
+ }
+
+ deltaTime.tv_usec = stopTime.tv_usec - startTime.tv_usec;
+ deltaTime.tv_sec = stopTime.tv_sec - startTime.tv_sec;
+
+ cout << "Time for query processing " << deltaTime.tv_sec << " sec " << deltaTime.tv_usec << " msec " << endl;
+ }
+
+ vector<QtData*>::iterator transIter;
+ int collNum;
+ collNum = transColl->size();
+
+ cout << "The result collection has " << collNum << " entries." << endl;
+
+ if( transColl != 0 && !noOutput )
+ {
+ int i;
+
+ for( transIter = transColl->begin(), i=0; transIter != transColl->end(); transIter++, i++ )
+ {
+ QtData* mddObj = *transIter;
+
+ cout << endl << " --" << i << ". MDD object in set:" << endl << " ";
+ mddObj->printStatus();
+
+ /*vector<Tile* >* tiles = mddObj->getTiles();
+ vector<Tile* >::iterator tileIter;
+
+ for( tileIter = tiles->begin(); tileIter!=tiles->end(); tileIter++ )
+ {
+ cout << endl << " Tile" << endl;
+ (*tileIter)->printStatus();
+ }
+
+ // delete the Tile elements of the vector and the vector itself
+ // release( tiles->begin(), tiles->end() );
+ for( tileIter = tiles->begin(); tileIter!=tiles->end(); tileIter++ )
+ delete *tileIter;
+
+ delete tiles;*/
+ }
+
+ // release dynamic memory for the collection (delete MDDObjs)
+ // transColl->eraseAll();
+ delete transColl;
+
+ // delete transIter;
+ };
+
+ }
+ else {
+ RMInit::logOut << " failed" << endl;
+ printf("Error parsing query\n");
+ }
+
+ delete parseQueryTree;
+
+ //
+ // end of body
+ //
+
+ cout << "Committing transaction ... " << flush;
+ ta.commit();
+ cout << "OK" << endl;
+
+ cout << "Closing database ..." << flush;
+ db.close();
+ cout << "OK" << endl;
+ cout << "Ending O2 session ..." << endl;
+ delete myAdmin;
+ cout << "OK" << endl;
+
+ return 0;
+}
diff --git a/qlparser/test/template_inst.hh b/qlparser/test/template_inst.hh
new file mode 100644
index 0000000..9ce08ed
--- /dev/null
+++ b/qlparser/test/template_inst.hh
@@ -0,0 +1,152 @@
+/*
+* This file is part of rasdaman community.
+*
+* Rasdaman community is free software: you can redistribute it and/or modify
+* it under the terms of the GNU General Public License as published by
+* the Free Software Foundation, either version 3 of the License, or
+* (at your option) any later version.
+*
+* Rasdaman community is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+* GNU General Public License for more details.
+*
+* You should have received a copy of the GNU General Public License
+* along with rasdaman community. If not, see <http://www.gnu.org/licenses/>.
+*
+* Copyright 2003, 2004, 2005, 2006, 2007, 2008, 2009 Peter Baumann /
+rasdaman GmbH.
+*
+* For more information please see <http://www.rasdaman.org>
+* or contact Peter Baumann via <baumann@rasdaman.com>.
+*/
+// This version was created based on rview. Let's see if the other programs compile
+// also.
+
+#ifndef _TEMPLATE_INST_RASLIB_
+#define _TEMPLATE_INST_RASLIB_
+
+#include <vector>
+
+#include "qlparser/symtab.hh"
+
+#include "raslib/attribute.hh"
+#include "raslib/itertype.hh"
+#include "raslib/dlist.hh"
+
+#include "tile.hh"
+
+#include "indexmgr/keyobject.hh"
+
+#include "reladminif/dbref.hh"
+#include "reladminif/dbobjectiditerator.hh"
+
+#include "relblobif/blobtile.hh"
+#include "relblobif/dbtile.hh"
+#include "relblobif/inlinetile.hh"
+
+#include "relcatalogif/typeiterator.hh"
+#include "relcatalogif/settype.hh"
+#include "relcatalogif/structtype.hh"
+#include "relcatalogif/mddtype.hh"
+#include "relcatalogif/inlineminterval.hh"
+#include "relcatalogif/dbminterval.hh"
+
+#include "relindexif/dbtcindex.hh"
+#include "relindexif/hierindex.hh"
+#include "relindexif/dbrcindexds.hh"
+
+#include "relmddif/dbmddobj.hh"
+#include "relmddif/dbmddset.hh"
+
+#include "relstorageif/dbudfds.hh"
+#include "relstorageif/dbudfpackageds.hh"
+#include "relstorageif/dbstoragelayout.hh"
+
+
+#include <qlparser/symtab.hh>
+#include <raslib/attribute.hh>
+#include <raslib/itertype.hh>
+#include <raslib/dlist.hh>
+#include <raslib/minterval.hh>
+
+
+#include "reladminif/dbref.hh"
+#include "reladminif/dbobjectiditerator.hh"
+
+#include "relindexif/dbtcindex.hh"
+#include "relindexif/hierindex.hh"
+#include "relindexif/dbrcindexds.hh"
+
+
+template class DBRef<DBHierIndex>;
+template class DBRef<DBRCIndexDS>;
+template class DBRef<DBTCIndex>;
+template class DBRef<BLOBTile>;
+template class DBRef<DBTile>;
+template class DBRef<InlineTile>;
+template class DBRef<DBMDDSet>;
+template class DBRef<DBMinterval>;
+template class DBRef<DBStorageLayout>;
+template class DBRef<DBUDFDS>;
+template class DBRef<DBUDFPackageDS>;
+template bool operator< (const DBRef<DBMDDObj>&, const DBRef<DBMDDObj>&);
+
+
+#include <rasodmg/tiling.hh>
+#include <rasodmg/stattiling.hh>
+#include <rasodmg/iterator.hh>
+#include <rasodmg/transaction.hh>
+#include <rasodmg/ref.hh>
+#include <rasodmg/object.hh>
+#include <rasodmg/set.hh>
+#include <rasodmg/collection.hh>
+#include <rasodmg/gmarray.hh>
+#include <rasodmg/marray.hh>
+#include <rasodmg/dirdecompose.hh>
+
+template class r_Ref<r_Object>;
+template class r_Ref<r_Minterval>;
+template class r_Collection<r_Transaction::GenRefElement *>;
+template class r_Set<r_Transaction::GenRefElement *>;
+template class r_Iterator<r_GMarray *>;
+template class r_Iterator<r_Ref<r_GMarray > >;
+template class r_Collection<r_Ref<r_GMarray> >;
+template class r_Collection<r_GMarray *>;
+template class r_Set<r_GMarray *>;
+template class r_Iterator<r_Ref<r_Object> >;
+template class r_IterType<r_Attribute>;
+template class r_Collection<r_Ref<r_Object> >;
+template class r_Set<r_Ref<r_Object> >;
+template class r_Iterator<r_Ref_Any>;
+template class r_Ref<r_GMarray>;
+template class r_Collection<r_Ref_Any>;
+template class std::vector<r_Minterval>;
+template class r_Iterator<r_Transaction::GenRefElement *>;
+template class r_Set<r_Ref<r_GMarray> >;
+template class r_Ref<r_Set<r_Ref<r_GMarray> > >;
+template class r_Set<r_Ref_Any>;
+template class r_Marray<r_ULong>;
+template class r_Marray<r_Char>;
+
+template class DBRef<DBMDDObj>;
+template class DBRef<DBObject>;
+
+template class DBObjectIdIterator<DBMDDObj>;
+template class DBObjectIterator<DBMDDObj>;
+template class DBObjectIterator<DBMDDSet>;
+template class DBObjectIterator<StructType>;
+template class DBObjectIterator<SetType>;
+template class DBObjectIterator<MDDType>;
+template class DBRef<StructType>;
+template class DBRef<SetType>;
+template class DBRef<MDDType>;
+
+
+template std::ostream& operator << (std::ostream& os, const std::vector<r_Minterval>& list);
+template std::ostream& operator << (std::ostream& os, const std::vector<r_Dir_Decompose>& list);
+template std::ostream& operator << (std::ostream& os, const std::vector<r_Access>& list);
+template std::ostream& operator << (std::ostream& os, const std::vector<double>& list);
+template class SymbolTable<int>;
+
+#endif
diff --git a/qlparser/test/test_evaluate.cc b/qlparser/test/test_evaluate.cc
new file mode 100644
index 0000000..b34ce9d
--- /dev/null
+++ b/qlparser/test/test_evaluate.cc
@@ -0,0 +1,338 @@
+/*
+* This file is part of rasdaman community.
+*
+* Rasdaman community is free software: you can redistribute it and/or modify
+* it under the terms of the GNU General Public License as published by
+* the Free Software Foundation, either version 3 of the License, or
+* (at your option) any later version.
+*
+* Rasdaman community is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+* GNU General Public License for more details.
+*
+* You should have received a copy of the GNU General Public License
+* along with rasdaman community. If not, see <http://www.gnu.org/licenses/>.
+*
+* Copyright 2003, 2004, 2005, 2006, 2007, 2008, 2009 Peter Baumann /
+rasdaman GmbH.
+*
+* For more information please see <http://www.rasdaman.org>
+* or contact Peter Baumann via <baumann@rasdaman.com>.
+*/
+/*************************************************************
+ *
+ *
+ * COMMENTS:
+ *
+ *
+ *
+ ************************************************************/
+
+#include <iostream.h> // cout
+#include <stdio.h> // fopen, perror
+#include <stdlib.h>
+#include <string.h>
+#include <time.h>
+
+#include "qlparser/querytree.hh"
+#include "raslib/rminit.hh"
+#include "raslib/rmdebug.hh"
+
+#include "adminif.hh"
+#include "databaseif.hh"
+#include "transactionif.hh"
+
+#include "mddmgr/mddobj.hh"
+#include "mddmgr/mddcoll.hh"
+#include "mddmgr/mddcolliter.hh"
+
+// init globals for server initialization
+RMINITGLOBALS('S')
+
+extern int yyparse();
+extern char* myExecArgv0 = "";
+extern int globalOptimizationLevel = 4;
+extern char* beginParseString;
+extern char* iterParseString;
+
+extern int RManDebug;
+extern int RManInfo = 0;
+extern int rewrite = 0;
+extern int loadopt = 0;
+
+extern QueryTree* parseQueryTree;
+
+
+int checkArguments( int argc, char** argv, const char* searchText, int& optionValueIndex )
+{
+ int found = 0;
+ int i=1;
+
+ while( !found && i<argc )
+ found = !strcmp( searchText, argv[i++] );
+
+ if( found && i<argc && !strchr(argv[i],'-') )
+ optionValueIndex = i;
+ else
+ optionValueIndex = 0;
+
+ return found;
+}
+
+
+int main( int argc, char** argv )
+{
+ FILE* inFile;
+ char baseName[255];
+ char query[4096];
+ struct timezone tzp;
+ struct timeval startTime, stopTime, deltaTime;
+ int timeTest;
+ int optionValueIndex;
+ int noOutput;
+
+ if( checkArguments( argc, argv, "-h", optionValueIndex ) )
+ {
+ cout << "Usage: test_evaluate basename queryfile [options]" << endl;
+ cout << "Options: -h ... this help" << endl;
+ cout << " -l <file> ... log is printed to <file> (default: server.log)" << endl;
+ cout << " -l log is printed to standard out" << endl;
+ cout << " -d <file> ... debug output is printed to <file> (default: server.dbg)" << endl;
+ cout << " -d debug output is printed to standard out" << endl;
+ cout << " -dl n ... debug level is set to n (0-4, default: 0)" << endl;
+ cout << " - 0 = no / 4 = maximal debug information" << endl;
+ cout << " -opt n ... maximal optimization level (0-4, default: 4)" << endl;
+ cout << " - 0 = no / 4 = maximal optimization" << endl;
+ cout << " -t time test is enabled" << endl;
+ cout << " -nooutput ... no output of result" << endl;
+ cout << endl;
+ return 0;
+ }
+
+ strcpy( baseName, argv[1] );
+
+ if( checkArguments( argc, argv, "-l", optionValueIndex ) )
+ if( optionValueIndex )
+ {
+ RMInit::logFileOut.open( argv[optionValueIndex] );
+ // RMInit::logOut = RMInit::logFileOut;
+ }
+ else {
+ // RMInit::logOut = cout.rdbuf();
+ }
+ else
+ {
+ // default
+ RMInit::logFileOut.open("server.log");
+ // RMInit::logOut = RMInit::logFileOut;
+ }
+
+ if( checkArguments( argc, argv, "-d", optionValueIndex ) )
+ if( optionValueIndex )
+ {
+ RMInit::dbgFileOut.open( argv[optionValueIndex] );
+ // RMInit::dbgOut = RMInit::dbgFileOut;
+ }
+ else {
+ // RMInit::logOut = cout.rdbuf();
+ }
+ else
+ {
+ // default
+ RMInit::dbgFileOut.open("server.dbg");
+ // RMInit::dbgOut = RMInit::dbgFileOut;
+ }
+
+ if( checkArguments( argc, argv, "-dl", optionValueIndex ) )
+ if( optionValueIndex )
+ RManDebug = (int)strtoul( argv[optionValueIndex], (char **)NULL, 10);
+
+ if( checkArguments( argc, argv, "-opt", optionValueIndex ) )
+ if( optionValueIndex )
+ globalOptimizationLevel = (int)strtoul( argv[optionValueIndex], (char **)NULL, 10);
+
+ timeTest = checkArguments( argc, argv, "-t", optionValueIndex );
+ noOutput = checkArguments( argc, argv, "-nooutput", optionValueIndex );
+
+ inFile = fopen( argv[2], "r" );
+
+ if( inFile == NULL )
+ {
+ cout << "Error opening query file " << argv[2] << endl;
+ return -1;
+ }
+
+ fread( &query, 1, 4095, inFile );
+ fclose( inFile );
+
+ cout << endl << "Query:" << endl << endl << query << endl;
+
+ //
+ // open database, start transaction
+ //
+
+ // variables representing O2 database, ta and session
+ DatabaseIf db;
+ TransactionIf ta;
+
+ // don't forget to initialize before using AdminIf!
+ cout << "Connecting to O2 ..." << flush;
+ myExecArgv0 = argv[0];
+ AdminIf* myAdmin = AdminIf::instance();
+ cout << "OK" << endl;
+
+ // connect to the database
+ cout << "Opening database " << baseName << "... " << flush;
+ db.open( baseName );
+ cout << "OK" << endl;
+
+ cout << "Starting transaction ... " << flush;
+ ta.begin(&db);
+ cout << "OK" << endl;
+
+ //
+ // body of test program
+ //
+
+ beginParseString = query;
+ iterParseString = query;
+
+ parseQueryTree = new QueryTree(); // create a query tree object...
+
+ if( timeTest )
+ gettimeofday (&startTime, &tzp);
+
+ RMInit::logOut << "Parsing..." << flush;
+
+ if( yyparse() == 0 )
+ {
+ RMInit::logOut << "OK" << endl << endl;
+
+ parseQueryTree->printTree( 2, RMInit::logOut );
+ RMInit::logOut << endl;
+
+ parseQueryTree->getRoot()->printAlgebraicExpression();
+ cout << endl << endl;
+
+ unsigned int localOptimizationLevel = globalOptimizationLevel < parseQueryTree->getOptimizationLevel() ?
+ globalOptimizationLevel : parseQueryTree->getOptimizationLevel();
+
+ RMInit::logOut << "Optimizing query on level " << localOptimizationLevel << endl;
+ try
+ {
+ parseQueryTree->optimize( localOptimizationLevel );
+ }
+ catch( ParseInfo& info )
+ {
+ RMInit::logOut << endl << "Optimization Error" << endl;
+ info.printStatus();
+ cout << endl;
+
+ return 0;
+ }
+
+ RMInit::logOut << endl;
+ parseQueryTree->printTree( 2, RMInit::logOut );
+ RMInit::logOut << endl;
+ parseQueryTree->getRoot()->printAlgebraicExpression( RMInit::logOut );
+ RMInit::logOut << endl << endl;
+
+ RMInit::logOut << "Evaluating... " << flush;
+
+ vector<QtData*>* transColl = 0;
+
+ try
+ {
+ transColl = parseQueryTree->evaluateRetrieval();
+ }
+ catch( ParseInfo& info )
+ {
+ RMInit::logOut << endl << "Query Execution Error" << endl;
+ info.printStatus();
+ cout << endl;
+
+ return 0;
+ }
+
+ RMInit::logOut << "OK" << endl << endl;
+
+ if( timeTest )
+ {
+ gettimeofday(&stopTime, &tzp);
+
+ if(startTime.tv_usec > stopTime.tv_usec) {
+ stopTime.tv_usec += 1000000;
+ stopTime.tv_sec--;
+ }
+
+ deltaTime.tv_usec = stopTime.tv_usec - startTime.tv_usec;
+ deltaTime.tv_sec = stopTime.tv_sec - startTime.tv_sec;
+
+ cout << "Time for query processing " << deltaTime.tv_sec << " sec " << deltaTime.tv_usec << " msec " << endl;
+ }
+
+ vector<QtData*>::iterator transIter;
+ int collNum;
+ collNum = transColl->size();
+
+ cout << "The result collection has " << collNum << " entries." << endl;
+
+ if( transColl != 0 && !noOutput )
+ {
+ int i;
+
+ for( transIter = transColl->begin(), i=0; transIter != transColl->end(); transIter++, i++ )
+ {
+ QtData* mddObj = *transIter;
+
+ cout << endl << " --" << i << ". MDD object in set:" << endl << " ";
+ mddObj->printStatus();
+
+ /*vector<Tile* >* tiles = mddObj->getTiles();
+ vector<Tile* >::iterator tileIter;
+
+ for( tileIter = tiles->begin(); tileIter!=tiles->end(); tileIter++ )
+ {
+ cout << endl << " Tile" << endl;
+ (*tileIter)->printStatus();
+ }
+
+ // delete the Tile elements of the vector and the vector itself
+ // release( tiles->begin(), tiles->end() );
+ for( tileIter = tiles->begin(); tileIter!=tiles->end(); tileIter++ )
+ delete *tileIter;
+
+ delete tiles;*/
+ }
+
+ // release dynamic memory for the collection (delete MDDObjs)
+ // transColl->eraseAll();
+ delete transColl;
+
+ // delete transIter;
+ };
+
+ }
+ else
+ RMInit::logOut << " failed" << endl;
+
+ delete parseQueryTree;
+
+ //
+ // end of body
+ //
+
+ cout << "Committing transaction ... " << flush;
+ ta.commit();
+ cout << "OK" << endl;
+
+ cout << "Closing database ..." << flush;
+ db.close();
+ cout << "OK" << endl;
+ cout << "Ending O2 session ..." << endl;
+ delete myAdmin;
+ cout << "OK" << endl;
+
+ return 0;
+}
diff --git a/qlparser/test/test_qlparser.cc b/qlparser/test/test_qlparser.cc
new file mode 100644
index 0000000..7753f2c
--- /dev/null
+++ b/qlparser/test/test_qlparser.cc
@@ -0,0 +1,205 @@
+/*
+* This file is part of rasdaman community.
+*
+* Rasdaman community is free software: you can redistribute it and/or modify
+* it under the terms of the GNU General Public License as published by
+* the Free Software Foundation, either version 3 of the License, or
+* (at your option) any later version.
+*
+* Rasdaman community is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+* GNU General Public License for more details.
+*
+* You should have received a copy of the GNU General Public License
+* along with rasdaman community. If not, see <http://www.gnu.org/licenses/>.
+*
+* Copyright 2003, 2004, 2005, 2006, 2007, 2008, 2009 Peter Baumann /
+rasdaman GmbH.
+*
+* For more information please see <http://www.rasdaman.org>
+* or contact Peter Baumann via <baumann@rasdaman.com>.
+*/
+/*************************************************************
+ *
+ *
+ * PURPOSE:
+ * Test program for the RasQL parser.
+ *
+ *
+ * COMMENTS:
+ *
+ *
+ ************************************************************/
+
+#ifdef EARLY_TEMPLATE
+#define __EXECUTABLE__
+#ifdef __GNUG__
+#include "qlparser/symtab.hh"
+#include "raslib/template_inst.hh"
+#endif
+#endif
+
+
+using namespace std;
+
+#define DEBUG_MAIN
+#include "debug-clt.hh"
+
+
+#include <iostream.h> // cout
+#include <stdio.h> // fopen, perror
+#include <stdlib.h>
+#include <string.h>
+#include <time.h>
+
+#include "qlparser/querytree.hh"
+
+#include "raslib/rminit.hh"
+#include "raslib/rmdebug.hh"
+
+#include "adminif.hh"
+#include "databaseif.hh"
+#include "transactionif.hh"
+
+#include "mddmgr/mddobj.hh"
+#include "mddmgr/mddcoll.hh"
+#include "mddmgr/mddcolliter.hh"
+
+// init globals for server initialization
+// RMINITGLOBALS('C')
+
+extern int yyparse();
+extern char* myExecArgv0 = "";
+extern char* beginParseString;
+extern char* iterParseString;
+
+extern QueryTree* parseQueryTree;
+
+int main( int ac, char** av )
+{
+ FILE* inFile;
+ char baseName[255];
+ char query[4096];
+
+ //
+ // read program arguments
+ //
+
+ if( ac <= 2 )
+ {
+ cout << "usage: test_qlparser basename queryfile" << endl;
+ return -1;
+ }
+
+ strcpy( baseName, av[1] );
+
+ inFile = fopen( av[2], "r" );
+
+ if( inFile == NULL )
+ {
+ cout << "Error opening file " << av[1] << endl;
+ return -1;
+ }
+
+ fread( &query, 1, 4095, inFile );
+ fclose( inFile );
+
+ cout << "Query:" << endl << endl << query << endl;
+
+ //
+ // open database, start transaction
+ //
+
+ // variables representing O2 database, ta and session
+ DatabaseIf db;
+ TransactionIf ta;
+
+ // don't forget to initialize before using AdminIf!
+ cout << "Connecting to O2 ..." << flush;
+ myExecArgv0 = av[0];
+ AdminIf* myAdmin = AdminIf::instance();
+ cout << "OK" << endl;
+
+ // connect to the database
+ cout << "Opening database " << baseName << "... " << flush;
+ db.open( baseName );
+ cout << "OK" << endl;
+
+ cout << "Starting transaction ... " << flush;
+ ta.begin(&db);
+ cout << "OK" << endl;
+
+ //
+ // body of test program
+ //
+
+ beginParseString = query;
+ iterParseString = query;
+
+ parseQueryTree = new QueryTree(); // create a query tree object...
+
+ cout << endl << "Parsing ..." << flush;
+
+ if( !yyparse() )
+ cout << " worked" << endl;
+ else
+ cout << " failed" << endl;
+
+ cout << endl;
+ parseQueryTree->printTree(2);
+ cout << endl;
+ parseQueryTree->getRoot()->printAlgebraicExpression();
+ cout << endl;
+
+ cout << "Simplifying ..." << flush;
+ try
+ {
+ parseQueryTree->getRoot()->simplify();
+ }
+ catch( ParseInfo& info )
+ {
+ info.printStatus( RMInit::logOut );
+ cout << "FAILED" << endl;
+ }
+
+ cout << "OK" << endl;
+
+ cout << endl;
+ parseQueryTree->printTree(2);
+ cout << endl;
+ parseQueryTree->getRoot()->printAlgebraicExpression();
+ cout << endl;
+
+ delete parseQueryTree;
+
+ //
+ // end of body
+ //
+
+ cout << "Committing transaction ... " << flush;
+ ta.commit();
+ cout << "OK" << endl;
+
+ cout << "Closing database ..." << flush;
+ db.close();
+ cout << "OK" << endl;
+ cout << "Ending O2 session ..." << endl;
+ delete myAdmin;
+ cout << "OK" << endl;
+
+ return 0;
+}
+
+
+
+
+
+
+
+
+
+
+
+
+