alf-shell 0.15.0 → 0.16.0

Sign up to get free protection for your applications and to get access to all the features.
data/CHANGELOG.md CHANGED
@@ -1,3 +1,15 @@
1
+ # 0.16.0 / 2014-02-18
2
+
3
+ * Added highline '~> 1.6' to runtime dependencies.
4
+ * Fixed --pretty behavior when stdout is a terminal.
5
+ * Fix `metadata` command when using input sources that do not provide heading
6
+ information (heading is infered through Relation coercion).
7
+ * Take 'alfrc' into account too (without the dot, for WIN32 users)
8
+
9
+ # 0.15.0 / 2013-11-01
10
+
11
+ * Removed all commands corresponding to operators. Use ruby expressions instead.
12
+
1
13
  # 0.14.0 / 2013-10-01
2
14
 
3
15
  * Added a .alfrc abstraction
data/Gemfile.lock CHANGED
@@ -1,14 +1,15 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- alf-shell (0.15.0)
5
- alf-core (~> 0.15.0)
4
+ alf-shell (0.16.0)
5
+ alf-core (= 0.16.0)
6
+ highline (~> 1.6)
6
7
  quickl (~> 0.4.3)
7
8
 
8
9
  PATH
9
10
  remote: ../alf-core
10
11
  specs:
11
- alf-core (0.15.0)
12
+ alf-core (0.16.0)
12
13
  domain (~> 1.0)
13
14
  myrrha (~> 3.0)
14
15
  path (~> 1.3)
@@ -17,8 +18,8 @@ PATH
17
18
  PATH
18
19
  remote: ../alf-doc
19
20
  specs:
20
- alf-doc (0.15.0)
21
- alf-core (~> 0.15.0)
21
+ alf-doc (0.16.0)
22
+ alf-core (= 0.16.0)
22
23
 
23
24
  GEM
24
25
  remote: http://rubygems.org/
@@ -0,0 +1,13 @@
1
+ .TH alf\-repl
2
+ .PP
3
+ Launches Alf's Read\-Eval\-Print\-Loop (REPL) web application.
4
+ .SH Synopsis
5
+ .PP
6
+ \fB\fCalf\fR [\fB\fC--db=...\fR] repl
7
+ .SH Description
8
+ .PP
9
+ This command launches the REPL in the current data context defined by the
10
+ \fB\fC.alfrc\fR file and common alf options (e.g. \fB\fC--db\fR).
11
+ .SH Example
12
+ .PP
13
+ \fB\fCalf\fR \fB\fC--db=postgres://...\fR repl
data/doc/man/alf.man CHANGED
@@ -72,6 +72,9 @@ Relational algebra at your fingertips
72
72
  .TP
73
73
  \fB\fCexplain\fR
74
74
  Show the logical (optimizer) and physical (compiler) plans of a query.
75
+ .TP
76
+ \fB\fCrepl\fR
77
+ Launches Alf's Read\-Eval\-Print\-Loop (REPL) web application.
75
78
  .PP
76
79
  See \fB\fCalf help COMMAND\fR for details about a specific command or \fB\fCalf help
77
80
  OPERATOR\fR for documentation of a relational operator.
data/doc/man/extend.man CHANGED
@@ -29,5 +29,5 @@ In other words, all computations are done in ruby, which may seriously
29
29
  hurt performance.
30
30
  .PP
31
31
  Similarly, as \fB\fCextend\fR tends to be a showstopper during compilation, it is
32
- strongly recommanded to use it as high as possible in query expressions
32
+ strongly recommended to use it as high as possible in query expressions
33
33
  trees so as to delegate the largest possible query parts to data engines.
