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,259 @@
1
+ # encoding: utf-8
2
+
3
+ module Veritas
4
+ class Optimizer
5
+ module Algebra
6
+
7
+ # Abstract base class representing Restriction optimizations
8
+ class Restriction < Relation::Operation::Unary
9
+
10
+ # The optimized predicate
11
+ #
12
+ # @return [Expression]
13
+ #
14
+ # @api private
15
+ attr_reader :predicate
16
+
17
+ # Initialize an Restriction optimizer
18
+ #
19
+ # @return [undefined]
20
+ #
21
+ # @api private
22
+ def initialize(*)
23
+ super
24
+ @predicate = self.class.optimize_predicate(operation.predicate)
25
+ end
26
+
27
+ private
28
+
29
+ # Wrap the operand's operand in a Restriction
30
+ #
31
+ # @return [Restriction]
32
+ #
33
+ # @api private
34
+ def wrap_operand
35
+ operation.class.new(operand.operand, predicate)
36
+ end
37
+
38
+ # Optimize the predicate if possible
39
+ #
40
+ # @param [Expression] predicate
41
+ #
42
+ # @return [Expression]
43
+ #
44
+ # @api private
45
+ def self.optimize_predicate(predicate)
46
+ predicate.respond_to?(:optimize) ? predicate.optimize : predicate
47
+ end
48
+
49
+ # Optimize when the predicate is a tautology
50
+ class Tautology < self
51
+
52
+ # Test if the predicate is a tautology
53
+ #
54
+ # @return [Boolean]
55
+ #
56
+ # @api private
57
+ def optimizable?
58
+ predicate.equal?(Veritas::Logic::Proposition::Tautology.instance)
59
+ end
60
+
61
+ # A Restriction with a tautology is a noop
62
+ #
63
+ # @return [Relation]
64
+ #
65
+ # @api private
66
+ def optimize
67
+ operand
68
+ end
69
+
70
+ end # class Tautology
71
+
72
+ # Optimize when the predicate is a contradiction
73
+ class Contradiction < self
74
+
75
+ # Test if the predicate is a contradiction
76
+ #
77
+ # @return [Boolean]
78
+ #
79
+ # @api private
80
+ def optimizable?
81
+ predicate.equal?(Veritas::Logic::Proposition::Contradiction.instance)
82
+ end
83
+
84
+ # A Restriction with a contradiction matches nothing
85
+ #
86
+ # @return [Relation]
87
+ #
88
+ # @api private
89
+ def optimize
90
+ Veritas::Relation::Empty.new(operation.header)
91
+ end
92
+
93
+ end # class Contradiction
94
+
95
+ # Optimize when the operand is a Restriction
96
+ class RestrictionOperand < self
97
+
98
+ # Test if the operand is a Restriction
99
+ #
100
+ # @return [Boolean]
101
+ #
102
+ # @api private
103
+ def optimizable?
104
+ operand.kind_of?(operation.class)
105
+ end
106
+
107
+ # Flatten nested Restrictions into a single Restriction
108
+ #
109
+ # @return [Projection]
110
+ #
111
+ # @api private
112
+ def optimize
113
+ operation.class.new(operand.operand, optimized_predicate)
114
+ end
115
+
116
+ private
117
+
118
+ # Join the operand and operation predicates and optimize them
119
+ #
120
+ # @return [Expression]
121
+ #
122
+ # @api private
123
+ def optimized_predicate
124
+ Veritas::Logic::Connective::Conjunction.new(operand.predicate, predicate).optimize
125
+ end
126
+
127
+ end # class RestrictionOperand
128
+
129
+ # Optimize when the operand is a Set
130
+ class SetOperand < self
131
+
132
+ # Test if the operand is a Restriction
133
+ #
134
+ # @return [Boolean]
135
+ #
136
+ # @api private
137
+ def optimizable?
138
+ operand.kind_of?(Veritas::Relation::Operation::Set)
139
+ end
140
+
141
+ # Wrap each operand in the Set in a Restriction
142
+ #
143
+ # @return [Set]
144
+ #
145
+ # @api private
146
+ def optimize
147
+ operand.class.new(wrap_left, wrap_right)
148
+ end
149
+
150
+ private
151
+
152
+ # Utility method to wrap the left operand in a Restriction
153
+ #
154
+ # @return [Restriction]
155
+ #
156
+ # @api private
157
+ def wrap_left
158
+ operation.class.new(operand.left, predicate)
159
+ end
160
+
161
+ # Utility method to wrap the right operand in a Restriction
162
+ #
163
+ # @return [Restriction]
164
+ #
165
+ # @api private
166
+ def wrap_right
167
+ operation.class.new(operand.right, predicate)
168
+ end
169
+
170
+ end # class SetOperand
171
+
172
+ # Optimize when the operand is a Reverse
173
+ class ReverseOperand < self
174
+
175
+ # Test if the operand is a Reverse
176
+ #
177
+ # @return [Boolean]
178
+ #
179
+ # @api private
180
+ def optimizable?
181
+ operand.kind_of?(Veritas::Relation::Operation::Reverse)
182
+ end
183
+
184
+ # Wrap the Restriction in a Reverse
185
+ #
186
+ # @return [Reverse]
187
+ #
188
+ # @api private
189
+ def optimize
190
+ operand.class.new(wrap_operand)
191
+ end
192
+
193
+ end # class ReverseOperand
194
+
195
+ # Optimize when the operand is an Order
196
+ class OrderOperand < self
197
+
198
+ # Test if the operand is an Order
199
+ #
200
+ # @return [Boolean]
201
+ #
202
+ # @api private
203
+ def optimizable?
204
+ operand.kind_of?(Veritas::Relation::Operation::Order)
205
+ end
206
+
207
+ # Wrap the Restriction in an Order
208
+ #
209
+ # @return [Order]
210
+ #
211
+ # @api private
212
+ def optimize
213
+ operand = self.operand
214
+ operand.class.new(wrap_operand, operand.directions)
215
+ end
216
+
217
+ end # class OrderOperand
218
+
219
+ # Optimize when operand is optimizable
220
+ class UnoptimizedOperand < self
221
+
222
+ # Test if the operand is unoptimized
223
+ #
224
+ # @return [Boolean]
225
+ #
226
+ # @api private
227
+ def optimizable?
228
+ operation = self.operation
229
+ !operand.equal?(operation.operand) ||
230
+ !predicate.equal?(operation.predicate)
231
+ end
232
+
233
+ # Return a Restriction with an optimized operand
234
+ #
235
+ # @return [Rename]
236
+ #
237
+ # @api private
238
+ def optimize
239
+ operation.class.new(operand, predicate)
240
+ end
241
+
242
+ end # class UnoptimizedOperand
243
+
244
+ Veritas::Algebra::Restriction.optimizer = chain(
245
+ Tautology,
246
+ Contradiction,
247
+ RestrictionOperand,
248
+ SetOperand,
249
+ ReverseOperand,
250
+ OrderOperand,
251
+ EmptyOperand,
252
+ MaterializedOperand,
253
+ UnoptimizedOperand
254
+ )
255
+
256
+ end # class Restriction
257
+ end # module Algebra
258
+ end # class Optimizer
259
+ end # module Veritas
@@ -0,0 +1,42 @@
1
+ # encoding: utf-8
2
+
3
+ module Veritas
4
+ class Optimizer
5
+ module Algebra
6
+
7
+ # Abstract base class representing Summarization optimizations
8
+ class Summarization < Relation::Operation::Unary
9
+
10
+ # Optimize when operand is optimizable
11
+ class UnoptimizedOperand < self
12
+
13
+ # Test if the operand is unoptimized
14
+ #
15
+ # @return [Boolean]
16
+ #
17
+ # @api private
18
+ def optimizable?
19
+ !operand.equal?(operation.operand)
20
+ end
21
+
22
+ # Return a Summarization with an optimized operand
23
+ #
24
+ # @return [Rename]
25
+ #
26
+ # @api private
27
+ def optimize
28
+ operation = self.operation
29
+ operation.class.new(operand, operation.summarize_by, operation.summarizers)
30
+ end
31
+
32
+ end # class UnoptimizedOperand
33
+
34
+ Veritas::Algebra::Summarization.optimizer = chain(
35
+ MaterializedOperand,
36
+ UnoptimizedOperand
37
+ )
38
+
39
+ end # class Summarization
40
+ end # module Algebra
41
+ end # class Optimizer
42
+ end # module Veritas
@@ -0,0 +1,66 @@
1
+ # encoding: utf-8
2
+
3
+ module Veritas
4
+ class Optimizer
5
+ module Algebra
6
+
7
+ # Abstract base class representing Difference optimizations
8
+ class Union < Relation::Operation::Binary
9
+
10
+ # Optimize when operands are equal
11
+ class EqualOperands < self
12
+ include Relation::Operation::Binary::EqualOperands
13
+
14
+ # A Union with equal operands is a noop
15
+ #
16
+ # @return [Relation]
17
+ #
18
+ # @api private
19
+ def optimize
20
+ left
21
+ end
22
+
23
+ end # class EqualOperands
24
+
25
+ # Optimize when the left operand is empty
26
+ class EmptyLeft < self
27
+ include Relation::Operation::Binary::EmptyLeft
28
+
29
+ # A Union with an empty left operand is equivalent to the right
30
+ #
31
+ # @return [Relation]
32
+ #
33
+ # @api private
34
+ def optimize
35
+ right
36
+ end
37
+
38
+ end # class EmptyLeft
39
+
40
+ # Optimize when the right operand is empty
41
+ class EmptyRight < self
42
+ include Relation::Operation::Binary::EmptyRight
43
+
44
+ # A Union with an empty right operand is equivalent to the left
45
+ #
46
+ # @return [Relation]
47
+ #
48
+ # @api private
49
+ def optimize
50
+ left
51
+ end
52
+
53
+ end # class EmptyRight
54
+
55
+ Veritas::Algebra::Union.optimizer = chain(
56
+ EqualOperands,
57
+ EmptyRight,
58
+ EmptyLeft,
59
+ MaterializedOperand,
60
+ UnoptimizedOperand
61
+ )
62
+
63
+ end # class Union
64
+ end # module Algebra
65
+ end # class Optimizer
66
+ end # module Veritas
@@ -0,0 +1,254 @@
1
+ # encoding: utf-8
2
+
3
+ module Veritas
4
+ class Optimizer
5
+ module Logic
6
+ module Connective
7
+
8
+ # Abstract base class representing Binary connective optimizations
9
+ class Binary < Optimizer
10
+
11
+ # The optimized left operand
12
+ #
13
+ # @return [Expression]
14
+ #
15
+ # @api private
16
+ attr_reader :left
17
+
18
+ # The optimized right operand
19
+ #
20
+ # @return [Expression]
21
+ #
22
+ # @api private
23
+ attr_reader :right
24
+
25
+ # Initialize an Binary optimizer
26
+ #
27
+ # @return [undefined]
28
+ #
29
+ # @api private
30
+ def initialize(*)
31
+ super
32
+ @left = optimize_left
33
+ @right = optimize_right
34
+ end
35
+
36
+ private
37
+
38
+ # Optimize the left operand
39
+ #
40
+ # @return [Expression]
41
+ #
42
+ # @api private
43
+ def optimize_left
44
+ # TODO: move Predicate.optimize_operand to a better location
45
+ Predicate.optimize_operand(operation.left)
46
+ end
47
+
48
+ # Optimize the right operand
49
+ #
50
+ # @return [Expression]
51
+ #
52
+ # @api private
53
+ def optimize_right
54
+ # TODO: move Predicate.optimize_operand to a better location
55
+ Predicate.optimize_operand(operation.right)
56
+ end
57
+
58
+ # Test if the operands are equality predicates for the same attribute
59
+ #
60
+ # @return [Boolean]
61
+ #
62
+ # @api private
63
+ def equality_with_same_attributes?
64
+ left.kind_of?(Veritas::Logic::Predicate::Equality) &&
65
+ right.kind_of?(Veritas::Logic::Predicate::Equality) &&
66
+ same_attribute? &&
67
+ constant_value?
68
+ end
69
+
70
+ # Test if the operands are inequality predicates for the same attribute
71
+ #
72
+ # @return [Boolean]
73
+ #
74
+ # @api private
75
+ def inequality_with_same_attributes?
76
+ left.kind_of?(Veritas::Logic::Predicate::Inequality) &&
77
+ right.kind_of?(Veritas::Logic::Predicate::Inequality) &&
78
+ same_attribute? &&
79
+ constant_value?
80
+ end
81
+
82
+ # Test if the left and right predicates are for the same attribute
83
+ #
84
+ # @return [Boolean]
85
+ #
86
+ # @api private
87
+ def same_attribute?
88
+ left.left.equal?(right.left)
89
+ end
90
+
91
+ # Test if the left and right predicates match against constant values
92
+ #
93
+ # @return [Boolean]
94
+ #
95
+ # @api private
96
+ def constant_value?
97
+ util = Predicate::Util
98
+ util.constant?(left.right) && util.constant?(right.right)
99
+ end
100
+
101
+ # Test if the left is a tautology
102
+ #
103
+ # @return [Boolean]
104
+ #
105
+ # @api private
106
+ def left_tautology?
107
+ left.equal?(Veritas::Logic::Proposition::Tautology.instance)
108
+ end
109
+
110
+ # Test if the right is a tautology
111
+ #
112
+ # @return [Boolean]
113
+ #
114
+ # @api private
115
+ def right_tautology?
116
+ right.equal?(Veritas::Logic::Proposition::Tautology.instance)
117
+ end
118
+
119
+ # Test if the left is a contradiction
120
+ #
121
+ # @return [Boolean]
122
+ #
123
+ # @api private
124
+ def left_contradiction?
125
+ left.equal?(Veritas::Logic::Proposition::Contradiction.instance)
126
+ end
127
+
128
+ # Test if the right is a contradiction
129
+ #
130
+ # @return [Boolean]
131
+ #
132
+ # @api private
133
+ def right_contradiction?
134
+ right.equal?(Veritas::Logic::Proposition::Contradiction.instance)
135
+ end
136
+
137
+ # Optimize when the operands are equal
138
+ class EqualOperands < self
139
+
140
+ # Test if the operands are equal
141
+ #
142
+ # @return [Boolean]
143
+ #
144
+ # @api private
145
+ def optimizable?
146
+ left.eql?(right)
147
+ end
148
+
149
+ # A Binary connective with equal operands is equivalent to the left
150
+ #
151
+ # @return [Expression]
152
+ #
153
+ # @api private
154
+ def optimize
155
+ left
156
+ end
157
+
158
+ end # class EqualOperands
159
+
160
+ # Optimize when the left operand is redundant
161
+ class RedundantLeftOperand < self
162
+
163
+ # Test if the left operand is redundant
164
+ #
165
+ # @return [Boolean]
166
+ #
167
+ # @api private
168
+ def optimizable?
169
+ left = self.left
170
+ operation.kind_of?(left.class) && right.eql?(left.right)
171
+ end
172
+
173
+ # A Binary connective with a redundant left operand is equivalent to the left
174
+ #
175
+ # @return [Expression]
176
+ #
177
+ # @api private
178
+ def optimize
179
+ left
180
+ end
181
+
182
+ end # class RedundantLeftOperand
183
+
184
+ # Optimize when the right operand is redundant
185
+ class RedundantRightOperand < self
186
+
187
+ # Test if the right operand is redundant
188
+ #
189
+ # @return [Boolean]
190
+ #
191
+ # @api private
192
+ def optimizable?
193
+ right = self.right
194
+ operation.kind_of?(right.class) && left.eql?(right.left)
195
+ end
196
+
197
+ # A Binary connective with a redundant right operand is equivalent to the right
198
+ #
199
+ # @return [Expression]
200
+ #
201
+ # @api private
202
+ def optimize
203
+ right
204
+ end
205
+
206
+ end # class RedundantRightOperand
207
+
208
+ # Optimize when the operands are unoptimized
209
+ class UnoptimizedOperand < self
210
+
211
+ # Test if the operands are unoptimized
212
+ #
213
+ # @return [Boolean]
214
+ #
215
+ # @api private
216
+ def optimizable?
217
+ left_optimizable? || right_optimizable?
218
+ end
219
+
220
+ # Return a Binary connective with optimized operands
221
+ #
222
+ # @return [Binary]
223
+ #
224
+ # @api private
225
+ def optimize
226
+ operation.class.new(left, right)
227
+ end
228
+
229
+ private
230
+
231
+ # Test if the left operand is optimizable
232
+ #
233
+ # @return [Boolean]
234
+ #
235
+ # @api private
236
+ def left_optimizable?
237
+ !left.equal?(operation.left)
238
+ end
239
+
240
+ # Test if the right operand is optimizable
241
+ #
242
+ # @return [Boolean]
243
+ #
244
+ # @api private
245
+ def right_optimizable?
246
+ !right.equal?(operation.right)
247
+ end
248
+
249
+ end # class UnoptimizedOperand
250
+ end # class Binary
251
+ end # module Connective
252
+ end # module Logic
253
+ end # class Optimizer
254
+ end # module Veritas