alf-core 0.13.1 → 0.14.0
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG.md +77 -0
- data/examples/operators/page.alf +4 -0
- data/lib/alf-adapter-fs/alf/adapter/folder.rb +4 -0
- data/lib/alf-adapter-fs/alf/adapter/folder/connection.rb +3 -2
- data/lib/alf-adapter/alf/adapter/connection.rb +1 -1
- data/lib/alf-algebra/alf/algebra/operand.rb +2 -2
- data/lib/alf-algebra/alf/algebra/operand/fake.rb +3 -3
- data/lib/alf-algebra/alf/algebra/operand/named.rb +1 -1
- data/lib/alf-algebra/alf/algebra/operand/proxy.rb +14 -0
- data/lib/alf-algebra/alf/algebra/operator.rb +4 -1
- data/lib/alf-algebra/alf/algebra/operator/clip.rb +7 -4
- data/lib/alf-algebra/alf/algebra/operator/frame.rb +22 -0
- data/lib/alf-algebra/alf/algebra/operator/hierarchize.rb +22 -0
- data/lib/alf-algebra/alf/algebra/operator/page.rb +22 -0
- data/lib/alf-algebra/alf/algebra/operator/project.rb +4 -9
- data/lib/alf-algebra/alf/algebra/operator/rank.rb +2 -2
- data/lib/alf-algebra/alf/algebra/support.rb +2 -0
- data/lib/alf-algebra/alf/algebra/support/signature.rb +2 -1
- data/lib/alf-algebra/alf/algebra/support/with_ordering.rb +11 -0
- data/lib/alf-core/ext/domain/heading_based.rb +16 -4
- data/lib/alf-core/facade.rb +5 -1
- data/lib/alf-core/version.rb +2 -2
- data/lib/alf-database/alf/database/connection.rb +2 -2
- data/lib/alf-database/alf/database/options.rb +0 -3
- data/lib/alf-engine/alf/engine.rb +4 -1
- data/lib/alf-engine/alf/engine/aggregate.rb +2 -1
- data/lib/alf-engine/alf/engine/autonum.rb +2 -1
- data/lib/alf-engine/alf/engine/clip.rb +2 -1
- data/lib/alf-engine/alf/engine/coerce.rb +2 -1
- data/lib/alf-engine/alf/engine/cog.rb +23 -0
- data/lib/alf-engine/alf/engine/compact.rb +3 -2
- data/lib/alf-engine/alf/engine/compact/set.rb +2 -1
- data/lib/alf-engine/alf/engine/compact/uniq.rb +2 -1
- data/lib/alf-engine/alf/engine/compiler.rb +60 -33
- data/lib/alf-engine/alf/engine/concat.rb +2 -1
- data/lib/alf-engine/alf/engine/defaults.rb +2 -1
- data/lib/alf-engine/alf/engine/filter.rb +4 -2
- data/lib/alf-engine/alf/engine/generator.rb +2 -1
- data/lib/alf-engine/alf/engine/group/hash.rb +4 -3
- data/lib/alf-engine/alf/engine/hierarchize.rb +87 -0
- data/lib/alf-engine/alf/engine/infer_heading.rb +2 -1
- data/lib/alf-engine/alf/engine/join.rb +5 -1
- data/lib/alf-engine/alf/engine/join/hash.rb +9 -2
- data/lib/alf-engine/alf/engine/leaf.rb +6 -1
- data/lib/alf-engine/alf/engine/materialize/array.rb +2 -1
- data/lib/alf-engine/alf/engine/materialize/hash.rb +2 -1
- data/lib/alf-engine/alf/engine/quota/cesure.rb +2 -1
- data/lib/alf-engine/alf/engine/rank/cesure.rb +2 -1
- data/lib/alf-engine/alf/engine/rename.rb +2 -1
- data/lib/alf-engine/alf/engine/semi/hash.rb +7 -1
- data/lib/alf-engine/alf/engine/set_attr.rb +4 -3
- data/lib/alf-engine/alf/engine/sort.rb +3 -2
- data/lib/alf-engine/alf/engine/sort/in_memory.rb +2 -1
- data/lib/alf-engine/alf/engine/summarize/cesure.rb +2 -1
- data/lib/alf-engine/alf/engine/summarize/hash.rb +3 -2
- data/lib/alf-engine/alf/engine/{cesure.rb → support/cesure.rb} +0 -0
- data/lib/alf-engine/alf/engine/take.rb +53 -0
- data/lib/alf-engine/alf/engine/to_array.rb +6 -5
- data/lib/alf-engine/alf/engine/type_safe.rb +2 -1
- data/lib/alf-engine/alf/engine/ungroup.rb +2 -1
- data/lib/alf-engine/alf/engine/unwrap.rb +2 -1
- data/lib/alf-engine/alf/engine/wrap.rb +2 -1
- data/lib/alf-io/alf/reader.rb +1 -1
- data/lib/alf-io/alf/reader/ruby.rb +23 -0
- data/lib/alf-io/alf/renderer/text.rb +22 -9
- data/lib/alf-lang/alf/lang/lispy.rb +41 -29
- data/lib/alf-lang/alf/lang/oo/algebra_methods.rb +17 -1
- data/lib/alf-optimizer/alf/optimizer/restrict.rb +7 -1
- data/lib/alf-predicate/alf/predicate.rb +11 -2
- data/lib/alf-relation/alf/relation.rb +21 -1
- data/lib/alf-relvar/alf/relvar.rb +21 -1
- data/lib/alf-relvar/alf/relvar/base.rb +11 -6
- data/lib/alf-relvar/alf/relvar/fake.rb +3 -2
- data/lib/alf-relvar/alf/relvar/virtual.rb +1 -2
- data/lib/alf-support/alf/support/bindable.rb +1 -1
- data/lib/alf-support/alf/support/config.rb +91 -18
- data/lib/alf-support/alf/support/tuple_scope.rb +8 -4
- data/lib/alf-types/alf/types.rb +2 -0
- data/lib/alf-types/alf/types/attr_list.rb +3 -1
- data/lib/alf-types/alf/types/heading.rb +4 -1
- data/lib/alf-types/alf/types/keys.rb +0 -4
- data/lib/alf-types/alf/types/ordering.rb +104 -18
- data/lib/alf-types/alf/types/selection.rb +18 -0
- data/lib/alf-types/alf/types/selector.rb +59 -0
- data/lib/alf-types/alf/types/tuple_computation.rb +2 -2
- data/lib/alf-types/alf/types/tuple_expression.rb +18 -2
- data/lib/alf-viewpoint/alf/viewpoint.rb +23 -8
- data/lib/alf-viewpoint/alf/viewpoint/metadata.rb +73 -0
- data/spec/integration/relation/test_extend.rb +20 -0
- data/spec/integration/relation/test_to_array.rb +1 -1
- data/spec/integration/test_examples.rb +18 -2
- data/spec/shared/a_cog.rb +36 -0
- data/spec/spec_helper.rb +8 -0
- data/spec/unit/alf-algebra/operand/test_proxy.rb +54 -0
- data/spec/unit/alf-algebra/operator/hierarchize/test_heading.rb +23 -0
- data/spec/unit/alf-algebra/operator/project/test_key_preserving.rb +3 -0
- data/spec/unit/alf-algebra/operator/project/test_keys.rb +54 -17
- data/spec/unit/alf-algebra/operator/rank/test_keys.rb +2 -2
- data/spec/unit/alf-algebra/operator/restrict/test_keys.rb +2 -2
- data/spec/unit/alf-algebra/operator/test_page.rb +30 -0
- data/spec/unit/alf-algebra/support/test_relational.rb +3 -0
- data/spec/unit/alf-algebra/support/with_ordering/test_total_ordering.rb +61 -0
- data/spec/unit/alf-database/connection/test_reconnect.rb +1 -1
- data/spec/unit/alf-database/options/test_new.rb +4 -4
- data/spec/unit/alf-database/shared_examples/a_facade_on_database_options.rb +1 -2
- data/spec/unit/alf-engine/cog/test_to_cog.rb +14 -0
- data/spec/unit/alf-engine/compiler/test_on_frame.rb +70 -0
- data/spec/unit/alf-engine/compiler/test_on_hierarchize.rb +33 -0
- data/spec/unit/alf-engine/compiler/test_on_page.rb +128 -0
- data/spec/unit/alf-engine/compiler/test_unsupported.rb +48 -0
- data/spec/unit/alf-engine/hierarchize/test_renamer.rb +18 -0
- data/spec/unit/alf-engine/test_filter.rb +43 -11
- data/spec/unit/alf-engine/test_hierarchize.rb +71 -0
- data/spec/unit/alf-engine/test_set_attr.rb +13 -0
- data/spec/unit/alf-engine/test_take.rb +46 -0
- data/spec/unit/alf-engine/test_to_array.rb +45 -28
- data/spec/unit/alf-io/reader/{input.rb → input.rash} +0 -0
- data/spec/unit/alf-io/reader/input.ruby +4 -0
- data/spec/unit/alf-io/reader/test_rash.rb +1 -1
- data/spec/unit/alf-io/reader/test_ruby.rb +25 -0
- data/spec/unit/alf-predicate/predicate/test_evaluate.rb +51 -13
- data/spec/unit/alf-relation/relation/class/test_recursive_type.rb +42 -0
- data/spec/unit/alf-relation/relation/test_equality.rb +19 -1
- data/spec/unit/alf-relation/relation/test_relops.rb +14 -2
- data/spec/unit/alf-relation/relation/test_to_hash.rb +31 -0
- data/spec/unit/alf-relvar/base/test_connection.rb +8 -2
- data/spec/unit/alf-relvar/base/test_delete.rb +2 -2
- data/spec/unit/alf-relvar/base/test_heading.rb +2 -2
- data/spec/unit/alf-relvar/base/test_insert.rb +3 -3
- data/spec/unit/alf-relvar/base/test_keys.rb +2 -2
- data/spec/unit/alf-relvar/base/test_lock.rb +2 -2
- data/spec/unit/alf-relvar/base/test_name.rb +3 -2
- data/spec/unit/alf-relvar/base/test_oo_lang.rb +2 -1
- data/spec/unit/alf-relvar/base/test_to_cog.rb +3 -3
- data/spec/unit/alf-relvar/base/test_to_lispy.rb +3 -2
- data/spec/unit/alf-relvar/base/test_to_relvar.rb +2 -1
- data/spec/unit/alf-relvar/base/test_to_s.rb +3 -2
- data/spec/unit/alf-relvar/base/test_update.rb +5 -4
- data/spec/unit/alf-relvar/virtual/test_connection.rb +3 -2
- data/spec/unit/alf-relvar/virtual/test_delete.rb +3 -4
- data/spec/unit/alf-relvar/virtual/test_expr.rb +3 -2
- data/spec/unit/alf-relvar/virtual/test_heading.rb +5 -4
- data/spec/unit/alf-relvar/virtual/test_insert.rb +2 -2
- data/spec/unit/alf-relvar/virtual/test_keys.rb +5 -4
- data/spec/unit/alf-relvar/virtual/test_oo_lang.rb +7 -2
- data/spec/unit/alf-relvar/virtual/test_to_cog.rb +4 -3
- data/spec/unit/alf-relvar/virtual/test_to_lispy.rb +3 -6
- data/spec/unit/alf-relvar/virtual/test_to_relvar.rb +2 -1
- data/spec/unit/alf-relvar/virtual/test_to_s.rb +3 -3
- data/spec/unit/alf-relvar/virtual/test_update.rb +4 -5
- data/spec/unit/alf-support/config/test_dup.rb +58 -0
- data/spec/unit/alf-support/config/test_freeze.rb +37 -0
- data/spec/unit/alf-support/config/test_hash_get.rb +41 -0
- data/spec/unit/alf-support/config/test_hash_set.rb +61 -0
- data/spec/unit/alf-support/config/test_new.rb +10 -0
- data/spec/unit/alf-support/config/test_option.rb +15 -0
- data/spec/unit/alf-support/config/test_option_setter.rb +72 -0
- data/spec/unit/alf-support/config/test_options.rb +22 -0
- data/spec/unit/alf-support/tuple_scope/test_hash_get.rb +20 -0
- data/spec/unit/alf-support/tuple_scope/test_respond_to.rb +6 -0
- data/spec/unit/alf-support/tuple_scope/test_to_s.rb +22 -0
- data/spec/unit/alf-types/keys/test_select.rb +57 -8
- data/spec/unit/alf-types/ordering/test_coerce.rb +46 -35
- data/spec/unit/alf-types/ordering/test_dive.rb +41 -0
- data/spec/unit/alf-types/ordering/test_hash_get.rb +20 -0
- data/spec/unit/alf-types/ordering/test_merge.rb +61 -0
- data/spec/unit/alf-types/ordering/test_reverse.rb +40 -0
- data/spec/unit/alf-types/ordering/test_selectors.rb +24 -0
- data/spec/unit/alf-types/ordering/test_sorter.rb +62 -8
- data/spec/unit/alf-types/ordering/test_to_attr_list.rb +16 -4
- data/spec/unit/alf-types/ordering/test_total.rb +56 -0
- data/spec/unit/alf-types/selection/test_coerce.rb +38 -0
- data/spec/unit/alf-types/selection/test_select.rb +34 -0
- data/spec/unit/alf-types/selector/test_coerce.rb +36 -0
- data/spec/unit/alf-types/selector/test_composite_q.rb +20 -0
- data/spec/unit/alf-types/selector/test_dive.rb +32 -0
- data/spec/unit/alf-types/selector/test_select.rb +40 -0
- data/spec/unit/alf-types/selector/test_simple_q.rb +20 -0
- data/spec/unit/alf-types/selector/test_to_a.rb +20 -0
- data/spec/unit/alf-types/selector/test_to_lispy.rb +20 -0
- data/spec/unit/alf-types/selector/test_to_ruby_literal.rb +20 -0
- data/spec/unit/alf-types/tuple_expression/test_evaluate.rb +38 -0
- data/spec/unit/alf-viewpoint/metadata/test_add_members.rb +38 -0
- data/spec/unit/alf-viewpoint/metadata/test_all_members.rb +33 -0
- data/spec/unit/alf-viewpoint/metadata/test_depends.rb +50 -0
- data/spec/unit/alf-viewpoint/metadata/test_dup.rb +32 -0
- data/spec/unit/alf-viewpoint/metadata/test_expand.rb +31 -0
- data/spec/unit/alf-viewpoint/metadata/test_expects.rb +38 -0
- data/spec/unit/alf-viewpoint/metadata/test_initialize.rb +40 -0
- data/spec/unit/alf-viewpoint/metadata/test_to_module.rb +37 -0
- data/spec/unit/alf-viewpoint/test_depends.rb +18 -0
- data/spec/unit/alf-viewpoint/test_expects.rb +18 -0
- data/spec/unit/alf-viewpoint/test_members.rb +33 -0
- data/spec/unit/alf-viewpoint/test_metadata.rb +27 -0
- data/spec/unit/alf-viewpoint/test_native_const.rb +6 -0
- metadata +125 -14
- data/spec/unit/alf-database/options/test_default_viewpoint.rb +0 -25
- data/spec/unit/alf-types/keys/test_compact.rb +0 -21
- data/spec/unit/alf-types/ordering/test_plus.rb +0 -27
- data/spec/unit/alf-viewpoint/test_namespace.rb +0 -23
@@ -4,6 +4,7 @@ module Alf
|
|
4
4
|
# Provides hash-based join.
|
5
5
|
#
|
6
6
|
class Join::Hash
|
7
|
+
include Join
|
7
8
|
include Cog
|
8
9
|
|
9
10
|
# @return [Enumerable] The left operand
|
@@ -13,18 +14,24 @@ module Alf
|
|
13
14
|
attr_reader :right
|
14
15
|
|
15
16
|
# Creates a Join::Hash instance
|
16
|
-
def initialize(left, right)
|
17
|
+
def initialize(left, right, expr = nil)
|
18
|
+
super(expr)
|
17
19
|
@left = left
|
18
20
|
@right = right
|
19
21
|
end
|
20
22
|
|
23
|
+
# Returns left and right operands in an array
|
24
|
+
def operands
|
25
|
+
[ left, right ]
|
26
|
+
end
|
27
|
+
|
21
28
|
# (see Cog#each)
|
22
29
|
def _each(&block)
|
23
30
|
index = nil
|
24
31
|
left.each do |left_tuple|
|
25
32
|
index ||= Materialize::Hash.new(right, lambda{|t|
|
26
33
|
AttrList.new(left_tuple.keys & t.keys)
|
27
|
-
}, false).prepare
|
34
|
+
}, false, expr).prepare
|
28
35
|
index[left_tuple, true].each do |right_tuple|
|
29
36
|
yield left_tuple.merge(right_tuple)
|
30
37
|
end
|
@@ -10,7 +10,8 @@ module Alf
|
|
10
10
|
attr_reader :operand
|
11
11
|
|
12
12
|
# Creates a Concat instance
|
13
|
-
def initialize(operand)
|
13
|
+
def initialize(operand, expr = nil)
|
14
|
+
super(expr)
|
14
15
|
@operand = operand
|
15
16
|
end
|
16
17
|
|
@@ -19,6 +20,10 @@ module Alf
|
|
19
20
|
operand.each(&block)
|
20
21
|
end
|
21
22
|
|
23
|
+
def to_s
|
24
|
+
"Engine::Leaf(#{operand})"
|
25
|
+
end
|
26
|
+
|
22
27
|
end # class Leaf
|
23
28
|
end # module Engine
|
24
29
|
end # module Alf
|
@@ -37,7 +37,8 @@ module Alf
|
|
37
37
|
attr_reader :ordering
|
38
38
|
|
39
39
|
# Creates a Materialize::Array instance
|
40
|
-
def initialize(operand, ordering = nil)
|
40
|
+
def initialize(operand, ordering = nil, expr = nil)
|
41
|
+
super(expr)
|
41
42
|
@operand = operand
|
42
43
|
@ordering = ordering
|
43
44
|
@materialized = nil
|
@@ -13,7 +13,8 @@ module Alf
|
|
13
13
|
attr_reader :summarization
|
14
14
|
|
15
15
|
# Creates an Quota::Cesure instance
|
16
|
-
def initialize(operand, by, summarization)
|
16
|
+
def initialize(operand, by, summarization, expr = nil)
|
17
|
+
super(expr)
|
17
18
|
@operand = operand
|
18
19
|
@by = by.to_attr_list
|
19
20
|
@summarization = summarization
|
@@ -16,12 +16,18 @@ module Alf
|
|
16
16
|
attr_reader :predicate
|
17
17
|
|
18
18
|
# Creates a Semi::Hash instance
|
19
|
-
def initialize(left, right, predicate)
|
19
|
+
def initialize(left, right, predicate, expr = nil)
|
20
|
+
super(expr)
|
20
21
|
@left = left
|
21
22
|
@right = right
|
22
23
|
@predicate = predicate
|
23
24
|
end
|
24
25
|
|
26
|
+
# Returns left and right operands in an array
|
27
|
+
def operands
|
28
|
+
[ left, right ]
|
29
|
+
end
|
30
|
+
|
25
31
|
# (see Cog#each)
|
26
32
|
def _each
|
27
33
|
index = nil
|
@@ -28,7 +28,8 @@ module Alf
|
|
28
28
|
attr_reader :computation
|
29
29
|
|
30
30
|
# Creates a SetAttr instance
|
31
|
-
def initialize(operand, computation)
|
31
|
+
def initialize(operand, computation, expr = nil)
|
32
|
+
super(expr)
|
32
33
|
@operand = operand
|
33
34
|
@computation = computation
|
34
35
|
end
|
@@ -37,8 +38,8 @@ module Alf
|
|
37
38
|
def _each
|
38
39
|
scope = tuple_scope
|
39
40
|
operand.each do |tuple|
|
40
|
-
|
41
|
-
yield tuple.merge(
|
41
|
+
t, c = scope.__set_tuple(tuple), expr && expr.connection
|
42
|
+
yield tuple.merge(@computation.evaluate(t, c))
|
42
43
|
end
|
43
44
|
end
|
44
45
|
|
@@ -13,14 +13,15 @@ module Alf
|
|
13
13
|
attr_reader :ordering
|
14
14
|
|
15
15
|
# Creates an Autonum instance
|
16
|
-
def initialize(operand, ordering)
|
16
|
+
def initialize(operand, ordering, expr = nil)
|
17
|
+
super(expr)
|
17
18
|
@operand = operand
|
18
19
|
@ordering = ordering
|
19
20
|
end
|
20
21
|
|
21
22
|
# (see Cog#each)
|
22
23
|
def _each(&block)
|
23
|
-
Sort::InMemory.new(operand, ordering).each(&block)
|
24
|
+
Sort::InMemory.new(operand, ordering, expr).each(&block)
|
24
25
|
end
|
25
26
|
|
26
27
|
end # class Sort
|
@@ -16,7 +16,8 @@ module Alf
|
|
16
16
|
attr_reader :allbut
|
17
17
|
|
18
18
|
# Creates an Summarize::Cesure instance
|
19
|
-
def initialize(operand, by, summarization, allbut)
|
19
|
+
def initialize(operand, by, summarization, allbut, expr = nil)
|
20
|
+
super(expr)
|
20
21
|
@operand = operand
|
21
22
|
@by = by
|
22
23
|
@summarization = summarization
|
@@ -16,7 +16,8 @@ module Alf
|
|
16
16
|
attr_reader :allbut
|
17
17
|
|
18
18
|
# Creates an Summarize::Hash instance
|
19
|
-
def initialize(operand, by, summarization, allbut)
|
19
|
+
def initialize(operand, by, summarization, allbut, expr = nil)
|
20
|
+
super(expr)
|
20
21
|
@operand = operand
|
21
22
|
@by = by
|
22
23
|
@summarization = summarization
|
@@ -25,7 +26,7 @@ module Alf
|
|
25
26
|
|
26
27
|
# (see Cog#each)
|
27
28
|
def _each
|
28
|
-
index = Materialize::Hash.new(operand, by, allbut)
|
29
|
+
index = Materialize::Hash.new(operand, by, allbut, expr)
|
29
30
|
index.each_pair do |k, v|
|
30
31
|
yield k.merge(summarization.summarize(v))
|
31
32
|
end
|
File without changes
|
@@ -0,0 +1,53 @@
|
|
1
|
+
module Alf
|
2
|
+
module Engine
|
3
|
+
#
|
4
|
+
# Take only a frame of the input relation according to an (offset, limit)
|
5
|
+
# parameter.
|
6
|
+
#
|
7
|
+
# Example:
|
8
|
+
#
|
9
|
+
# res = [
|
10
|
+
# {:name => "Jones", :price => 12.0, :id => 1},
|
11
|
+
# {:name => "Smith", :price => 10.0, :id => 2},
|
12
|
+
# {:name => "Blake", :price => 14.0, :id => 3}
|
13
|
+
# {:name => "Adams", :price => 13.0, :id => 4}
|
14
|
+
# ]
|
15
|
+
# Aggregate.new(res, 1, 2).to_a
|
16
|
+
# # => [
|
17
|
+
# # {:name => "Smith", :price => 10.0, :id => 2},
|
18
|
+
# # {:name => "Blake", :price => 14.0, :id => 3}
|
19
|
+
# # ]
|
20
|
+
#
|
21
|
+
class Take
|
22
|
+
include Cog
|
23
|
+
|
24
|
+
# @return [Enumerable] The operand
|
25
|
+
attr_reader :operand
|
26
|
+
|
27
|
+
# @return [Integer] The frame offset
|
28
|
+
attr_reader :offset
|
29
|
+
|
30
|
+
# @return [Integer] The frame limit
|
31
|
+
attr_reader :limit
|
32
|
+
|
33
|
+
# Creates a Take instance
|
34
|
+
def initialize(operand, offset, limit, expr = nil)
|
35
|
+
super(expr)
|
36
|
+
@operand = operand
|
37
|
+
@offset = offset
|
38
|
+
@limit = limit
|
39
|
+
end
|
40
|
+
|
41
|
+
# (see Cog#each)
|
42
|
+
def _each
|
43
|
+
i = -1
|
44
|
+
operand.each do |tuple|
|
45
|
+
next if (i += 1) < offset
|
46
|
+
return if i >= offset+limit
|
47
|
+
yield(tuple)
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
end # class Take
|
52
|
+
end # module Engine
|
53
|
+
end # module Alf
|
@@ -26,7 +26,8 @@ module Alf
|
|
26
26
|
attr_reader :ordering
|
27
27
|
|
28
28
|
# Creates an ToArray instance
|
29
|
-
def initialize(operand, ordering)
|
29
|
+
def initialize(operand, ordering, expr = nil)
|
30
|
+
super(expr)
|
30
31
|
@operand = operand
|
31
32
|
@ordering = ordering
|
32
33
|
end
|
@@ -43,15 +44,15 @@ module Alf
|
|
43
44
|
def recurse(tuple)
|
44
45
|
case tuple
|
45
46
|
when Hash
|
46
|
-
Hash[tuple.map{|k,v| [k, reorder(v)] }]
|
47
|
+
Hash[tuple.map{|k,v| [ k, reorder(k,v) ] }]
|
47
48
|
when Tuple
|
48
|
-
tuple.remap{|k,v| reorder(v) }
|
49
|
+
tuple.remap{|k,v| reorder(k, v) }
|
49
50
|
end
|
50
51
|
end
|
51
52
|
|
52
|
-
def reorder(value)
|
53
|
+
def reorder(key, value)
|
53
54
|
if RelationLike===value
|
54
|
-
ToArray.new(value, ordering).to_a
|
55
|
+
ToArray.new(value, ordering.dive(key)).to_a
|
55
56
|
else
|
56
57
|
value
|
57
58
|
end
|
@@ -19,7 +19,8 @@ module Alf
|
|
19
19
|
attr_reader :allbut
|
20
20
|
|
21
21
|
# Creates a SetAttr instance
|
22
|
-
def initialize(operand, attributes, as, allbut)
|
22
|
+
def initialize(operand, attributes, as, allbut, expr = nil)
|
23
|
+
super(expr)
|
23
24
|
@operand = operand
|
24
25
|
@attributes = attributes
|
25
26
|
@as = as
|
data/lib/alf-io/alf/reader.rb
CHANGED
@@ -20,7 +20,6 @@ module Alf
|
|
20
20
|
# r = Reader.foo([a path or a IO object])
|
21
21
|
#
|
22
22
|
class Reader
|
23
|
-
include Alf::Engine::Cog
|
24
23
|
include Enumerable
|
25
24
|
|
26
25
|
class << self
|
@@ -187,3 +186,4 @@ end # module Alf
|
|
187
186
|
require_relative 'reader/rash'
|
188
187
|
require_relative 'reader/csv'
|
189
188
|
require_relative 'reader/json'
|
189
|
+
require_relative 'reader/ruby'
|
@@ -0,0 +1,23 @@
|
|
1
|
+
module Alf
|
2
|
+
class Reader
|
3
|
+
#
|
4
|
+
# Specialization of the Reader contract for .rb files.
|
5
|
+
#
|
6
|
+
# A .rb file/stream contains some ruby code that evaluates to a Relation-like
|
7
|
+
# object, typically an Array of hashes.
|
8
|
+
#
|
9
|
+
class Ruby < Reader
|
10
|
+
|
11
|
+
def self.mime_type
|
12
|
+
nil
|
13
|
+
end
|
14
|
+
|
15
|
+
def each(&bl)
|
16
|
+
return to_enum unless block_given?
|
17
|
+
::Kernel.eval(input_text).each(&bl)
|
18
|
+
end
|
19
|
+
|
20
|
+
Reader.register(:ruby, [".rb", ".ruby"], self)
|
21
|
+
end # class Ruby
|
22
|
+
end # class Reader
|
23
|
+
end # module Alf
|
@@ -124,20 +124,33 @@ module Alf
|
|
124
124
|
end
|
125
125
|
|
126
126
|
def sep
|
127
|
-
@sep ||= '+-' << sizes.map{|s| '-' * s}.join('-+-') << '-+'
|
127
|
+
@sep ||= '+-' << sizes.map{|s| '-' * s}.join('-+-') << '-+'
|
128
|
+
end
|
129
|
+
|
130
|
+
def each_line(pretty = options[:pretty])
|
131
|
+
if pretty
|
132
|
+
trim = options[:trim_at]
|
133
|
+
each_line(false) do |line|
|
134
|
+
yield(line[0..trim])
|
135
|
+
end
|
136
|
+
else
|
137
|
+
yield(sep)
|
138
|
+
yield(header.rendering_lines(sizes).first)
|
139
|
+
yield(sep)
|
140
|
+
rows.each do |row|
|
141
|
+
row.rendering_lines(sizes).each do |line|
|
142
|
+
yield(line)
|
143
|
+
end
|
144
|
+
end
|
145
|
+
yield(sep)
|
146
|
+
end
|
128
147
|
end
|
129
148
|
|
130
149
|
def each
|
131
150
|
return to_enum unless block_given?
|
132
|
-
|
133
|
-
|
134
|
-
yield(sep)
|
135
|
-
rows.each do |row|
|
136
|
-
row.rendering_lines(sizes).each do |line|
|
137
|
-
yield(line << "\n")
|
138
|
-
end
|
151
|
+
each_line do |line|
|
152
|
+
yield(line.strip << "\n")
|
139
153
|
end
|
140
|
-
yield(sep)
|
141
154
|
end
|
142
155
|
|
143
156
|
def to_s
|
@@ -1,43 +1,55 @@
|
|
1
1
|
module Alf
|
2
2
|
module Lang
|
3
|
-
class Lispy
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
expr = expr.bind(connection) if expr.is_a?(Support::Bindable) && connection
|
14
|
-
expr
|
3
|
+
class Lispy
|
4
|
+
include Functional
|
5
|
+
include Predicates
|
6
|
+
|
7
|
+
# Creates a language instance
|
8
|
+
def initialize(helpers = [ ], connection = nil)
|
9
|
+
@connection = connection
|
10
|
+
@extensions = helpers
|
11
|
+
helpers.each do |helper|
|
12
|
+
helper.send(:extend_object, self)
|
15
13
|
end
|
14
|
+
end
|
16
15
|
|
17
|
-
|
16
|
+
attr_reader :connection
|
18
17
|
|
19
|
-
|
20
|
-
|
21
|
-
|
18
|
+
def connection!
|
19
|
+
connection.tap{|c| ::Kernel.raise(UnboundError, "#{self} not bound") unless c }
|
20
|
+
end
|
21
|
+
|
22
|
+
def evaluate(expr = nil, path=nil, line=nil, &bl)
|
23
|
+
return instance_exec(&bl) if bl
|
24
|
+
::Kernel.eval expr, __eval_binding, *[path, line].compact
|
25
|
+
end
|
22
26
|
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
.compact
|
27
|
-
.reject{|x| x =~ /^Alf::|OwnMethods/}
|
28
|
-
.join(',')
|
29
|
-
"Lispy(#{mods})"
|
27
|
+
def parse(expr = nil, path = nil, line = nil, &block)
|
28
|
+
if (expr && block) || (expr.nil? and block.nil?)
|
29
|
+
raise ArgumentError, "Either `expr` or `block` should be specified"
|
30
30
|
end
|
31
|
-
|
31
|
+
expr = evaluate(expr, path, line, &block) if block or expr.is_a?(String)
|
32
|
+
expr = __send__(expr) if expr.is_a?(Symbol)
|
33
|
+
expr = expr.bind(connection) if expr.is_a?(Support::Bindable) && connection
|
34
|
+
expr
|
35
|
+
end
|
32
36
|
|
33
|
-
|
37
|
+
def to_s
|
38
|
+
"Lispy(#{@extensions.map(&:name).compact.join(',')})"
|
39
|
+
end
|
34
40
|
|
35
|
-
|
36
|
-
|
37
|
-
@connection = connection
|
38
|
-
super [ OwnMethods, Functional, Predicates ] + helpers
|
41
|
+
def inspect
|
42
|
+
"Lispy(#{@extensions.inspect})"
|
39
43
|
end
|
40
44
|
|
45
|
+
private
|
46
|
+
|
47
|
+
def __eval_binding
|
48
|
+
::Kernel.binding
|
49
|
+
end
|
50
|
+
|
51
|
+
public
|
52
|
+
|
41
53
|
# Resolve DUM and DEE in ruby 1.9.2 context
|
42
54
|
def self.const_missing(name)
|
43
55
|
case name.to_s
|