Kirill Simonov avatar Kirill Simonov committed 633a8e5

Fixed rewriting of kernel expressions.

Comments (0)

Files changed (2)

src/htsql/tr/rewrite.py

         return self.unit.clone(code=code, plural_flow=plural_flow, flow=flow)
 
 
+class RewriteKernel(RewriteUnit):
+
+    adapts(KernelUnit)
+
+    def __call__(self):
+        # At this stage, the kernel code is an element of the family kernel.
+        assert self.unit.code in self.unit.flow.family.kernels
+        index = self.unit.flow.family.kernels.index(self.unit.code)
+        # Rewrite the quotient flow.
+        flow = self.state.rewrite(self.unit.flow)
+        # Get the new kernel code.
+        code = flow.family.kernels[index]
+        return self.unit.clone(code=code, flow=flow)
+
+
 class UnmaskKernel(UnmaskUnit):
 
     adapts(KernelUnit)
 
     def __call__(self):
-        # The kernel expression is evaluated against the seed flow of
-        # the quotient, so use the seed as the mask.
-        code = self.state.unmask(self.unit.code,
-                                 mask=self.unit.flow.family.seed)
-        # Unmask the unit flow.
+        # At this stage, the kernel code is an element of the family kernel.
+        assert self.unit.code in self.unit.flow.family.kernels
+        index = self.unit.flow.family.kernels.index(self.unit.code)
+        # Unmask the quotient flow.
         flow = self.state.unmask(self.unit.flow)
+        # Get the new kernel code.
+        code = flow.family.kernels[index]
         return self.unit.clone(code=code, flow=flow)
 
 
+class ReplaceKernel(ReplaceUnit):
+
+    adapts(KernelUnit)
+
+    def __call__(self):
+        # At this stage, the kernel code is an element of the family kernel.
+        assert self.unit.code in self.unit.flow.family.kernels
+        index = self.unit.flow.family.kernels.index(self.unit.code)
+        # Recombine the quotient flow.
+        substate = self.state.spawn()
+        substate.collect(self.unit.flow)
+        substate.recombine()
+        flow = substate.replace(self.unit.flow)
+        # Get the new kernel code.
+        code = flow.family.kernels[index]
+        return self.unit.clone(code=code, flow=flow)
+
+
 class UnmaskCovering(UnmaskUnit):
+    # FIXME: not used?
 
     adapts(CoveringUnit)
 

src/htsql/tr/term.py

     def __str__(self):
         # Display:
         #   (<kid> | <lop>=<rop>, ...)
-        conditions = ", ".join("%s=%s" % joint for joint in self.joints)
+        conditions = ", ".join("%s=%s" % (joint.lop, joint.rop)
+                               for joint in self.joints)
         if conditions:
             conditions = " | %s" % conditions
         return "(%s%s)" % (self.kid, conditions)
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.