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
@@ -0,0 +1,51 @@
|
|
1
|
+
module Alf
|
2
|
+
module Algebra
|
3
|
+
module TypeCheck
|
4
|
+
|
5
|
+
def type_check_error!(msg)
|
6
|
+
raise TypeCheckError, msg
|
7
|
+
end
|
8
|
+
|
9
|
+
def no_unknown!(unknown)
|
10
|
+
unknown = unknown.to_a
|
11
|
+
unless unknown.empty?
|
12
|
+
msg = "#{to_s}: no such attribute"
|
13
|
+
msg << ((unknown.size > 1) ? "s " : " ")
|
14
|
+
msg << unknown.map{|a| "`#{a}`" }.join(',')
|
15
|
+
type_check_error!(msg)
|
16
|
+
end
|
17
|
+
end
|
18
|
+
private :no_unknown!
|
19
|
+
|
20
|
+
def no_name_clash!(left, right)
|
21
|
+
commons = (left & right).to_a
|
22
|
+
unless commons.empty?
|
23
|
+
msg = "#{to_s}: cannot override "
|
24
|
+
msg << commons.map{|a| "`#{a}`" }.join(',')
|
25
|
+
type_check_error!(msg)
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
def valid_ordering!(ordering, attr_list)
|
30
|
+
no_unknown!(ordering.to_attr_list - attr_list)
|
31
|
+
end
|
32
|
+
|
33
|
+
def same_heading!(left, right)
|
34
|
+
unless left == right
|
35
|
+
type_check_error!("heading mismatch `#{left}` vs. `#{right}`")
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
def joinable_headings!(left, right, options)
|
40
|
+
if options[:strict]
|
41
|
+
commons = left.to_attr_list & right.to_attr_list
|
42
|
+
left_h, right_h = left.project(commons), right.project(commons)
|
43
|
+
same_heading!(left_h, right_h)
|
44
|
+
else
|
45
|
+
left & right
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
end # module TypeCheck
|
50
|
+
end # module Algebra
|
51
|
+
end # module Alf
|
File without changes
|
@@ -15,8 +15,9 @@ module Alf
|
|
15
15
|
def to_method_name(expr, prefix = "on_")
|
16
16
|
case expr
|
17
17
|
when Algebra::Operator
|
18
|
-
name =
|
18
|
+
name = expr.class.rubycase_name
|
19
19
|
meth = :"#{prefix}#{name}"
|
20
|
+
meth = :"#{prefix}shortcut" if expr.is_a?(Algebra::Shortcut) and !respond_to?(meth)
|
20
21
|
meth = :"#{prefix}missing" unless respond_to?(meth)
|
21
22
|
meth
|
22
23
|
when Algebra::Operand
|
File without changes
|
data/lib/alf/compiler.rb
ADDED
@@ -0,0 +1,57 @@
|
|
1
|
+
module Alf
|
2
|
+
class Compiler
|
3
|
+
|
4
|
+
def supports_reuse?
|
5
|
+
false
|
6
|
+
end
|
7
|
+
|
8
|
+
def join(plan)
|
9
|
+
nil
|
10
|
+
end
|
11
|
+
|
12
|
+
def call(expr)
|
13
|
+
Plan.new(self).compile(expr)
|
14
|
+
end
|
15
|
+
|
16
|
+
def compile(plan, expr, compiled, usage_count)
|
17
|
+
send(to_method_name(expr), plan, expr, *compiled)
|
18
|
+
end
|
19
|
+
|
20
|
+
def on_leaf_operand(plan, expr)
|
21
|
+
expr.to_cog(plan)
|
22
|
+
end
|
23
|
+
|
24
|
+
def on_shortcut(plan, expr, *compiled)
|
25
|
+
plan.recompile(*compiled){|p| expr.expand }
|
26
|
+
end
|
27
|
+
|
28
|
+
def on_missing(plan, expr, *compiled)
|
29
|
+
raise NotSupportedError, "Unable to compile `#{expr}` (#{self})"
|
30
|
+
end
|
31
|
+
|
32
|
+
def on_unsupported(plan, expr, *args)
|
33
|
+
raise NotSupportedError, "Unsupported expression `#{expr}`"
|
34
|
+
end
|
35
|
+
|
36
|
+
private
|
37
|
+
|
38
|
+
def to_method_name(expr)
|
39
|
+
case expr
|
40
|
+
when Algebra::Operator
|
41
|
+
name = expr.class.rubycase_name
|
42
|
+
meth = :"on_#{name}"
|
43
|
+
meth = :"on_shortcut" if expr.is_a?(Algebra::Shortcut) and !respond_to?(meth)
|
44
|
+
meth = :"on_missing" if !respond_to?(meth)
|
45
|
+
meth
|
46
|
+
when Algebra::Operand
|
47
|
+
:on_leaf_operand
|
48
|
+
else
|
49
|
+
:on_unsupported
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
end # class Compiler
|
54
|
+
end # module Alf
|
55
|
+
require_relative 'compiler/plan'
|
56
|
+
require_relative 'compiler/cog'
|
57
|
+
require_relative 'compiler/default'
|
@@ -0,0 +1,39 @@
|
|
1
|
+
module Alf
|
2
|
+
class Compiler
|
3
|
+
module Cog
|
4
|
+
extend Forwardable
|
5
|
+
|
6
|
+
def initialize(expr, compiler)
|
7
|
+
@expr = expr
|
8
|
+
@compiler = compiler
|
9
|
+
end
|
10
|
+
attr_reader :expr
|
11
|
+
attr_reader :compiler
|
12
|
+
|
13
|
+
def_delegators :expr, :connection,
|
14
|
+
:heading,
|
15
|
+
:keys
|
16
|
+
|
17
|
+
def cog_orders
|
18
|
+
[]
|
19
|
+
end
|
20
|
+
|
21
|
+
def orderedby?(order)
|
22
|
+
cog_orders.any?{|o| order <= o }
|
23
|
+
end
|
24
|
+
|
25
|
+
def to_cog
|
26
|
+
self
|
27
|
+
end
|
28
|
+
|
29
|
+
def to_ascii_tree
|
30
|
+
Support::Tree.new(self).to_text
|
31
|
+
end
|
32
|
+
|
33
|
+
def to_relation
|
34
|
+
Relation.coerce(each.to_set)
|
35
|
+
end
|
36
|
+
|
37
|
+
end # module Cog
|
38
|
+
end # class Compiler
|
39
|
+
end # module Alf
|
@@ -0,0 +1,168 @@
|
|
1
|
+
module Alf
|
2
|
+
class Compiler
|
3
|
+
class Default < Compiler
|
4
|
+
|
5
|
+
def supports_reuse?
|
6
|
+
true
|
7
|
+
end
|
8
|
+
|
9
|
+
def reuse(plan, cog)
|
10
|
+
cog
|
11
|
+
end
|
12
|
+
|
13
|
+
### non relational
|
14
|
+
|
15
|
+
def on_autonum(plan, expr, compiled)
|
16
|
+
factor(Engine::Autonum, expr, compiled, expr.as)
|
17
|
+
end
|
18
|
+
|
19
|
+
def on_clip(plan, expr, compiled)
|
20
|
+
factor(Engine::Clip, expr, compiled, expr.attributes, expr.allbut)
|
21
|
+
end
|
22
|
+
|
23
|
+
def on_coerce(plan, expr, compiled)
|
24
|
+
factor(Engine::Coerce, expr, compiled, expr.coercions)
|
25
|
+
end
|
26
|
+
|
27
|
+
def on_compact(plan, expr, compiled)
|
28
|
+
factor(Engine::Compact, expr, compiled)
|
29
|
+
end
|
30
|
+
|
31
|
+
def on_defaults(plan, expr, compiled)
|
32
|
+
compiled = plan.recompile(compiled){|p|
|
33
|
+
p.clip(expr.operand, expr.defaults.to_attr_list)
|
34
|
+
} if expr.strict
|
35
|
+
factor(Engine::Defaults, expr, compiled, expr.defaults)
|
36
|
+
end
|
37
|
+
|
38
|
+
def on_generator(plan, expr)
|
39
|
+
factor(Engine::Generator, expr, expr.as, 1, 1, expr.size)
|
40
|
+
end
|
41
|
+
|
42
|
+
def on_sort(plan, expr, compiled)
|
43
|
+
return compiled if compiled.orderedby?(expr.ordering)
|
44
|
+
factor(Engine::Sort, expr, compiled, expr.ordering)
|
45
|
+
end
|
46
|
+
|
47
|
+
### relational
|
48
|
+
|
49
|
+
def on_extend(plan, expr, compiled)
|
50
|
+
factor(Engine::SetAttr, expr, compiled, expr.ext)
|
51
|
+
end
|
52
|
+
|
53
|
+
def on_frame(plan, expr, compiled)
|
54
|
+
compiled = plan.recompile(compiled){|p|
|
55
|
+
ordering = expr.total_ordering rescue expr.ordering
|
56
|
+
p.sort(expr.operand, ordering)
|
57
|
+
}
|
58
|
+
factor(Engine::Take, expr, compiled, expr.offset, expr.limit)
|
59
|
+
end
|
60
|
+
|
61
|
+
def on_group(plan, expr, compiled)
|
62
|
+
factor(Engine::Group::Hash, expr, compiled, expr.attributes, expr.as, expr.allbut)
|
63
|
+
end
|
64
|
+
|
65
|
+
def on_hierarchize(plan, expr, compiled)
|
66
|
+
factor(Engine::Hierarchize, expr, compiled, expr.id, expr.parent, expr.as)
|
67
|
+
end
|
68
|
+
|
69
|
+
def on_intersect(plan, expr, left, right)
|
70
|
+
factor(Engine::Join::Hash, expr, left, right)
|
71
|
+
end
|
72
|
+
|
73
|
+
def on_join(plan, expr, left, right)
|
74
|
+
factor(Engine::Join::Hash, expr, left, right)
|
75
|
+
end
|
76
|
+
|
77
|
+
def on_matching(plan, expr, left, right)
|
78
|
+
factor(Engine::Semi::Hash, expr, left, right, true)
|
79
|
+
end
|
80
|
+
|
81
|
+
def on_minus(plan, expr, left, right)
|
82
|
+
factor(Engine::Semi::Hash, expr, left, right, false)
|
83
|
+
end
|
84
|
+
|
85
|
+
def on_not_matching(plan, expr, left, right)
|
86
|
+
factor(Engine::Semi::Hash, expr, left, right, false)
|
87
|
+
end
|
88
|
+
|
89
|
+
def on_page(plan, expr, compiled)
|
90
|
+
index, size = expr.page_index, expr.page_size
|
91
|
+
compiled = plan.recompile(compiled){|p|
|
92
|
+
ordering = expr.total_ordering rescue expr.ordering
|
93
|
+
ordering = ordering.reverse if index < 0
|
94
|
+
p.sort(expr.operand, ordering)
|
95
|
+
}
|
96
|
+
factor(Engine::Take, expr, compiled, (index.abs - 1) * size, size)
|
97
|
+
end
|
98
|
+
|
99
|
+
def on_project(plan, expr, compiled)
|
100
|
+
preserving = expr.key_preserving? rescue false
|
101
|
+
compiled = plan.recompile(compiled){|p|
|
102
|
+
p.clip(expr.operand, expr.attributes, allbut: expr.allbut)
|
103
|
+
}
|
104
|
+
compiled = factor(Engine::Compact, expr, compiled) unless preserving
|
105
|
+
compiled
|
106
|
+
end
|
107
|
+
|
108
|
+
def on_quota(plan, expr, compiled)
|
109
|
+
compiled = plan.recompile(compiled){|p|
|
110
|
+
p.sort(expr.operand, expr.by.to_ordering + expr.order)
|
111
|
+
}
|
112
|
+
factor(Engine::Quota::Cesure, expr, compiled, expr.by, expr.summarization)
|
113
|
+
end
|
114
|
+
|
115
|
+
def on_rank(plan, expr, compiled)
|
116
|
+
compiled = plan.recompile(compiled){|p|
|
117
|
+
p.sort(expr.operand, expr.order)
|
118
|
+
}
|
119
|
+
factor(Engine::Rank::Cesure, expr, compiled, expr.order, expr.as)
|
120
|
+
end
|
121
|
+
|
122
|
+
def on_rename(plan, expr, compiled)
|
123
|
+
factor(Engine::Rename, expr, compiled, expr.renaming)
|
124
|
+
end
|
125
|
+
|
126
|
+
def on_restrict(plan, expr, compiled)
|
127
|
+
factor(Engine::Filter, expr, compiled, expr.predicate)
|
128
|
+
end
|
129
|
+
|
130
|
+
def on_summarize(plan, expr, compiled)
|
131
|
+
if expr.allbut
|
132
|
+
factor(Engine::Summarize::Hash, expr, compiled, expr.by, expr.summarization, expr.allbut)
|
133
|
+
else
|
134
|
+
compiled = plan.recompile(compiled){|p|
|
135
|
+
p.sort(expr.operand, expr.by.to_ordering)
|
136
|
+
}
|
137
|
+
factor(Engine::Summarize::Cesure, expr, compiled, expr.by, expr.summarization, expr.allbut)
|
138
|
+
end
|
139
|
+
end
|
140
|
+
|
141
|
+
def on_ungroup(plan, expr, compiled)
|
142
|
+
factor(Engine::Ungroup, expr, compiled, expr.attribute)
|
143
|
+
end
|
144
|
+
|
145
|
+
def on_union(plan, expr, left, right)
|
146
|
+
compiled = factor(Engine::Concat, expr, [left, right])
|
147
|
+
compiled = factor(Engine::Compact, expr, compiled)
|
148
|
+
#
|
149
|
+
compiled
|
150
|
+
end
|
151
|
+
|
152
|
+
def on_unwrap(plan, expr, compiled)
|
153
|
+
factor(Engine::Unwrap, expr, compiled, expr.attribute)
|
154
|
+
end
|
155
|
+
|
156
|
+
def on_wrap(plan, expr, compiled)
|
157
|
+
factor(Engine::Wrap, expr, compiled, expr.attributes, expr.as, expr.allbut)
|
158
|
+
end
|
159
|
+
|
160
|
+
private
|
161
|
+
|
162
|
+
def factor(clazz, expr, *args)
|
163
|
+
clazz.new(*args, expr, self)
|
164
|
+
end
|
165
|
+
|
166
|
+
end # class Default
|
167
|
+
end # class Compiler
|
168
|
+
end # module Alf
|
@@ -0,0 +1,77 @@
|
|
1
|
+
require 'tsort'
|
2
|
+
module Alf
|
3
|
+
class Compiler
|
4
|
+
class Plan
|
5
|
+
|
6
|
+
def initialize(compiler = Compiler.new)
|
7
|
+
@parser = Lang::Parser::Lispy.new
|
8
|
+
@compilers = {}
|
9
|
+
@compiled = {}
|
10
|
+
@usage_count = Hash.new{|h,k| h[k] = 0 }
|
11
|
+
@main_compiler = compiler
|
12
|
+
join(compiler)
|
13
|
+
end
|
14
|
+
attr_reader :parser, :main_compiler
|
15
|
+
|
16
|
+
def join(compiler)
|
17
|
+
@compilers[compiler] ||= compiler.join(self)
|
18
|
+
compiler
|
19
|
+
end
|
20
|
+
|
21
|
+
def options(compiler)
|
22
|
+
@compilers[compiler]
|
23
|
+
end
|
24
|
+
|
25
|
+
# Pre-visit
|
26
|
+
def compile(sexpr)
|
27
|
+
visit(sexpr)
|
28
|
+
_compile(sexpr)
|
29
|
+
end
|
30
|
+
|
31
|
+
# Post-visit, pre-reuse
|
32
|
+
def _compile(expr)
|
33
|
+
compiled = @compiled[expr]
|
34
|
+
return @compiled[expr] = __compile(expr) unless compiled
|
35
|
+
return __compile(expr) unless compiler = compiled.compiler
|
36
|
+
return __compile(expr) unless compiler.supports_reuse?
|
37
|
+
compiler.reuse(self, compiled)
|
38
|
+
end
|
39
|
+
|
40
|
+
# Real compilation, post-reuse
|
41
|
+
def __compile(expr = nil, compiled = nil, &bl)
|
42
|
+
expr ||= bl.call(parser)
|
43
|
+
compiled ||= children(expr).map{|op| _compile(op) }
|
44
|
+
compiler = compiler(compiled)
|
45
|
+
usage_count = @usage_count[expr]
|
46
|
+
compiler.compile(self, expr, compiled, usage_count)
|
47
|
+
rescue NotSupportedError
|
48
|
+
main_compiler.compile(self, expr, compiled, usage_count)
|
49
|
+
end
|
50
|
+
|
51
|
+
def recompile(*compiled, &bl)
|
52
|
+
__compile(nil, compiled, &bl)
|
53
|
+
end
|
54
|
+
|
55
|
+
def visit(expr)
|
56
|
+
@usage_count[expr] += 1
|
57
|
+
children(expr).each{|op| visit(op) }
|
58
|
+
end
|
59
|
+
|
60
|
+
private
|
61
|
+
|
62
|
+
EMPTY_CHILDREN = []
|
63
|
+
|
64
|
+
def children(expr)
|
65
|
+
return EMPTY_CHILDREN unless expr.is_a?(Algebra::Operator)
|
66
|
+
expr.operands
|
67
|
+
end
|
68
|
+
|
69
|
+
def compiler(compiled)
|
70
|
+
candidates = compiled.map(&:compiler).uniq
|
71
|
+
candidates.size > 1 ? main_compiler \
|
72
|
+
: candidates.first || main_compiler
|
73
|
+
end
|
74
|
+
|
75
|
+
end # class Plan
|
76
|
+
end # class Compiler
|
77
|
+
end # module Alf
|
File without changes
|
File without changes
|
@@ -24,6 +24,7 @@ module Alf
|
|
24
24
|
def reconnect(opts = {})
|
25
25
|
close unless (opts.keys & [:schema_cache]).empty?
|
26
26
|
@options = options.merge(opts)
|
27
|
+
@parser = nil
|
27
28
|
open!
|
28
29
|
end
|
29
30
|
|
@@ -34,6 +35,7 @@ module Alf
|
|
34
35
|
def close
|
35
36
|
adapter_connection.close unless closed?
|
36
37
|
@adapter_connection = nil
|
38
|
+
@parser = nil
|
37
39
|
end
|
38
40
|
|
39
41
|
### logical level
|
@@ -47,7 +49,7 @@ module Alf
|
|
47
49
|
end
|
48
50
|
|
49
51
|
def relvar(*args, &bl)
|
50
|
-
|
52
|
+
optimize(*args, &bl).to_relvar
|
51
53
|
end
|
52
54
|
|
53
55
|
def query(*args, &bl)
|
@@ -72,31 +74,14 @@ module Alf
|
|
72
74
|
raise FactAssertionError, msg
|
73
75
|
end
|
74
76
|
|
75
|
-
### middleware level
|
76
|
-
|
77
|
-
def cog(expr, *args, &bl)
|
78
|
-
case expr
|
79
|
-
when Symbol then adapter_connection.cog(*args.unshift(expr), &bl)
|
80
|
-
when Algebra::Operand then compile(expr)
|
81
|
-
else
|
82
|
-
raise ArgumentError, "Unable to compile `#{expr}` to a cog"
|
83
|
-
end
|
84
|
-
end
|
85
|
-
|
86
|
-
def lock(expr, mode = :exclusive, &bl)
|
87
|
-
case expr
|
88
|
-
when Symbol then adapter_connection.lock(expr, mode, &bl)
|
89
|
-
else
|
90
|
-
raise NotImplementedError, "Unable to lock virtual relvars"
|
91
|
-
end
|
92
|
-
end
|
93
|
-
|
94
77
|
### physical level
|
95
78
|
|
96
79
|
def_delegators :adapter_connection, :in_transaction,
|
97
80
|
:knows?,
|
98
81
|
:heading,
|
99
82
|
:keys,
|
83
|
+
:cog,
|
84
|
+
:lock,
|
100
85
|
:insert,
|
101
86
|
:delete,
|
102
87
|
:update
|
@@ -111,44 +96,17 @@ module Alf
|
|
111
96
|
"Alf::Database::Connection(#{adapter_connection})"
|
112
97
|
end
|
113
98
|
|
114
|
-
def compile(expr)
|
115
|
-
if df = options.debug_folder
|
116
|
-
where, i = options.debug_naming.call(expr), 1
|
117
|
-
debug_dot(expr, df/"#{where}/#{i}-Algebra.dot")
|
118
|
-
compilation_chain.inject(expr){|e,c|
|
119
|
-
c.call(e).tap{|mid|
|
120
|
-
name = "#{i}-#{Alf::Support.class_name(c.class)}"
|
121
|
-
debug_dot(mid, df/"#{where}/#{name}.dot")
|
122
|
-
i += 1
|
123
|
-
}
|
124
|
-
}
|
125
|
-
else
|
126
|
-
compilation_chain.inject(expr){|e,c| c.call(e) }
|
127
|
-
end
|
128
|
-
end
|
129
|
-
|
130
99
|
private
|
131
100
|
|
132
101
|
def optimizer
|
133
|
-
Optimizer.new.
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
[ optimizer, adapter_connection.compiler ]
|
102
|
+
Optimizer.new.tap{|op|
|
103
|
+
op.register(Optimizer::Restrict.new)
|
104
|
+
op.register(Optimizer::Project.new)
|
105
|
+
}
|
138
106
|
end
|
139
107
|
|
140
108
|
def parser
|
141
|
-
options.
|
142
|
-
end
|
143
|
-
|
144
|
-
def debug_dot(e, where)
|
145
|
-
where.parent.mkdir_p
|
146
|
-
where.open('w') do |io|
|
147
|
-
e.to_dot(io)
|
148
|
-
end
|
149
|
-
rescue => ex
|
150
|
-
$stderr.puts ex.message
|
151
|
-
$stderr.puts ex.backtrace.join("\n")
|
109
|
+
@parser ||= options.parser.new([ options.viewpoint ], self)
|
152
110
|
end
|
153
111
|
|
154
112
|
end # class Connection
|