data/doc/man/image.man ADDED
@@ -0,0 +1,50 @@
1
+ .TH Image
2
+ .PP
3
+ Extend the left operand with a new relation\-valued attribute, image of the
4
+ tuple in the right relation.
5
+ .SH Signature
6
+ .PP
7
+ .RS
8
+ .nf
9
+ image(left: Relation, right: Relation, as: AttrName) -> Relation
10
+ .fi
11
+ .RE
12
+ .SH Examples
13
+ .PP
14
+ .RS
15
+ .nf
16
+ image(suppliers, supplies, :supplying)
17
+ .fi
18
+ .RE
19
+ .SH Description
20
+ .PP
21
+ This operator extends each tuple of the left operand, say \fB\fCt\fR, with a new
22
+ attribute called \fB\fCas\fR\&. The latter is a relation\-valued attribute, and is the
23
+ image of \fB\fCt\fR with respect to the right relation. The image is defined as a
24
+ restriction\-projection: restriction on tuples that match \fB\fCt\fR and projection
25
+ on all but common attributes between left and right.
26
+ .PP
27
+ In other words, this operator is a shortcut for the following longer
28
+ expression:
29
+ .PP
30
+ .RS
31
+ .nf
32
+ def image(left, right, as)
33
+ extend(left, as => ->(t){
34
+ allbut(
35
+ matching(right,
36
+ .BR Relation (t)),
37
+ left.attr_list & right.attr_list)
38
+ })
39
+ end
40
+ image(suppliers, supplies, :supplying)
41
+ .fi
42
+ .RE
43
+ .PP
44
+ Note that the image operator is such that every tuple of the left operand
45
+ appears in the result, including those whose image is empty on right. As
46
+ expected, an empty relation of correct relation type is used for those.
47
+ .SH Implementation notes
48
+ .PP
49
+ As of current Alf version, the current SQL compilation is not optimal and
50
+ partly relies on in\-memory operations. Please check the compilation plans.
data/doc/man/page.man CHANGED
@@ -41,6 +41,7 @@ def page(operand, order, nth, page_size)
41
41
  lte((nth-1)*page_size, :rank) & lt(:rank, nth*page_size)),
42
42
  [:rank])
43
43
  end
44
+ page(suppliers, [:status, :sid], 1, 3)
44
45
  .fi
45
46
  .RE
46
47
  .PP
data/doc/man/restrict.man CHANGED
@@ -35,4 +35,4 @@ predicate evaluates to TRUE.
35
35
  .PP
36
36
  As of current Alf version, native predicates (through ruby \fB\fCProc\fR objects)
37
37
  cannot be optimized nor compiled to SQL. The use of predicate factories
38
- (\fB\fCeq\fR, \fB\fCgt\fR, etc.) is strongly recommanded.
38
+ (\fB\fCeq\fR, \fB\fCgt\fR, etc.) is strongly recommended.
@@ -41,5 +41,5 @@ That means that all computations are done in ruby, which may seriously
41
41
  hurt performance.
42
42
  .PP
43
43
  Similarly, as \fB\fCsummarize\fR tends to be a showstopper during compilation, it
44
- is strongly recommanded to use it as high as possible in query expressions
44
+ is strongly recommended to use it as high as possible in query expressions
45
45
  trees so as to delegate the largest possible query parts to data engines.
@@ -0,0 +1,16 @@
1
+ # alf-repl
2
+
3
+ Launches Alf's Read-Eval-Print-Loop (REPL) web application.
4
+
5
+ ## Synopsis
6
+
7
+ `alf` [`--db=...`] repl
8
+
9
+ ## Description
10
+
11
+ This command launches the REPL in the current data context defined by the
12
+ `.alfrc` file and common alf options (e.g. `--db`).
13
+
14
+ ## Example
15
+
16
+ `alf` `--db=postgres://...` repl
data/doc/txt/alf.man CHANGED
@@ -76,5 +76,8 @@ Relational algebra at your fingertips
76
76
  `explain`
77
77
  Show the logical (optimizer) and physical (compiler) plans of a query.
78
78
 
79
+ `repl`
80
+ Launches Alf's Read-Eval-Print-Loop (REPL) web application.
81
+
79
82
  See `alf help COMMAND` for details about a specific command or `alf help
80
83
  OPERATOR` for documentation of a relational operator.
data/doc/txt/extend.txt CHANGED
@@ -25,5 +25,5 @@ In other words, all computations are done in ruby, which may seriously
25
25
  hurt performance.
26
26
 
27
27
  Similarly, as `extend` tends to be a showstopper during compilation, it is
28
- strongly recommanded to use it as high as possible in query expressions
28
+ strongly recommended to use it as high as possible in query expressions
29
29
  trees so as to delegate the largest possible query parts to data engines.
