[Checkins] SVN: Sandbox/adamg/ocql/trunk/src/ocql/ improving docs, getFromIndex: <, >, <=, >= were switched

Adam Groszer agroszer at gmail.com
Fri Aug 22 03:34:49 EDT 2008


Log message for revision 90113:
  improving docs, getFromIndex: <, >, <=, >= were switched

Changed:
  U   Sandbox/adamg/ocql/trunk/src/ocql/aoptimizer/aoptimizer.txt
  U   Sandbox/adamg/ocql/trunk/src/ocql/compiler/compiler.txt
  U   Sandbox/adamg/ocql/trunk/src/ocql/compiler/compiler_optimized.txt
  A   Sandbox/adamg/ocql/trunk/src/ocql/database/database.txt
  U   Sandbox/adamg/ocql/trunk/src/ocql/database/index.py
  U   Sandbox/adamg/ocql/trunk/src/ocql/database/metadata.py
  U   Sandbox/adamg/ocql/trunk/src/ocql/database/tests.py

-=-
Modified: Sandbox/adamg/ocql/trunk/src/ocql/aoptimizer/aoptimizer.txt
===================================================================
--- Sandbox/adamg/ocql/trunk/src/ocql/aoptimizer/aoptimizer.txt	2008-08-22 04:14:10 UTC (rev 90112)
+++ Sandbox/adamg/ocql/trunk/src/ocql/aoptimizer/aoptimizer.txt	2008-08-22 07:34:48 UTC (rev 90113)
@@ -2,6 +2,9 @@
 Algebra optimizer
 =================
 
+Input: Algebra tree
+Output: Algebra tree (optimized)
+
 The Algebra optimizer's task is to optimize the inputted algebra tree the
 best it can. The output is also an algebra tree.
 

Modified: Sandbox/adamg/ocql/trunk/src/ocql/compiler/compiler.txt
===================================================================
--- Sandbox/adamg/ocql/trunk/src/ocql/compiler/compiler.txt	2008-08-22 04:14:10 UTC (rev 90112)
+++ Sandbox/adamg/ocql/trunk/src/ocql/compiler/compiler.txt	2008-08-22 07:34:48 UTC (rev 90113)
@@ -2,6 +2,9 @@
 Compiler
 ========
 
+Input: Algebra tree
+Output: RunnableQuery (python code)
+
 The task of the compiler is to compile the inputted algebra tree to python code.
 
 I'm sorry, but I'm lazy here, in reality we would have to create

Modified: Sandbox/adamg/ocql/trunk/src/ocql/compiler/compiler_optimized.txt
===================================================================
--- Sandbox/adamg/ocql/trunk/src/ocql/compiler/compiler_optimized.txt	2008-08-22 04:14:10 UTC (rev 90112)
+++ Sandbox/adamg/ocql/trunk/src/ocql/compiler/compiler_optimized.txt	2008-08-22 07:34:48 UTC (rev 90113)
@@ -91,4 +91,36 @@
 
     >>> result = run.execute()
     >>> result
-    set([u'5'])
\ No newline at end of file
+    set([u'5'])
+
+
+    >>> query = "set [ i in IOptimizedClass ; i.value <= 5 | i.name ]"
+    >>> run = OCQLEngine().compile(query)
+    >>> result = run.execute()
+    >>> sorted(result)
+    [u'0', u'1', u'2', u'3', u'4', u'5']
+
+    >>> query = "set [ i in IOptimizedClass ; i.value >= 5 | i.name ]"
+    >>> run = OCQLEngine().compile(query)
+    >>> result = run.execute()
+    >>> sorted(result)
+    [u'5', u'6', u'7', u'8', u'9']
+
+
+    >>> query = "set [ i in IOptimizedClass ; i.value < 5 | i.name ]"
+    >>> run = OCQLEngine().compile(query)
+    >>> result = run.execute()
+    >>> sorted(result)
+    [u'0', u'1', u'2', u'3', u'4']
+
+    >>> query = "set [ i in IOptimizedClass ; i.value > 5 | i.name ]"
+    >>> run = OCQLEngine().compile(query)
+    >>> result = run.execute()
+    >>> sorted(result)
+    [u'6', u'7', u'8', u'9']
+
+    >>> query = "set [ i in IOptimizedClass ; i.value != 5 | i.name ]"
+    >>> run = OCQLEngine().compile(query)
+    >>> result = run.execute()
+    >>> sorted(result)
+    [u'0', u'1', u'2', u'3', u'4', u'6', u'7', u'8', u'9']
\ No newline at end of file

