veritas-optimizer 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (279) hide show
  1. data/Gemfile +33 -0
  2. data/LICENSE +20 -0
  3. data/README.rdoc +27 -0
  4. data/Rakefile +25 -0
  5. data/TODO +75 -0
  6. data/config/flay.yml +3 -0
  7. data/config/flog.yml +2 -0
  8. data/config/roodi.yml +16 -0
  9. data/config/site.reek +91 -0
  10. data/config/yardstick.yml +2 -0
  11. data/lib/veritas/optimizer/algebra/difference.rb +66 -0
  12. data/lib/veritas/optimizer/algebra/extension.rb +42 -0
  13. data/lib/veritas/optimizer/algebra/intersection.rb +66 -0
  14. data/lib/veritas/optimizer/algebra/join.rb +44 -0
  15. data/lib/veritas/optimizer/algebra/product.rb +70 -0
  16. data/lib/veritas/optimizer/algebra/projection.rb +174 -0
  17. data/lib/veritas/optimizer/algebra/rename.rb +396 -0
  18. data/lib/veritas/optimizer/algebra/restriction.rb +259 -0
  19. data/lib/veritas/optimizer/algebra/summarization.rb +42 -0
  20. data/lib/veritas/optimizer/algebra/union.rb +66 -0
  21. data/lib/veritas/optimizer/logic/connective/binary.rb +254 -0
  22. data/lib/veritas/optimizer/logic/connective/conjunction.rb +122 -0
  23. data/lib/veritas/optimizer/logic/connective/disjunction.rb +122 -0
  24. data/lib/veritas/optimizer/logic/connective/negation.rb +71 -0
  25. data/lib/veritas/optimizer/logic/predicate/comparable.rb +134 -0
  26. data/lib/veritas/optimizer/logic/predicate/enumerable.rb +141 -0
  27. data/lib/veritas/optimizer/logic/predicate/equality.rb +44 -0
  28. data/lib/veritas/optimizer/logic/predicate/exclusion.rb +53 -0
  29. data/lib/veritas/optimizer/logic/predicate/greater_than.rb +54 -0
  30. data/lib/veritas/optimizer/logic/predicate/greater_than_or_equal_to.rb +56 -0
  31. data/lib/veritas/optimizer/logic/predicate/inclusion.rb +53 -0
  32. data/lib/veritas/optimizer/logic/predicate/inequality.rb +44 -0
  33. data/lib/veritas/optimizer/logic/predicate/less_than.rb +54 -0
  34. data/lib/veritas/optimizer/logic/predicate/less_than_or_equal_to.rb +56 -0
  35. data/lib/veritas/optimizer/logic/predicate/match.rb +19 -0
  36. data/lib/veritas/optimizer/logic/predicate/no_match.rb +19 -0
  37. data/lib/veritas/optimizer/logic/predicate.rb +177 -0
  38. data/lib/veritas/optimizer/optimizable.rb +59 -0
  39. data/lib/veritas/optimizer/relation/materialized.rb +40 -0
  40. data/lib/veritas/optimizer/relation/operation/binary.rb +168 -0
  41. data/lib/veritas/optimizer/relation/operation/combination.rb +33 -0
  42. data/lib/veritas/optimizer/relation/operation/limit.rb +149 -0
  43. data/lib/veritas/optimizer/relation/operation/offset.rb +114 -0
  44. data/lib/veritas/optimizer/relation/operation/order.rb +96 -0
  45. data/lib/veritas/optimizer/relation/operation/reverse.rb +94 -0
  46. data/lib/veritas/optimizer/relation/operation/unary.rb +88 -0
  47. data/lib/veritas/optimizer/version.rb +7 -0
  48. data/lib/veritas/optimizer.rb +136 -0
  49. data/lib/veritas-optimizer.rb +3 -0
  50. data/spec/integration/veritas/algebra/difference/optimize_spec.rb +152 -0
  51. data/spec/integration/veritas/algebra/intersection/optimize_spec.rb +152 -0
  52. data/spec/integration/veritas/algebra/join/optimize_spec.rb +110 -0
  53. data/spec/integration/veritas/algebra/product/optimize_spec.rb +176 -0
  54. data/spec/integration/veritas/algebra/projection/optimize_spec.rb +237 -0
  55. data/spec/integration/veritas/algebra/rename/optimize_spec.rb +440 -0
  56. data/spec/integration/veritas/algebra/restriction/optimize_spec.rb +216 -0
  57. data/spec/integration/veritas/algebra/union/optimize_spec.rb +192 -0
  58. data/spec/integration/veritas/logic/connective/conjunction/optimize_spec.rb +234 -0
  59. data/spec/integration/veritas/logic/connective/disjunction/optimize_spec.rb +235 -0
  60. data/spec/integration/veritas/logic/connective/negation/optimize_spec.rb +41 -0
  61. data/spec/integration/veritas/logic/expression/optimize_spec.rb +42 -0
  62. data/spec/integration/veritas/logic/predicate/equality/optimize_spec.rb +90 -0
  63. data/spec/integration/veritas/logic/predicate/exclusion/optimize_spec.rb +131 -0
  64. data/spec/integration/veritas/logic/predicate/greater_than/optimize_spec.rb +100 -0
  65. data/spec/integration/veritas/logic/predicate/greater_than_or_equal_to/optimize_spec.rb +100 -0
  66. data/spec/integration/veritas/logic/predicate/inclusion/optimize_spec.rb +131 -0
  67. data/spec/integration/veritas/logic/predicate/inequality/optimize_spec.rb +90 -0
  68. data/spec/integration/veritas/logic/predicate/less_than/optimize_spec.rb +100 -0
  69. data/spec/integration/veritas/logic/predicate/less_than_or_equal_to/optimize_spec.rb +100 -0
  70. data/spec/integration/veritas/relation/empty/optimize_spec.rb +11 -0
  71. data/spec/integration/veritas/relation/materialized/optimize_spec.rb +37 -0
  72. data/spec/integration/veritas/relation/operation/limit/optimize_spec.rb +140 -0
  73. data/spec/integration/veritas/relation/operation/offset/optimize_spec.rb +98 -0
  74. data/spec/integration/veritas/relation/operation/order/optimize_spec.rb +103 -0
  75. data/spec/integration/veritas/relation/operation/reverse/optimize_spec.rb +113 -0
  76. data/spec/integration/veritas/relation/optimize_spec.rb +33 -0
  77. data/spec/rcov.opts +6 -0
  78. data/spec/shared/idempotent_method_behavior.rb +5 -0
  79. data/spec/shared/logic_connective_binary_optimize_behavior.rb +100 -0
  80. data/spec/shared/optimize_method_behavior.rb +14 -0
  81. data/spec/spec.opts +3 -0
  82. data/spec/spec_helper.rb +16 -0
  83. data/spec/support/add_method_missing.rb +13 -0
  84. data/spec/unit/veritas/optimizer/algebra/difference/empty_left/optimize_spec.rb +17 -0
  85. data/spec/unit/veritas/optimizer/algebra/difference/empty_right/optimize_spec.rb +17 -0
  86. data/spec/unit/veritas/optimizer/algebra/difference/equal_operands/optimize_spec.rb +19 -0
  87. data/spec/unit/veritas/optimizer/algebra/extension/unoptimized_operand/optimizable_spec.rb +27 -0
  88. data/spec/unit/veritas/optimizer/algebra/extension/unoptimized_operand/optimize_spec.rb +25 -0
  89. data/spec/unit/veritas/optimizer/algebra/intersection/empty_left/optimize_spec.rb +17 -0
  90. data/spec/unit/veritas/optimizer/algebra/intersection/empty_right/optimize_spec.rb +17 -0
  91. data/spec/unit/veritas/optimizer/algebra/intersection/equal_operands/optimize_spec.rb +17 -0
  92. data/spec/unit/veritas/optimizer/algebra/join/equal_headers/optimizable_spec.rb +27 -0
  93. data/spec/unit/veritas/optimizer/algebra/join/equal_headers/optimize_spec.rb +21 -0
  94. data/spec/unit/veritas/optimizer/algebra/product/table_dee_left/optimizable_spec.rb +25 -0
  95. data/spec/unit/veritas/optimizer/algebra/product/table_dee_left/optimize_spec.rb +16 -0
  96. data/spec/unit/veritas/optimizer/algebra/product/table_dee_right/optimizable_spec.rb +25 -0
  97. data/spec/unit/veritas/optimizer/algebra/product/table_dee_right/optimize_spec.rb +16 -0
  98. data/spec/unit/veritas/optimizer/algebra/projection/empty_operand/optimizable_spec.rb +25 -0
  99. data/spec/unit/veritas/optimizer/algebra/projection/empty_operand/optimize_spec.rb +18 -0
  100. data/spec/unit/veritas/optimizer/algebra/projection/header_spec.rb +16 -0
  101. data/spec/unit/veritas/optimizer/algebra/projection/projection_operand/optimizable_spec.rb +26 -0
  102. data/spec/unit/veritas/optimizer/algebra/projection/projection_operand/optimize_spec.rb +20 -0
  103. data/spec/unit/veritas/optimizer/algebra/projection/set_operand/optimizable_spec.rb +27 -0
  104. data/spec/unit/veritas/optimizer/algebra/projection/set_operand/optimize_spec.rb +23 -0
  105. data/spec/unit/veritas/optimizer/algebra/projection/unchanged_header/optimizable_spec.rb +26 -0
  106. data/spec/unit/veritas/optimizer/algebra/projection/unchanged_header/optimize_spec.rb +16 -0
  107. data/spec/unit/veritas/optimizer/algebra/projection/unoptimized_operand/optimizable_spec.rb +26 -0
  108. data/spec/unit/veritas/optimizer/algebra/projection/unoptimized_operand/optimize_spec.rb +20 -0
  109. data/spec/unit/veritas/optimizer/algebra/rename/aliases_spec.rb +31 -0
  110. data/spec/unit/veritas/optimizer/algebra/rename/class_methods/union_aliases_spec.rb +27 -0
  111. data/spec/unit/veritas/optimizer/algebra/rename/empty_operand/optimizable_spec.rb +25 -0
  112. data/spec/unit/veritas/optimizer/algebra/rename/empty_operand/optimize_spec.rb +17 -0
  113. data/spec/unit/veritas/optimizer/algebra/rename/header_spec.rb +19 -0
  114. data/spec/unit/veritas/optimizer/algebra/rename/limit_operand/optimizable_spec.rb +26 -0
  115. data/spec/unit/veritas/optimizer/algebra/rename/limit_operand/optimize_spec.rb +21 -0
  116. data/spec/unit/veritas/optimizer/algebra/rename/offset_operand/optimizable_spec.rb +26 -0
  117. data/spec/unit/veritas/optimizer/algebra/rename/offset_operand/optimize_spec.rb +21 -0
  118. data/spec/unit/veritas/optimizer/algebra/rename/order_operand/optimizable_spec.rb +26 -0
  119. data/spec/unit/veritas/optimizer/algebra/rename/order_operand/optimize_spec.rb +20 -0
  120. data/spec/unit/veritas/optimizer/algebra/rename/projection_operand/optimizable_spec.rb +26 -0
  121. data/spec/unit/veritas/optimizer/algebra/rename/projection_operand/optimize_spec.rb +20 -0
  122. data/spec/unit/veritas/optimizer/algebra/rename/rename_operand/optimizable_spec.rb +28 -0
  123. data/spec/unit/veritas/optimizer/algebra/rename/rename_operand/optimize_spec.rb +20 -0
  124. data/spec/unit/veritas/optimizer/algebra/rename/rename_operand_and_empty_aliases/optimizable_spec.rb +35 -0
  125. data/spec/unit/veritas/optimizer/algebra/rename/rename_operand_and_empty_aliases/optimize_spec.rb +16 -0
  126. data/spec/unit/veritas/optimizer/algebra/rename/restriction_operand/optimizable_spec.rb +27 -0
  127. data/spec/unit/veritas/optimizer/algebra/rename/restriction_operand/optimize_spec.rb +21 -0
  128. data/spec/unit/veritas/optimizer/algebra/rename/reverse_operand/optimizable_spec.rb +25 -0
  129. data/spec/unit/veritas/optimizer/algebra/rename/reverse_operand/optimize_spec.rb +21 -0
  130. data/spec/unit/veritas/optimizer/algebra/rename/set_operand/optimizable_spec.rb +27 -0
  131. data/spec/unit/veritas/optimizer/algebra/rename/set_operand/optimize_spec.rb +21 -0
  132. data/spec/unit/veritas/optimizer/algebra/rename/unchanged_header/optimizable_spec.rb +26 -0
  133. data/spec/unit/veritas/optimizer/algebra/rename/unchanged_header/optimize_spec.rb +16 -0
  134. data/spec/unit/veritas/optimizer/algebra/rename/unoptimized_operand/optimizable_spec.rb +42 -0
  135. data/spec/unit/veritas/optimizer/algebra/rename/unoptimized_operand/optimize_spec.rb +21 -0
  136. data/spec/unit/veritas/optimizer/algebra/restriction/class_methods/optimize_predicate_spec.rb +31 -0
  137. data/spec/unit/veritas/optimizer/algebra/restriction/contradiction/optimizable_spec.rb +26 -0
  138. data/spec/unit/veritas/optimizer/algebra/restriction/contradiction/optimize_spec.rb +19 -0
  139. data/spec/unit/veritas/optimizer/algebra/restriction/order_operand/optimizable_spec.rb +26 -0
  140. data/spec/unit/veritas/optimizer/algebra/restriction/order_operand/optimize_spec.rb +18 -0
  141. data/spec/unit/veritas/optimizer/algebra/restriction/predicate_spec.rb +16 -0
  142. data/spec/unit/veritas/optimizer/algebra/restriction/restriction_operand/optimizable_spec.rb +28 -0
  143. data/spec/unit/veritas/optimizer/algebra/restriction/restriction_operand/optimize_spec.rb +22 -0
  144. data/spec/unit/veritas/optimizer/algebra/restriction/reverse_operand/optimizable_spec.rb +26 -0
  145. data/spec/unit/veritas/optimizer/algebra/restriction/reverse_operand/optimize_spec.rb +18 -0
  146. data/spec/unit/veritas/optimizer/algebra/restriction/set_operand/optimizable_spec.rb +28 -0
  147. data/spec/unit/veritas/optimizer/algebra/restriction/set_operand/optimize_spec.rb +22 -0
  148. data/spec/unit/veritas/optimizer/algebra/restriction/tautology/optimizable_spec.rb +25 -0
  149. data/spec/unit/veritas/optimizer/algebra/restriction/tautology/optimize_spec.rb +17 -0
  150. data/spec/unit/veritas/optimizer/algebra/restriction/unoptimized_operand/optimizable_spec.rb +42 -0
  151. data/spec/unit/veritas/optimizer/algebra/restriction/unoptimized_operand/optimize_spec.rb +22 -0
  152. data/spec/unit/veritas/optimizer/algebra/summarization/unoptimized_operand/optimizable_spec.rb +27 -0
  153. data/spec/unit/veritas/optimizer/algebra/summarization/unoptimized_operand/optimize_spec.rb +27 -0
  154. data/spec/unit/veritas/optimizer/algebra/union/empty_left/optimize_spec.rb +17 -0
  155. data/spec/unit/veritas/optimizer/algebra/union/empty_right/optimize_spec.rb +17 -0
  156. data/spec/unit/veritas/optimizer/algebra/union/equal_operands/optimize_spec.rb +17 -0
  157. data/spec/unit/veritas/optimizer/class_methods/chain_spec.rb +54 -0
  158. data/spec/unit/veritas/optimizer/logic/connective/binary/equal_operands/optimizable_spec.rb +27 -0
  159. data/spec/unit/veritas/optimizer/logic/connective/binary/equal_operands/optimize_spec.rb +17 -0
  160. data/spec/unit/veritas/optimizer/logic/connective/binary/left_spec.rb +14 -0
  161. data/spec/unit/veritas/optimizer/logic/connective/binary/redundant_left_operand/optimizable_spec.rb +26 -0
  162. data/spec/unit/veritas/optimizer/logic/connective/binary/redundant_left_operand/optimize_spec.rb +21 -0
  163. data/spec/unit/veritas/optimizer/logic/connective/binary/redundant_right_operand/optimizable_spec.rb +26 -0
  164. data/spec/unit/veritas/optimizer/logic/connective/binary/redundant_right_operand/optimize_spec.rb +21 -0
  165. data/spec/unit/veritas/optimizer/logic/connective/binary/right_spec.rb +14 -0
  166. data/spec/unit/veritas/optimizer/logic/connective/binary/unoptimized_operand/optimizable_spec.rb +34 -0
  167. data/spec/unit/veritas/optimizer/logic/connective/binary/unoptimized_operand/optimize_spec.rb +21 -0
  168. data/spec/unit/veritas/optimizer/logic/connective/conjunction/contradiction/optimizable_spec.rb +41 -0
  169. data/spec/unit/veritas/optimizer/logic/connective/conjunction/contradiction/optimize_spec.rb +17 -0
  170. data/spec/unit/veritas/optimizer/logic/connective/conjunction/left_operand_tautology/optimizable_spec.rb +27 -0
  171. data/spec/unit/veritas/optimizer/logic/connective/conjunction/left_operand_tautology/optimize_spec.rb +17 -0
  172. data/spec/unit/veritas/optimizer/logic/connective/conjunction/optimizable_to_exclusion/optimizable_spec.rb +27 -0
  173. data/spec/unit/veritas/optimizer/logic/connective/conjunction/optimizable_to_exclusion/optimize_spec.rb +36 -0
  174. data/spec/unit/veritas/optimizer/logic/connective/conjunction/right_operand_tautology/optimizable_spec.rb +27 -0
  175. data/spec/unit/veritas/optimizer/logic/connective/conjunction/right_operand_tautology/optimize_spec.rb +17 -0
  176. data/spec/unit/veritas/optimizer/logic/connective/disjunction/contradiction_left_operand/optimizable_spec.rb +27 -0
  177. data/spec/unit/veritas/optimizer/logic/connective/disjunction/contradiction_left_operand/optimize_spec.rb +17 -0
  178. data/spec/unit/veritas/optimizer/logic/connective/disjunction/contradiction_right_operand/optimizable_spec.rb +27 -0
  179. data/spec/unit/veritas/optimizer/logic/connective/disjunction/contradiction_right_operand/optimize_spec.rb +17 -0
  180. data/spec/unit/veritas/optimizer/logic/connective/disjunction/optimizable_to_inclusion/optimizable_spec.rb +27 -0
  181. data/spec/unit/veritas/optimizer/logic/connective/disjunction/optimizable_to_inclusion/optimize_spec.rb +36 -0
  182. data/spec/unit/veritas/optimizer/logic/connective/disjunction/tautology/optimizable_spec.rb +41 -0
  183. data/spec/unit/veritas/optimizer/logic/connective/disjunction/tautology/optimize_spec.rb +17 -0
  184. data/spec/unit/veritas/optimizer/logic/connective/negation/invertible_operand/optimizable_spec.rb +26 -0
  185. data/spec/unit/veritas/optimizer/logic/connective/negation/invertible_operand/optimize_spec.rb +20 -0
  186. data/spec/unit/veritas/optimizer/logic/connective/negation/operand_spec.rb +12 -0
  187. data/spec/unit/veritas/optimizer/logic/predicate/class_methods/optimize_operand_spec.rb +20 -0
  188. data/spec/unit/veritas/optimizer/logic/predicate/comparable/never_comparable/optimizable_spec.rb +58 -0
  189. data/spec/unit/veritas/optimizer/logic/predicate/comparable/never_equivalent/optimizable_spec.rb +58 -0
  190. data/spec/unit/veritas/optimizer/logic/predicate/comparable/normalizable_operands/optimizable_spec.rb +41 -0
  191. data/spec/unit/veritas/optimizer/logic/predicate/comparable/normalizable_operands/optimize_spec.rb +19 -0
  192. data/spec/unit/veritas/optimizer/logic/predicate/constant_operands/optimizable_spec.rb +29 -0
  193. data/spec/unit/veritas/optimizer/logic/predicate/constant_operands/optimize_spec.rb +14 -0
  194. data/spec/unit/veritas/optimizer/logic/predicate/contradiction/optimize_spec.rb +16 -0
  195. data/spec/unit/veritas/optimizer/logic/predicate/enumerable/empty_right_operand/optimizable_spec.rb +76 -0
  196. data/spec/unit/veritas/optimizer/logic/predicate/enumerable/one_right_operand/optimizable_spec.rb +76 -0
  197. data/spec/unit/veritas/optimizer/logic/predicate/enumerable/unoptimized_operand/optimizable_spec.rb +49 -0
  198. data/spec/unit/veritas/optimizer/logic/predicate/enumerable/unoptimized_operand/optimize_spec.rb +53 -0
  199. data/spec/unit/veritas/optimizer/logic/predicate/equality/tautology/optimizable_spec.rb +27 -0
  200. data/spec/unit/veritas/optimizer/logic/predicate/exclusion/empty_right_operand/optimize_spec.rb +43 -0
  201. data/spec/unit/veritas/optimizer/logic/predicate/exclusion/one_right_operand/optimize_spec.rb +63 -0
  202. data/spec/unit/veritas/optimizer/logic/predicate/greater_than/contradiction/optimizable_spec.rb +41 -0
  203. data/spec/unit/veritas/optimizer/logic/predicate/greater_than/tautology/optimizable_spec.rb +26 -0
  204. data/spec/unit/veritas/optimizer/logic/predicate/greater_than_or_equal_to/contradiction/optimizable_spec.rb +41 -0
  205. data/spec/unit/veritas/optimizer/logic/predicate/greater_than_or_equal_to/tautology/optimizable_spec.rb +41 -0
  206. data/spec/unit/veritas/optimizer/logic/predicate/inclusion/empty_right_operand/optimize_spec.rb +43 -0
  207. data/spec/unit/veritas/optimizer/logic/predicate/inclusion/one_right_operand/optimize_spec.rb +64 -0
  208. data/spec/unit/veritas/optimizer/logic/predicate/inequality/contradiction/optimizable_spec.rb +27 -0
  209. data/spec/unit/veritas/optimizer/logic/predicate/left_spec.rb +25 -0
  210. data/spec/unit/veritas/optimizer/logic/predicate/less_than/contradiction/optimizable_spec.rb +41 -0
  211. data/spec/unit/veritas/optimizer/logic/predicate/less_than/tautology/optimizable_spec.rb +26 -0
  212. data/spec/unit/veritas/optimizer/logic/predicate/less_than_or_equal_to/contradiction/optimizable_spec.rb +41 -0
  213. data/spec/unit/veritas/optimizer/logic/predicate/less_than_or_equal_to/tautology/optimizable_spec.rb +41 -0
  214. data/spec/unit/veritas/optimizer/logic/predicate/right_spec.rb +25 -0
  215. data/spec/unit/veritas/optimizer/logic/predicate/tautology/optimize_spec.rb +16 -0
  216. data/spec/unit/veritas/optimizer/logic/predicate/util/class_methods/attribute_spec.rb +19 -0
  217. data/spec/unit/veritas/optimizer/logic/predicate/util/class_methods/constant_spec.rb +19 -0
  218. data/spec/unit/veritas/optimizer/logic/predicate/util/class_methods/max_spec.rb +19 -0
  219. data/spec/unit/veritas/optimizer/logic/predicate/util/class_methods/min_spec.rb +19 -0
  220. data/spec/unit/veritas/optimizer/operation_spec.rb +11 -0
  221. data/spec/unit/veritas/optimizer/optimizable/class_methods/optimizer_spec.rb +32 -0
  222. data/spec/unit/veritas/optimizer/optimizable/optimize_spec.rb +36 -0
  223. data/spec/unit/veritas/optimizer/optimizable_spec.rb +15 -0
  224. data/spec/unit/veritas/optimizer/optimize_spec.rb +15 -0
  225. data/spec/unit/veritas/optimizer/relation/materialized/empty_operand/optimizable_spec.rb +20 -0
  226. data/spec/unit/veritas/optimizer/relation/materialized/empty_operand/optimize_spec.rb +17 -0
  227. data/spec/unit/veritas/optimizer/relation/operation/binary/empty_left/optimizable_spec.rb +30 -0
  228. data/spec/unit/veritas/optimizer/relation/operation/binary/empty_right/optimizable_spec.rb +30 -0
  229. data/spec/unit/veritas/optimizer/relation/operation/binary/equal_operands/optimizable_spec.rb +34 -0
  230. data/spec/unit/veritas/optimizer/relation/operation/binary/left_spec.rb +17 -0
  231. data/spec/unit/veritas/optimizer/relation/operation/binary/materialized_operand/optimizable_spec.rb +35 -0
  232. data/spec/unit/veritas/optimizer/relation/operation/binary/materialized_operand/optimize_spec.rb +20 -0
  233. data/spec/unit/veritas/optimizer/relation/operation/binary/right_spec.rb +17 -0
  234. data/spec/unit/veritas/optimizer/relation/operation/binary/unoptimized_operand/optimizable_spec.rb +38 -0
  235. data/spec/unit/veritas/optimizer/relation/operation/binary/unoptimized_operand/optimize_spec.rb +22 -0
  236. data/spec/unit/veritas/optimizer/relation/operation/combination/optimize_spec.rb +14 -0
  237. data/spec/unit/veritas/optimizer/relation/operation/limit/equal_limit_operand/optimizable_spec.rb +31 -0
  238. data/spec/unit/veritas/optimizer/relation/operation/limit/equal_limit_operand/optimize_spec.rb +16 -0
  239. data/spec/unit/veritas/optimizer/relation/operation/limit/limit_operand/optimizable_spec.rb +25 -0
  240. data/spec/unit/veritas/optimizer/relation/operation/limit/limit_operand/optimize_spec.rb +33 -0
  241. data/spec/unit/veritas/optimizer/relation/operation/limit/unoptimized_operand/optimizable_spec.rb +26 -0
  242. data/spec/unit/veritas/optimizer/relation/operation/limit/unoptimized_operand/optimize_spec.rb +20 -0
  243. data/spec/unit/veritas/optimizer/relation/operation/limit/zero_limit/optimizable_spec.rb +25 -0
  244. data/spec/unit/veritas/optimizer/relation/operation/limit/zero_limit/optimize_spec.rb +18 -0
  245. data/spec/unit/veritas/optimizer/relation/operation/offset/offset_operand/optimizable_spec.rb +25 -0
  246. data/spec/unit/veritas/optimizer/relation/operation/offset/offset_operand/optimize_spec.rb +19 -0
  247. data/spec/unit/veritas/optimizer/relation/operation/offset/unoptimized_operand/optimizable_spec.rb +26 -0
  248. data/spec/unit/veritas/optimizer/relation/operation/offset/unoptimized_operand/optimize_spec.rb +20 -0
  249. data/spec/unit/veritas/optimizer/relation/operation/offset/zero_offset/optimizable_spec.rb +25 -0
  250. data/spec/unit/veritas/optimizer/relation/operation/offset/zero_offset/optimize_spec.rb +15 -0
  251. data/spec/unit/veritas/optimizer/relation/operation/order/one_limit_operand/optimizable_spec.rb +31 -0
  252. data/spec/unit/veritas/optimizer/relation/operation/order/one_limit_operand/optimize_spec.rb +16 -0
  253. data/spec/unit/veritas/optimizer/relation/operation/order/order_operand/optimizable_spec.rb +25 -0
  254. data/spec/unit/veritas/optimizer/relation/operation/order/order_operand/optimize_spec.rb +20 -0
  255. data/spec/unit/veritas/optimizer/relation/operation/order/unoptimized_operand/optimizable_spec.rb +26 -0
  256. data/spec/unit/veritas/optimizer/relation/operation/order/unoptimized_operand/optimize_spec.rb +21 -0
  257. data/spec/unit/veritas/optimizer/relation/operation/reverse/order_operand/optimizable_spec.rb +25 -0
  258. data/spec/unit/veritas/optimizer/relation/operation/reverse/order_operand/optimize_spec.rb +20 -0
  259. data/spec/unit/veritas/optimizer/relation/operation/reverse/reverse_operand/optimizable_spec.rb +25 -0
  260. data/spec/unit/veritas/optimizer/relation/operation/reverse/reverse_operand/optimize_spec.rb +17 -0
  261. data/spec/unit/veritas/optimizer/relation/operation/reverse/unoptimized_operand/optimizable_spec.rb +25 -0
  262. data/spec/unit/veritas/optimizer/relation/operation/reverse/unoptimized_operand/optimize_spec.rb +22 -0
  263. data/spec/unit/veritas/optimizer/relation/operation/unary/empty_operand/optimizable_spec.rb +20 -0
  264. data/spec/unit/veritas/optimizer/relation/operation/unary/empty_operand/optimize_spec.rb +15 -0
  265. data/spec/unit/veritas/optimizer/relation/operation/unary/materialized_operand/optimizable_spec.rb +20 -0
  266. data/spec/unit/veritas/optimizer/relation/operation/unary/materialized_operand/optimize_spec.rb +18 -0
  267. data/spec/unit/veritas/optimizer/relation/operation/unary/operand_spec.rb +13 -0
  268. data/tasks/quality/ci.rake +2 -0
  269. data/tasks/quality/flay.rake +41 -0
  270. data/tasks/quality/flog.rake +45 -0
  271. data/tasks/quality/heckle.rake +203 -0
  272. data/tasks/quality/metric_fu.rake +26 -0
  273. data/tasks/quality/reek.rake +9 -0
  274. data/tasks/quality/roodi.rake +15 -0
  275. data/tasks/quality/yardstick.rake +23 -0
  276. data/tasks/spec.rake +38 -0
  277. data/tasks/yard.rake +9 -0
  278. data/veritas-optimizer.gemspec +550 -0
  279. metadata +613 -0
