alf-core 0.14.0 → 0.15.0
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG.md +10 -0
- data/Gemfile +2 -8
- data/Gemfile.lock +9 -17
- data/examples/operators/frame.alf +2 -0
- data/lib/alf-core.rb +24 -22
- data/lib/{alf-adapter/alf → alf}/adapter.rb +0 -0
- data/lib/{alf-adapter/alf → alf}/adapter/connection.rb +4 -10
- data/lib/{alf-adapter/alf → alf}/adapter/connection/schema_cached.rb +0 -0
- data/lib/{alf-adapter-fs/alf → alf}/adapter/folder.rb +0 -0
- data/lib/{alf-adapter-fs/alf → alf}/adapter/folder/connection.rb +3 -2
- data/lib/{alf-adapter-fs/alf → alf}/adapter/fs.rb +0 -0
- data/lib/{alf-aggregator/alf → alf}/aggregator.rb +12 -9
- data/lib/{alf-aggregator/alf → alf}/aggregator/avg.rb +0 -0
- data/lib/{alf-aggregator/alf → alf}/aggregator/collect.rb +0 -0
- data/lib/{alf-aggregator/alf → alf}/aggregator/concat.rb +0 -0
- data/lib/{alf-aggregator/alf → alf}/aggregator/count.rb +0 -0
- data/lib/{alf-aggregator/alf → alf}/aggregator/max.rb +0 -0
- data/lib/{alf-aggregator/alf → alf}/aggregator/min.rb +0 -0
- data/lib/{alf-aggregator/alf → alf}/aggregator/stddev.rb +0 -0
- data/lib/{alf-aggregator/alf → alf}/aggregator/sum.rb +0 -0
- data/lib/{alf-aggregator/alf → alf}/aggregator/variance.rb +0 -0
- data/lib/{alf-algebra/alf → alf}/algebra.rb +1 -0
- data/lib/{alf-algebra/alf → alf}/algebra/operand.rb +13 -6
- data/lib/{alf-algebra/alf → alf}/algebra/operand/fake.rb +18 -4
- data/lib/alf/algebra/operand/named.rb +65 -0
- data/lib/{alf-algebra/alf → alf}/algebra/operand/proxy.rb +7 -3
- data/lib/{alf-algebra/alf → alf}/algebra/operator.rb +40 -12
- data/lib/{alf-algebra/alf → alf}/algebra/operator/autonum.rb +9 -1
- data/lib/{alf-algebra/alf → alf}/algebra/operator/clip.rb +9 -1
- data/lib/{alf-algebra/alf → alf}/algebra/operator/coerce.rb +9 -1
- data/lib/{alf-algebra/alf → alf}/algebra/operator/compact.rb +8 -1
- data/lib/{alf-algebra/alf → alf}/algebra/operator/defaults.rb +8 -1
- data/lib/{alf-algebra/alf → alf}/algebra/operator/extend.rb +9 -1
- data/lib/{alf-algebra/alf → alf}/algebra/operator/frame.rb +12 -1
- data/lib/{alf-algebra/alf → alf}/algebra/operator/generator.rb +8 -1
- data/lib/{alf-algebra/alf → alf}/algebra/operator/group.rb +10 -1
- data/lib/{alf-algebra/alf → alf}/algebra/operator/hierarchize.rb +8 -0
- data/lib/{alf-algebra/alf → alf}/algebra/operator/intersect.rb +9 -1
- data/lib/{alf-algebra/alf → alf}/algebra/operator/join.rb +9 -1
- data/lib/{alf-algebra/alf → alf}/algebra/operator/matching.rb +10 -2
- data/lib/{alf-algebra/alf → alf}/algebra/operator/minus.rb +9 -1
- data/lib/{alf-algebra/alf → alf}/algebra/operator/not_matching.rb +9 -1
- data/lib/{alf-algebra/alf → alf}/algebra/operator/page.rb +11 -1
- data/lib/{alf-algebra/alf → alf}/algebra/operator/project.rb +9 -1
- data/lib/{alf-algebra/alf → alf}/algebra/operator/quota.rb +12 -1
- data/lib/{alf-algebra/alf → alf}/algebra/operator/rank.rb +11 -2
- data/lib/{alf-algebra/alf → alf}/algebra/operator/rename.rb +10 -1
- data/lib/{alf-algebra/alf → alf}/algebra/operator/restrict.rb +12 -2
- data/lib/{alf-algebra/alf → alf}/algebra/operator/sort.rb +9 -1
- data/lib/{alf-algebra/alf → alf}/algebra/operator/summarize.rb +10 -1
- data/lib/{alf-algebra/alf → alf}/algebra/operator/ungroup.rb +11 -1
- data/lib/{alf-algebra/alf → alf}/algebra/operator/union.rb +9 -1
- data/lib/{alf-algebra/alf → alf}/algebra/operator/unwrap.rb +13 -1
- data/lib/{alf-algebra/alf → alf}/algebra/operator/wrap.rb +10 -1
- data/lib/alf/algebra/shortcut.rb +40 -0
- data/lib/alf/algebra/shortcut/allbut.rb +25 -0
- data/lib/{alf-algebra/alf → alf}/algebra/support.rb +2 -1
- data/lib/{alf-algebra/alf → alf}/algebra/support/binary.rb +0 -0
- data/lib/{alf-algebra/alf → alf}/algebra/support/classification.rb +0 -0
- data/lib/{alf-algebra/alf → alf}/algebra/support/compiler.rb +0 -0
- data/lib/{alf-algebra/alf → alf}/algebra/support/experimental.rb +0 -0
- data/lib/{alf-algebra/alf → alf}/algebra/support/non_relational.rb +0 -0
- data/lib/{alf-algebra/alf → alf}/algebra/support/nullary.rb +0 -0
- data/lib/{alf-algebra/alf → alf}/algebra/support/relational.rb +0 -0
- data/lib/{alf-algebra/alf → alf}/algebra/support/rewriter.rb +4 -0
- data/lib/{alf-algebra/alf → alf}/algebra/support/signature.rb +7 -8
- data/lib/alf/algebra/support/type_check.rb +51 -0
- data/lib/{alf-algebra/alf → alf}/algebra/support/unary.rb +0 -0
- data/lib/{alf-algebra/alf → alf}/algebra/support/visitor.rb +2 -1
- data/lib/{alf-algebra/alf → alf}/algebra/support/with_ordering.rb +0 -0
- data/lib/alf/compiler.rb +57 -0
- data/lib/alf/compiler/cog.rb +39 -0
- data/lib/alf/compiler/default.rb +168 -0
- data/lib/alf/compiler/plan.rb +77 -0
- data/lib/{alf-core → alf/core}/loader.rb +0 -0
- data/lib/{alf-core → alf/core}/version.rb +1 -1
- data/lib/{alf-database/alf → alf}/database.rb +0 -0
- data/lib/{alf-database/alf → alf}/database/connection.rb +10 -52
- data/lib/{alf-database/alf → alf}/database/options.rb +2 -5
- data/lib/{alf-core → alf}/dsl.rb +4 -4
- data/lib/{alf-engine/alf → alf}/engine.rb +0 -2
- data/lib/{alf-engine/alf → alf}/engine/aggregate.rb +6 -2
- data/lib/{alf-engine/alf → alf}/engine/autonum.rb +6 -2
- data/lib/{alf-engine/alf → alf}/engine/clip.rb +10 -2
- data/lib/{alf-engine/alf → alf}/engine/coerce.rb +6 -2
- data/lib/alf/engine/cog.rb +58 -0
- data/lib/{alf-engine/alf → alf}/engine/compact.rb +2 -2
- data/lib/{alf-engine/alf → alf}/engine/compact/set.rb +2 -2
- data/lib/{alf-engine/alf → alf}/engine/compact/uniq.rb +2 -2
- data/lib/{alf-engine/alf → alf}/engine/concat.rb +2 -2
- data/lib/{alf-engine/alf → alf}/engine/defaults.rb +6 -2
- data/lib/{alf-engine/alf → alf}/engine/filter.rb +8 -4
- data/lib/{alf-engine/alf → alf}/engine/generator.rb +6 -2
- data/lib/alf/engine/group.rb +7 -0
- data/lib/{alf-engine/alf → alf}/engine/group/hash.rb +11 -2
- data/lib/{alf-engine/alf → alf}/engine/hierarchize.rb +6 -2
- data/lib/{alf-engine/alf → alf}/engine/infer_heading.rb +2 -2
- data/lib/{alf-engine/alf → alf}/engine/join.rb +0 -0
- data/lib/{alf-engine/alf → alf}/engine/join/hash.rb +2 -2
- data/lib/{alf-engine/alf → alf}/engine/leaf.rb +7 -3
- data/lib/{alf-engine/alf → alf}/engine/materialize.rb +5 -1
- data/lib/{alf-engine/alf → alf}/engine/materialize/array.rb +3 -2
- data/lib/{alf-engine/alf → alf}/engine/materialize/hash.rb +3 -2
- data/lib/alf/engine/quota.rb +7 -0
- data/lib/{alf-engine/alf → alf}/engine/quota/cesure.rb +8 -3
- data/lib/alf/engine/rank.rb +7 -0
- data/lib/{alf-engine/alf → alf}/engine/rank/cesure.rb +8 -3
- data/lib/{alf-engine/alf → alf}/engine/rename.rb +6 -2
- data/lib/alf/engine/semi.rb +7 -0
- data/lib/{alf-engine/alf → alf}/engine/semi/hash.rb +7 -2
- data/lib/{alf-engine/alf → alf}/engine/set_attr.rb +8 -4
- data/lib/alf/engine/sort.rb +13 -0
- data/lib/{alf-engine/alf → alf}/engine/sort/in_memory.rb +12 -2
- data/lib/alf/engine/summarize.rb +13 -0
- data/lib/{alf-engine/alf → alf}/engine/summarize/cesure.rb +5 -4
- data/lib/{alf-engine/alf → alf}/engine/summarize/hash.rb +3 -2
- data/lib/{alf-engine/alf → alf}/engine/support/cesure.rb +0 -0
- data/lib/{alf-engine/alf → alf}/engine/take.rb +6 -2
- data/lib/{alf-engine/alf → alf}/engine/to_array.rb +13 -5
- data/lib/{alf-engine/alf → alf}/engine/type_safe.rb +2 -2
- data/lib/{alf-engine/alf → alf}/engine/ungroup.rb +7 -2
- data/lib/{alf-engine/alf → alf}/engine/unwrap.rb +11 -5
- data/lib/{alf-engine/alf → alf}/engine/wrap.rb +6 -2
- data/lib/{alf-core → alf}/errors.rb +2 -3
- data/lib/{alf-core → alf}/ext.rb +0 -0
- data/lib/{alf-core → alf}/ext/domain/heading_based.rb +5 -0
- data/lib/alf/facade.rb +53 -0
- data/lib/{alf-lang/alf → alf}/lang.rb +1 -1
- data/lib/{alf-lang/alf → alf}/lang/functional.rb +0 -4
- data/lib/{alf-lang/alf → alf}/lang/object_oriented.rb +0 -0
- data/lib/{alf-lang/alf → alf}/lang/oo/aggregation_methods.rb +1 -1
- data/lib/{alf-lang/alf → alf}/lang/oo/algebra_methods.rb +0 -12
- data/lib/{alf-lang/alf → alf}/lang/oo/rendering_methods.rb +1 -1
- data/lib/alf/lang/parser.rb +9 -0
- data/lib/alf/lang/parser/lispy.rb +63 -0
- data/lib/alf/lang/parser/safer.rb +69 -0
- data/lib/{alf-lang/alf → alf}/lang/predicates.rb +1 -1
- data/lib/{alf-optimizer/alf → alf}/optimizer.rb +15 -7
- data/lib/alf/optimizer/project.rb +182 -0
- data/lib/{alf-optimizer/alf → alf}/optimizer/restrict.rb +48 -50
- data/lib/{alf-predicate/alf → alf}/predicate.rb +16 -12
- data/lib/{alf-predicate/alf → alf}/predicate/factory.rb +13 -8
- data/lib/{alf-predicate/alf → alf}/predicate/grammar.rb +2 -5
- data/lib/{alf-predicate/alf → alf}/predicate/grammar.sexp.yml +11 -7
- data/lib/{alf-predicate/alf → alf}/predicate/nodes/and.rb +0 -0
- data/lib/{alf-predicate/alf → alf}/predicate/nodes/contradiction.rb +0 -0
- data/lib/{alf-predicate/alf → alf}/predicate/nodes/dyadic_comp.rb +0 -0
- data/lib/{alf-predicate/alf → alf}/predicate/nodes/eq.rb +0 -0
- data/lib/{alf-predicate/alf → alf}/predicate/nodes/expr.rb +10 -5
- data/lib/{alf-predicate/alf → alf}/predicate/nodes/gt.rb +0 -0
- data/lib/{alf-predicate/alf → alf}/predicate/nodes/gte.rb +0 -0
- data/lib/{alf-predicate/alf/predicate/nodes/var_ref.rb → alf/predicate/nodes/identifier.rb} +3 -3
- data/lib/{alf-predicate/alf → alf}/predicate/nodes/in.rb +2 -2
- data/lib/{alf-predicate/alf → alf}/predicate/nodes/literal.rb +0 -0
- data/lib/{alf-predicate/alf → alf}/predicate/nodes/lt.rb +0 -0
- data/lib/{alf-predicate/alf → alf}/predicate/nodes/lte.rb +0 -0
- data/lib/{alf-predicate/alf → alf}/predicate/nodes/nadic_bool.rb +0 -0
- data/lib/alf/predicate/nodes/native.rb +32 -0
- data/lib/{alf-predicate/alf → alf}/predicate/nodes/neq.rb +0 -0
- data/lib/{alf-predicate/alf → alf}/predicate/nodes/not.rb +0 -0
- data/lib/{alf-predicate/alf → alf}/predicate/nodes/or.rb +0 -0
- data/lib/{alf-predicate/alf/predicate/nodes/native.rb → alf/predicate/nodes/qualified_identifier.rb} +8 -4
- data/lib/{alf-predicate/alf → alf}/predicate/nodes/tautology.rb +0 -0
- data/lib/alf/predicate/processors.rb +3 -0
- data/lib/alf/predicate/processors/qualifier.rb +25 -0
- data/lib/alf/predicate/processors/renamer.rb +27 -0
- data/lib/{alf-predicate/alf → alf}/predicate/processors/to_ruby_code.rb +6 -11
- data/lib/{alf-io/alf → alf}/reader.rb +11 -2
- data/lib/{alf-io/alf → alf}/reader/csv.rb +0 -0
- data/lib/{alf-io/alf → alf}/reader/json.rb +0 -0
- data/lib/{alf-io/alf → alf}/reader/rash.rb +0 -0
- data/lib/{alf-io/alf → alf}/reader/ruby.rb +0 -0
- data/lib/alf/reader/yaml.rb +25 -0
- data/lib/{alf-relation/alf → alf}/relation.rb +12 -2
- data/lib/{alf-relvar/alf → alf}/relvar.rb +14 -21
- data/lib/alf/relvar/base.rb +35 -0
- data/lib/{alf-relvar/alf → alf}/relvar/fake.rb +3 -2
- data/lib/{alf-relvar/alf → alf}/relvar/read_only.rb +6 -30
- data/lib/{alf-relvar/alf → alf}/relvar/virtual.rb +0 -31
- data/lib/{alf-io/alf → alf}/renderer.rb +0 -0
- data/lib/{alf-io/alf → alf}/renderer/csv.rb +0 -0
- data/lib/{alf-io/alf → alf}/renderer/json.rb +0 -0
- data/lib/{alf-io/alf → alf}/renderer/rash.rb +0 -0
- data/lib/{alf-io/alf → alf}/renderer/text.rb +0 -0
- data/lib/{alf-io/alf → alf}/renderer/yaml.rb +2 -2
- data/lib/{alf-support/alf → alf}/support.rb +2 -1
- data/lib/{alf-support/alf → alf}/support/coerce.rb +0 -0
- data/lib/{alf-support/alf → alf}/support/config.rb +0 -0
- data/lib/{alf-io/alf → alf}/support/csv_utils.rb +0 -0
- data/lib/{alf-support/alf → alf}/support/dot_utils.rb +0 -0
- data/lib/{alf-support/alf → alf}/support/miscellaneous.rb +0 -0
- data/lib/{alf-support/alf → alf}/support/ordered_set.rb +0 -0
- data/lib/{alf-support/alf → alf}/support/registry.rb +0 -0
- data/lib/{alf-support/alf → alf}/support/scope.rb +0 -0
- data/lib/{alf-support/alf → alf}/support/to_lispy.rb +6 -1
- data/lib/{alf-support/alf → alf}/support/to_ruby_literal.rb +0 -0
- data/lib/alf/support/tree.rb +51 -0
- data/lib/{alf-support/alf → alf}/support/tuple_scope.rb +9 -1
- data/lib/{alf-relation/alf → alf}/tuple.rb +1 -1
- data/lib/{alf-types/alf → alf}/types.rb +0 -0
- data/lib/{alf-types/alf → alf}/types/attr_list.rb +2 -2
- data/lib/{alf-types/alf → alf}/types/attr_name.rb +0 -0
- data/lib/{alf-types/alf → alf}/types/boolean.rb +0 -0
- data/lib/{alf-types/alf → alf}/types/heading.rb +0 -0
- data/lib/{alf-types/alf → alf}/types/keys.rb +0 -0
- data/lib/{alf-types/alf → alf}/types/ordering.rb +7 -1
- data/lib/{alf-types/alf → alf}/types/renaming.rb +0 -0
- data/lib/{alf-types/alf → alf}/types/selection.rb +0 -0
- data/lib/{alf-types/alf → alf}/types/selector.rb +0 -0
- data/lib/{alf-types/alf → alf}/types/size.rb +0 -0
- data/lib/{alf-types/alf → alf}/types/summarization.rb +0 -0
- data/lib/{alf-types/alf → alf}/types/tuple_computation.rb +13 -4
- data/lib/{alf-types/alf → alf}/types/tuple_expression.rb +6 -19
- data/lib/{alf-types/alf → alf}/types/type_check.rb +1 -0
- data/lib/{alf-update/alf → alf}/update.rb +0 -0
- data/lib/{alf-update/alf → alf}/update/deleter.rb +0 -3
- data/lib/{alf-update/alf → alf}/update/inserter.rb +1 -7
- data/lib/{alf-update/alf → alf}/update/updater.rb +0 -2
- data/lib/{alf-viewpoint/alf → alf}/viewpoint.rb +9 -7
- data/lib/{alf-viewpoint/alf → alf}/viewpoint/metadata.rb +5 -2
- data/spec/compiler_helper.rb +20 -0
- data/spec/integration/relation/test_to_array.rb +6 -6
- data/spec/integration/test_examples.rb +14 -6
- data/spec/shared/a_cog.rb +8 -4
- data/spec/shared/a_valid_type_implementation.rb +4 -7
- data/spec/spec_helper.rb +9 -5
- data/spec/type_check_helper.rb +1 -0
- data/spec/unit/alf-adapter/shared_examples/an_adapter_with_readable_cogs.rb +1 -1
- data/spec/unit/alf-aggregator/test_concat.rb +8 -0
- data/spec/unit/alf-algebra/operand/named/test_hash_and_equal.rb +53 -0
- data/spec/unit/alf-algebra/operand/named/test_keys.rb +1 -1
- data/spec/unit/alf-algebra/operand/named/test_to_ascii_tree.rb +18 -0
- data/spec/unit/alf-algebra/operand/named/test_to_cog.rb +24 -0
- data/spec/unit/alf-algebra/operand/named/test_to_relvar.rb +1 -1
- data/spec/unit/alf-algebra/operand/named/test_type_check.rb +38 -0
- data/spec/unit/alf-algebra/operand/proxy/test_to_cog.rb +42 -0
- data/spec/unit/alf-algebra/operand/test_coerce.rb +0 -6
- data/spec/unit/alf-algebra/operand/test_proxy.rb +1 -1
- data/spec/unit/alf-algebra/operator/allbut/test_key_preserving.rb +1 -1
- data/spec/unit/alf-algebra/operator/allbut/test_keys.rb +1 -1
- data/spec/unit/alf-algebra/operator/allbut/test_type_check.rb +42 -0
- data/spec/unit/alf-algebra/operator/autonum/test_type_check.rb +30 -0
- data/spec/unit/alf-algebra/operator/clip/test_type_check.rb +42 -0
- data/spec/unit/alf-algebra/operator/coerce/test_type_check.rb +42 -0
- data/spec/unit/alf-algebra/operator/commons/test_resulting_type.rb +20 -0
- data/spec/unit/alf-algebra/operator/commons/test_to_ascii_tree.rb +40 -0
- data/spec/unit/alf-algebra/operator/extend/test_type_check.rb +42 -0
- data/spec/unit/alf-algebra/operator/frame/test_type_check.rb +54 -0
- data/spec/unit/alf-algebra/operator/group/test_type_check.rb +50 -0
- data/spec/unit/alf-algebra/operator/hierarchize/test_type_check.rb +54 -0
- data/spec/unit/alf-algebra/operator/intersect/test_type_check.rb +30 -0
- data/spec/unit/alf-algebra/operator/join/test_type_check.rb +62 -0
- data/spec/unit/alf-algebra/operator/matching/test_keys.rb +1 -1
- data/spec/unit/alf-algebra/operator/matching/test_type_check.rb +62 -0
- data/spec/unit/alf-algebra/operator/minus/test_type_check.rb +30 -0
- data/spec/unit/alf-algebra/operator/not_matching/test_type_check.rb +62 -0
- data/spec/unit/alf-algebra/operator/page/test_type_check.rb +50 -0
- data/spec/unit/alf-algebra/operator/project/test_type_check.rb +42 -0
- data/spec/unit/alf-algebra/operator/quota/test_type_check.rb +54 -0
- data/spec/unit/alf-algebra/operator/rank/test_type_check.rb +42 -0
- data/spec/unit/alf-algebra/operator/rename/test_type_check.rb +42 -0
- data/spec/unit/alf-algebra/operator/restrict/test_type_check.rb +46 -0
- data/spec/unit/alf-algebra/operator/shared/test_to_cog.rb +34 -0
- data/spec/unit/alf-algebra/operator/sort/test_type_check.rb +30 -0
- data/spec/unit/alf-algebra/operator/summarize/test_type_check.rb +42 -0
- data/spec/unit/alf-algebra/operator/test_hash_and_equal.rb +59 -0
- data/spec/unit/alf-algebra/operator/ungroup/test_type_check.rb +44 -0
- data/spec/unit/alf-algebra/operator/union/test_type_check.rb +30 -0
- data/spec/unit/alf-algebra/operator/unwrap/test_type_check.rb +44 -0
- data/spec/unit/alf-algebra/operator/wrap/test_type_check.rb +50 -0
- data/spec/unit/alf-algebra/support/signature/test_to_lispy.rb +24 -9
- data/spec/unit/alf-algebra/support/test_non_relational.rb +1 -2
- data/spec/unit/alf-algebra/support/test_relational.rb +1 -1
- data/spec/unit/alf-compiler/default/test_allbut.rb +65 -0
- data/spec/unit/alf-compiler/default/test_autonum.rb +30 -0
- data/spec/unit/alf-compiler/default/test_clip.rb +30 -0
- data/spec/unit/alf-compiler/default/test_coerce.rb +30 -0
- data/spec/unit/alf-compiler/default/test_compact.rb +26 -0
- data/spec/unit/alf-compiler/default/test_completude.rb +16 -0
- data/spec/unit/alf-compiler/default/test_defaults.rb +50 -0
- data/spec/unit/alf-compiler/default/test_extend.rb +34 -0
- data/spec/unit/alf-compiler/default/test_frame.rb +77 -0
- data/spec/unit/alf-compiler/default/test_generator.rb +30 -0
- data/spec/unit/alf-compiler/default/test_group.rb +38 -0
- data/spec/unit/alf-compiler/default/test_hierarchize.rb +40 -0
- data/spec/unit/alf-compiler/default/test_intersect.rb +34 -0
- data/spec/unit/alf-compiler/default/test_join.rb +34 -0
- data/spec/unit/alf-compiler/default/test_matching.rb +38 -0
- data/spec/unit/alf-compiler/default/test_minus.rb +38 -0
- data/spec/unit/alf-compiler/default/test_not_matching.rb +38 -0
- data/spec/unit/alf-compiler/default/test_page.rb +91 -0
- data/spec/unit/alf-compiler/default/test_project.rb +76 -0
- data/spec/unit/alf-compiler/default/test_quota.rb +88 -0
- data/spec/unit/alf-compiler/default/test_rank.rb +71 -0
- data/spec/unit/alf-compiler/default/test_rename.rb +30 -0
- data/spec/unit/alf-compiler/default/test_restrict.rb +34 -0
- data/spec/unit/alf-compiler/default/test_sort.rb +81 -0
- data/spec/unit/alf-compiler/default/test_summarize.rb +85 -0
- data/spec/unit/alf-compiler/default/test_ungroup.rb +30 -0
- data/spec/unit/alf-compiler/default/test_union.rb +36 -0
- data/spec/unit/alf-compiler/default/test_unwrap.rb +30 -0
- data/spec/unit/alf-compiler/default/test_wrap.rb +38 -0
- data/spec/unit/alf-compiler/shared/compiled_examples.rb +111 -0
- data/spec/unit/alf-compiler/test_principle.rb +332 -0
- data/spec/unit/alf-core/test_aggregator.rb +0 -24
- data/spec/unit/alf-database/connection/test_parse.rb +0 -49
- data/spec/unit/alf-database/connection/test_relvar.rb +1 -9
- data/spec/unit/alf-database/options/test_parser.rb +23 -0
- data/spec/unit/alf-engine/cog/test_to_ascii_tree.rb +14 -0
- data/spec/unit/alf-engine/test_aggregate.rb +2 -2
- data/spec/unit/alf-engine/test_filter.rb +1 -1
- data/spec/unit/alf-engine/test_to_array.rb +16 -2
- data/spec/unit/alf-io/reader/test_yaml.rb +30 -0
- data/spec/unit/alf-io/renderer/test_yaml.rb +11 -0
- data/spec/unit/alf-lang/functional/test_aggregation.rb +18 -4
- data/spec/unit/alf-lang/parser/lispy/test_connection_bang.rb +28 -0
- data/spec/unit/alf-lang/parser/lispy/test_parse.rb +38 -0
- data/spec/unit/alf-lang/parser/lispy/test_to_s.rb +16 -0
- data/spec/unit/alf-lang/parser/safer/safe.txt +5 -0
- data/spec/unit/alf-lang/parser/safer/test_parse.rb +82 -0
- data/spec/unit/alf-lang/parser/safer/unsafe.txt +14 -0
- data/spec/unit/alf-optimizer/restrict/test_on_autonum.rb +1 -1
- data/spec/unit/alf-optimizer/test_quota.rb +1 -1
- data/spec/unit/alf-optimizer/test_rename.rb +7 -0
- data/spec/unit/alf-optimizer/test_summarize.rb +1 -1
- data/spec/unit/alf-predicate/expr/test_to_proc.rb +4 -6
- data/spec/unit/alf-predicate/expr/test_to_ruby_code.rb +23 -23
- data/spec/unit/alf-predicate/factory/shared/a_comparison_factory_method.rb +3 -3
- data/spec/unit/alf-predicate/factory/test_between.rb +1 -1
- data/spec/unit/alf-predicate/factory/test_comp.rb +3 -3
- data/spec/unit/alf-predicate/factory/test_factor_predicate.rb +3 -3
- data/spec/unit/alf-predicate/factory/{test_var_ref.rb → test_identifier.rb} +4 -4
- data/spec/unit/alf-predicate/factory/test_in.rb +1 -1
- data/spec/unit/alf-predicate/factory/test_native.rb +9 -4
- data/spec/unit/alf-predicate/factory/test_qualified_identifier.rb +17 -0
- data/spec/unit/alf-predicate/grammar/test_match.rb +9 -9
- data/spec/unit/alf-predicate/grammar/test_sexpr.rb +11 -11
- data/spec/unit/alf-predicate/nodes/{var_ref → identifier}/test_and_split.rb +2 -2
- data/spec/unit/alf-predicate/nodes/{var_ref → identifier}/test_free_variables.rb +2 -2
- data/spec/unit/alf-predicate/nodes/identifier/test_name.rb +14 -0
- data/spec/unit/alf-predicate/nodes/qualified_identifier/test_and_split.rb +25 -0
- data/spec/unit/alf-predicate/nodes/qualified_identifier/test_free_variables.rb +14 -0
- data/spec/unit/alf-predicate/nodes/qualified_identifier/test_name.rb +14 -0
- data/spec/unit/alf-predicate/nodes/qualified_identifier/test_qualifier.rb +14 -0
- data/spec/unit/alf-predicate/predicate/test_and_split.rb +4 -4
- data/spec/unit/alf-predicate/predicate/test_bool_and.rb +1 -1
- data/spec/unit/alf-predicate/predicate/test_bool_not.rb +1 -1
- data/spec/unit/alf-predicate/predicate/test_bool_or.rb +1 -1
- data/spec/unit/alf-predicate/predicate/test_coerce.rb +9 -8
- data/spec/unit/alf-predicate/predicate/test_contradiction.rb +2 -2
- data/spec/unit/alf-predicate/predicate/test_factory_methods.rb +12 -12
- data/spec/unit/alf-predicate/predicate/test_qualify.rb +36 -0
- data/spec/unit/alf-predicate/predicate/test_rename.rb +58 -15
- data/spec/unit/alf-predicate/predicate/test_tautology.rb +2 -2
- data/spec/unit/alf-predicate/predicate/test_to_ruby_code.rb +8 -2
- data/spec/unit/alf-predicate/predicate/test_to_ruby_literal.rb +1 -1
- data/spec/unit/alf-predicate/test_predicate.rb +7 -8
- data/spec/unit/alf-relation/relation/class/test_dum.rb +19 -0
- data/spec/unit/alf-relation/relation/test_heading.rb +1 -1
- data/spec/unit/alf-relation/relation/test_keys.rb +17 -0
- data/spec/unit/alf-relation/relation/test_relation.rb +1 -1
- data/spec/unit/alf-relation/relation/test_to_a.rb +10 -10
- data/spec/unit/alf-relvar/base/test_oo_lang.rb +26 -10
- data/spec/unit/alf-relvar/base/test_to_cog.rb +2 -2
- data/spec/unit/alf-relvar/read_only/test_to_relation.rb +17 -0
- data/spec/unit/alf-relvar/read_only/test_type.rb +0 -4
- data/spec/unit/alf-relvar/virtual/test_oo_lang.rb +0 -4
- data/spec/unit/alf-relvar/virtual/test_to_cog.rb +4 -4
- data/spec/unit/alf-relvar/virtual/test_to_s.rb +1 -1
- data/spec/unit/alf-support/test_to_lispy.rb +13 -31
- data/spec/unit/alf-support/test_tuple_scope.rb +11 -0
- data/spec/unit/alf-types/ordering/test_coerce.rb +13 -0
- data/spec/unit/alf-types/ordering/test_lte.rb +43 -0
- data/spec/unit/alf-types/summarization/test_coerce.rb +2 -2
- data/spec/unit/alf-types/summarization/test_least.rb +1 -1
- data/spec/unit/alf-types/summarization/test_summarize.rb +1 -1
- data/spec/unit/alf-types/test_summarization.rb +2 -2
- data/spec/unit/alf-types/test_tuple_expression.rb +2 -2
- data/spec/unit/alf-types/tuple_computation/test_coerce.rb +4 -13
- data/spec/unit/alf-types/tuple_computation/test_empty.rb +24 -0
- data/spec/unit/alf-types/tuple_computation/test_project.rb +46 -0
- data/spec/unit/alf-types/tuple_expression/test_coerce.rb +1 -10
- data/spec/unit/alf-types/tuple_expression/test_evaluate.rb +0 -8
- data/spec/unit/alf-types/tuple_expression/test_to_ruby_literal.rb +0 -5
- data/spec/unit/alf-update/deleter/{test_var_ref.rb → test_identifier.rb} +1 -1
- data/spec/unit/alf-update/inserter/{test_var_ref.rb → test_identifier.rb} +1 -1
- data/spec/unit/alf-update/updater/{test_var_ref.rb → test_identifier.rb} +1 -1
- data/spec/unit/alf-viewpoint/test_native_const.rb +1 -1
- data/spec/update_helper.rb +18 -2
- metadata +417 -313
- data/lib/alf-algebra/alf/algebra/operand/named.rb +0 -36
- data/lib/alf-algebra/alf/algebra/operator/infer_heading.rb +0 -19
- data/lib/alf-algebra/alf/algebra/operator/type_safe.rb +0 -21
- data/lib/alf-algebra/alf/algebra/support/to_dot.rb +0 -196
- data/lib/alf-core/facade.rb +0 -39
- data/lib/alf-engine/alf/engine/cog.rb +0 -50
- data/lib/alf-engine/alf/engine/compiler.rb +0 -171
- data/lib/alf-engine/alf/engine/group.rb +0 -3
- data/lib/alf-engine/alf/engine/quota.rb +0 -3
- data/lib/alf-engine/alf/engine/rank.rb +0 -3
- data/lib/alf-engine/alf/engine/semi.rb +0 -3
- data/lib/alf-engine/alf/engine/sort.rb +0 -30
- data/lib/alf-engine/alf/engine/summarize.rb +0 -4
- data/lib/alf-engine/alf/engine/to_dot.rb +0 -60
- data/lib/alf-io/alf/io.rb +0 -6
- data/lib/alf-lang/alf/lang/lispy.rb +0 -65
- data/lib/alf-predicate/alf/predicate/parser.rb +0 -12
- data/lib/alf-predicate/alf/predicate/processors.rb +0 -3
- data/lib/alf-predicate/alf/predicate/processors/renamer.rb +0 -19
- data/lib/alf-predicate/alf/predicate/processors/to_proc.rb +0 -35
- data/lib/alf-relvar/alf/relvar/base.rb +0 -69
- data/lib/alf-support/alf/support/bindable.rb +0 -26
- data/spec/integration/algebra/test_to_dot.rb +0 -14
- data/spec/integration/relvar/test_type_safe.rb +0 -22
- data/spec/unit/alf-algebra/operator/infer_heading/test_keys.rb +0 -23
- data/spec/unit/alf-algebra/operator/test_infer_heading.rb +0 -16
- data/spec/unit/alf-algebra/operator/type_safe/test_heading.rb +0 -26
- data/spec/unit/alf-algebra/operator/type_safe/test_keys.rb +0 -26
- data/spec/unit/alf-engine/compiler/test_on_frame.rb +0 -70
- data/spec/unit/alf-engine/compiler/test_on_hierarchize.rb +0 -33
- data/spec/unit/alf-engine/compiler/test_on_page.rb +0 -128
- data/spec/unit/alf-engine/compiler/test_unsupported.rb +0 -48
- data/spec/unit/alf-lang/lispy/test_connection_bang.rb +0 -26
- data/spec/unit/alf-lang/lispy/test_parse.rb +0 -38
- data/spec/unit/alf-lang/lispy/test_to_s.rb +0 -14
- data/spec/unit/alf-optimizer/optimizer/test_optimizer.rb +0 -37
- data/spec/unit/alf-optimizer/test_infer_heading.rb +0 -9
- data/spec/unit/alf-predicate/grammar/test_parse.rb +0 -23
- data/spec/unit/alf-predicate/nodes/var_ref/test_var_name.rb +0 -14
- data/spec/unit/alf-relvar/base/test_name.rb +0 -15
- data/spec/unit/alf-relvar/virtual/test_connection.rb +0 -15
- data/spec/unit/alf-support/bindable/test_bind.rb +0 -60
- data/spec/unit/alf-support/bindable/test_bound.rb +0 -31
- data/spec/unit/alf-support/bindable/test_connection.rb +0 -31
- data/spec/unit/alf-support/bindable/test_connection_bang.rb +0 -35
- data/spec/unit/alf-update/inserter/test_type_safe.rb +0 -72
@@ -19,8 +19,8 @@ module Alf
|
|
19
19
|
attr_reader :allbut
|
20
20
|
|
21
21
|
# Creates a SetAttr instance
|
22
|
-
def initialize(operand, attributes, as, allbut, expr = nil)
|
23
|
-
super(expr)
|
22
|
+
def initialize(operand, attributes, as, allbut, expr = nil, compiler = nil)
|
23
|
+
super(expr, compiler)
|
24
24
|
@operand = operand
|
25
25
|
@attributes = attributes
|
26
26
|
@as = as
|
@@ -36,6 +36,10 @@ module Alf
|
|
36
36
|
end
|
37
37
|
end
|
38
38
|
|
39
|
+
def arguments
|
40
|
+
[ attribute ]
|
41
|
+
end
|
42
|
+
|
39
43
|
end # class Wrap
|
40
44
|
end # module Engine
|
41
45
|
end # module Alf
|
@@ -10,7 +10,6 @@ module Alf
|
|
10
10
|
class ReadOnlyError < Error; end
|
11
11
|
class TypeCheckError < Error; end
|
12
12
|
class IllegalStateError < Error; end
|
13
|
-
|
14
|
-
|
15
|
-
class UnsupportedError < Error; end
|
13
|
+
class SecurityError < Error; end
|
14
|
+
class UnsupportedMimeTypeError < Error; end
|
16
15
|
end
|
data/lib/{alf-core → alf}/ext.rb
RENAMED
File without changes
|
@@ -1,6 +1,8 @@
|
|
1
1
|
module Domain
|
2
2
|
class HeadingBased < Module
|
3
3
|
|
4
|
+
EMPTY_SET = Set.new.freeze
|
5
|
+
|
4
6
|
def initialize(master_class)
|
5
7
|
define_method(:new){|*args|
|
6
8
|
raise "#{master_class}.new may not be called directly" if master_class==self
|
@@ -31,6 +33,9 @@ module Domain
|
|
31
33
|
define_method(:generating_type){
|
32
34
|
gt
|
33
35
|
}
|
36
|
+
define_method(:dum){
|
37
|
+
@dum ||= new(EMPTY_SET)
|
38
|
+
}
|
34
39
|
define_method(:<=>){|other|
|
35
40
|
return 0 if self == other
|
36
41
|
return nil unless other.ancestors.include?(master_class)
|
data/lib/alf/facade.rb
ADDED
@@ -0,0 +1,53 @@
|
|
1
|
+
module Alf
|
2
|
+
module Facade
|
3
|
+
|
4
|
+
def database(*args, &bl)
|
5
|
+
Alf::Database.new(*args, &bl)
|
6
|
+
end
|
7
|
+
|
8
|
+
def connect(*args, &bl)
|
9
|
+
Alf::Database.connect(*args, &bl)
|
10
|
+
end
|
11
|
+
|
12
|
+
def query(*args, &bl)
|
13
|
+
connect(*args) do |conn|
|
14
|
+
conn.query(&bl)
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
def examples_adapter
|
19
|
+
Path.backfind('examples/suppliers_and_parts')
|
20
|
+
end
|
21
|
+
|
22
|
+
def examples(&bl)
|
23
|
+
Alf::Database.connect examples_adapter, &bl
|
24
|
+
end
|
25
|
+
|
26
|
+
def reader(source, *args)
|
27
|
+
Alf::Reader.reader(source, *args)
|
28
|
+
end
|
29
|
+
|
30
|
+
def Relation(first, *rest, &bl)
|
31
|
+
if first.respond_to?(:to_relation) && rest.empty? && bl.nil?
|
32
|
+
return first.to_relation
|
33
|
+
else
|
34
|
+
Alf::Relation.coerce(*rest.unshift(first), &bl)
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
def Tuple(first, *rest, &bl)
|
39
|
+
if first.respond_to?(:to_tuple) && rest.empty? && bl.nil?
|
40
|
+
return first.to_tuple
|
41
|
+
else
|
42
|
+
tuple = Alf::Tuple.coerce(*rest.unshift(first))
|
43
|
+
tuple = tuple.remap(&bl) if bl
|
44
|
+
tuple
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
def Heading(*args, &bl)
|
49
|
+
Alf::Heading.coerce(*args, &bl)
|
50
|
+
end
|
51
|
+
|
52
|
+
end
|
53
|
+
end
|
File without changes
|
@@ -14,14 +14,6 @@ module Alf
|
|
14
14
|
# build the new expression
|
15
15
|
expr = clazz.new(operands, *arguments)
|
16
16
|
|
17
|
-
# bind it if operands were bound
|
18
|
-
conns = operands.map(&:connection).uniq
|
19
|
-
if conns.size == 1
|
20
|
-
expr.connection = conns.first
|
21
|
-
elsif conns.size > 1
|
22
|
-
raise NotSupportedError, "Multiple connections unsupported"
|
23
|
-
end
|
24
|
-
|
25
17
|
# let the abstraction have a chance to of decorating it
|
26
18
|
_operator_output(expr)
|
27
19
|
end
|
@@ -31,10 +23,6 @@ module Alf
|
|
31
23
|
def_operator_method(name, clazz)
|
32
24
|
end
|
33
25
|
|
34
|
-
def allbut(attributes)
|
35
|
-
project(attributes, :allbut => true)
|
36
|
-
end
|
37
|
-
|
38
26
|
def +(other)
|
39
27
|
union(other)
|
40
28
|
end
|
@@ -0,0 +1,63 @@
|
|
1
|
+
module Alf
|
2
|
+
module Lang
|
3
|
+
module Parser
|
4
|
+
class Lispy
|
5
|
+
include Parser
|
6
|
+
include Functional
|
7
|
+
include Predicates
|
8
|
+
|
9
|
+
def initialize(helpers = [], connection = nil)
|
10
|
+
@connection = connection
|
11
|
+
@extensions = helpers
|
12
|
+
helpers.each do |helper|
|
13
|
+
helper.send(:extend_object, self)
|
14
|
+
end
|
15
|
+
end
|
16
|
+
attr_reader :connection
|
17
|
+
|
18
|
+
def connection!
|
19
|
+
connection.tap{|c|
|
20
|
+
::Kernel.raise(UnboundError, "#{self} not bound") unless c
|
21
|
+
}
|
22
|
+
end
|
23
|
+
|
24
|
+
def parse(expr = nil, path = nil, line = nil, &block)
|
25
|
+
if (expr && block) || (expr.nil? and block.nil?)
|
26
|
+
raise ArgumentError, "Either `expr` or `block` should be specified"
|
27
|
+
end
|
28
|
+
expr = evaluate(expr, path, line, &block) if block or expr.is_a?(String)
|
29
|
+
expr = __send__(expr) if expr.is_a?(Symbol)
|
30
|
+
expr
|
31
|
+
end
|
32
|
+
|
33
|
+
def to_s
|
34
|
+
"Lispy(#{@extensions.map(&:name).compact.join(',')})"
|
35
|
+
end
|
36
|
+
|
37
|
+
def inspect
|
38
|
+
"Lispy(#{@extensions.inspect})"
|
39
|
+
end
|
40
|
+
|
41
|
+
private
|
42
|
+
|
43
|
+
def evaluate(expr = nil, path=nil, line=nil, &bl)
|
44
|
+
return instance_exec(&bl) if bl
|
45
|
+
instance_eval(expr, *[path, line].compact.map(&:to_s))
|
46
|
+
end
|
47
|
+
|
48
|
+
public
|
49
|
+
|
50
|
+
# Resolve DUM and DEE in ruby 1.9.2 context
|
51
|
+
def self.const_missing(name)
|
52
|
+
case name.to_s
|
53
|
+
when 'DEE' then ::Alf::Relation::DEE
|
54
|
+
when 'DUM' then ::Alf::Relation::DUM
|
55
|
+
else
|
56
|
+
super
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
end # class Lispy
|
61
|
+
end # module Parser
|
62
|
+
end # module Lang
|
63
|
+
end # module Alf
|
@@ -0,0 +1,69 @@
|
|
1
|
+
require 'ruby_cop'
|
2
|
+
module Alf
|
3
|
+
module Lang
|
4
|
+
module Parser
|
5
|
+
class Safer
|
6
|
+
include Parser
|
7
|
+
|
8
|
+
def initialize(helpers = [], connection = nil)
|
9
|
+
@lispy = Lispy.new(helpers, connection)
|
10
|
+
end
|
11
|
+
|
12
|
+
def parse(expr = nil, *rest, &bl)
|
13
|
+
if expr.nil? and bl
|
14
|
+
raise SecurityError, "Parsing of ruby blocks forbidden"
|
15
|
+
end
|
16
|
+
return expr if expr.is_a?(Algebra::Operand)
|
17
|
+
check_safety!(expr.to_s)
|
18
|
+
@lispy.parse(expr.to_s, *rest, &bl)
|
19
|
+
end
|
20
|
+
|
21
|
+
private
|
22
|
+
|
23
|
+
def check_safety!(query)
|
24
|
+
policy = Policy.new
|
25
|
+
ast = RubyCop::NodeBuilder.build(query)
|
26
|
+
unless ast.accept(policy)
|
27
|
+
raise SecurityError, "Forbidden for security reasons"
|
28
|
+
end
|
29
|
+
query
|
30
|
+
end
|
31
|
+
|
32
|
+
class Policy < RubyCop::Policy
|
33
|
+
|
34
|
+
ALF_CALL_BLACKLIST = %w[
|
35
|
+
gem
|
36
|
+
puts
|
37
|
+
to_cog
|
38
|
+
to_relvar
|
39
|
+
to_relation
|
40
|
+
insert
|
41
|
+
delete
|
42
|
+
update
|
43
|
+
affect
|
44
|
+
upsert
|
45
|
+
].to_set.freeze
|
46
|
+
|
47
|
+
def visit_Call(node)
|
48
|
+
super && !ALF_CALL_BLACKLIST.include?(node.identifier.token.to_s)
|
49
|
+
end
|
50
|
+
|
51
|
+
ALF_CONSTANT_WHITELIST = %w[
|
52
|
+
DEE
|
53
|
+
DUM
|
54
|
+
].to_set.freeze
|
55
|
+
|
56
|
+
def visit_Constant(node)
|
57
|
+
ALF_CONSTANT_WHITELIST.include?(node.token.to_s)
|
58
|
+
end
|
59
|
+
|
60
|
+
def visit_ConstantAssignment(node)
|
61
|
+
raise SecurityError, "Forbidden: constant assignment"
|
62
|
+
end
|
63
|
+
|
64
|
+
end # class Policy
|
65
|
+
|
66
|
+
end # class Safer
|
67
|
+
end # module Parser
|
68
|
+
end # module Lang
|
69
|
+
end # module Alf
|
@@ -1,4 +1,3 @@
|
|
1
|
-
require_relative 'optimizer/restrict'
|
2
1
|
module Alf
|
3
2
|
class Optimizer
|
4
3
|
|
@@ -7,16 +6,23 @@ module Alf
|
|
7
6
|
end
|
8
7
|
|
9
8
|
def call(expr)
|
10
|
-
@processors.inject(expr)
|
11
|
-
Search.new(p, k).call(c)
|
12
|
-
end
|
9
|
+
@processors.inject(expr){|c,p| p.call(c) }
|
13
10
|
end
|
14
11
|
|
15
|
-
def register(processor
|
16
|
-
@processors <<
|
12
|
+
def register(processor)
|
13
|
+
@processors << processor
|
17
14
|
self
|
18
15
|
end
|
19
16
|
|
17
|
+
class Base < Algebra::Rewriter
|
18
|
+
include Lang::Functional
|
19
|
+
|
20
|
+
def call(expr, search = nil)
|
21
|
+
return Search.new(self, search_predicate).call(expr) unless search
|
22
|
+
_call(expr, search)
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
20
26
|
class Search < Algebra::Rewriter
|
21
27
|
|
22
28
|
def initialize(processor, interest)
|
@@ -35,4 +41,6 @@ module Alf
|
|
35
41
|
end # class Search
|
36
42
|
|
37
43
|
end # class Optimizer
|
38
|
-
end # module Alf
|
44
|
+
end # module Alf
|
45
|
+
require_relative 'optimizer/restrict'
|
46
|
+
require_relative 'optimizer/project'
|
@@ -0,0 +1,182 @@
|
|
1
|
+
module Alf
|
2
|
+
class Optimizer
|
3
|
+
class Project < Optimizer::Base
|
4
|
+
|
5
|
+
###
|
6
|
+
|
7
|
+
def project(operand, attributes, options)
|
8
|
+
options[:allbut] ? allbut(operand, attributes) : super
|
9
|
+
end
|
10
|
+
|
11
|
+
### overridings
|
12
|
+
|
13
|
+
def search_predicate
|
14
|
+
Algebra::Project
|
15
|
+
end
|
16
|
+
|
17
|
+
def _call(project, search)
|
18
|
+
apply(project.operand, project.attributes, project.allbut, search)
|
19
|
+
end
|
20
|
+
|
21
|
+
def apply(expr, attributes, allbut, search)
|
22
|
+
check_stop(expr, attributes, allbut, search){ super }
|
23
|
+
rescue NotSupportedError
|
24
|
+
project(expr, attributes, allbut)
|
25
|
+
end
|
26
|
+
|
27
|
+
def check_stop(expr, attributes, allbut, search)
|
28
|
+
return search.call(expr) if (allbut && attributes.empty?)
|
29
|
+
return search.call(expr) if (!allbut && attributes==expr.attr_list)
|
30
|
+
yield
|
31
|
+
rescue NotSupportedError
|
32
|
+
yield
|
33
|
+
end
|
34
|
+
|
35
|
+
### callbacks
|
36
|
+
|
37
|
+
def on_unoptimizable(expr, attributes, allbut, search)
|
38
|
+
project(search.call(expr), attributes, allbut: allbut)
|
39
|
+
end
|
40
|
+
alias :on_missing :on_unoptimizable
|
41
|
+
alias :on_todo :on_unoptimizable
|
42
|
+
alias :on_leaf_operand :on_unoptimizable
|
43
|
+
|
44
|
+
###
|
45
|
+
|
46
|
+
alias :on_autonum :on_todo
|
47
|
+
|
48
|
+
def on_clip(expr, attributes, allbut, search)
|
49
|
+
inside, outside = expr.attributes, attributes
|
50
|
+
if expr.allbut != allbut
|
51
|
+
attributes = allbut ? inside - outside : outside - inside
|
52
|
+
allbut = false
|
53
|
+
else
|
54
|
+
attributes = allbut ? inside | outside : inside & outside
|
55
|
+
end
|
56
|
+
apply(expr.operand, attributes, allbut, search)
|
57
|
+
end
|
58
|
+
|
59
|
+
alias :on_coerce :on_todo
|
60
|
+
alias :on_compact :on_todo
|
61
|
+
alias :on_defaults :on_todo
|
62
|
+
|
63
|
+
def on_extend(expr, attributes, allbut, search)
|
64
|
+
ext = expr.ext.project(attributes, allbut)
|
65
|
+
if ext.empty?
|
66
|
+
apply(expr.operand, attributes, allbut, search)
|
67
|
+
else
|
68
|
+
op = search.call(expr.operand)
|
69
|
+
project(extend(op, ext), attributes, allbut: allbut)
|
70
|
+
end
|
71
|
+
end
|
72
|
+
|
73
|
+
alias :on_frame :on_todo
|
74
|
+
alias :on_generator :on_unoptimizable
|
75
|
+
alias :on_group :on_todo
|
76
|
+
alias :on_hierarchize :on_unoptimizable
|
77
|
+
alias :on_intersect :on_unoptimizable
|
78
|
+
|
79
|
+
def on_join(expr, attributes, allbut, search)
|
80
|
+
commons = expr.left.attr_list & expr.right.attr_list
|
81
|
+
|
82
|
+
# compute actual projection attributes on left and right
|
83
|
+
proj_a = allbut ? attributes - commons : attributes + commons
|
84
|
+
left_a = expr.left.attr_list & proj_a
|
85
|
+
right_a = expr.right.attr_list & proj_a
|
86
|
+
|
87
|
+
# make both projections
|
88
|
+
left = apply(expr.left, left_a, allbut, search)
|
89
|
+
right = apply(expr.right, right_a, allbut, search)
|
90
|
+
|
91
|
+
# re-apply the join
|
92
|
+
rw = join(left, right)
|
93
|
+
|
94
|
+
# add the outer projection unless the job has already been done
|
95
|
+
unless attributes == (left_a + right_a)
|
96
|
+
outside = allbut ? attributes - left_a - right_a : attributes
|
97
|
+
rw = project(rw, outside, allbut: allbut)
|
98
|
+
end
|
99
|
+
|
100
|
+
rw
|
101
|
+
end
|
102
|
+
|
103
|
+
def on_binary_splitable(expr, attributes, allbut, search)
|
104
|
+
commons = expr.left.attr_list & expr.right.attr_list
|
105
|
+
|
106
|
+
# compute inside and outside projection attributes such as preserving
|
107
|
+
# commons
|
108
|
+
inside = allbut ? attributes - commons : attributes + commons
|
109
|
+
outside = allbut ? attributes - inside : attributes
|
110
|
+
|
111
|
+
# apply on left operand with inside attributes
|
112
|
+
left = apply(expr.left, inside, allbut, search)
|
113
|
+
right = expr.right
|
114
|
+
|
115
|
+
# rewrite it now
|
116
|
+
rw = expr.class.new([left, right])
|
117
|
+
|
118
|
+
# add the outside projection unless the job is already done by the
|
119
|
+
# inside projection
|
120
|
+
rw = project(rw, outside, allbut: allbut) unless inside == attributes
|
121
|
+
|
122
|
+
rw
|
123
|
+
end
|
124
|
+
alias :on_matching :on_binary_splitable
|
125
|
+
alias :on_not_matching :on_binary_splitable
|
126
|
+
alias :on_minus :on_unoptimizable
|
127
|
+
alias :on_page :on_todo
|
128
|
+
alias :on_project :on_clip
|
129
|
+
alias :on_quota :on_todo
|
130
|
+
alias :on_rank :on_todo
|
131
|
+
|
132
|
+
def on_rename(expr, attributes, allbut, search)
|
133
|
+
inside = expr.renaming.invert.rename_attr_list(attributes)
|
134
|
+
|
135
|
+
# project the operand on renamed attributes
|
136
|
+
rw = apply(expr.operand, inside, allbut, search)
|
137
|
+
|
138
|
+
# apply the renaming unless all attributes have been projected away
|
139
|
+
renaming = inside.project_tuple(expr.renaming.to_hash, allbut)
|
140
|
+
unless renaming.empty?
|
141
|
+
rw = rename(rw, renaming)
|
142
|
+
end
|
143
|
+
|
144
|
+
rw
|
145
|
+
end
|
146
|
+
|
147
|
+
alias :on_restrict :on_todo
|
148
|
+
|
149
|
+
def on_sort(expr, attributes, allbut, search)
|
150
|
+
sort_a = expr.ordering.to_attr_list
|
151
|
+
|
152
|
+
# compute inside projection attributes
|
153
|
+
inside = allbut ? attributes - sort_a : attributes + sort_a
|
154
|
+
|
155
|
+
# project the operand and sort the result
|
156
|
+
rw = apply(expr.operand, inside, allbut, search)
|
157
|
+
rw = sort(rw, expr.ordering)
|
158
|
+
|
159
|
+
# project unless the job has already been done
|
160
|
+
unless inside == attributes
|
161
|
+
outside = allbut ? attributes - inside : attributes
|
162
|
+
rw = project(rw, outside, allbut: allbut)
|
163
|
+
end
|
164
|
+
|
165
|
+
rw
|
166
|
+
end
|
167
|
+
|
168
|
+
alias :on_summarize :on_todo
|
169
|
+
alias :on_ungroup :on_todo
|
170
|
+
|
171
|
+
def on_union(expr, attributes, allbut, search)
|
172
|
+
left = apply(expr.left, attributes, allbut, search)
|
173
|
+
right = apply(expr.right, attributes, allbut, search)
|
174
|
+
union(left, right)
|
175
|
+
end
|
176
|
+
|
177
|
+
alias :on_unwrap :on_todo
|
178
|
+
alias :on_wrap :on_todo
|
179
|
+
|
180
|
+
end # class Project
|
181
|
+
end # class Optimizer
|
182
|
+
end # module Alf
|