Added: Sandbox/adamg/ocql/trunk/src/ocql/database/database.txt
===================================================================
--- Sandbox/adamg/ocql/trunk/src/ocql/database/database.txt	                        (rev 0)
+++ Sandbox/adamg/ocql/trunk/src/ocql/database/database.txt	2008-08-22 07:34:48 UTC (rev 90113)
@@ -0,0 +1,19 @@
+
+Database
+========
+
+This package contains classes related to database specific functions.
+
+index.py:
+---------
+There is a special index which holds all instances of objects with a specified
+interface. This is needed to be able to simply retrieve all instances of a kind.
+
+metadata.py:
+------------
+Classes here provide information about the data in the database and object
+instances as well.
+This is the gateway between the engine and the database.
+
+
+See each file for detailes infos
\ No newline at end of file


Property changes on: Sandbox/adamg/ocql/trunk/src/ocql/database/database.txt
___________________________________________________________________
Name: svn:keywords
   + Date Author Id Revision
Name: svn:eol-style
   + native

Modified: Sandbox/adamg/ocql/trunk/src/ocql/database/index.py
===================================================================
--- Sandbox/adamg/ocql/trunk/src/ocql/database/index.py	2008-08-22 04:14:10 UTC (rev 90112)
+++ Sandbox/adamg/ocql/trunk/src/ocql/database/index.py	2008-08-22 07:34:48 UTC (rev 90113)
@@ -20,13 +20,13 @@
 import zope.app.catalog.interfaces
 
 class IAllIndex(zope.interface.Interface):
-    """I index objects by first adapting them to an interface, then
-       retrieving a field on the adapted object.
+    """Index all objects of a specified interface.
+    Collects all instances, not any property value.
     """
 
     interface = zope.schema.Choice(
         title=_(u"Interface"),
-        description=_(u"Objects will be adapted to this interface"),
+        description=_(u"Collect objects of this interface"),
         vocabulary="Interfaces",
         required=False,
         )
@@ -38,7 +38,7 @@
     """
 
 class AllMixinIndex(object):
-    """Index interface-defined attributes
+    """Index all objects of a specified interface.
 
        Mixin for indexing all objects providing a particular interface.
 

Modified: Sandbox/adamg/ocql/trunk/src/ocql/database/metadata.py
===================================================================
--- Sandbox/adamg/ocql/trunk/src/ocql/database/metadata.py	2008-08-22 04:14:10 UTC (rev 90112)
+++ Sandbox/adamg/ocql/trunk/src/ocql/database/metadata.py	2008-08-22 07:34:48 UTC (rev 90113)
@@ -15,6 +15,12 @@
 from ocql.exceptions import ReanalyzeRequired
 
 class MetaType:
