veritas-optimizer 0.0.3
Sign up to get free protection for your applications and to get access to all the features.
- data/Gemfile +33 -0
- data/LICENSE +20 -0
- data/README.rdoc +27 -0
- data/Rakefile +25 -0
- data/TODO +75 -0
- data/config/flay.yml +3 -0
- data/config/flog.yml +2 -0
- data/config/roodi.yml +16 -0
- data/config/site.reek +91 -0
- data/config/yardstick.yml +2 -0
- data/lib/veritas/optimizer/algebra/difference.rb +66 -0
- data/lib/veritas/optimizer/algebra/extension.rb +42 -0
- data/lib/veritas/optimizer/algebra/intersection.rb +66 -0
- data/lib/veritas/optimizer/algebra/join.rb +44 -0
- data/lib/veritas/optimizer/algebra/product.rb +70 -0
- data/lib/veritas/optimizer/algebra/projection.rb +174 -0
- data/lib/veritas/optimizer/algebra/rename.rb +396 -0
- data/lib/veritas/optimizer/algebra/restriction.rb +259 -0
- data/lib/veritas/optimizer/algebra/summarization.rb +42 -0
- data/lib/veritas/optimizer/algebra/union.rb +66 -0
- data/lib/veritas/optimizer/logic/connective/binary.rb +254 -0
- data/lib/veritas/optimizer/logic/connective/conjunction.rb +122 -0
- data/lib/veritas/optimizer/logic/connective/disjunction.rb +122 -0
- data/lib/veritas/optimizer/logic/connective/negation.rb +71 -0
- data/lib/veritas/optimizer/logic/predicate/comparable.rb +134 -0
- data/lib/veritas/optimizer/logic/predicate/enumerable.rb +141 -0
- data/lib/veritas/optimizer/logic/predicate/equality.rb +44 -0
- data/lib/veritas/optimizer/logic/predicate/exclusion.rb +53 -0
- data/lib/veritas/optimizer/logic/predicate/greater_than.rb +54 -0
- data/lib/veritas/optimizer/logic/predicate/greater_than_or_equal_to.rb +56 -0
- data/lib/veritas/optimizer/logic/predicate/inclusion.rb +53 -0
- data/lib/veritas/optimizer/logic/predicate/inequality.rb +44 -0
- data/lib/veritas/optimizer/logic/predicate/less_than.rb +54 -0
- data/lib/veritas/optimizer/logic/predicate/less_than_or_equal_to.rb +56 -0
- data/lib/veritas/optimizer/logic/predicate/match.rb +19 -0
- data/lib/veritas/optimizer/logic/predicate/no_match.rb +19 -0
- data/lib/veritas/optimizer/logic/predicate.rb +177 -0
- data/lib/veritas/optimizer/optimizable.rb +59 -0
- data/lib/veritas/optimizer/relation/materialized.rb +40 -0
- data/lib/veritas/optimizer/relation/operation/binary.rb +168 -0
- data/lib/veritas/optimizer/relation/operation/combination.rb +33 -0
- data/lib/veritas/optimizer/relation/operation/limit.rb +149 -0
- data/lib/veritas/optimizer/relation/operation/offset.rb +114 -0
- data/lib/veritas/optimizer/relation/operation/order.rb +96 -0
- data/lib/veritas/optimizer/relation/operation/reverse.rb +94 -0
- data/lib/veritas/optimizer/relation/operation/unary.rb +88 -0
- data/lib/veritas/optimizer/version.rb +7 -0
- data/lib/veritas/optimizer.rb +136 -0
- data/lib/veritas-optimizer.rb +3 -0
- data/spec/integration/veritas/algebra/difference/optimize_spec.rb +152 -0
- data/spec/integration/veritas/algebra/intersection/optimize_spec.rb +152 -0
- data/spec/integration/veritas/algebra/join/optimize_spec.rb +110 -0
- data/spec/integration/veritas/algebra/product/optimize_spec.rb +176 -0
- data/spec/integration/veritas/algebra/projection/optimize_spec.rb +237 -0
- data/spec/integration/veritas/algebra/rename/optimize_spec.rb +440 -0
- data/spec/integration/veritas/algebra/restriction/optimize_spec.rb +216 -0
- data/spec/integration/veritas/algebra/union/optimize_spec.rb +192 -0
- data/spec/integration/veritas/logic/connective/conjunction/optimize_spec.rb +234 -0
- data/spec/integration/veritas/logic/connective/disjunction/optimize_spec.rb +235 -0
- data/spec/integration/veritas/logic/connective/negation/optimize_spec.rb +41 -0
- data/spec/integration/veritas/logic/expression/optimize_spec.rb +42 -0
- data/spec/integration/veritas/logic/predicate/equality/optimize_spec.rb +90 -0
- data/spec/integration/veritas/logic/predicate/exclusion/optimize_spec.rb +131 -0
- data/spec/integration/veritas/logic/predicate/greater_than/optimize_spec.rb +100 -0
- data/spec/integration/veritas/logic/predicate/greater_than_or_equal_to/optimize_spec.rb +100 -0
- data/spec/integration/veritas/logic/predicate/inclusion/optimize_spec.rb +131 -0
- data/spec/integration/veritas/logic/predicate/inequality/optimize_spec.rb +90 -0
- data/spec/integration/veritas/logic/predicate/less_than/optimize_spec.rb +100 -0
- data/spec/integration/veritas/logic/predicate/less_than_or_equal_to/optimize_spec.rb +100 -0
- data/spec/integration/veritas/relation/empty/optimize_spec.rb +11 -0
- data/spec/integration/veritas/relation/materialized/optimize_spec.rb +37 -0
- data/spec/integration/veritas/relation/operation/limit/optimize_spec.rb +140 -0
- data/spec/integration/veritas/relation/operation/offset/optimize_spec.rb +98 -0
- data/spec/integration/veritas/relation/operation/order/optimize_spec.rb +103 -0
- data/spec/integration/veritas/relation/operation/reverse/optimize_spec.rb +113 -0
- data/spec/integration/veritas/relation/optimize_spec.rb +33 -0
- data/spec/rcov.opts +6 -0
- data/spec/shared/idempotent_method_behavior.rb +5 -0
- data/spec/shared/logic_connective_binary_optimize_behavior.rb +100 -0
- data/spec/shared/optimize_method_behavior.rb +14 -0
- data/spec/spec.opts +3 -0
- data/spec/spec_helper.rb +16 -0
- data/spec/support/add_method_missing.rb +13 -0
- data/spec/unit/veritas/optimizer/algebra/difference/empty_left/optimize_spec.rb +17 -0
- data/spec/unit/veritas/optimizer/algebra/difference/empty_right/optimize_spec.rb +17 -0
- data/spec/unit/veritas/optimizer/algebra/difference/equal_operands/optimize_spec.rb +19 -0
- data/spec/unit/veritas/optimizer/algebra/extension/unoptimized_operand/optimizable_spec.rb +27 -0
- data/spec/unit/veritas/optimizer/algebra/extension/unoptimized_operand/optimize_spec.rb +25 -0
- data/spec/unit/veritas/optimizer/algebra/intersection/empty_left/optimize_spec.rb +17 -0
- data/spec/unit/veritas/optimizer/algebra/intersection/empty_right/optimize_spec.rb +17 -0
- data/spec/unit/veritas/optimizer/algebra/intersection/equal_operands/optimize_spec.rb +17 -0
- data/spec/unit/veritas/optimizer/algebra/join/equal_headers/optimizable_spec.rb +27 -0
- data/spec/unit/veritas/optimizer/algebra/join/equal_headers/optimize_spec.rb +21 -0
- data/spec/unit/veritas/optimizer/algebra/product/table_dee_left/optimizable_spec.rb +25 -0
- data/spec/unit/veritas/optimizer/algebra/product/table_dee_left/optimize_spec.rb +16 -0
- data/spec/unit/veritas/optimizer/algebra/product/table_dee_right/optimizable_spec.rb +25 -0
- data/spec/unit/veritas/optimizer/algebra/product/table_dee_right/optimize_spec.rb +16 -0
- data/spec/unit/veritas/optimizer/algebra/projection/empty_operand/optimizable_spec.rb +25 -0
- data/spec/unit/veritas/optimizer/algebra/projection/empty_operand/optimize_spec.rb +18 -0
- data/spec/unit/veritas/optimizer/algebra/projection/header_spec.rb +16 -0
- data/spec/unit/veritas/optimizer/algebra/projection/projection_operand/optimizable_spec.rb +26 -0
- data/spec/unit/veritas/optimizer/algebra/projection/projection_operand/optimize_spec.rb +20 -0
- data/spec/unit/veritas/optimizer/algebra/projection/set_operand/optimizable_spec.rb +27 -0
- data/spec/unit/veritas/optimizer/algebra/projection/set_operand/optimize_spec.rb +23 -0
- data/spec/unit/veritas/optimizer/algebra/projection/unchanged_header/optimizable_spec.rb +26 -0
- data/spec/unit/veritas/optimizer/algebra/projection/unchanged_header/optimize_spec.rb +16 -0
- data/spec/unit/veritas/optimizer/algebra/projection/unoptimized_operand/optimizable_spec.rb +26 -0
- data/spec/unit/veritas/optimizer/algebra/projection/unoptimized_operand/optimize_spec.rb +20 -0
- data/spec/unit/veritas/optimizer/algebra/rename/aliases_spec.rb +31 -0
- data/spec/unit/veritas/optimizer/algebra/rename/class_methods/union_aliases_spec.rb +27 -0
- data/spec/unit/veritas/optimizer/algebra/rename/empty_operand/optimizable_spec.rb +25 -0
- data/spec/unit/veritas/optimizer/algebra/rename/empty_operand/optimize_spec.rb +17 -0
- data/spec/unit/veritas/optimizer/algebra/rename/header_spec.rb +19 -0
- data/spec/unit/veritas/optimizer/algebra/rename/limit_operand/optimizable_spec.rb +26 -0
- data/spec/unit/veritas/optimizer/algebra/rename/limit_operand/optimize_spec.rb +21 -0
- data/spec/unit/veritas/optimizer/algebra/rename/offset_operand/optimizable_spec.rb +26 -0
- data/spec/unit/veritas/optimizer/algebra/rename/offset_operand/optimize_spec.rb +21 -0
- data/spec/unit/veritas/optimizer/algebra/rename/order_operand/optimizable_spec.rb +26 -0
- data/spec/unit/veritas/optimizer/algebra/rename/order_operand/optimize_spec.rb +20 -0
- data/spec/unit/veritas/optimizer/algebra/rename/projection_operand/optimizable_spec.rb +26 -0
- data/spec/unit/veritas/optimizer/algebra/rename/projection_operand/optimize_spec.rb +20 -0
- data/spec/unit/veritas/optimizer/algebra/rename/rename_operand/optimizable_spec.rb +28 -0
- data/spec/unit/veritas/optimizer/algebra/rename/rename_operand/optimize_spec.rb +20 -0
- data/spec/unit/veritas/optimizer/algebra/rename/rename_operand_and_empty_aliases/optimizable_spec.rb +35 -0
- data/spec/unit/veritas/optimizer/algebra/rename/rename_operand_and_empty_aliases/optimize_spec.rb +16 -0
- data/spec/unit/veritas/optimizer/algebra/rename/restriction_operand/optimizable_spec.rb +27 -0
- data/spec/unit/veritas/optimizer/algebra/rename/restriction_operand/optimize_spec.rb +21 -0
- data/spec/unit/veritas/optimizer/algebra/rename/reverse_operand/optimizable_spec.rb +25 -0
- data/spec/unit/veritas/optimizer/algebra/rename/reverse_operand/optimize_spec.rb +21 -0
- data/spec/unit/veritas/optimizer/algebra/rename/set_operand/optimizable_spec.rb +27 -0
- data/spec/unit/veritas/optimizer/algebra/rename/set_operand/optimize_spec.rb +21 -0
- data/spec/unit/veritas/optimizer/algebra/rename/unchanged_header/optimizable_spec.rb +26 -0
- data/spec/unit/veritas/optimizer/algebra/rename/unchanged_header/optimize_spec.rb +16 -0
- data/spec/unit/veritas/optimizer/algebra/rename/unoptimized_operand/optimizable_spec.rb +42 -0
- data/spec/unit/veritas/optimizer/algebra/rename/unoptimized_operand/optimize_spec.rb +21 -0
- data/spec/unit/veritas/optimizer/algebra/restriction/class_methods/optimize_predicate_spec.rb +31 -0
- data/spec/unit/veritas/optimizer/algebra/restriction/contradiction/optimizable_spec.rb +26 -0
- data/spec/unit/veritas/optimizer/algebra/restriction/contradiction/optimize_spec.rb +19 -0
- data/spec/unit/veritas/optimizer/algebra/restriction/order_operand/optimizable_spec.rb +26 -0
- data/spec/unit/veritas/optimizer/algebra/restriction/order_operand/optimize_spec.rb +18 -0
- data/spec/unit/veritas/optimizer/algebra/restriction/predicate_spec.rb +16 -0
- data/spec/unit/veritas/optimizer/algebra/restriction/restriction_operand/optimizable_spec.rb +28 -0
- data/spec/unit/veritas/optimizer/algebra/restriction/restriction_operand/optimize_spec.rb +22 -0
- data/spec/unit/veritas/optimizer/algebra/restriction/reverse_operand/optimizable_spec.rb +26 -0
- data/spec/unit/veritas/optimizer/algebra/restriction/reverse_operand/optimize_spec.rb +18 -0
- data/spec/unit/veritas/optimizer/algebra/restriction/set_operand/optimizable_spec.rb +28 -0
- data/spec/unit/veritas/optimizer/algebra/restriction/set_operand/optimize_spec.rb +22 -0
- data/spec/unit/veritas/optimizer/algebra/restriction/tautology/optimizable_spec.rb +25 -0
- data/spec/unit/veritas/optimizer/algebra/restriction/tautology/optimize_spec.rb +17 -0
- data/spec/unit/veritas/optimizer/algebra/restriction/unoptimized_operand/optimizable_spec.rb +42 -0
- data/spec/unit/veritas/optimizer/algebra/restriction/unoptimized_operand/optimize_spec.rb +22 -0
- data/spec/unit/veritas/optimizer/algebra/summarization/unoptimized_operand/optimizable_spec.rb +27 -0
- data/spec/unit/veritas/optimizer/algebra/summarization/unoptimized_operand/optimize_spec.rb +27 -0
- data/spec/unit/veritas/optimizer/algebra/union/empty_left/optimize_spec.rb +17 -0
- data/spec/unit/veritas/optimizer/algebra/union/empty_right/optimize_spec.rb +17 -0
- data/spec/unit/veritas/optimizer/algebra/union/equal_operands/optimize_spec.rb +17 -0
- data/spec/unit/veritas/optimizer/class_methods/chain_spec.rb +54 -0
- data/spec/unit/veritas/optimizer/logic/connective/binary/equal_operands/optimizable_spec.rb +27 -0
- data/spec/unit/veritas/optimizer/logic/connective/binary/equal_operands/optimize_spec.rb +17 -0
- data/spec/unit/veritas/optimizer/logic/connective/binary/left_spec.rb +14 -0
- data/spec/unit/veritas/optimizer/logic/connective/binary/redundant_left_operand/optimizable_spec.rb +26 -0
- data/spec/unit/veritas/optimizer/logic/connective/binary/redundant_left_operand/optimize_spec.rb +21 -0
- data/spec/unit/veritas/optimizer/logic/connective/binary/redundant_right_operand/optimizable_spec.rb +26 -0
- data/spec/unit/veritas/optimizer/logic/connective/binary/redundant_right_operand/optimize_spec.rb +21 -0
- data/spec/unit/veritas/optimizer/logic/connective/binary/right_spec.rb +14 -0
- data/spec/unit/veritas/optimizer/logic/connective/binary/unoptimized_operand/optimizable_spec.rb +34 -0
- data/spec/unit/veritas/optimizer/logic/connective/binary/unoptimized_operand/optimize_spec.rb +21 -0
- data/spec/unit/veritas/optimizer/logic/connective/conjunction/contradiction/optimizable_spec.rb +41 -0
- data/spec/unit/veritas/optimizer/logic/connective/conjunction/contradiction/optimize_spec.rb +17 -0
- data/spec/unit/veritas/optimizer/logic/connective/conjunction/left_operand_tautology/optimizable_spec.rb +27 -0
- data/spec/unit/veritas/optimizer/logic/connective/conjunction/left_operand_tautology/optimize_spec.rb +17 -0
- data/spec/unit/veritas/optimizer/logic/connective/conjunction/optimizable_to_exclusion/optimizable_spec.rb +27 -0
- data/spec/unit/veritas/optimizer/logic/connective/conjunction/optimizable_to_exclusion/optimize_spec.rb +36 -0
- data/spec/unit/veritas/optimizer/logic/connective/conjunction/right_operand_tautology/optimizable_spec.rb +27 -0
- data/spec/unit/veritas/optimizer/logic/connective/conjunction/right_operand_tautology/optimize_spec.rb +17 -0
- data/spec/unit/veritas/optimizer/logic/connective/disjunction/contradiction_left_operand/optimizable_spec.rb +27 -0
- data/spec/unit/veritas/optimizer/logic/connective/disjunction/contradiction_left_operand/optimize_spec.rb +17 -0
- data/spec/unit/veritas/optimizer/logic/connective/disjunction/contradiction_right_operand/optimizable_spec.rb +27 -0
- data/spec/unit/veritas/optimizer/logic/connective/disjunction/contradiction_right_operand/optimize_spec.rb +17 -0
- data/spec/unit/veritas/optimizer/logic/connective/disjunction/optimizable_to_inclusion/optimizable_spec.rb +27 -0
- data/spec/unit/veritas/optimizer/logic/connective/disjunction/optimizable_to_inclusion/optimize_spec.rb +36 -0
- data/spec/unit/veritas/optimizer/logic/connective/disjunction/tautology/optimizable_spec.rb +41 -0
- data/spec/unit/veritas/optimizer/logic/connective/disjunction/tautology/optimize_spec.rb +17 -0
- data/spec/unit/veritas/optimizer/logic/connective/negation/invertible_operand/optimizable_spec.rb +26 -0
- data/spec/unit/veritas/optimizer/logic/connective/negation/invertible_operand/optimize_spec.rb +20 -0
- data/spec/unit/veritas/optimizer/logic/connective/negation/operand_spec.rb +12 -0
- data/spec/unit/veritas/optimizer/logic/predicate/class_methods/optimize_operand_spec.rb +20 -0
- data/spec/unit/veritas/optimizer/logic/predicate/comparable/never_comparable/optimizable_spec.rb +58 -0
- data/spec/unit/veritas/optimizer/logic/predicate/comparable/never_equivalent/optimizable_spec.rb +58 -0
- data/spec/unit/veritas/optimizer/logic/predicate/comparable/normalizable_operands/optimizable_spec.rb +41 -0
- data/spec/unit/veritas/optimizer/logic/predicate/comparable/normalizable_operands/optimize_spec.rb +19 -0
- data/spec/unit/veritas/optimizer/logic/predicate/constant_operands/optimizable_spec.rb +29 -0
- data/spec/unit/veritas/optimizer/logic/predicate/constant_operands/optimize_spec.rb +14 -0
- data/spec/unit/veritas/optimizer/logic/predicate/contradiction/optimize_spec.rb +16 -0
- data/spec/unit/veritas/optimizer/logic/predicate/enumerable/empty_right_operand/optimizable_spec.rb +76 -0
- data/spec/unit/veritas/optimizer/logic/predicate/enumerable/one_right_operand/optimizable_spec.rb +76 -0
- data/spec/unit/veritas/optimizer/logic/predicate/enumerable/unoptimized_operand/optimizable_spec.rb +49 -0
- data/spec/unit/veritas/optimizer/logic/predicate/enumerable/unoptimized_operand/optimize_spec.rb +53 -0
- data/spec/unit/veritas/optimizer/logic/predicate/equality/tautology/optimizable_spec.rb +27 -0
- data/spec/unit/veritas/optimizer/logic/predicate/exclusion/empty_right_operand/optimize_spec.rb +43 -0
- data/spec/unit/veritas/optimizer/logic/predicate/exclusion/one_right_operand/optimize_spec.rb +63 -0
- data/spec/unit/veritas/optimizer/logic/predicate/greater_than/contradiction/optimizable_spec.rb +41 -0
- data/spec/unit/veritas/optimizer/logic/predicate/greater_than/tautology/optimizable_spec.rb +26 -0
- data/spec/unit/veritas/optimizer/logic/predicate/greater_than_or_equal_to/contradiction/optimizable_spec.rb +41 -0
- data/spec/unit/veritas/optimizer/logic/predicate/greater_than_or_equal_to/tautology/optimizable_spec.rb +41 -0
- data/spec/unit/veritas/optimizer/logic/predicate/inclusion/empty_right_operand/optimize_spec.rb +43 -0
- data/spec/unit/veritas/optimizer/logic/predicate/inclusion/one_right_operand/optimize_spec.rb +64 -0
- data/spec/unit/veritas/optimizer/logic/predicate/inequality/contradiction/optimizable_spec.rb +27 -0
- data/spec/unit/veritas/optimizer/logic/predicate/left_spec.rb +25 -0
- data/spec/unit/veritas/optimizer/logic/predicate/less_than/contradiction/optimizable_spec.rb +41 -0
- data/spec/unit/veritas/optimizer/logic/predicate/less_than/tautology/optimizable_spec.rb +26 -0
- data/spec/unit/veritas/optimizer/logic/predicate/less_than_or_equal_to/contradiction/optimizable_spec.rb +41 -0
- data/spec/unit/veritas/optimizer/logic/predicate/less_than_or_equal_to/tautology/optimizable_spec.rb +41 -0
- data/spec/unit/veritas/optimizer/logic/predicate/right_spec.rb +25 -0
- data/spec/unit/veritas/optimizer/logic/predicate/tautology/optimize_spec.rb +16 -0
- data/spec/unit/veritas/optimizer/logic/predicate/util/class_methods/attribute_spec.rb +19 -0
- data/spec/unit/veritas/optimizer/logic/predicate/util/class_methods/constant_spec.rb +19 -0
- data/spec/unit/veritas/optimizer/logic/predicate/util/class_methods/max_spec.rb +19 -0
- data/spec/unit/veritas/optimizer/logic/predicate/util/class_methods/min_spec.rb +19 -0
- data/spec/unit/veritas/optimizer/operation_spec.rb +11 -0
- data/spec/unit/veritas/optimizer/optimizable/class_methods/optimizer_spec.rb +32 -0
- data/spec/unit/veritas/optimizer/optimizable/optimize_spec.rb +36 -0
- data/spec/unit/veritas/optimizer/optimizable_spec.rb +15 -0
- data/spec/unit/veritas/optimizer/optimize_spec.rb +15 -0
- data/spec/unit/veritas/optimizer/relation/materialized/empty_operand/optimizable_spec.rb +20 -0
- data/spec/unit/veritas/optimizer/relation/materialized/empty_operand/optimize_spec.rb +17 -0
- data/spec/unit/veritas/optimizer/relation/operation/binary/empty_left/optimizable_spec.rb +30 -0
- data/spec/unit/veritas/optimizer/relation/operation/binary/empty_right/optimizable_spec.rb +30 -0
- data/spec/unit/veritas/optimizer/relation/operation/binary/equal_operands/optimizable_spec.rb +34 -0
- data/spec/unit/veritas/optimizer/relation/operation/binary/left_spec.rb +17 -0
- data/spec/unit/veritas/optimizer/relation/operation/binary/materialized_operand/optimizable_spec.rb +35 -0
- data/spec/unit/veritas/optimizer/relation/operation/binary/materialized_operand/optimize_spec.rb +20 -0
- data/spec/unit/veritas/optimizer/relation/operation/binary/right_spec.rb +17 -0
- data/spec/unit/veritas/optimizer/relation/operation/binary/unoptimized_operand/optimizable_spec.rb +38 -0
- data/spec/unit/veritas/optimizer/relation/operation/binary/unoptimized_operand/optimize_spec.rb +22 -0
- data/spec/unit/veritas/optimizer/relation/operation/combination/optimize_spec.rb +14 -0
- data/spec/unit/veritas/optimizer/relation/operation/limit/equal_limit_operand/optimizable_spec.rb +31 -0
- data/spec/unit/veritas/optimizer/relation/operation/limit/equal_limit_operand/optimize_spec.rb +16 -0
- data/spec/unit/veritas/optimizer/relation/operation/limit/limit_operand/optimizable_spec.rb +25 -0
- data/spec/unit/veritas/optimizer/relation/operation/limit/limit_operand/optimize_spec.rb +33 -0
- data/spec/unit/veritas/optimizer/relation/operation/limit/unoptimized_operand/optimizable_spec.rb +26 -0
- data/spec/unit/veritas/optimizer/relation/operation/limit/unoptimized_operand/optimize_spec.rb +20 -0
- data/spec/unit/veritas/optimizer/relation/operation/limit/zero_limit/optimizable_spec.rb +25 -0
- data/spec/unit/veritas/optimizer/relation/operation/limit/zero_limit/optimize_spec.rb +18 -0
- data/spec/unit/veritas/optimizer/relation/operation/offset/offset_operand/optimizable_spec.rb +25 -0
- data/spec/unit/veritas/optimizer/relation/operation/offset/offset_operand/optimize_spec.rb +19 -0
- data/spec/unit/veritas/optimizer/relation/operation/offset/unoptimized_operand/optimizable_spec.rb +26 -0
- data/spec/unit/veritas/optimizer/relation/operation/offset/unoptimized_operand/optimize_spec.rb +20 -0
- data/spec/unit/veritas/optimizer/relation/operation/offset/zero_offset/optimizable_spec.rb +25 -0
- data/spec/unit/veritas/optimizer/relation/operation/offset/zero_offset/optimize_spec.rb +15 -0
- data/spec/unit/veritas/optimizer/relation/operation/order/one_limit_operand/optimizable_spec.rb +31 -0
- data/spec/unit/veritas/optimizer/relation/operation/order/one_limit_operand/optimize_spec.rb +16 -0
- data/spec/unit/veritas/optimizer/relation/operation/order/order_operand/optimizable_spec.rb +25 -0
- data/spec/unit/veritas/optimizer/relation/operation/order/order_operand/optimize_spec.rb +20 -0
- data/spec/unit/veritas/optimizer/relation/operation/order/unoptimized_operand/optimizable_spec.rb +26 -0
- data/spec/unit/veritas/optimizer/relation/operation/order/unoptimized_operand/optimize_spec.rb +21 -0
- data/spec/unit/veritas/optimizer/relation/operation/reverse/order_operand/optimizable_spec.rb +25 -0
- data/spec/unit/veritas/optimizer/relation/operation/reverse/order_operand/optimize_spec.rb +20 -0
- data/spec/unit/veritas/optimizer/relation/operation/reverse/reverse_operand/optimizable_spec.rb +25 -0
- data/spec/unit/veritas/optimizer/relation/operation/reverse/reverse_operand/optimize_spec.rb +17 -0
- data/spec/unit/veritas/optimizer/relation/operation/reverse/unoptimized_operand/optimizable_spec.rb +25 -0
- data/spec/unit/veritas/optimizer/relation/operation/reverse/unoptimized_operand/optimize_spec.rb +22 -0
- data/spec/unit/veritas/optimizer/relation/operation/unary/empty_operand/optimizable_spec.rb +20 -0
- data/spec/unit/veritas/optimizer/relation/operation/unary/empty_operand/optimize_spec.rb +15 -0
- data/spec/unit/veritas/optimizer/relation/operation/unary/materialized_operand/optimizable_spec.rb +20 -0
- data/spec/unit/veritas/optimizer/relation/operation/unary/materialized_operand/optimize_spec.rb +18 -0
- data/spec/unit/veritas/optimizer/relation/operation/unary/operand_spec.rb +13 -0
- data/tasks/quality/ci.rake +2 -0
- data/tasks/quality/flay.rake +41 -0
- data/tasks/quality/flog.rake +45 -0
- data/tasks/quality/heckle.rake +203 -0
- data/tasks/quality/metric_fu.rake +26 -0
- data/tasks/quality/reek.rake +9 -0
- data/tasks/quality/roodi.rake +15 -0
- data/tasks/quality/yardstick.rake +23 -0
- data/tasks/spec.rake +38 -0
- data/tasks/yard.rake +9 -0
- data/veritas-optimizer.gemspec +550 -0
- metadata +613 -0
@@ -0,0 +1,100 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Logic::Predicate::LessThan, '#optimize' do
|
4
|
+
subject { object.optimize }
|
5
|
+
|
6
|
+
let(:attribute) { Attribute::Integer.new(:id, :required => false) }
|
7
|
+
let(:left) { attribute }
|
8
|
+
let(:right) { attribute }
|
9
|
+
let(:object) { described_class.new(left, right) }
|
10
|
+
|
11
|
+
context 'left and right are attributes' do
|
12
|
+
context 'and equivalent' do
|
13
|
+
it { should equal(Logic::Proposition::Contradiction.instance) }
|
14
|
+
|
15
|
+
it_should_behave_like 'an optimize method'
|
16
|
+
end
|
17
|
+
|
18
|
+
context 'and are not comparable' do
|
19
|
+
let(:right) { Attribute::Float.new(:float) }
|
20
|
+
|
21
|
+
it { should equal(Logic::Proposition::Contradiction.instance) }
|
22
|
+
|
23
|
+
it_should_behave_like 'an optimize method'
|
24
|
+
end
|
25
|
+
|
26
|
+
context 'and left is always less than right' do
|
27
|
+
let(:left) { attribute }
|
28
|
+
let(:right) { Attribute::Integer.new(:right, :size => 2**31..2**31) }
|
29
|
+
|
30
|
+
it { should equal(Logic::Proposition::Tautology.instance) }
|
31
|
+
|
32
|
+
it_should_behave_like 'an optimize method'
|
33
|
+
end
|
34
|
+
|
35
|
+
context 'and left is always greater than or equal to right' do
|
36
|
+
let(:left) { attribute }
|
37
|
+
let(:right) { Attribute::Integer.new(:right, :size => 0..0) }
|
38
|
+
|
39
|
+
it { should equal(Logic::Proposition::Contradiction.instance) }
|
40
|
+
|
41
|
+
it_should_behave_like 'an optimize method'
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
context 'left is an attribute' do
|
46
|
+
context 'right is a valid value' do
|
47
|
+
let(:right) { 1 }
|
48
|
+
|
49
|
+
it { should equal(object) }
|
50
|
+
|
51
|
+
it_should_behave_like 'an optimize method'
|
52
|
+
end
|
53
|
+
|
54
|
+
context 'right is an invalid primitive' do
|
55
|
+
let(:right) { nil }
|
56
|
+
|
57
|
+
it { should equal(Logic::Proposition::Contradiction.instance) }
|
58
|
+
|
59
|
+
it_should_behave_like 'an optimize method'
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
63
|
+
context 'right is an attribute' do
|
64
|
+
context 'left is a valid value' do
|
65
|
+
let(:left) { 1 }
|
66
|
+
|
67
|
+
it { should eql(Logic::Predicate::GreaterThan.new(attribute, 1)) }
|
68
|
+
|
69
|
+
it_should_behave_like 'an optimize method'
|
70
|
+
end
|
71
|
+
|
72
|
+
context 'left is an invalid primitive' do
|
73
|
+
let(:left) { nil }
|
74
|
+
|
75
|
+
it { should equal(Logic::Proposition::Contradiction.instance) }
|
76
|
+
|
77
|
+
it_should_behave_like 'an optimize method'
|
78
|
+
end
|
79
|
+
end
|
80
|
+
|
81
|
+
context 'left and right are constants' do
|
82
|
+
context 'that will evaluate to a tautology' do
|
83
|
+
let(:left) { 1 }
|
84
|
+
let(:right) { 2 }
|
85
|
+
|
86
|
+
it { should equal(Logic::Proposition::Tautology.instance) }
|
87
|
+
|
88
|
+
it_should_behave_like 'an optimize method'
|
89
|
+
end
|
90
|
+
|
91
|
+
context 'that will evaluate to a contradiction' do
|
92
|
+
let(:left) { 1 }
|
93
|
+
let(:right) { 1 }
|
94
|
+
|
95
|
+
it { should equal(Logic::Proposition::Contradiction.instance) }
|
96
|
+
|
97
|
+
it_should_behave_like 'an optimize method'
|
98
|
+
end
|
99
|
+
end
|
100
|
+
end
|
@@ -0,0 +1,100 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Logic::Predicate::LessThanOrEqualTo, '#optimize' do
|
4
|
+
subject { object.optimize }
|
5
|
+
|
6
|
+
let(:attribute) { Attribute::Integer.new(:id, :required => false) }
|
7
|
+
let(:left) { attribute }
|
8
|
+
let(:right) { attribute }
|
9
|
+
let(:object) { described_class.new(left, right) }
|
10
|
+
|
11
|
+
context 'left and right are attributes' do
|
12
|
+
context 'and equivalent' do
|
13
|
+
it { should equal(Logic::Proposition::Tautology.instance) }
|
14
|
+
|
15
|
+
it_should_behave_like 'an optimize method'
|
16
|
+
end
|
17
|
+
|
18
|
+
context 'and are not comparable' do
|
19
|
+
let(:right) { Attribute::Float.new(:float) }
|
20
|
+
|
21
|
+
it { should equal(Logic::Proposition::Contradiction.instance) }
|
22
|
+
|
23
|
+
it_should_behave_like 'an optimize method'
|
24
|
+
end
|
25
|
+
|
26
|
+
context 'and left is always less than right' do
|
27
|
+
let(:left) { attribute }
|
28
|
+
let(:right) { Attribute::Integer.new(:right, :size => 2**31..2**31) }
|
29
|
+
|
30
|
+
it { should equal(Logic::Proposition::Tautology.instance) }
|
31
|
+
|
32
|
+
it_should_behave_like 'an optimize method'
|
33
|
+
end
|
34
|
+
|
35
|
+
context 'and left is always greater than right' do
|
36
|
+
let(:left) { attribute }
|
37
|
+
let(:right) { Attribute::Integer.new(:right, :size => -1..-1) }
|
38
|
+
|
39
|
+
it { should equal(Logic::Proposition::Contradiction.instance) }
|
40
|
+
|
41
|
+
it_should_behave_like 'an optimize method'
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
context 'left is an attribute' do
|
46
|
+
context 'right is a valid value' do
|
47
|
+
let(:right) { 1 }
|
48
|
+
|
49
|
+
it { should equal(object) }
|
50
|
+
|
51
|
+
it_should_behave_like 'an optimize method'
|
52
|
+
end
|
53
|
+
|
54
|
+
context 'right is an invalid primitive' do
|
55
|
+
let(:right) { nil }
|
56
|
+
|
57
|
+
it { should equal(Logic::Proposition::Contradiction.instance) }
|
58
|
+
|
59
|
+
it_should_behave_like 'an optimize method'
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
63
|
+
context 'right is an attribute' do
|
64
|
+
context 'left is a valid value' do
|
65
|
+
let(:left) { 1 }
|
66
|
+
|
67
|
+
it { should eql(Logic::Predicate::GreaterThanOrEqualTo.new(attribute, 1)) }
|
68
|
+
|
69
|
+
it_should_behave_like 'an optimize method'
|
70
|
+
end
|
71
|
+
|
72
|
+
context 'left is an invalid primitive' do
|
73
|
+
let(:left) { nil }
|
74
|
+
|
75
|
+
it { should equal(Logic::Proposition::Contradiction.instance) }
|
76
|
+
|
77
|
+
it_should_behave_like 'an optimize method'
|
78
|
+
end
|
79
|
+
end
|
80
|
+
|
81
|
+
context 'left and right are constants' do
|
82
|
+
context 'that will evaluate to a tautology' do
|
83
|
+
let(:left) { 1 }
|
84
|
+
let(:right) { 1 }
|
85
|
+
|
86
|
+
it { should equal(Logic::Proposition::Tautology.instance) }
|
87
|
+
|
88
|
+
it_should_behave_like 'an optimize method'
|
89
|
+
end
|
90
|
+
|
91
|
+
context 'that will evaluate to a contradiction' do
|
92
|
+
let(:left) { 2 }
|
93
|
+
let(:right) { 1 }
|
94
|
+
|
95
|
+
it { should equal(Logic::Proposition::Contradiction.instance) }
|
96
|
+
|
97
|
+
it_should_behave_like 'an optimize method'
|
98
|
+
end
|
99
|
+
end
|
100
|
+
end
|
@@ -0,0 +1,37 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Relation::Materialized, '#optimize' do
|
4
|
+
subject { object.optimize }
|
5
|
+
|
6
|
+
let(:object) { described_class.new([ [ :id, Integer ] ], body) }
|
7
|
+
|
8
|
+
context 'with an empty Array' do
|
9
|
+
let(:body) { [] }
|
10
|
+
|
11
|
+
it { should eql(Relation::Empty.new(object.header)) }
|
12
|
+
|
13
|
+
it 'returns an equivalent object to the unoptimized operation' do
|
14
|
+
should == object
|
15
|
+
end
|
16
|
+
|
17
|
+
it 'does not execute body#each' do
|
18
|
+
body.should_not_receive(:each)
|
19
|
+
subject
|
20
|
+
end
|
21
|
+
|
22
|
+
it_should_behave_like 'an optimize method'
|
23
|
+
end
|
24
|
+
|
25
|
+
context 'with an nonempty Array' do
|
26
|
+
let(:body) { [ [ 1 ] ] }
|
27
|
+
|
28
|
+
it { should equal(object) }
|
29
|
+
|
30
|
+
it 'does not execute body#each' do
|
31
|
+
body.should_not_receive(:each)
|
32
|
+
subject
|
33
|
+
end
|
34
|
+
|
35
|
+
it_should_behave_like 'an optimize method'
|
36
|
+
end
|
37
|
+
end
|
@@ -0,0 +1,140 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Relation::Operation::Limit, '#optimize' do
|
4
|
+
subject { object.optimize }
|
5
|
+
|
6
|
+
let(:body) { [ [ 1 ], [ 2 ], [ 3 ] ].each }
|
7
|
+
let(:relation) { Relation.new([ [ :id, Integer ] ], body) }
|
8
|
+
let(:directions) { [ relation[:id] ] }
|
9
|
+
let(:order) { relation.order(directions) }
|
10
|
+
let(:operand) { order }
|
11
|
+
let(:limit) { 1 }
|
12
|
+
let(:object) { described_class.new(operand, limit) }
|
13
|
+
|
14
|
+
context 'when the limit is 0' do
|
15
|
+
let(:limit) { 0 }
|
16
|
+
|
17
|
+
it { should be_kind_of(Relation::Empty) }
|
18
|
+
|
19
|
+
it 'returns an equivalent relation to the unoptimized operation' do
|
20
|
+
should == object
|
21
|
+
end
|
22
|
+
|
23
|
+
it 'does not execute body#each' do
|
24
|
+
body.should_not_receive(:each)
|
25
|
+
subject
|
26
|
+
end
|
27
|
+
|
28
|
+
it_should_behave_like 'an optimize method'
|
29
|
+
end
|
30
|
+
|
31
|
+
context 'containing an order operation' do
|
32
|
+
it { should equal(object) }
|
33
|
+
|
34
|
+
it 'does not execute body#each' do
|
35
|
+
body.should_not_receive(:each)
|
36
|
+
subject
|
37
|
+
end
|
38
|
+
|
39
|
+
it_should_behave_like 'an optimize method'
|
40
|
+
end
|
41
|
+
|
42
|
+
context 'containing an optimizable order operation' do
|
43
|
+
let(:operand) { order.rename({}) }
|
44
|
+
|
45
|
+
it { should be_kind_of(described_class) }
|
46
|
+
|
47
|
+
its(:operand) { should equal(order) }
|
48
|
+
|
49
|
+
its(:limit) { should == 1 }
|
50
|
+
|
51
|
+
it 'returns an equivalent relation to the unoptimized operation' do
|
52
|
+
should == object
|
53
|
+
end
|
54
|
+
|
55
|
+
it 'does not execute body#each' do
|
56
|
+
body.should_not_receive(:each)
|
57
|
+
subject
|
58
|
+
end
|
59
|
+
|
60
|
+
it_should_behave_like 'an optimize method'
|
61
|
+
end
|
62
|
+
|
63
|
+
context 'containing a more restrictive object operation' do
|
64
|
+
let(:operand) { order.take(5) }
|
65
|
+
let(:limit) { 10 }
|
66
|
+
|
67
|
+
it { should be_kind_of(described_class) }
|
68
|
+
|
69
|
+
its(:operand) { should equal(order) }
|
70
|
+
|
71
|
+
it 'uses the more restrictive object' do
|
72
|
+
subject.limit.should == 5
|
73
|
+
end
|
74
|
+
|
75
|
+
it 'returns an equivalent relation to the unoptimized operation' do
|
76
|
+
should == object
|
77
|
+
end
|
78
|
+
|
79
|
+
it 'does not execute body#each' do
|
80
|
+
body.should_not_receive(:each)
|
81
|
+
subject
|
82
|
+
end
|
83
|
+
|
84
|
+
it_should_behave_like 'an optimize method'
|
85
|
+
end
|
86
|
+
|
87
|
+
context 'containing a less restrictive object operation' do
|
88
|
+
let(:operand) { order.take(10) }
|
89
|
+
let(:limit) { 5 }
|
90
|
+
|
91
|
+
it { should be_kind_of(described_class) }
|
92
|
+
|
93
|
+
its(:operand) { should equal(order) }
|
94
|
+
|
95
|
+
it 'uses the more restrictive object' do
|
96
|
+
subject.limit.should == 5
|
97
|
+
end
|
98
|
+
|
99
|
+
it 'returns an equivalent relation to the unoptimized operation' do
|
100
|
+
should == object
|
101
|
+
end
|
102
|
+
|
103
|
+
it 'does not execute body#each' do
|
104
|
+
body.should_not_receive(:each)
|
105
|
+
subject
|
106
|
+
end
|
107
|
+
|
108
|
+
it_should_behave_like 'an optimize method'
|
109
|
+
end
|
110
|
+
|
111
|
+
context 'containing a similar object operation' do
|
112
|
+
let(:operand) { order.take(10) }
|
113
|
+
let(:limit) { 10 }
|
114
|
+
|
115
|
+
it { should equal(operand) }
|
116
|
+
|
117
|
+
it 'returns an equivalent relation to the unoptimized operation' do
|
118
|
+
should == object
|
119
|
+
end
|
120
|
+
|
121
|
+
it 'does not execute body#each' do
|
122
|
+
body.should_not_receive(:each)
|
123
|
+
subject
|
124
|
+
end
|
125
|
+
|
126
|
+
it_should_behave_like 'an optimize method'
|
127
|
+
end
|
128
|
+
|
129
|
+
context 'containing a materialized relation' do
|
130
|
+
let(:relation) { Relation.new([ [ :id, Integer ] ], [ [ 1 ], [ 2 ], [ 3 ] ]) }
|
131
|
+
|
132
|
+
it { should eql(Relation::Materialized.new([ [ :id, Integer ] ], [ [ 1 ] ])) }
|
133
|
+
|
134
|
+
it 'returns an equivalent relation to the unoptimized operation' do
|
135
|
+
should == object
|
136
|
+
end
|
137
|
+
|
138
|
+
it_should_behave_like 'an optimize method'
|
139
|
+
end
|
140
|
+
end
|
@@ -0,0 +1,98 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Relation::Operation::Offset, '#optimize' do
|
4
|
+
subject { object.optimize }
|
5
|
+
|
6
|
+
let(:body) { [ [ 1 ], [ 2 ], [ 3 ] ].each }
|
7
|
+
let(:relation) { Relation.new([ [ :id, Integer ] ], body) }
|
8
|
+
let(:directions) { [ relation[:id] ] }
|
9
|
+
let(:order) { relation.order(directions) }
|
10
|
+
let(:operand) { order }
|
11
|
+
let(:offset) { 1 }
|
12
|
+
let(:object) { described_class.new(operand, offset) }
|
13
|
+
|
14
|
+
context 'with an object of 0' do
|
15
|
+
let(:offset) { 0 }
|
16
|
+
|
17
|
+
it { should equal(order) }
|
18
|
+
|
19
|
+
it 'returns an equivalent relation to the unoptimized operation' do
|
20
|
+
should == object
|
21
|
+
end
|
22
|
+
|
23
|
+
it 'does not execute body#each' do
|
24
|
+
body.should_not_receive(:each)
|
25
|
+
subject
|
26
|
+
end
|
27
|
+
|
28
|
+
it_should_behave_like 'an optimize method'
|
29
|
+
end
|
30
|
+
|
31
|
+
context 'containing an order operation' do
|
32
|
+
it { should equal(object) }
|
33
|
+
|
34
|
+
it 'does not execute body#each' do
|
35
|
+
body.should_not_receive(:each)
|
36
|
+
subject
|
37
|
+
end
|
38
|
+
|
39
|
+
it_should_behave_like 'an optimize method'
|
40
|
+
end
|
41
|
+
|
42
|
+
context 'containing an optimizable order operation' do
|
43
|
+
let(:operand) { order.rename({}) }
|
44
|
+
|
45
|
+
it { should be_kind_of(described_class) }
|
46
|
+
|
47
|
+
its(:operand) { should equal(order) }
|
48
|
+
|
49
|
+
its(:offset) { should == 1 }
|
50
|
+
|
51
|
+
it 'returns an equivalent relation to the unoptimized operation' do
|
52
|
+
should == object
|
53
|
+
end
|
54
|
+
|
55
|
+
it 'does not execute body#each' do
|
56
|
+
body.should_not_receive(:each)
|
57
|
+
subject
|
58
|
+
end
|
59
|
+
|
60
|
+
it_should_behave_like 'an optimize method'
|
61
|
+
end
|
62
|
+
|
63
|
+
context 'containing an object operation' do
|
64
|
+
let(:operand) { order.drop(5) }
|
65
|
+
let(:offset) { 10 }
|
66
|
+
|
67
|
+
it { should be_kind_of(described_class) }
|
68
|
+
|
69
|
+
its(:operand) { should equal(order) }
|
70
|
+
|
71
|
+
it 'adds the object of the operations' do
|
72
|
+
subject.offset.should == 15
|
73
|
+
end
|
74
|
+
|
75
|
+
it 'returns an equivalent relation to the unoptimized operation' do
|
76
|
+
should == object
|
77
|
+
end
|
78
|
+
|
79
|
+
it 'does not execute body#each' do
|
80
|
+
body.should_not_receive(:each)
|
81
|
+
subject
|
82
|
+
end
|
83
|
+
|
84
|
+
it_should_behave_like 'an optimize method'
|
85
|
+
end
|
86
|
+
|
87
|
+
context 'containing a materialized relation' do
|
88
|
+
let(:relation) { Relation.new([ [ :id, Integer ] ], [ [ 1 ], [ 2 ], [ 3 ] ]) }
|
89
|
+
|
90
|
+
it { should eql(Relation::Materialized.new([ [ :id, Integer ] ], [ [ 2 ], [ 3 ] ])) }
|
91
|
+
|
92
|
+
it 'returns an equivalent relation to the unoptimized operation' do
|
93
|
+
should == object
|
94
|
+
end
|
95
|
+
|
96
|
+
it_should_behave_like 'an optimize method'
|
97
|
+
end
|
98
|
+
end
|
@@ -0,0 +1,103 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Relation::Operation::Order, '#optimize' do
|
4
|
+
subject { object.optimize }
|
5
|
+
|
6
|
+
let(:body) { [ [ 1 ], [ 2 ], [ 3 ] ].each }
|
7
|
+
let(:relation) { Relation.new([ [ :id, Integer ] ], body) }
|
8
|
+
let(:operand) { relation }
|
9
|
+
let(:directions) { [ relation[:id] ] }
|
10
|
+
let(:object) { described_class.new(operand, directions) }
|
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 optimizable relation' do
|
24
|
+
let(:operand) { relation.project(relation.header) }
|
25
|
+
|
26
|
+
it { should eql(relation.order(directions)) }
|
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 object operation' do
|
41
|
+
let(:operand) { relation.order { |r| [ r[:id].desc ] } }
|
42
|
+
|
43
|
+
it { should eql(relation.order(directions)) }
|
44
|
+
|
45
|
+
it 'returns an equivalent relation to the unoptimized operation' do
|
46
|
+
should == object
|
47
|
+
end
|
48
|
+
|
49
|
+
it 'does not execute body#each' do
|
50
|
+
body.should_not_receive(:each)
|
51
|
+
subject
|
52
|
+
end
|
53
|
+
|
54
|
+
it_should_behave_like 'an optimize method'
|
55
|
+
end
|
56
|
+
|
57
|
+
context 'containing a reverse operation' do
|
58
|
+
let(:operand) { relation.order.reverse }
|
59
|
+
|
60
|
+
it { should eql(relation.order) }
|
61
|
+
|
62
|
+
it 'returns an equivalent relation to the unoptimized operation' do
|
63
|
+
should == object
|
64
|
+
end
|
65
|
+
|
66
|
+
it 'does not execute body#each' do
|
67
|
+
body.should_not_receive(:each)
|
68
|
+
subject
|
69
|
+
end
|
70
|
+
|
71
|
+
it_should_behave_like 'an optimize method'
|
72
|
+
end
|
73
|
+
|
74
|
+
context 'containing a limit(1) operation' do
|
75
|
+
let(:operand) { relation.order.take(1) }
|
76
|
+
|
77
|
+
it { should equal(operand) }
|
78
|
+
|
79
|
+
it 'returns an equivalent relation to the unoptimized operation' do
|
80
|
+
should == object
|
81
|
+
end
|
82
|
+
|
83
|
+
it 'does not execute body#each' do
|
84
|
+
body.should_not_receive(:each)
|
85
|
+
subject
|
86
|
+
end
|
87
|
+
|
88
|
+
it_should_behave_like 'an optimize method'
|
89
|
+
end
|
90
|
+
|
91
|
+
context 'containing a materialized relation' do
|
92
|
+
let(:relation) { Relation.new([ [ :id, Integer ] ], [ [ 1 ], [ 2 ], [ 3 ] ]) }
|
93
|
+
let(:object) { described_class.new(relation, directions) }
|
94
|
+
|
95
|
+
it { should eql(Relation::Materialized.new([ [ :id, Integer ] ], [ [ 1 ], [ 2 ], [ 3 ] ])) }
|
96
|
+
|
97
|
+
it 'returns an equivalent relation to the unoptimized operation' do
|
98
|
+
should == object
|
99
|
+
end
|
100
|
+
|
101
|
+
it_should_behave_like 'an optimize method'
|
102
|
+
end
|
103
|
+
end
|
@@ -0,0 +1,113 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Relation::Operation::Reverse, '#optimize' do
|
4
|
+
subject { object.optimize }
|
5
|
+
|
6
|
+
let(:body) { [ [ 1 ], [ 2 ], [ 3 ] ].each }
|
7
|
+
let(:relation) { Relation.new([ [ :id, Integer ] ], body) }
|
8
|
+
let(:order) { relation.order }
|
9
|
+
let(:operand) { order }
|
10
|
+
let(:object) { described_class.new(operand) }
|
11
|
+
|
12
|
+
context 'with a object operation' do
|
13
|
+
let(:limit) { order.take(2) }
|
14
|
+
let(:operand) { limit.reverse }
|
15
|
+
|
16
|
+
it 'cancels out the operations and return the contained operation' do
|
17
|
+
should equal(limit)
|
18
|
+
end
|
19
|
+
|
20
|
+
it 'returns an equivalent relation to the unoptimized operation' do
|
21
|
+
should == object
|
22
|
+
end
|
23
|
+
|
24
|
+
it 'does not execute body#each' do
|
25
|
+
body.should_not_receive(:each)
|
26
|
+
subject
|
27
|
+
end
|
28
|
+
|
29
|
+
it_should_behave_like 'an optimize method'
|
30
|
+
end
|
31
|
+
|
32
|
+
context 'with a object operation when optimized' do
|
33
|
+
let(:limit) { order.take(2) }
|
34
|
+
let(:operand) { limit.reverse.rename({}) }
|
35
|
+
|
36
|
+
it 'cancels out the operations and return the contained operation' do
|
37
|
+
should equal(limit)
|
38
|
+
end
|
39
|
+
|
40
|
+
it 'returns an equivalent relation to the unoptimized operation' do
|
41
|
+
should == object
|
42
|
+
end
|
43
|
+
|
44
|
+
it 'does not execute body#each' do
|
45
|
+
body.should_not_receive(:each)
|
46
|
+
subject
|
47
|
+
end
|
48
|
+
|
49
|
+
it_should_behave_like 'an optimize method'
|
50
|
+
end
|
51
|
+
|
52
|
+
context 'with an order operation' do
|
53
|
+
it { should eql(relation.order(object.directions)) }
|
54
|
+
|
55
|
+
it 'returns an equivalent relation to the unoptimized operation' do
|
56
|
+
should == object
|
57
|
+
end
|
58
|
+
|
59
|
+
it 'does not execute body#each' do
|
60
|
+
body.should_not_receive(:each)
|
61
|
+
subject
|
62
|
+
end
|
63
|
+
|
64
|
+
it_should_behave_like 'an optimize method'
|
65
|
+
end
|
66
|
+
|
67
|
+
context 'with an order operation when optimized' do
|
68
|
+
let(:operand) { order.rename({}) }
|
69
|
+
|
70
|
+
it { should eql(relation.order(object.directions)) }
|
71
|
+
|
72
|
+
it 'returns an equivalent relation to the unoptimized operation' do
|
73
|
+
should == object
|
74
|
+
end
|
75
|
+
|
76
|
+
it 'does not execute body#each' do
|
77
|
+
body.should_not_receive(:each)
|
78
|
+
subject
|
79
|
+
end
|
80
|
+
|
81
|
+
it_should_behave_like 'an optimize method'
|
82
|
+
end
|
83
|
+
|
84
|
+
context 'with an optimizable operation' do
|
85
|
+
let(:limit) { order.take(2) }
|
86
|
+
let(:operand) { limit.rename({}) }
|
87
|
+
|
88
|
+
it { should eql(order.take(2).reverse) }
|
89
|
+
|
90
|
+
it 'returns an equivalent relation to the unoptimized operation' do
|
91
|
+
should == object
|
92
|
+
end
|
93
|
+
|
94
|
+
it 'does not execute body#each' do
|
95
|
+
body.should_not_receive(:each)
|
96
|
+
subject
|
97
|
+
end
|
98
|
+
|
99
|
+
it_should_behave_like 'an optimize method'
|
100
|
+
end
|
101
|
+
|
102
|
+
context 'containing a materialized relation' do
|
103
|
+
let(:relation) { Relation.new([ [ :id, Integer ] ], [ [ 1 ], [ 2 ], [ 3 ] ]) }
|
104
|
+
|
105
|
+
it { should eql(Relation::Materialized.new([ [ :id, Integer ] ], [ [ 3 ], [ 2 ], [ 1 ] ])) }
|
106
|
+
|
107
|
+
it 'returns an equivalent relation to the unoptimized operation' do
|
108
|
+
should == object
|
109
|
+
end
|
110
|
+
|
111
|
+
it_should_behave_like 'an optimize method'
|
112
|
+
end
|
113
|
+
end
|