@@ -0,0 +1,440 @@
1
+ require 'spec_helper'
2
+
3
+ describe Algebra::Rename, '#optimize' do
4
+ subject { object.optimize }
5
+
6
+ let(:body) { [ [ 1, 'Dan Kubb' ] ].each }
7
+ let(:relation) { Relation.new([ [ :id, Integer ], [ :name, String ] ], body) }
8
+ let(:operand) { relation }
9
+ let(:aliases) { { :id => :other_id } }
10
+ let(:object) { described_class.new(operand, aliases) }
11
+
12
+ context 'containing a relation' do
13
+ it { should equal(object) }
14
+
15
+ it 'does not execute body#each' do
16
+ body.should_not_receive(:each)
17
+ subject
18
+ end
19
+
20
+ it_should_behave_like 'an optimize method'
21
+ end
22
+
23
+ context 'containing an empty relation' do
24
+ let(:operand) { Relation::Empty.new(relation.header) }
25
+
26
+ it { should eql(Relation::Empty.new(object.header)) }
27
+
28
+ it 'returns an equivalent relation to the unoptimized operation' do
29
+ should == object
30
+ end
31
+
32
+ it 'does not execute body#each' do
33
+ body.should_not_receive(:each)
34
+ subject
35
+ end
36
+
37
+ it_should_behave_like 'an optimize method'
38
+ end
39
+
40
+ context 'containing an optimizable relation' do
41
+ let(:operand) { relation.project(relation.header) }
42
+
43
+ it { should_not equal(object) }
44
+
45
+ it { should be_kind_of(described_class) }
46
+
47
+ it 'sets aliases the same as the original object' do
48
+ subject.aliases.should == object.aliases
49
+ end
50
+
51
+ its(:operand) { should equal(relation) }
52
+
53
+ it 'returns an equivalent relation to the unoptimized operation' do
54
+ should == object
55
+ end
56
+
57
+ it 'does not execute body#each' do
58
+ body.should_not_receive(:each)
59
+ subject
60
+ end
61
+
62
+ it_should_behave_like 'an optimize method'
63
+ end
64
+
65
+ context 'containing a object operation' do
66
+ let(:operand) { described_class.new(relation, :id => :other_id) }
67
+ let(:aliases) { { :name => :other_name } }
68
+
69
+ it { should_not equal(object) }
70
+
71
+ it { should be_kind_of(described_class) }
72
+
73
+ it 'sets aliases as a union of both aliases' do
74
+ subject.aliases.should == described_class::Aliases.coerce(
75
+ relation.header,
76
+ :id => :other_id,
77
+ :name => :other_name
78
+ )
79
+ end
80
+
81
+ its(:operand) { should equal(relation) }
82
+
83
+ it 'returns an equivalent relation to the unoptimized operation' do
84
+ should == object
85
+ end
86
+
87
+ it 'does not execute body#each' do
88
+ body.should_not_receive(:each)
89
+ subject
90
+ end
91
+
92
+ it_should_behave_like 'an optimize method'
93
+ end
94
+
95
+ context 'containing a object operation with overlapping aliases' do
96
+ let(:operand) { described_class.new(relation, :id => :other_id) }
97
+ let(:aliases) { { :other_id => :another_id } }
98
+
99
+ it { should_not equal(object) }
100
+
101
+ it { should be_kind_of(described_class) }
102
+
103
+ it 'sets aliases as a union of both aliases' do
104
+ subject.aliases.should == described_class::Aliases.coerce(
105
+ relation.header,
106
+ :id => :another_id
107
+ )
108
+ end
109
+
110
+ its(:operand) { should equal(relation) }
111
+
112
+ it 'returns an equivalent relation to the unoptimized operation' do
113
+ should == object
114
+ end
115
+
116
+ it 'does not execute body#each' do
117
+ body.should_not_receive(:each)
118
+ subject
119
+ end
120
+
121
+ it_should_behave_like 'an optimize method'
122
+ end
123
+
124
+ context 'containing an inverse object operation' do
125
+ let(:operand) { described_class.new(relation, :id => :other_id) }
126
+ let(:aliases) { { :other_id => :id } }
127
+
128
+ it { should equal(relation) }
129
+
130
+ it 'returns an equivalent relation to the unoptimized operation' do
131
+ should == object
132
+ end
133
+
134
+ it 'does not execute body#each' do
135
+ body.should_not_receive(:each)
136
+ subject
137
+ end
138
+
139
+ it_should_behave_like 'an optimize method'
140
+ end
141
+
142
+ context 'containing a projection' do
143
+ let(:operand) { relation.project([ :id ]) }
144
+
145
+ it { should be_kind_of(Algebra::Projection) }
146
+
147
+ its(:operand) { should eql(described_class.new(relation, aliases)) }
148
+
149
+ its(:header) { should == [ [ :other_id, Integer ] ] }
150
+
151
+ it 'returns an equivalent relation to the unoptimized operation' do
152
+ should == object
153
+ end
154
+
155
+ it 'does not execute body#each' do
156
+ body.should_not_receive(:each)
157
+ subject
158
+ end
159
+
160
+ it_should_behave_like 'an optimize method'
161
+ end
162
+
163
+ context 'containing a projection, containing a object that cancels out' do
164
+ let(:operand) { relation.rename(:id => :other_id).project([ :other_id ]) }
165
+ let(:aliases) { { :other_id => :id } }
166
+
167
+ it 'pushes the object before the projection, and then cancel it out' do
168
+ should eql(relation.project([ :id ]))
169
+ end
170
+
171
+ it 'returns an equivalent relation to the unoptimized operation' do
172
+ should == object
173
+ end
174
+
175
+ it 'does not execute body#each' do
176
+ body.should_not_receive(:each)
177
+ subject
178
+ end
179
+
180
+ it_should_behave_like 'an optimize method'
181
+ end
182
+
183
+ context 'containing a restriction' do
184
+ let(:operand) { relation.restrict { |r| r[:id].eq(1) } }
185
+
186
+ it { should be_kind_of(Algebra::Restriction) }
187
+
188
+ its(:operand) { should eql(described_class.new(relation, aliases)) }
189
+
190
+ its(:header) { should == [ [ :other_id, Integer ], [ :name, String ] ] }
191
+
192
+ it 'returns an equivalent relation to the unoptimized operation' do
193
+ should == object
194
+ end
195
+
196
+ it 'does not execute body#each' do
197
+ body.should_not_receive(:each)
198
+ subject
199
+ end
200
+
201
+ it_should_behave_like 'an optimize method'
202
+ end
203
+
204
+ context 'containing a restriction, containing a object that cancels out' do
205
+ let(:operand) { relation.rename(:id => :other_id).restrict { |r| r[:other_id].eq(1) } }
206
+ let(:aliases) { { :other_id => :id } }
207
+
208
+ it 'pushes the object before the restriction, and then cancel it out' do
209
+ should eql(relation.restrict { |r| r[:id].eq(1) })
210
+ end
211
+
212
+ it 'returns an equivalent relation to the unoptimized operation' do
213
+ should == object
214
+ end
215
+
216
+ it 'does not execute body#each' do
217
+ body.should_not_receive(:each)
218
+ subject
219
+ end
220
+
221
+ it_should_behave_like 'an optimize method'
222
+ end
223
+
224
+ context 'containing a set operation' do
225
+ let(:left) { Relation.new([ [ :id, Integer ], [ :name, String ] ], [ [ 1, 'Dan Kubb' ] ].each) }
226
+ let(:right) { Relation.new([ [ :id, Integer ], [ :name, String ] ], [ [ 2, 'Dan Kubb' ] ].each) }
227
+ let(:operand) { left.union(right) }
228
+
229
+ it 'pushes the object to each relation' do
230
+ should eql(left.rename(aliases).union(right.rename(aliases)))
231
+ end
232
+
233
+ it 'returns an equivalent relation to the unoptimized operation' do
234
+ should == object
235
+ end
236
+
237
+ it 'does not execute body#each' do
238
+ body.should_not_receive(:each)
239
+ subject
240
+ end
241
+
242
+ it_should_behave_like 'an optimize method'
243
+ end
244
+
245
+ context 'containing a set operation, containing a object that cancels out' do
246
+ let(:left) { Relation.new([ [ :id, Integer ], [ :name, String ] ], [ [ 1, 'Dan Kubb' ] ].each) }
247
+ let(:right) { Relation.new([ [ :id, Integer ], [ :name, String ] ], [ [ 2, 'Dan Kubb' ] ].each) }
248
+ let(:operand) { left.rename(:id => :other_id).union(right.rename(:id => :other_id)) }
249
+ let(:aliases) { { :other_id => :id } }
250
+
251
+ it 'pushes the object to each relation, then cancel it out' do
252
+ should eql(left.union(right))
253
+ end
254
+
255
+ it 'returns an equivalent relation to the unoptimized operation' do
256
+ should == object
257
+ end
258
+
259
+ it 'does not execute body#each' do
260
+ body.should_not_receive(:each)
261
+ subject
262
+ end
263
+
264
+ it_should_behave_like 'an optimize method'
265
+ end
266
+
267
+ context 'containing a reverse operation' do
268
+ let(:limit) { relation.order.take(2) }
269
+ let(:operand) { limit.reverse }
270
+
271
+ it 'pushes the object under the order, limit and reverse' do
272
+ should eql(relation.rename(aliases).order.take(2).reverse)
273
+ end
274
+
275
+ it 'returns an equivalent relation to the unoptimized operation' do
276
+ should == object
277
+ end
278
+
279
+ it 'does not execute body#each' do
280
+ body.should_not_receive(:each)
281
+ subject
282
+ end
283
+
284
+ it_should_behave_like 'an optimize method'
285
+ end
286
+
287
+ context 'containing a reverse operation, containing a object that cancels out' do
288
+ let(:limit) { relation.order.take(2) }
289
+ let(:operand) { limit.rename(:id => :other_id).reverse }
290
+ let(:aliases) { { :other_id => :id } }
291
+
292
+ it 'pushes the object under the order, limit and reverse, and then cancel it out' do
293
+ should eql(relation.order.take(2).reverse)
294
+ end
295
+
296
+ it 'returns an equivalent relation to the unoptimized operation' do
297
+ should == object
298
+ end
299
+
300
+ it 'does not execute body#each' do
301
+ body.should_not_receive(:each)
302
+ subject
303
+ end
304
+
305
+ it_should_behave_like 'an optimize method'
306
+ end
307
+
308
+ context 'containing an order operation' do
309
+ let(:operand) { relation.order }
310
+
311
+ it 'pushes the object under the order' do
312
+ should eql(relation.rename(aliases).order)
313
+ end
314
+
315
+ it 'returns an equivalent relation to the unoptimized operation' do
316
+ should == object
317
+ end
318
+
319
+ it 'does not execute body#each' do
320
+ body.should_not_receive(:each)
321
+ subject
322
+ end
323
+
324
+ it_should_behave_like 'an optimize method'
325
+ end
326
+
327
+ context 'containing an order operation, containing a object that cancels out' do
328
+ let(:operand) { relation.rename(:id => :other_id).order }
329
+ let(:aliases) { { :other_id => :id } }
330
+
331
+ it 'pushes the object under the order, and then cancel it out' do
332
+ should eql(relation.order)
333
+ end
334
+
335
+ it 'returns an equivalent relation to the unoptimized operation' do
336
+ should == object
337
+ end
338
+
339
+ it 'does not execute body#each' do
340
+ body.should_not_receive(:each)
341
+ subject
342
+ end
343
+
344
+ it_should_behave_like 'an optimize method'
345
+ end
346
+
347
+ context 'containing a limit operation' do
348
+ let(:order) { relation.order }
349
+ let(:operand) { order.take(2) }
350
+
351
+ it 'pushes the object under the limit and order' do
352
+ should eql(relation.rename(aliases).order.take(2))
353
+ end
354
+
355
+ it 'returns an equivalent relation to the unoptimized operation' do
356
+ should == object
357
+ end
358
+
359
+ it 'does not execute body#each' do
360
+ body.should_not_receive(:each)
361
+ subject
362
+ end
363
+
364
+ it_should_behave_like 'an optimize method'
365
+ end
366
+
367
+ context 'containing a limit operation, containing a object that cancels out' do
368
+ let(:order) { relation.order }
369
+ let(:operand) { order.rename(:id => :other_id).take(2) }
370
+ let(:aliases) { { :other_id => :id } }
371
+
372
+ it 'pushes the object under the limit and order, and then cancel it out' do
373
+ should eql(relation.order.take(2))
374
+ end
375
+
376
+ it 'returns an equivalent relation to the unoptimized operation' do
377
+ should == object
378
+ end
379
+
380
+ it 'does not execute body#each' do
381
+ body.should_not_receive(:each)
382
+ subject
383
+ end
384
+
385
+ it_should_behave_like 'an optimize method'
386
+ end
387
+
388
+ context 'containing an offset operation' do
389
+ let(:order) { relation.order }
390
+ let(:operand) { order.drop(1) }
391
+
392
+ it 'pushes the object under the offset and order' do
393
+ should eql(relation.rename(aliases).order.drop(1))
394
+ end
395
+
396
+ it 'returns an equivalent relation to the unoptimized operation' do
397
+ should == object
398
+ end
399
+
400
+ it 'does not execute body#each' do
401
+ body.should_not_receive(:each)
402
+ subject
403
+ end
404
+
405
+ it_should_behave_like 'an optimize method'
406
+ end
407
+
408
+ context 'containing an offset operation, containing a object that cancels out' do
409
+ let(:order) { relation.order }
410
+ let(:operand) { order.rename(:id => :other_id).drop(1) }
411
+ let(:aliases) { { :other_id => :id } }
412
+
413
+ it 'pushes the object under the offset and order, and then cancel it out' do
414
+ should eql(relation.order.drop(1))
415
+ end
416
+
417
+ it 'returns an equivalent relation to the unoptimized operation' do
418
+ should == object
419
+ end
420
+
421
+ it 'does not execute body#each' do
422
+ body.should_not_receive(:each)
423
+ subject
424
+ end
425
+
426
+ it_should_behave_like 'an optimize method'
427
+ end
428
+
429
+ context 'containing a materialized relation' do
430
+ let(:operand) { Relation.new([ [ :id, Integer ], [ :name, String ] ], [ [ 1, 'Dan Kubb' ] ]) }
431
+
432
+ it { should eql(Relation::Materialized.new([ [ :other_id, Integer ], [ :name, String ] ], [ [ 1, 'Dan Kubb' ] ])) }
433
+
434
+ it 'returns an equivalent relation to the unoptimized operation' do
435
+ should == object
436
+ end
437
+
438
+ it_should_behave_like 'an optimize method'
439
+ end
440
+ end
@@ -0,0 +1,216 @@
1
+ require 'spec_helper'
2
+
3
+ describe Algebra::Restriction, '#optimize' do
4
+ subject { object.optimize }
5
+
6
+ let(:body) { [ [ 1 ] ].each }
7
+ let(:relation) { Relation.new([ [ :id, Integer ] ], body) }
8
+ let(:operand) { relation }
9
+ let(:object) { described_class.new(operand, predicate) }
10
+
11
+ context 'with a tautology' do
12
+ let(:predicate) { Logic::Proposition::Tautology.instance }
13
+
14
+ it { should equal(relation) }
15
+
16
+ it 'does not execute body#each' do
17
+ body.should_not_receive(:each)
18
+ subject
19
+ end
20
+
21
+ it_should_behave_like 'an optimize method'
22
+ end
23
+
24
+ context 'with a contradiction' do
25
+ let(:predicate) { Logic::Proposition::Contradiction.instance }
26
+
27
+ it { should eql(Relation::Empty.new(relation.header)) }
28
+
29
+ it 'returns an equivalent relation to the unoptimized operation' do
30
+ should == object
31
+ end
32
+
33
+ it 'does not execute body#each' do
34
+ body.should_not_receive(:each)
35
+ subject
36
+ end
37
+
38
+ it_should_behave_like 'an optimize method'
39
+ end
40
+
41
+ context 'with a predicate' do
42
+ let(:predicate) { relation[:id].eq(1) }
43
+
44
+ it { should equal(object) }
45
+
46
+ it 'does not execute body#each' do
47
+ body.should_not_receive(:each)
48
+ subject
49
+ end
50
+
51
+ it_should_behave_like 'an optimize method'
52
+ end
53
+
54
+ context 'with an optimizable predicate' do
55
+ let(:predicate) { relation[:id].eq(1).and(Logic::Proposition::Tautology.instance) }
56
+
57
+ it { should_not equal(object) }
58
+
59
+ it { should be_kind_of(described_class) }
60
+
61
+ its(:predicate) { should eql(relation[:id].eq(1)) }
62
+
63
+ its(:operand) { should equal(relation) }
64
+
65
+ it 'returns an equivalent relation to the unoptimized operation' do
66
+ should == object
67
+ end
68
+
69
+ it 'does not execute body#each' do
70
+ body.should_not_receive(:each)
71
+ subject
72
+ end
73
+
74
+ it_should_behave_like 'an optimize method'
75
+ end
76
+
77
+ context 'with an optimizable operand' do
78
+ let(:operand) { relation.project(relation.header) }
79
+ let(:predicate) { relation[:id].eq(1) }
80
+
81
+ it { should_not equal(object) }
82
+
83
+ it { should be_kind_of(described_class) }
84
+
85
+ its(:predicate) { should equal(predicate) }
86
+
87
+ its(:operand) { should equal(relation) }
88
+
89
+ it 'returns an equivalent relation to the unoptimized operation' do
90
+ should == object
91
+ end
92
+
93
+ it 'does not execute body#each' do
94
+ body.should_not_receive(:each)
95
+ subject
96
+ end
97
+
98
+ it_should_behave_like 'an optimize method'
99
+ end
100
+
101
+ context 'with an empty relation' do
102
+ let(:operand) { Relation::Empty.new([ [ :id, Integer ] ]) }
103
+ let(:predicate) { operand[:id].gte(1) }
104
+
105
+ it { should equal(operand) }
106
+
107
+ it 'returns an equivalent relation to the unoptimized operation' do
108
+ should == object
109
+ end
110
+
111
+ it 'does not execute body#each' do
112
+ body.should_not_receive(:each)
113
+ subject
114
+ end
115
+
116
+ it_should_behave_like 'an optimize method'
117
+ end
118
+
119
+ context 'with an empty relation when optimized' do
120
+ let(:operand) { described_class.new(relation, Logic::Proposition::Contradiction.instance) }
121
+ let(:predicate) { operand[:id].gte(1) }
122
+
123
+ it { should eql(Relation::Empty.new(relation.header)) }
124
+
125
+ it 'returns an equivalent relation to the unoptimized operation' do
126
+ should == object
127
+ end
128
+
129
+ it 'does not execute body#each' do
130
+ body.should_not_receive(:each)
131
+ subject
132
+ end
133
+
134
+ it_should_behave_like 'an optimize method'
135
+ end
136
+
137
+ context 'with a restriction' do
138
+ let(:other_predicate) { relation[:id].lt(2) }
139
+ let(:operand) { described_class.new(relation, other_predicate) }
140
+ let(:predicate) { operand[:id].gte(1) }
141
+
142
+ it { should_not equal(object) }
143
+
144
+ it { should be_kind_of(described_class) }
145
+
146
+ its(:predicate) { should eql(other_predicate & predicate) }
147
+
148
+ its(:operand) { should equal(relation) }
149
+
150
+ it 'returns an equivalent relation to the unoptimized operation' do
151
+ should == object
152
+ end
153
+
154
+ it 'does not execute body#each' do
155
+ body.should_not_receive(:each)
156
+ subject
157
+ end
158
+
159
+ it_should_behave_like 'an optimize method'
160
+ end
161
+
162
+ context 'with a set operation' do
163
+ let(:left) { Relation.new([ [ :id, Integer ] ], [ [ 1 ] ].each) }
164
+ let(:right) { Relation.new([ [ :id, Integer ] ], [ [ 2 ] ].each) }
165
+ let(:operand) { left.union(right) }
166
+ let(:predicate) { operand[:id].gte(1) }
167
+
168
+ it 'pushes the object to each relation' do
169
+ should eql(left.restrict { |r| r[:id].gte(1) }.union(right.restrict { |r| r[:id].gte(1) }))
170
+ end
171
+
172
+ it 'returns an equivalent relation to the unoptimized operation' do
173
+ should == object
174
+ end
175
+
176
+ it 'does not execute body#each' do
177
+ body.should_not_receive(:each)
178
+ subject
179
+ end
180
+
181
+ it_should_behave_like 'an optimize method'
182
+ end
183
+
184
+ context 'with an order operation' do
185
+ let(:operand) { relation.order }
186
+ let(:predicate) { operand[:id].gte(1) }
187
+
188
+ it 'pushes the object under the order' do
189
+ should eql(relation.restrict(predicate).order)
190
+ end
191
+
192
+ it 'returns an equivalent relation to the unoptimized operation' do
193
+ should == object
194
+ end
195
+
196
+ it 'does not execute body#each' do
197
+ body.should_not_receive(:each)
198
+ subject
199
+ end
200
+
201
+ it_should_behave_like 'an optimize method'
202
+ end
203
+
204
+ context 'containing a materialized relation' do
205
+ let(:operand) { Relation.new([ [ :id, Integer ] ], [ [ 1 ], [ 2 ] ]) }
206
+ let(:predicate) { operand[:id].eq(1) }
207
+
208
+ it { should eql(Relation::Materialized.new([ [ :id, Integer ] ], [ [ 1 ] ])) }
209
+
210
+ it 'returns an equivalent relation to the unoptimized operation' do
211
+ should == object
212
+ end
213
+
214
+ it_should_behave_like 'an optimize method'
215
+ end
216
+ end