data/doc/txt/image.txt ADDED
@@ -0,0 +1,41 @@
1
+ # Image
2
+
3
+ Extend the left operand with a new relation-valued attribute, image of the
4
+ tuple in the right relation.
5
+
6
+ ## Signature
7
+
8
+ image(left: Relation, right: Relation, as: AttrName) -> Relation
9
+
10
+ ## Examples
11
+
12
+ image(suppliers, supplies, :supplying)
13
+
14
+ ## Description
15
+
16
+ This operator extends each tuple of the left operand, say `t`, with a new
17
+ attribute called `as`. The latter is a relation-valued attribute, and is the
18
+ image of `t` with respect to the right relation. The image is defined as a
19
+ restriction-projection: restriction on tuples that match `t` and projection
20
+ on all but common attributes between left and right.
21
+
22
+ In other words, this operator is a shortcut for the following longer
23
+ expression:
24
+
25
+ def image(left, right, as)
26
+ extend(left, as => ->(t){
27
+ allbut(
28
+ matching(right, Relation(t)),
29
+ left.attr_list & right.attr_list)
30
+ })
31
+ end
32
+ image(suppliers, supplies, :supplying)
33
+
34
+ Note that the image operator is such that every tuple of the left operand
35
+ appears in the result, including those whose image is empty on right. As
36
+ expected, an empty relation of correct relation type is used for those.
37
+
38
+ ## Implementation notes
39
+
40
+ As of current Alf version, the current SQL compilation is not optimal and
41
+ partly relies on in-memory operations. Please check the compilation plans.
data/doc/txt/page.txt CHANGED
@@ -30,6 +30,7 @@ def page(operand, order, nth, page_size)
30
30
  lte((nth-1)*page_size, :rank) & lt(:rank, nth*page_size)),
31
31
  [:rank])
32
32
  end
33
+ page(suppliers, [:status, :sid], 1, 3)
33
34
 
34
35
  As of current Alf version, for this operator to be semantically sound and
35
36
  deterministic, `order` MUST be a total order, that is, it must at least
data/doc/txt/restrict.txt CHANGED
@@ -23,4 +23,4 @@ predicate evaluates to TRUE.
23
23
 
24
24
  As of current Alf version, native predicates (through ruby `Proc` objects)
25
25
  cannot be optimized nor compiled to SQL. The use of predicate factories
26
- (`eq`, `gt`, etc.) is strongly recommanded.
26
+ (`eq`, `gt`, etc.) is strongly recommended.
@@ -29,5 +29,5 @@ That means that all computations are done in ruby, which may seriously
29
29
  hurt performance.
30
30
 
31
31
  Similarly, as `summarize` tends to be a showstopper during compilation, it
32
- is strongly recommanded to use it as high as possible in query expressions
32
+ is strongly recommended to use it as high as possible in query expressions
33
33
  trees so as to delegate the largest possible query parts to data engines.
data/lib/alf-shell.rb CHANGED
@@ -1 +1 @@
1
- require_relative "alf/shell"
1
+ require_relative "alf/shell"
@@ -3,3 +3,4 @@ require_relative 'command/help'
3
3
  require_relative 'command/show'
4
4
  require_relative 'command/metadata'
5
5
  require_relative 'command/explain'
6
+ require_relative 'command/repl'
@@ -95,7 +95,7 @@ module Alf
95
95
 
96
96
  def load_config
97
97
  config = Alf::Shell::DEFAULT_CONFIG.dup
98
- if alfrc_file = Path.pwd.backfind('.alfrc')
98
+ if alfrc_file = Path.pwd.backfind('.alfrc') || Path.pwd.backfind('alfrc')
99
99
  config.alfrc(alfrc_file)
100
100
  end
101
101
  config
@@ -114,10 +114,8 @@ module Alf
114
114
 
115
115
  def rendering_options
116
116
  options = { float_format: config.float_format }
117
- if config.pretty? and (hl = highline) and (hl.output_cols)
118
- options[:pretty] = config.pretty?
119
- options[:trim_at] = hl.output_cols - 1
120
- end
117
+ options[:pretty] = config.pretty?
118
+ options[:trim_at] = trim_at if options[:pretty]
121
119
  options
122
120
  end
123
121
 
@@ -126,6 +124,12 @@ module Alf
126
124
  renderer.execute(out)
127
125
  end
128
126
 
127
+ def trim_at
128
+ return nil unless hl = highline
129
+ return nil unless cols = hl.output_cols
130
+ hl.output_cols - 1
131
+ end
132
+
129
133
  def highline
130
134
  require 'highline'
131
135
  HighLine.new($stdin, $stdout)
@@ -24,7 +24,12 @@ module Alf
24
24
  end
25
25
 
26
26
  def compile(argv)
27
- operand(argv.shift)
27
+ op = operand(argv.shift)
28
+ op.heading
29
+ op
30
+ rescue Alf::NotSupportedError
31
+ op = op.to_relation
32
+ op
28
33
  end
29
34
 
30
35
  end # class Metadata