+    """Class to provide type details used by the database
+
+    Might be used later, in case we want to do syntax and symbol
+    checks before execution, e.g. in the parser.
+    """
+
     def get_property(self, name):
         """
             Get type information and metadata for property.
@@ -38,21 +44,33 @@
 
 
 class MClass(MetaType):
-    #interface suspect thing
+    """Class to provide details of an interface used by the database
+
+    Might be used later, in case we want to do syntax and symbol
+    checks before execution, e.g. in the parser.
+    """
+
     def __init__(self, klass):
         self.klass = klass
 
     def is_collection(self):
+        #not used
         return True
 
     def get_collection_type(self):
+        """Returns always 'set' because this is the
+        collection of instances of an interface
+        """
         return set
 
     def get_contained(self):
+        #not used
         return self.klass
 
-    def __getitem__(self, name):
-        x = self.klass[name]._type
+    def __getitem__(self, fieldname):
+        """Extract property information from the interface
+        """
+        x = self.klass[fieldname]._type
         try:
             return x[-1]
         except TypeError:
@@ -60,6 +78,10 @@
 
 
 class Metadata:
+    """Class to provide details and data of all the interfaces used
+    by the database
+    """
+
     implements(IDB)
     adapts(None)
 
@@ -82,6 +104,19 @@
         #            #need to continue if this is required
 
     def getAll(self, klassname):
+        """Return all instances of the given interface as a list
+
+            >>> from ocql.testing import utils
+            >>> utils.setupInterfaces(None)
+            >>> utils.setupCatalog(None)
+
+            >>> db = IDB(None)
+            >>> result = db.getAll('IStudent')
+            >>> type(result)
+            <type 'list'>
+            >>> sorted(result, key=lambda x:x.name)
+            [Student <Ann>, Student <Charith>, Student <Jane>, Student <Stewart>]
+        """
         #objects have to be retrieved always on call
         #as they are subject to change
 
@@ -96,6 +131,19 @@
                         return obj_list
 
     def getFromIndex(self, klass, property, operator, value):
+        """Return all instances of the given interface as a list
+
+            >>> from ocql.testing import utils_opt
+            >>> utils_opt.setupInterfaces(None)
+            >>> utils_opt.setupCatalog(None)
+
+            >>> db = IDB(None)
+            >>> result = db.getFromIndex('IOptimizedClass', 'value', '<=', 5)
+            >>> type(result)
+            <type 'list'>
+            >>> sorted(result)
+            [Opt: 0, Opt: 1, Opt: 2, Opt: 3, Opt: 4, Opt: 5]
+        """
         catalogs = getUtilitiesFor(ICatalog)
         intids = getUtility(IIntIds)
         for name, catalog in catalogs:
@@ -109,15 +157,15 @@
                         all = catalog.apply({iname:(None, None)})
                         temp = catalog.apply({iname:(value, value)})
                         results = difference(all, temp)
-                    elif operator == '<=':
+                    elif operator == '>=':
                         results = catalog.apply({iname:(value, None)})
-                    elif operator == '<':
+                    elif operator == '>':
                         lt_eq = catalog.apply({iname:(value, None)})
                         temp = catalog.apply({iname:(value, value)})
                         results = difference(lt_eq, temp)
-                    elif operator == '>=':
+                    elif operator == '<=':
                         results = catalog.apply({iname:(None, value)})
-                    elif operator == '>':
+                    elif operator == '<':
                         gt_eq = catalog.apply({iname:(None, value)})
                         temp = catalog.apply({iname:(value, value)})
                         results = difference(gt_eq, temp)
@@ -128,6 +176,18 @@
         raise ReanalyzeRequired()
 
     def hasPropertyIndex(self, klass, property):
+        """Check if an interface's property has a FieldIndex
+
+            >>> from ocql.testing import utils_opt
+            >>> utils_opt.setupInterfaces(None)
+            >>> utils_opt.setupCatalog(None)
+
+            >>> db = IDB(None)
+            >>> db.hasPropertyIndex('IHalfOptimizedClass', 'name')
+            True
+            >>> db.hasPropertyIndex('IHalfOptimizedClass', 'valueNoOpt')
+            False
+        """
         catalogs = getUtilitiesFor(ICatalog)
         for name, catalog in catalogs:
             for iname, index in catalog.items():

Modified: Sandbox/adamg/ocql/trunk/src/ocql/database/tests.py
===================================================================
--- Sandbox/adamg/ocql/trunk/src/ocql/database/tests.py	2008-08-22 04:14:10 UTC (rev 90112)
+++ Sandbox/adamg/ocql/trunk/src/ocql/database/tests.py	2008-08-22 07:34:48 UTC (rev 90113)
@@ -2,10 +2,14 @@
 import doctest
 from zope.testing.doctestunit import DocTestSuite,DocFileSuite
 
+from ocql.testing import utils
+
 def test_suite():
     flags =  doctest.NORMALIZE_WHITESPACE|doctest.ELLIPSIS
     return unittest.TestSuite((
-        DocTestSuite('ocql.database.index')
+        DocTestSuite('ocql.database.index', optionflags=flags),
+        DocTestSuite('ocql.database.metadata', optionflags=flags,
+                     setUp = utils.setupAdapters),
         ))
 
 



More information about the Checkins mailing list