Commits

Kirill Simonov  committed 633a8e5

Fixed rewriting of kernel expressions.

  • Participants
  • Parent commits 2b54ecd

Comments (0)

Files changed (2)

File 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)
 

File 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)