@@ -0,0 +1,22 @@
1
+ module Alf
2
+ module Shell
3
+ class Repl < Shell::Command(__FILE__, __LINE__)
4
+
5
+ options do |opt|
6
+
7
+ opt.on_tail('-h', "--help", "Show help") do
8
+ show_help("alf-repl")
9
+ end
10
+
11
+ end
12
+
13
+ def run(argv, requester)
14
+ require 'alf-repl'
15
+ Alf::Repl.database = requester.config.database
16
+ Alf::Repl.launch
17
+ Kernel.exit
18
+ end
19
+
20
+ end # class Repl
21
+ end # module Shell
22
+ end # module Alf
@@ -22,7 +22,7 @@ module Alf
22
22
  end
23
23
 
24
24
  def show_help(who)
25
- who = "alf-#{who}" if /explain|metadata|show/ =~ who
25
+ who = "alf-#{who}" if /explain|metadata|show|repl/ =~ who
26
26
  if p = Path.backfind("doc/man/#{who}.man")
27
27
  exit if system("man #{p}")
28
28
  puts Path.backfind("doc/txt/#{who}.txt").read
@@ -3,7 +3,7 @@ module Alf
3
3
  module Version
4
4
 
5
5
  MAJOR = 0
6
- MINOR = 15
6
+ MINOR = 16
7
7
  TINY = 0
8
8
 
9
9
  def self.to_s
@@ -13,4 +13,4 @@ module Alf
13
13
  end
14
14
  VERSION = Version.to_s
15
15
  end
16
- end
16
+ end
@@ -1,22 +1,21 @@
1
1
  ---
2
- - :sid: S1
3
- :name: Smith
4
- :status: 20
5
- :city: London
6
- - :sid: S2
7
- :name: Jones
8
- :status: 10
9
- :city: Paris
10
- - :sid: S3
11
- :name: Blake
12
- :status: 30
13
- :city: Paris
14
- - :sid: S4
15
- :name: Clark
16
- :status: 20
17
- :city: London
18
- - :sid: S5
19
- :name: Adams
20
- :status: 30
21
- :city: Athens
22
-
2
+ - sid: S1
3
+ name: Smith
4
+ status: 20
5
+ city: London
6
+ - sid: S2
7
+ name: Jones
8
+ status: 10
9
+ city: Paris
10
+ - sid: S3
11
+ name: Blake
12
+ status: 30
13
+ city: Paris
14
+ - sid: S4
15
+ name: Clark
16
+ status: 20
17
+ city: London
18
+ - sid: S5
19
+ name: Adams
20
+ status: 30
21
+ city: Athens
@@ -1,22 +1,21 @@
1
1
  ---
2
- - :sid: S1
3
- :name: Smith
4
- :status: 20
5
- :city: London
6
- - :sid: S2
7
- :name: Jones
8
- :status: 10
9
- :city: Paris
10
- - :sid: S3
11
- :name: Blake
12
- :status: 30
13
- :city: Paris
14
- - :sid: S4
15
- :name: Clark
16
- :status: 20
17
- :city: London
18
- - :sid: S5
19
- :name: Adams
20
- :status: 30
21
- :city: Athens
22
-
2
+ - sid: S1
3
+ name: Smith
4
+ status: 20
5
+ city: London
6
+ - sid: S2
7
+ name: Jones
8
+ status: 10
9
+ city: Paris
10
+ - sid: S3
11
+ name: Blake
12
+ status: 30
13
+ city: Paris
14
+ - sid: S4
15
+ name: Clark
16
+ status: 20
17
+ city: London
18
+ - sid: S5
19
+ name: Adams
20
+ status: 30
21
+ city: Athens
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: alf-shell
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.15.0
4
+ version: 0.16.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-10-31 00:00:00.000000000 Z
12
+ date: 2014-02-18 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rake
@@ -48,41 +48,41 @@ dependencies:
48
48
  requirement: !ruby/object:Gem::Requirement
49
49
  none: false
50
50
  requirements:
51
- - - ~>
51
+ - - '='
52
52
  - !ruby/object:Gem::Version
53
- version: 0.15.0
53
+ version: 0.16.0
54
54
  type: :development
55
55
  prerelease: false
56
56
  version_requirements: !ruby/object:Gem::Requirement
57
57
  none: false
58
58
  requirements:
59
- - - ~>
59
+ - - '='
60
60
  - !ruby/object:Gem::Version
61
- version: 0.15.0
61
+ version: 0.16.0
62
62
  - !ruby/object:Gem::Dependency
63
- name: highline
63
+ name: quickl
64
64
  requirement: !ruby/object:Gem::Requirement
65
65
  none: false
66
66
  requirements:
67
67
  - - ~>
68
68
  - !ruby/object:Gem::Version
69
- version: '1.6'
70
- type: :development
69
+ version: 0.4.3
70
+ type: :runtime
71
71
  prerelease: false
72
72
  version_requirements: !ruby/object:Gem::Requirement
73
73
  none: false
74
74
  requirements:
75
75
  - - ~>
76
76
  - !ruby/object:Gem::Version
77
- version: '1.6'
77
+ version: 0.4.3
78
78
  - !ruby/object:Gem::Dependency
79
- name: alf-core
79
+ name: highline
80
80
  requirement: !ruby/object:Gem::Requirement
81
81
  none: false
82
82
  requirements:
83
83
  - - ~>
84
84
  - !ruby/object:Gem::Version
85
- version: 0.15.0
85
+ version: '1.6'
86
86
  type: :runtime
87
87
  prerelease: false
88
88
  version_requirements: !ruby/object:Gem::Requirement
@@ -90,23 +90,23 @@ dependencies:
90
90
  requirements:
91
91
  - - ~>
92
92
  - !ruby/object:Gem::Version
93
- version: 0.15.0
93
+ version: '1.6'
94
94
  - !ruby/object:Gem::Dependency
95
- name: quickl
95
+ name: alf-core
96
96
  requirement: !ruby/object:Gem::Requirement
97
97
  none: false
98
98
  requirements:
99
- - - ~>
99
+ - - '='
100
100
  - !ruby/object:Gem::Version
101
- version: 0.4.3
101
+ version: 0.16.0
102
102
  type: :runtime
103
103
  prerelease: false
104
104
  version_requirements: !ruby/object:Gem::Requirement
105
105
  none: false
106
106
  requirements:
107
- - - ~>
107
+ - - '='
108
108
  - !ruby/object:Gem::Version
109
- version: 0.4.3
109
+ version: 0.16.0
110
110
  description: This project implements the `alf` commandline tool.
111
111
  email:
112
112
  - blambeau at gmail.com
@@ -121,6 +121,7 @@ files:
121
121
  - bin/alf
122
122
  - doc/man/alf-explain.man
123
123
  - doc/man/alf-metadata.man
124
+ - doc/man/alf-repl.man
124
125
  - doc/man/alf-show.man
125
126
  - doc/man/alf.man
126
127
  - doc/man/allbut.man
@@ -136,6 +137,7 @@ files:
136
137
  - doc/man/group.man
137
138
  - doc/man/gt.man
138
139
  - doc/man/gte.man
140
+ - doc/man/image.man
139
141
  - doc/man/intersect.man
140
142
  - doc/man/join.man
141
143
  - doc/man/lt.man
@@ -163,6 +165,7 @@ files:
163
165
  - doc/man/wrap.man
164
166
  - doc/txt/alf-explain.man
165
167
  - doc/txt/alf-metadata.man
168
+ - doc/txt/alf-repl.man
166
169
  - doc/txt/alf-show.man
167
170
  - doc/txt/alf.man
168
171
  - doc/txt/allbut.txt
@@ -178,6 +181,7 @@ files:
178
181
  - doc/txt/group.txt
179
182
  - doc/txt/gt.txt
180
183
  - doc/txt/gte.txt
184
+ - doc/txt/image.txt
181
185
  - doc/txt/intersect.txt
182
186
  - doc/txt/join.txt
183
187
  - doc/txt/lt.txt
@@ -208,6 +212,7 @@ files:
208
212
  - lib/alf/shell/command/help.rb
209
213
  - lib/alf/shell/command/main.rb
210
214
  - lib/alf/shell/command/metadata.rb
215
+ - lib/alf/shell/command/repl.rb
211
216
  - lib/alf/shell/command/show.rb
212
217
  - lib/alf/shell/command.rb
213
218
  - lib/alf/shell/loader.rb
@@ -277,7 +282,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
277
282
  version: '0'
278
283
  segments:
279
284
  - 0
280
- hash: 1197934734732335619
285
+ hash: -1823649938307432080
281
286
  required_rubygems_version: !ruby/object:Gem::Requirement
282
287
  none: false
283
288
  requirements:
@@ -286,7 +291,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
286
291
  version: '0'
287
292
  segments:
288
293
  - 0
289
- hash: 1197934734732335619
294
+ hash: -1823649938307432080
290
295
  requirements: []
291
296
  rubyforge_project:
292
297
  rubygems_version: 1.8.25