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.
Files changed (436) hide show
  1. data/CHANGELOG.md +10 -0
  2. data/Gemfile +2 -8
  3. data/Gemfile.lock +9 -17
  4. data/examples/operators/frame.alf +2 -0
  5. data/lib/alf-core.rb +24 -22
  6. data/lib/{alf-adapter/alf → alf}/adapter.rb +0 -0
  7. data/lib/{alf-adapter/alf → alf}/adapter/connection.rb +4 -10
  8. data/lib/{alf-adapter/alf → alf}/adapter/connection/schema_cached.rb +0 -0
  9. data/lib/{alf-adapter-fs/alf → alf}/adapter/folder.rb +0 -0
  10. data/lib/{alf-adapter-fs/alf → alf}/adapter/folder/connection.rb +3 -2
  11. data/lib/{alf-adapter-fs/alf → alf}/adapter/fs.rb +0 -0
  12. data/lib/{alf-aggregator/alf → alf}/aggregator.rb +12 -9
  13. data/lib/{alf-aggregator/alf → alf}/aggregator/avg.rb +0 -0
  14. data/lib/{alf-aggregator/alf → alf}/aggregator/collect.rb +0 -0
  15. data/lib/{alf-aggregator/alf → alf}/aggregator/concat.rb +0 -0
  16. data/lib/{alf-aggregator/alf → alf}/aggregator/count.rb +0 -0
  17. data/lib/{alf-aggregator/alf → alf}/aggregator/max.rb +0 -0
  18. data/lib/{alf-aggregator/alf → alf}/aggregator/min.rb +0 -0
  19. data/lib/{alf-aggregator/alf → alf}/aggregator/stddev.rb +0 -0
  20. data/lib/{alf-aggregator/alf → alf}/aggregator/sum.rb +0 -0
  21. data/lib/{alf-aggregator/alf → alf}/aggregator/variance.rb +0 -0
  22. data/lib/{alf-algebra/alf → alf}/algebra.rb +1 -0
  23. data/lib/{alf-algebra/alf → alf}/algebra/operand.rb +13 -6
  24. data/lib/{alf-algebra/alf → alf}/algebra/operand/fake.rb +18 -4
  25. data/lib/alf/algebra/operand/named.rb +65 -0
  26. data/lib/{alf-algebra/alf → alf}/algebra/operand/proxy.rb +7 -3
  27. data/lib/{alf-algebra/alf → alf}/algebra/operator.rb +40 -12
  28. data/lib/{alf-algebra/alf → alf}/algebra/operator/autonum.rb +9 -1
  29. data/lib/{alf-algebra/alf → alf}/algebra/operator/clip.rb +9 -1
  30. data/lib/{alf-algebra/alf → alf}/algebra/operator/coerce.rb +9 -1
  31. data/lib/{alf-algebra/alf → alf}/algebra/operator/compact.rb +8 -1
  32. data/lib/{alf-algebra/alf → alf}/algebra/operator/defaults.rb +8 -1
  33. data/lib/{alf-algebra/alf → alf}/algebra/operator/extend.rb +9 -1
  34. data/lib/{alf-algebra/alf → alf}/algebra/operator/frame.rb +12 -1
  35. data/lib/{alf-algebra/alf → alf}/algebra/operator/generator.rb +8 -1
  36. data/lib/{alf-algebra/alf → alf}/algebra/operator/group.rb +10 -1
  37. data/lib/{alf-algebra/alf → alf}/algebra/operator/hierarchize.rb +8 -0
  38. data/lib/{alf-algebra/alf → alf}/algebra/operator/intersect.rb +9 -1
  39. data/lib/{alf-algebra/alf → alf}/algebra/operator/join.rb +9 -1
  40. data/lib/{alf-algebra/alf → alf}/algebra/operator/matching.rb +10 -2
  41. data/lib/{alf-algebra/alf → alf}/algebra/operator/minus.rb +9 -1
  42. data/lib/{alf-algebra/alf → alf}/algebra/operator/not_matching.rb +9 -1
  43. data/lib/{alf-algebra/alf → alf}/algebra/operator/page.rb +11 -1
  44. data/lib/{alf-algebra/alf → alf}/algebra/operator/project.rb +9 -1
  45. data/lib/{alf-algebra/alf → alf}/algebra/operator/quota.rb +12 -1
  46. data/lib/{alf-algebra/alf → alf}/algebra/operator/rank.rb +11 -2
  47. data/lib/{alf-algebra/alf → alf}/algebra/operator/rename.rb +10 -1
  48. data/lib/{alf-algebra/alf → alf}/algebra/operator/restrict.rb +12 -2
  49. data/lib/{alf-algebra/alf → alf}/algebra/operator/sort.rb +9 -1
  50. data/lib/{alf-algebra/alf → alf}/algebra/operator/summarize.rb +10 -1
  51. data/lib/{alf-algebra/alf → alf}/algebra/operator/ungroup.rb +11 -1
  52. data/lib/{alf-algebra/alf → alf}/algebra/operator/union.rb +9 -1
  53. data/lib/{alf-algebra/alf → alf}/algebra/operator/unwrap.rb +13 -1
  54. data/lib/{alf-algebra/alf → alf}/algebra/operator/wrap.rb +10 -1
  55. data/lib/alf/algebra/shortcut.rb +40 -0
  56. data/lib/alf/algebra/shortcut/allbut.rb +25 -0
  57. data/lib/{alf-algebra/alf → alf}/algebra/support.rb +2 -1
  58. data/lib/{alf-algebra/alf → alf}/algebra/support/binary.rb +0 -0
  59. data/lib/{alf-algebra/alf → alf}/algebra/support/classification.rb +0 -0
  60. data/lib/{alf-algebra/alf → alf}/algebra/support/compiler.rb +0 -0
  61. data/lib/{alf-algebra/alf → alf}/algebra/support/experimental.rb +0 -0
  62. data/lib/{alf-algebra/alf → alf}/algebra/support/non_relational.rb +0 -0
  63. data/lib/{alf-algebra/alf → alf}/algebra/support/nullary.rb +0 -0
  64. data/lib/{alf-algebra/alf → alf}/algebra/support/relational.rb +0 -0
  65. data/lib/{alf-algebra/alf → alf}/algebra/support/rewriter.rb +4 -0
  66. data/lib/{alf-algebra/alf → alf}/algebra/support/signature.rb +7 -8
  67. data/lib/alf/algebra/support/type_check.rb +51 -0
  68. data/lib/{alf-algebra/alf → alf}/algebra/support/unary.rb +0 -0
  69. data/lib/{alf-algebra/alf → alf}/algebra/support/visitor.rb +2 -1
  70. data/lib/{alf-algebra/alf → alf}/algebra/support/with_ordering.rb +0 -0
  71. data/lib/alf/compiler.rb +57 -0
  72. data/lib/alf/compiler/cog.rb +39 -0
  73. data/lib/alf/compiler/default.rb +168 -0
  74. data/lib/alf/compiler/plan.rb +77 -0
  75. data/lib/{alf-core → alf/core}/loader.rb +0 -0
  76. data/lib/{alf-core → alf/core}/version.rb +1 -1
  77. data/lib/{alf-database/alf → alf}/database.rb +0 -0
  78. data/lib/{alf-database/alf → alf}/database/connection.rb +10 -52
  79. data/lib/{alf-database/alf → alf}/database/options.rb +2 -5
  80. data/lib/{alf-core → alf}/dsl.rb +4 -4
  81. data/lib/{alf-engine/alf → alf}/engine.rb +0 -2
  82. data/lib/{alf-engine/alf → alf}/engine/aggregate.rb +6 -2
  83. data/lib/{alf-engine/alf → alf}/engine/autonum.rb +6 -2
  84. data/lib/{alf-engine/alf → alf}/engine/clip.rb +10 -2
  85. data/lib/{alf-engine/alf → alf}/engine/coerce.rb +6 -2
  86. data/lib/alf/engine/cog.rb +58 -0
  87. data/lib/{alf-engine/alf → alf}/engine/compact.rb +2 -2
  88. data/lib/{alf-engine/alf → alf}/engine/compact/set.rb +2 -2
  89. data/lib/{alf-engine/alf → alf}/engine/compact/uniq.rb +2 -2
  90. data/lib/{alf-engine/alf → alf}/engine/concat.rb +2 -2
  91. data/lib/{alf-engine/alf → alf}/engine/defaults.rb +6 -2
  92. data/lib/{alf-engine/alf → alf}/engine/filter.rb +8 -4
  93. data/lib/{alf-engine/alf → alf}/engine/generator.rb +6 -2
  94. data/lib/alf/engine/group.rb +7 -0
  95. data/lib/{alf-engine/alf → alf}/engine/group/hash.rb +11 -2
  96. data/lib/{alf-engine/alf → alf}/engine/hierarchize.rb +6 -2
  97. data/lib/{alf-engine/alf → alf}/engine/infer_heading.rb +2 -2
  98. data/lib/{alf-engine/alf → alf}/engine/join.rb +0 -0
  99. data/lib/{alf-engine/alf → alf}/engine/join/hash.rb +2 -2
  100. data/lib/{alf-engine/alf → alf}/engine/leaf.rb +7 -3
  101. data/lib/{alf-engine/alf → alf}/engine/materialize.rb +5 -1
  102. data/lib/{alf-engine/alf → alf}/engine/materialize/array.rb +3 -2
  103. data/lib/{alf-engine/alf → alf}/engine/materialize/hash.rb +3 -2
  104. data/lib/alf/engine/quota.rb +7 -0
  105. data/lib/{alf-engine/alf → alf}/engine/quota/cesure.rb +8 -3
  106. data/lib/alf/engine/rank.rb +7 -0
  107. data/lib/{alf-engine/alf → alf}/engine/rank/cesure.rb +8 -3
  108. data/lib/{alf-engine/alf → alf}/engine/rename.rb +6 -2
  109. data/lib/alf/engine/semi.rb +7 -0
  110. data/lib/{alf-engine/alf → alf}/engine/semi/hash.rb +7 -2
  111. data/lib/{alf-engine/alf → alf}/engine/set_attr.rb +8 -4
  112. data/lib/alf/engine/sort.rb +13 -0
  113. data/lib/{alf-engine/alf → alf}/engine/sort/in_memory.rb +12 -2
  114. data/lib/alf/engine/summarize.rb +13 -0
  115. data/lib/{alf-engine/alf → alf}/engine/summarize/cesure.rb +5 -4
  116. data/lib/{alf-engine/alf → alf}/engine/summarize/hash.rb +3 -2
  117. data/lib/{alf-engine/alf → alf}/engine/support/cesure.rb +0 -0
  118. data/lib/{alf-engine/alf → alf}/engine/take.rb +6 -2
  119. data/lib/{alf-engine/alf → alf}/engine/to_array.rb +13 -5
  120. data/lib/{alf-engine/alf → alf}/engine/type_safe.rb +2 -2
  121. data/lib/{alf-engine/alf → alf}/engine/ungroup.rb +7 -2
  122. data/lib/{alf-engine/alf → alf}/engine/unwrap.rb +11 -5
  123. data/lib/{alf-engine/alf → alf}/engine/wrap.rb +6 -2
  124. data/lib/{alf-core → alf}/errors.rb +2 -3
  125. data/lib/{alf-core → alf}/ext.rb +0 -0
  126. data/lib/{alf-core → alf}/ext/domain/heading_based.rb +5 -0
  127. data/lib/alf/facade.rb +53 -0
  128. data/lib/{alf-lang/alf → alf}/lang.rb +1 -1
  129. data/lib/{alf-lang/alf → alf}/lang/functional.rb +0 -4
  130. data/lib/{alf-lang/alf → alf}/lang/object_oriented.rb +0 -0
  131. data/lib/{alf-lang/alf → alf}/lang/oo/aggregation_methods.rb +1 -1
  132. data/lib/{alf-lang/alf → alf}/lang/oo/algebra_methods.rb +0 -12
  133. data/lib/{alf-lang/alf → alf}/lang/oo/rendering_methods.rb +1 -1
  134. data/lib/alf/lang/parser.rb +9 -0
  135. data/lib/alf/lang/parser/lispy.rb +63 -0
  136. data/lib/alf/lang/parser/safer.rb +69 -0
  137. data/lib/{alf-lang/alf → alf}/lang/predicates.rb +1 -1
  138. data/lib/{alf-optimizer/alf → alf}/optimizer.rb +15 -7
  139. data/lib/alf/optimizer/project.rb +182 -0
  140. data/lib/{alf-optimizer/alf → alf}/optimizer/restrict.rb +48 -50
  141. data/lib/{alf-predicate/alf → alf}/predicate.rb +16 -12
  142. data/lib/{alf-predicate/alf → alf}/predicate/factory.rb +13 -8
  143. data/lib/{alf-predicate/alf → alf}/predicate/grammar.rb +2 -5
  144. data/lib/{alf-predicate/alf → alf}/predicate/grammar.sexp.yml +11 -7
  145. data/lib/{alf-predicate/alf → alf}/predicate/nodes/and.rb +0 -0
  146. data/lib/{alf-predicate/alf → alf}/predicate/nodes/contradiction.rb +0 -0
  147. data/lib/{alf-predicate/alf → alf}/predicate/nodes/dyadic_comp.rb +0 -0
  148. data/lib/{alf-predicate/alf → alf}/predicate/nodes/eq.rb +0 -0
  149. data/lib/{alf-predicate/alf → alf}/predicate/nodes/expr.rb +10 -5
  150. data/lib/{alf-predicate/alf → alf}/predicate/nodes/gt.rb +0 -0
  151. data/lib/{alf-predicate/alf → alf}/predicate/nodes/gte.rb +0 -0
  152. data/lib/{alf-predicate/alf/predicate/nodes/var_ref.rb → alf/predicate/nodes/identifier.rb} +3 -3
  153. data/lib/{alf-predicate/alf → alf}/predicate/nodes/in.rb +2 -2
  154. data/lib/{alf-predicate/alf → alf}/predicate/nodes/literal.rb +0 -0
  155. data/lib/{alf-predicate/alf → alf}/predicate/nodes/lt.rb +0 -0
  156. data/lib/{alf-predicate/alf → alf}/predicate/nodes/lte.rb +0 -0
  157. data/lib/{alf-predicate/alf → alf}/predicate/nodes/nadic_bool.rb +0 -0
  158. data/lib/alf/predicate/nodes/native.rb +32 -0
  159. data/lib/{alf-predicate/alf → alf}/predicate/nodes/neq.rb +0 -0
  160. data/lib/{alf-predicate/alf → alf}/predicate/nodes/not.rb +0 -0
  161. data/lib/{alf-predicate/alf → alf}/predicate/nodes/or.rb +0 -0
  162. data/lib/{alf-predicate/alf/predicate/nodes/native.rb → alf/predicate/nodes/qualified_identifier.rb} +8 -4
  163. data/lib/{alf-predicate/alf → alf}/predicate/nodes/tautology.rb +0 -0
  164. data/lib/alf/predicate/processors.rb +3 -0
  165. data/lib/alf/predicate/processors/qualifier.rb +25 -0
  166. data/lib/alf/predicate/processors/renamer.rb +27 -0
  167. data/lib/{alf-predicate/alf → alf}/predicate/processors/to_ruby_code.rb +6 -11
  168. data/lib/{alf-io/alf → alf}/reader.rb +11 -2
  169. data/lib/{alf-io/alf → alf}/reader/csv.rb +0 -0
  170. data/lib/{alf-io/alf → alf}/reader/json.rb +0 -0
  171. data/lib/{alf-io/alf → alf}/reader/rash.rb +0 -0
  172. data/lib/{alf-io/alf → alf}/reader/ruby.rb +0 -0
  173. data/lib/alf/reader/yaml.rb +25 -0
  174. data/lib/{alf-relation/alf → alf}/relation.rb +12 -2
  175. data/lib/{alf-relvar/alf → alf}/relvar.rb +14 -21
  176. data/lib/alf/relvar/base.rb +35 -0
  177. data/lib/{alf-relvar/alf → alf}/relvar/fake.rb +3 -2
  178. data/lib/{alf-relvar/alf → alf}/relvar/read_only.rb +6 -30
  179. data/lib/{alf-relvar/alf → alf}/relvar/virtual.rb +0 -31
  180. data/lib/{alf-io/alf → alf}/renderer.rb +0 -0
  181. data/lib/{alf-io/alf → alf}/renderer/csv.rb +0 -0
  182. data/lib/{alf-io/alf → alf}/renderer/json.rb +0 -0
  183. data/lib/{alf-io/alf → alf}/renderer/rash.rb +0 -0
  184. data/lib/{alf-io/alf → alf}/renderer/text.rb +0 -0
  185. data/lib/{alf-io/alf → alf}/renderer/yaml.rb +2 -2
  186. data/lib/{alf-support/alf → alf}/support.rb +2 -1
  187. data/lib/{alf-support/alf → alf}/support/coerce.rb +0 -0
  188. data/lib/{alf-support/alf → alf}/support/config.rb +0 -0
  189. data/lib/{alf-io/alf → alf}/support/csv_utils.rb +0 -0
  190. data/lib/{alf-support/alf → alf}/support/dot_utils.rb +0 -0
  191. data/lib/{alf-support/alf → alf}/support/miscellaneous.rb +0 -0
  192. data/lib/{alf-support/alf → alf}/support/ordered_set.rb +0 -0
  193. data/lib/{alf-support/alf → alf}/support/registry.rb +0 -0
  194. data/lib/{alf-support/alf → alf}/support/scope.rb +0 -0
  195. data/lib/{alf-support/alf → alf}/support/to_lispy.rb +6 -1
  196. data/lib/{alf-support/alf → alf}/support/to_ruby_literal.rb +0 -0
  197. data/lib/alf/support/tree.rb +51 -0
  198. data/lib/{alf-support/alf → alf}/support/tuple_scope.rb +9 -1
  199. data/lib/{alf-relation/alf → alf}/tuple.rb +1 -1
  200. data/lib/{alf-types/alf → alf}/types.rb +0 -0
  201. data/lib/{alf-types/alf → alf}/types/attr_list.rb +2 -2
  202. data/lib/{alf-types/alf → alf}/types/attr_name.rb +0 -0
  203. data/lib/{alf-types/alf → alf}/types/boolean.rb +0 -0
  204. data/lib/{alf-types/alf → alf}/types/heading.rb +0 -0
  205. data/lib/{alf-types/alf → alf}/types/keys.rb +0 -0
  206. data/lib/{alf-types/alf → alf}/types/ordering.rb +7 -1
  207. data/lib/{alf-types/alf → alf}/types/renaming.rb +0 -0
  208. data/lib/{alf-types/alf → alf}/types/selection.rb +0 -0
  209. data/lib/{alf-types/alf → alf}/types/selector.rb +0 -0
  210. data/lib/{alf-types/alf → alf}/types/size.rb +0 -0
  211. data/lib/{alf-types/alf → alf}/types/summarization.rb +0 -0
  212. data/lib/{alf-types/alf → alf}/types/tuple_computation.rb +13 -4
  213. data/lib/{alf-types/alf → alf}/types/tuple_expression.rb +6 -19
  214. data/lib/{alf-types/alf → alf}/types/type_check.rb +1 -0
  215. data/lib/{alf-update/alf → alf}/update.rb +0 -0
  216. data/lib/{alf-update/alf → alf}/update/deleter.rb +0 -3
  217. data/lib/{alf-update/alf → alf}/update/inserter.rb +1 -7
  218. data/lib/{alf-update/alf → alf}/update/updater.rb +0 -2
  219. data/lib/{alf-viewpoint/alf → alf}/viewpoint.rb +9 -7
  220. data/lib/{alf-viewpoint/alf → alf}/viewpoint/metadata.rb +5 -2
  221. data/spec/compiler_helper.rb +20 -0
  222. data/spec/integration/relation/test_to_array.rb +6 -6
  223. data/spec/integration/test_examples.rb +14 -6
  224. data/spec/shared/a_cog.rb +8 -4
  225. data/spec/shared/a_valid_type_implementation.rb +4 -7
  226. data/spec/spec_helper.rb +9 -5
  227. data/spec/type_check_helper.rb +1 -0
  228. data/spec/unit/alf-adapter/shared_examples/an_adapter_with_readable_cogs.rb +1 -1
  229. data/spec/unit/alf-aggregator/test_concat.rb +8 -0
  230. data/spec/unit/alf-algebra/operand/named/test_hash_and_equal.rb +53 -0
  231. data/spec/unit/alf-algebra/operand/named/test_keys.rb +1 -1
  232. data/spec/unit/alf-algebra/operand/named/test_to_ascii_tree.rb +18 -0
  233. data/spec/unit/alf-algebra/operand/named/test_to_cog.rb +24 -0
  234. data/spec/unit/alf-algebra/operand/named/test_to_relvar.rb +1 -1
  235. data/spec/unit/alf-algebra/operand/named/test_type_check.rb +38 -0
  236. data/spec/unit/alf-algebra/operand/proxy/test_to_cog.rb +42 -0
  237. data/spec/unit/alf-algebra/operand/test_coerce.rb +0 -6
  238. data/spec/unit/alf-algebra/operand/test_proxy.rb +1 -1
  239. data/spec/unit/alf-algebra/operator/allbut/test_key_preserving.rb +1 -1
  240. data/spec/unit/alf-algebra/operator/allbut/test_keys.rb +1 -1
  241. data/spec/unit/alf-algebra/operator/allbut/test_type_check.rb +42 -0
  242. data/spec/unit/alf-algebra/operator/autonum/test_type_check.rb +30 -0
  243. data/spec/unit/alf-algebra/operator/clip/test_type_check.rb +42 -0
  244. data/spec/unit/alf-algebra/operator/coerce/test_type_check.rb +42 -0
  245. data/spec/unit/alf-algebra/operator/commons/test_resulting_type.rb +20 -0
  246. data/spec/unit/alf-algebra/operator/commons/test_to_ascii_tree.rb +40 -0
  247. data/spec/unit/alf-algebra/operator/extend/test_type_check.rb +42 -0
  248. data/spec/unit/alf-algebra/operator/frame/test_type_check.rb +54 -0
  249. data/spec/unit/alf-algebra/operator/group/test_type_check.rb +50 -0
  250. data/spec/unit/alf-algebra/operator/hierarchize/test_type_check.rb +54 -0
  251. data/spec/unit/alf-algebra/operator/intersect/test_type_check.rb +30 -0
  252. data/spec/unit/alf-algebra/operator/join/test_type_check.rb +62 -0
  253. data/spec/unit/alf-algebra/operator/matching/test_keys.rb +1 -1
  254. data/spec/unit/alf-algebra/operator/matching/test_type_check.rb +62 -0
  255. data/spec/unit/alf-algebra/operator/minus/test_type_check.rb +30 -0
  256. data/spec/unit/alf-algebra/operator/not_matching/test_type_check.rb +62 -0
  257. data/spec/unit/alf-algebra/operator/page/test_type_check.rb +50 -0
  258. data/spec/unit/alf-algebra/operator/project/test_type_check.rb +42 -0
  259. data/spec/unit/alf-algebra/operator/quota/test_type_check.rb +54 -0
  260. data/spec/unit/alf-algebra/operator/rank/test_type_check.rb +42 -0
  261. data/spec/unit/alf-algebra/operator/rename/test_type_check.rb +42 -0
  262. data/spec/unit/alf-algebra/operator/restrict/test_type_check.rb +46 -0
  263. data/spec/unit/alf-algebra/operator/shared/test_to_cog.rb +34 -0
  264. data/spec/unit/alf-algebra/operator/sort/test_type_check.rb +30 -0
  265. data/spec/unit/alf-algebra/operator/summarize/test_type_check.rb +42 -0
  266. data/spec/unit/alf-algebra/operator/test_hash_and_equal.rb +59 -0
  267. data/spec/unit/alf-algebra/operator/ungroup/test_type_check.rb +44 -0
  268. data/spec/unit/alf-algebra/operator/union/test_type_check.rb +30 -0
  269. data/spec/unit/alf-algebra/operator/unwrap/test_type_check.rb +44 -0
  270. data/spec/unit/alf-algebra/operator/wrap/test_type_check.rb +50 -0
  271. data/spec/unit/alf-algebra/support/signature/test_to_lispy.rb +24 -9
  272. data/spec/unit/alf-algebra/support/test_non_relational.rb +1 -2
  273. data/spec/unit/alf-algebra/support/test_relational.rb +1 -1
  274. data/spec/unit/alf-compiler/default/test_allbut.rb +65 -0
  275. data/spec/unit/alf-compiler/default/test_autonum.rb +30 -0
  276. data/spec/unit/alf-compiler/default/test_clip.rb +30 -0
  277. data/spec/unit/alf-compiler/default/test_coerce.rb +30 -0
  278. data/spec/unit/alf-compiler/default/test_compact.rb +26 -0
  279. data/spec/unit/alf-compiler/default/test_completude.rb +16 -0
  280. data/spec/unit/alf-compiler/default/test_defaults.rb +50 -0
  281. data/spec/unit/alf-compiler/default/test_extend.rb +34 -0
  282. data/spec/unit/alf-compiler/default/test_frame.rb +77 -0
  283. data/spec/unit/alf-compiler/default/test_generator.rb +30 -0
  284. data/spec/unit/alf-compiler/default/test_group.rb +38 -0
  285. data/spec/unit/alf-compiler/default/test_hierarchize.rb +40 -0
  286. data/spec/unit/alf-compiler/default/test_intersect.rb +34 -0
  287. data/spec/unit/alf-compiler/default/test_join.rb +34 -0
  288. data/spec/unit/alf-compiler/default/test_matching.rb +38 -0
  289. data/spec/unit/alf-compiler/default/test_minus.rb +38 -0
  290. data/spec/unit/alf-compiler/default/test_not_matching.rb +38 -0
  291. data/spec/unit/alf-compiler/default/test_page.rb +91 -0
  292. data/spec/unit/alf-compiler/default/test_project.rb +76 -0
  293. data/spec/unit/alf-compiler/default/test_quota.rb +88 -0
  294. data/spec/unit/alf-compiler/default/test_rank.rb +71 -0
  295. data/spec/unit/alf-compiler/default/test_rename.rb +30 -0
  296. data/spec/unit/alf-compiler/default/test_restrict.rb +34 -0
  297. data/spec/unit/alf-compiler/default/test_sort.rb +81 -0
  298. data/spec/unit/alf-compiler/default/test_summarize.rb +85 -0
  299. data/spec/unit/alf-compiler/default/test_ungroup.rb +30 -0
  300. data/spec/unit/alf-compiler/default/test_union.rb +36 -0
  301. data/spec/unit/alf-compiler/default/test_unwrap.rb +30 -0
  302. data/spec/unit/alf-compiler/default/test_wrap.rb +38 -0
  303. data/spec/unit/alf-compiler/shared/compiled_examples.rb +111 -0
  304. data/spec/unit/alf-compiler/test_principle.rb +332 -0
  305. data/spec/unit/alf-core/test_aggregator.rb +0 -24
  306. data/spec/unit/alf-database/connection/test_parse.rb +0 -49
  307. data/spec/unit/alf-database/connection/test_relvar.rb +1 -9
  308. data/spec/unit/alf-database/options/test_parser.rb +23 -0
  309. data/spec/unit/alf-engine/cog/test_to_ascii_tree.rb +14 -0
  310. data/spec/unit/alf-engine/test_aggregate.rb +2 -2
  311. data/spec/unit/alf-engine/test_filter.rb +1 -1
  312. data/spec/unit/alf-engine/test_to_array.rb +16 -2
  313. data/spec/unit/alf-io/reader/test_yaml.rb +30 -0
  314. data/spec/unit/alf-io/renderer/test_yaml.rb +11 -0
  315. data/spec/unit/alf-lang/functional/test_aggregation.rb +18 -4
  316. data/spec/unit/alf-lang/parser/lispy/test_connection_bang.rb +28 -0
  317. data/spec/unit/alf-lang/parser/lispy/test_parse.rb +38 -0
  318. data/spec/unit/alf-lang/parser/lispy/test_to_s.rb +16 -0
  319. data/spec/unit/alf-lang/parser/safer/safe.txt +5 -0
  320. data/spec/unit/alf-lang/parser/safer/test_parse.rb +82 -0
  321. data/spec/unit/alf-lang/parser/safer/unsafe.txt +14 -0
  322. data/spec/unit/alf-optimizer/restrict/test_on_autonum.rb +1 -1
  323. data/spec/unit/alf-optimizer/test_quota.rb +1 -1
  324. data/spec/unit/alf-optimizer/test_rename.rb +7 -0
  325. data/spec/unit/alf-optimizer/test_summarize.rb +1 -1
  326. data/spec/unit/alf-predicate/expr/test_to_proc.rb +4 -6
  327. data/spec/unit/alf-predicate/expr/test_to_ruby_code.rb +23 -23
  328. data/spec/unit/alf-predicate/factory/shared/a_comparison_factory_method.rb +3 -3
  329. data/spec/unit/alf-predicate/factory/test_between.rb +1 -1
  330. data/spec/unit/alf-predicate/factory/test_comp.rb +3 -3
  331. data/spec/unit/alf-predicate/factory/test_factor_predicate.rb +3 -3
  332. data/spec/unit/alf-predicate/factory/{test_var_ref.rb → test_identifier.rb} +4 -4
  333. data/spec/unit/alf-predicate/factory/test_in.rb +1 -1
  334. data/spec/unit/alf-predicate/factory/test_native.rb +9 -4
  335. data/spec/unit/alf-predicate/factory/test_qualified_identifier.rb +17 -0
  336. data/spec/unit/alf-predicate/grammar/test_match.rb +9 -9
  337. data/spec/unit/alf-predicate/grammar/test_sexpr.rb +11 -11
  338. data/spec/unit/alf-predicate/nodes/{var_ref → identifier}/test_and_split.rb +2 -2
  339. data/spec/unit/alf-predicate/nodes/{var_ref → identifier}/test_free_variables.rb +2 -2
  340. data/spec/unit/alf-predicate/nodes/identifier/test_name.rb +14 -0
  341. data/spec/unit/alf-predicate/nodes/qualified_identifier/test_and_split.rb +25 -0
  342. data/spec/unit/alf-predicate/nodes/qualified_identifier/test_free_variables.rb +14 -0
  343. data/spec/unit/alf-predicate/nodes/qualified_identifier/test_name.rb +14 -0
  344. data/spec/unit/alf-predicate/nodes/qualified_identifier/test_qualifier.rb +14 -0
  345. data/spec/unit/alf-predicate/predicate/test_and_split.rb +4 -4
  346. data/spec/unit/alf-predicate/predicate/test_bool_and.rb +1 -1
  347. data/spec/unit/alf-predicate/predicate/test_bool_not.rb +1 -1
  348. data/spec/unit/alf-predicate/predicate/test_bool_or.rb +1 -1
  349. data/spec/unit/alf-predicate/predicate/test_coerce.rb +9 -8
  350. data/spec/unit/alf-predicate/predicate/test_contradiction.rb +2 -2
  351. data/spec/unit/alf-predicate/predicate/test_factory_methods.rb +12 -12
  352. data/spec/unit/alf-predicate/predicate/test_qualify.rb +36 -0
  353. data/spec/unit/alf-predicate/predicate/test_rename.rb +58 -15
  354. data/spec/unit/alf-predicate/predicate/test_tautology.rb +2 -2
  355. data/spec/unit/alf-predicate/predicate/test_to_ruby_code.rb +8 -2
  356. data/spec/unit/alf-predicate/predicate/test_to_ruby_literal.rb +1 -1
  357. data/spec/unit/alf-predicate/test_predicate.rb +7 -8
  358. data/spec/unit/alf-relation/relation/class/test_dum.rb +19 -0
  359. data/spec/unit/alf-relation/relation/test_heading.rb +1 -1
  360. data/spec/unit/alf-relation/relation/test_keys.rb +17 -0
  361. data/spec/unit/alf-relation/relation/test_relation.rb +1 -1
  362. data/spec/unit/alf-relation/relation/test_to_a.rb +10 -10
  363. data/spec/unit/alf-relvar/base/test_oo_lang.rb +26 -10
  364. data/spec/unit/alf-relvar/base/test_to_cog.rb +2 -2
  365. data/spec/unit/alf-relvar/read_only/test_to_relation.rb +17 -0
  366. data/spec/unit/alf-relvar/read_only/test_type.rb +0 -4
  367. data/spec/unit/alf-relvar/virtual/test_oo_lang.rb +0 -4
  368. data/spec/unit/alf-relvar/virtual/test_to_cog.rb +4 -4
  369. data/spec/unit/alf-relvar/virtual/test_to_s.rb +1 -1
  370. data/spec/unit/alf-support/test_to_lispy.rb +13 -31
  371. data/spec/unit/alf-support/test_tuple_scope.rb +11 -0
  372. data/spec/unit/alf-types/ordering/test_coerce.rb +13 -0
  373. data/spec/unit/alf-types/ordering/test_lte.rb +43 -0
  374. data/spec/unit/alf-types/summarization/test_coerce.rb +2 -2
  375. data/spec/unit/alf-types/summarization/test_least.rb +1 -1
  376. data/spec/unit/alf-types/summarization/test_summarize.rb +1 -1
  377. data/spec/unit/alf-types/test_summarization.rb +2 -2
  378. data/spec/unit/alf-types/test_tuple_expression.rb +2 -2
  379. data/spec/unit/alf-types/tuple_computation/test_coerce.rb +4 -13
  380. data/spec/unit/alf-types/tuple_computation/test_empty.rb +24 -0
  381. data/spec/unit/alf-types/tuple_computation/test_project.rb +46 -0
  382. data/spec/unit/alf-types/tuple_expression/test_coerce.rb +1 -10
  383. data/spec/unit/alf-types/tuple_expression/test_evaluate.rb +0 -8
  384. data/spec/unit/alf-types/tuple_expression/test_to_ruby_literal.rb +0 -5
  385. data/spec/unit/alf-update/deleter/{test_var_ref.rb → test_identifier.rb} +1 -1
  386. data/spec/unit/alf-update/inserter/{test_var_ref.rb → test_identifier.rb} +1 -1
  387. data/spec/unit/alf-update/updater/{test_var_ref.rb → test_identifier.rb} +1 -1
  388. data/spec/unit/alf-viewpoint/test_native_const.rb +1 -1
  389. data/spec/update_helper.rb +18 -2
  390. metadata +417 -313
  391. data/lib/alf-algebra/alf/algebra/operand/named.rb +0 -36
  392. data/lib/alf-algebra/alf/algebra/operator/infer_heading.rb +0 -19
  393. data/lib/alf-algebra/alf/algebra/operator/type_safe.rb +0 -21
  394. data/lib/alf-algebra/alf/algebra/support/to_dot.rb +0 -196
  395. data/lib/alf-core/facade.rb +0 -39
  396. data/lib/alf-engine/alf/engine/cog.rb +0 -50
  397. data/lib/alf-engine/alf/engine/compiler.rb +0 -171
  398. data/lib/alf-engine/alf/engine/group.rb +0 -3
  399. data/lib/alf-engine/alf/engine/quota.rb +0 -3
  400. data/lib/alf-engine/alf/engine/rank.rb +0 -3
  401. data/lib/alf-engine/alf/engine/semi.rb +0 -3
  402. data/lib/alf-engine/alf/engine/sort.rb +0 -30
  403. data/lib/alf-engine/alf/engine/summarize.rb +0 -4
  404. data/lib/alf-engine/alf/engine/to_dot.rb +0 -60
  405. data/lib/alf-io/alf/io.rb +0 -6
  406. data/lib/alf-lang/alf/lang/lispy.rb +0 -65
  407. data/lib/alf-predicate/alf/predicate/parser.rb +0 -12
  408. data/lib/alf-predicate/alf/predicate/processors.rb +0 -3
  409. data/lib/alf-predicate/alf/predicate/processors/renamer.rb +0 -19
  410. data/lib/alf-predicate/alf/predicate/processors/to_proc.rb +0 -35
  411. data/lib/alf-relvar/alf/relvar/base.rb +0 -69
  412. data/lib/alf-support/alf/support/bindable.rb +0 -26
  413. data/spec/integration/algebra/test_to_dot.rb +0 -14
  414. data/spec/integration/relvar/test_type_safe.rb +0 -22
  415. data/spec/unit/alf-algebra/operator/infer_heading/test_keys.rb +0 -23
  416. data/spec/unit/alf-algebra/operator/test_infer_heading.rb +0 -16
  417. data/spec/unit/alf-algebra/operator/type_safe/test_heading.rb +0 -26
  418. data/spec/unit/alf-algebra/operator/type_safe/test_keys.rb +0 -26
  419. data/spec/unit/alf-engine/compiler/test_on_frame.rb +0 -70
  420. data/spec/unit/alf-engine/compiler/test_on_hierarchize.rb +0 -33
  421. data/spec/unit/alf-engine/compiler/test_on_page.rb +0 -128
  422. data/spec/unit/alf-engine/compiler/test_unsupported.rb +0 -48
  423. data/spec/unit/alf-lang/lispy/test_connection_bang.rb +0 -26
  424. data/spec/unit/alf-lang/lispy/test_parse.rb +0 -38
  425. data/spec/unit/alf-lang/lispy/test_to_s.rb +0 -14
  426. data/spec/unit/alf-optimizer/optimizer/test_optimizer.rb +0 -37
  427. data/spec/unit/alf-optimizer/test_infer_heading.rb +0 -9
  428. data/spec/unit/alf-predicate/grammar/test_parse.rb +0 -23
  429. data/spec/unit/alf-predicate/nodes/var_ref/test_var_name.rb +0 -14
  430. data/spec/unit/alf-relvar/base/test_name.rb +0 -15
  431. data/spec/unit/alf-relvar/virtual/test_connection.rb +0 -15
  432. data/spec/unit/alf-support/bindable/test_bind.rb +0 -60
  433. data/spec/unit/alf-support/bindable/test_bound.rb +0 -31
  434. data/spec/unit/alf-support/bindable/test_connection.rb +0 -31
  435. data/spec/unit/alf-support/bindable/test_connection_bang.rb +0 -35
  436. data/spec/unit/alf-update/inserter/test_type_safe.rb +0 -72
@@ -0,0 +1,23 @@
1
+ require 'spec_helper'
2
+ module Alf
3
+ class Database
4
+ describe Options, "parser" do
5
+
6
+ subject{ opts.parser }
7
+
8
+ let(:opts){ Options.new }
9
+
10
+ context 'by default' do
11
+
12
+ it { should be(Lang::Parser::Lispy) }
13
+ end
14
+
15
+ context 'when explicitely set' do
16
+ before{ opts.parser = Lang::Parser::Safer }
17
+
18
+ it{ should be(Lang::Parser::Safer) }
19
+ end
20
+
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,14 @@
1
+ require 'spec_helper'
2
+ module Alf
3
+ module Engine
4
+ describe Cog, "to_cog" do
5
+
6
+ let(:cog){ Clip.new([], AttrList[:name], true) }
7
+
8
+ subject{ cog.to_ascii_tree }
9
+
10
+ it { should eq("Clip ..., [:name], {:allbut => true}\n+-- []\n") }
11
+
12
+ end
13
+ end
14
+ end
@@ -12,8 +12,8 @@ module Alf
12
12
  {:name => "Jones", :price => 12.0, :id => 1},
13
13
  {:name => "Smith", :price => 10.0, :id => 2}
14
14
  ]
15
- agg = Summarization[:size => "count",
16
- :total => "sum{ price }"]
15
+ agg = Summarization[:size => Aggregator.count,
16
+ :total => Aggregator.sum{|t| t.price }]
17
17
  exp = [
18
18
  {:size => 2, :total => 22.0}
19
19
  ]
@@ -20,7 +20,7 @@ module Alf
20
20
  ]
21
21
  }
22
22
  let(:predicate){
23
- Predicate.parse("name =~ /^J/")
23
+ Predicate.native(->(t){ t.name =~ /^J/ })
24
24
  }
25
25
  let(:expected){
26
26
  [
@@ -5,6 +5,20 @@ module Alf
5
5
 
6
6
  subject{ ToArray.new(rel, ordering).to_a }
7
7
 
8
+ context 'when ordering is nil' do
9
+ let(:rel){[
10
+ {name: "Jones", parts: Relation::DEE},
11
+ {name: "Smith", parts: Relation::DUM}
12
+ ]}
13
+ let(:ordering){ nil }
14
+ let(:expected){[
15
+ {name: "Jones", parts: [{}]},
16
+ {name: "Smith", parts: []}
17
+ ]}
18
+
19
+ it{ should eq(expected) }
20
+ end
21
+
8
22
  context 'when both empty' do
9
23
  let(:rel) { [] }
10
24
  let(:ordering){ Ordering::EMPTY }
@@ -48,8 +62,8 @@ module Alf
48
62
  {name: "Jones", rva: Relation(id: [1, 3]) }
49
63
  ]}
50
64
  let(:expected){[
51
- {name: "Jones", rva: [Tuple(id: 1), Tuple(id: 3)] },
52
- {name: "Smith", rva: [Tuple(id: 7), Tuple(id: 8)] }
65
+ {name: "Jones", rva: [{id: 1}, {id: 3}] },
66
+ {name: "Smith", rva: [{id: 7}, {id: 8}] }
53
67
  ]}
54
68
  let(:ordering){ Ordering.new([[:name, :asc], [[:rva, :id], :asc]]) }
55
69
 
@@ -0,0 +1,30 @@
1
+ require 'spec_helper'
2
+ require 'json'
3
+ module Alf
4
+ describe Reader::YAML do
5
+ it_should_behave_like "a Reader class"
6
+
7
+ let(:str) { input.to_yaml }
8
+ let(:io) { StringIO.new(str) }
9
+ let(:reader){ Reader::YAML.new(io) }
10
+
11
+ subject{ reader.to_a }
12
+
13
+ describe "when called on a Array" do
14
+ let(:input){ [{:id => 1},{:id => 2}] }
15
+
16
+ it "read the lines as expected" do
17
+ subject.should eq(input)
18
+ end
19
+ end
20
+
21
+ describe "when called on a Hash" do
22
+ let(:input){ {:id => 1} }
23
+
24
+ it "should yield the single Hash" do
25
+ subject.should eq([input])
26
+ end
27
+ end
28
+
29
+ end
30
+ end
@@ -17,6 +17,17 @@ module Alf
17
17
  end
18
18
  end
19
19
 
20
+ describe "when relation-valued attributes" do
21
+ subject{ YAML.new(input).execute("") }
22
+
23
+ let(:input){ Relation(sid: "S1", parts: Relation(pid: ["P1", "P2"])) }
24
+
25
+ it 'converts to arrays and hashes' do
26
+ subject.should_not =~ /Relation/
27
+ subject.should_not =~ /Tuple/
28
+ end
29
+ end
30
+
20
31
  end
21
32
  end
22
33
  end
@@ -13,12 +13,26 @@ module Alf
13
13
  {:tested => 30, :other => "a", :upcase => "A"},
14
14
  ]}
15
15
 
16
- it "should have sum" do
17
- sum{ qty }.should be_a(Aggregator::Sum)
16
+ context 'on sum' do
17
+ it "should have sum with immediate block" do
18
+ sum{|t| t.qty }.should be_a(Aggregator::Sum)
19
+ end
20
+
21
+ it "should have sum with a Proc" do
22
+ sum(->(t){ qty }).should be_a(Aggregator::Sum)
23
+ end
18
24
  end
19
25
 
20
- it "should have stddev aggregator" do
21
- stddev{ qty }.should be_a(Aggregator::Stddev)
26
+ context 'on concat' do
27
+ it "should have concat with immediate block" do
28
+ concat{|t| t.name }.should be_a(Aggregator::Concat)
29
+ end
30
+
31
+ it "should have sum with a Proc" do
32
+ agg = concat(->(t){ t.name }, between: ', ')
33
+ agg.should be_a(Aggregator::Concat)
34
+ agg.options[:between].should eq(', ')
35
+ end
22
36
  end
23
37
 
24
38
  end
@@ -0,0 +1,28 @@
1
+ require 'spec_helper'
2
+ module Alf
3
+ module Lang
4
+ module Parser
5
+ describe Lispy, 'connection!' do
6
+
7
+ context 'when bound' do
8
+ let(:lispy){ Lispy.new([], 12) }
9
+
10
+ it 'allows obtaining its connection' do
11
+ lispy.connection!.should eq(12)
12
+ end
13
+ end
14
+
15
+ context 'when unbound' do
16
+ let(:lispy){ Lispy.new }
17
+
18
+ it 'raises when connection is used without being bound' do
19
+ lambda{
20
+ lispy.connection!
21
+ }.should raise_error(UnboundError)
22
+ end
23
+ end
24
+
25
+ end
26
+ end
27
+ end
28
+ end
@@ -0,0 +1,38 @@
1
+ require 'spec_helper'
2
+ module Alf
3
+ module Lang
4
+ module Parser
5
+ describe Lispy do
6
+
7
+ context 'when unbound' do
8
+ let(:lispy){ Lispy.new }
9
+
10
+ it 'allows parsing predicate expressions' do
11
+ p = lispy.parse{ eq(:x, 1) & neq(:y, 2) }
12
+ p.should be_a(Alf::Predicate)
13
+ end
14
+
15
+ it 'allows parsing relational expressions' do
16
+ p = lispy.parse{ project(:suppliers, [:sid]) }
17
+ p.should be_a(Algebra::Project)
18
+ end
19
+ end
20
+
21
+ context 'when bound' do
22
+ let(:lispy){ Lispy.new([], 12) }
23
+
24
+ it 'allows parsing predicate expressions' do
25
+ p = lispy.parse{ eq(:x, 1) & neq(:y, 2) }
26
+ p.should be_a(Alf::Predicate)
27
+ end
28
+
29
+ it 'deeply binds parsed relational expressions' do
30
+ p = lispy.parse{ project(:suppliers, [:sid]) }
31
+ p.should be_a(Algebra::Project)
32
+ end
33
+ end
34
+
35
+ end
36
+ end
37
+ end
38
+ end
@@ -0,0 +1,16 @@
1
+ require 'spec_helper'
2
+ module Alf
3
+ module Lang
4
+ module Parser
5
+ describe Lispy, 'to_s' do
6
+
7
+ let(:lispy){ Lispy.new }
8
+
9
+ subject{ lispy.to_s }
10
+
11
+ it{ should eq("Lispy()") }
12
+
13
+ end
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,5 @@
1
+ project(:suppliers, [:sid])
2
+ Tuple(sid: 1)
3
+ Relation(sid: 1)
4
+ DEE
5
+ DUM
@@ -0,0 +1,82 @@
1
+ require 'spec_helper'
2
+ module Alf
3
+ module Lang
4
+ module Parser
5
+ describe Safer, "test_parse" do
6
+
7
+ let(:viewpoint) do
8
+ Module.new{
9
+ def suppliers
10
+ Algebra::Operand::Named.new(:suppliers)
11
+ end
12
+ }
13
+ end
14
+
15
+ let(:parser){ Safer.new([viewpoint]) }
16
+
17
+ context 'with a ruby block' do
18
+ subject{ parser.parse{} }
19
+
20
+ it 'raises a SecurityError' do
21
+ lambda{
22
+ subject
23
+ }.should raise_error(SecurityError, /Parsing of ruby blocks forbidden/)
24
+ end
25
+ end
26
+
27
+ context 'with a symbol' do
28
+ let(:op){ Algebra::Operand::Named.new(:suppliers) }
29
+ subject{ parser.parse(:suppliers) }
30
+
31
+ it 'passes and returns the operand' do
32
+ subject.should eq(op)
33
+ end
34
+ end
35
+
36
+ context 'with an operand' do
37
+ let(:op){ Algebra::Operand::Named.new(:suppliers) }
38
+ subject{ parser.parse(op) }
39
+
40
+ it 'returns it immediately' do
41
+ subject.should be(op)
42
+ end
43
+ end
44
+
45
+ context 'with an attempt attack based on a symbol' do
46
+ subject{ parser.parse(:"send(:suppliers)") }
47
+
48
+ it 'fails with a security error' do
49
+ lambda{
50
+ subject
51
+ }.should raise_error(SecurityError, /Forbidden/)
52
+ end
53
+ end
54
+
55
+ (Path.dir/'safe.txt').each_line do |line|
56
+ context "on '#{line.strip}'" do
57
+ subject{ parser.parse(line.strip) }
58
+
59
+ it 'succeeds' do
60
+ lambda{
61
+ subject
62
+ }.should_not raise_error
63
+ end
64
+ end
65
+ end
66
+
67
+ (Path.dir/'unsafe.txt').each_line do |line|
68
+ context "on '#{line.strip}'" do
69
+ subject{ parser.parse(line.strip) }
70
+
71
+ it 'raises a SecurityError' do
72
+ lambda{
73
+ subject
74
+ }.should raise_error(SecurityError, /Forbidden/)
75
+ end
76
+ end
77
+ end
78
+
79
+ end
80
+ end
81
+ end
82
+ end
@@ -0,0 +1,14 @@
1
+ `ls -lA`
2
+ ::Kernel
3
+ exit
4
+ require "blah"
5
+ load "blah"
6
+ gem 'unsecure'
7
+ suppliers.to_relvar
8
+ suppliers.insert
9
+ suppliers.delete
10
+ suppliers.update
11
+ Alf::Adapter::Connection
12
+ Alf.connect
13
+ Relation.new
14
+ Tuple.new
@@ -10,7 +10,7 @@ module Alf
10
10
 
11
11
  context 'when the restriction does not apply to auto at all' do
12
12
  let(:predicate){ comp(:x => 12) }
13
- let(:expected) { autonum(restrict(inside, predicate)) }
13
+ let(:expected) { autonum(restrict(inside, predicate), :auto) }
14
14
 
15
15
  it{ should eq(expected) }
16
16
  end
@@ -3,7 +3,7 @@ module Alf
3
3
  describe "quota" do
4
4
 
5
5
  let(:summarization){
6
- Summarization.coerce(:total => "sum{ qty }")
6
+ Summarization.coerce(:total => Aggregator.sum{ qty })
7
7
  }
8
8
 
9
9
  subject{ quota(an_operand, [:id], [[:x, :asc]], summarization) }
@@ -15,5 +15,12 @@ module Alf
15
15
  it_behaves_like "a pass-through expression for restrict"
16
16
  end
17
17
 
18
+ context 'on a native predicate' do
19
+ let(:predicate){ Predicate.native(->(t){ t.x == 2 }) }
20
+ let(:renaming) { {:x => :y} }
21
+
22
+ it_behaves_like "an unoptimizable expression for restrict"
23
+ end
24
+
18
25
  end
19
26
  end
@@ -3,7 +3,7 @@ module Alf
3
3
  describe "summarize" do
4
4
 
5
5
  let(:summarization){
6
- Summarization.coerce(:total => "sum{ qty }")
6
+ Summarization.coerce(:total => Aggregator.sum{ qty })
7
7
  }
8
8
  subject{ summarize(an_operand, [:id], summarization) }
9
9
 
@@ -7,13 +7,11 @@ module Alf
7
7
 
8
8
  subject{ expr.to_proc }
9
9
 
10
- before do
11
- subject.should be_a(Proc)
12
- end
10
+ it{ should be_a(Proc) }
13
11
 
14
- specify{
15
- subject.to_ruby_literal.should eq("lambda{ x <= 2 }")
16
- }
12
+ it 'has arity 1' do
13
+ subject.arity.should eq(1)
14
+ end
17
15
 
18
16
  end
19
17
  end
@@ -10,7 +10,7 @@ module Alf
10
10
  after do
11
11
  unless expr.is_a?(Native)
12
12
  lambda{
13
- eval "lambda{ #{subject} }"
13
+ eval(subject)
14
14
  }.should_not raise_error
15
15
  end
16
16
  end
@@ -18,103 +18,103 @@ module Alf
18
18
  context 'tautology' do
19
19
  let(:expr){ f.tautology }
20
20
 
21
- it{ should eq("true") }
21
+ it{ should eq("->(t){ true }") }
22
22
  end
23
23
 
24
24
  context 'contradiction' do
25
25
  let(:expr){ f.contradiction }
26
26
 
27
- it{ should eq("false") }
27
+ it{ should eq("->(t){ false }") }
28
28
  end
29
29
 
30
- describe "var_ref" do
31
- let(:expr){ f.var_ref(:name) }
30
+ describe "identifier" do
31
+ let(:expr){ f.identifier(:name) }
32
32
 
33
- it{ should eq("name") }
33
+ it{ should eq("->(t){ t.name }") }
34
34
  end
35
35
 
36
36
  describe "and" do
37
37
  let(:expr){ f.and(f.contradiction, f.contradiction) }
38
38
 
39
- it{ should eq("false && false") }
39
+ it{ should eq("->(t){ false && false }") }
40
40
  end
41
41
 
42
42
  describe "or" do
43
43
  let(:expr){ f.or(f.contradiction, f.contradiction) }
44
44
 
45
- it{ should eq("false || false") }
45
+ it{ should eq("->(t){ false || false }") }
46
46
  end
47
47
 
48
48
  describe "not" do
49
49
  let(:expr){ f.not(f.contradiction) }
50
50
 
51
- it{ should eq("!false") }
51
+ it{ should eq("->(t){ !false }") }
52
52
  end
53
53
 
54
54
  describe "comp" do
55
55
  let(:expr){ f.comp(:lt, {:x => 2}) }
56
56
 
57
- it{ should eq("x < 2") }
57
+ it{ should eq("->(t){ t.x < 2 }") }
58
58
  end
59
59
 
60
60
  describe "eq" do
61
61
  let(:expr){ f.eq(:x, 2) }
62
62
 
63
- it{ should eq("x == 2") }
63
+ it{ should eq("->(t){ t.x == 2 }") }
64
64
  end
65
65
 
66
66
  describe "eq (parentheses required)" do
67
67
  let(:expr){ f.eq(f.eq(:y, 2), true) }
68
68
 
69
- it{ should eq("(y == 2) == true") }
69
+ it{ should eq("->(t){ (t.y == 2) == true }") }
70
70
  end
71
71
 
72
72
  describe "comp (multiple)" do
73
73
  let(:expr){ f.comp(:eq, :x => 2, :y => 3) }
74
74
 
75
- it{ should eq("(x == 2) && (y == 3)") }
75
+ it{ should eq("->(t){ (t.x == 2) && (t.y == 3) }") }
76
76
  end
77
77
 
78
78
  describe "in" do
79
79
  let(:expr){ f.in(:x, [2, 3]) }
80
80
 
81
- it{ should eq("[2, 3].include?(x)") }
81
+ it{ should eq("->(t){ [2, 3].include?(t.x) }") }
82
82
  end
83
83
 
84
84
  describe "neq" do
85
85
  let(:expr){ f.neq(:x, 2) }
86
86
 
87
- it{ should eq("x != 2") }
87
+ it{ should eq("->(t){ t.x != 2 }") }
88
88
  end
89
89
 
90
90
  describe "gt" do
91
91
  let(:expr){ f.gt(:x, 2) }
92
92
 
93
- it{ should eq("x > 2") }
93
+ it{ should eq("->(t){ t.x > 2 }") }
94
94
  end
95
95
 
96
96
  describe "gte" do
97
97
  let(:expr){ f.gte(:x, 2) }
98
98
 
99
- it{ should eq("x >= 2") }
99
+ it{ should eq("->(t){ t.x >= 2 }") }
100
100
  end
101
101
 
102
102
  describe "lt" do
103
103
  let(:expr){ f.lt(:x, 2) }
104
104
 
105
- it{ should eq("x < 2") }
105
+ it{ should eq("->(t){ t.x < 2 }") }
106
106
  end
107
107
 
108
108
  describe "lte" do
109
109
  let(:expr){ f.lte(:x, 2) }
110
110
 
111
- it{ should eq("x <= 2") }
111
+ it{ should eq("->(t){ t.x <= 2 }") }
112
112
  end
113
113
 
114
114
  describe "literal" do
115
115
  let(:expr){ f.literal(12) }
116
116
 
117
- it{ should eq("12") }
117
+ it{ should eq("->(t){ 12 }") }
118
118
  end
119
119
 
120
120
  describe "native" do
@@ -130,7 +130,7 @@ module Alf
130
130
  f.and(f.eq(:x, 2), f.eq(:y, 3))
131
131
  }
132
132
 
133
- it{ should eq("(x == 2) && (y == 3)") }
133
+ it{ should eq("->(t){ (t.x == 2) && (t.y == 3) }") }
134
134
  end
135
135
 
136
136
  describe "conjunction of two comps" do
@@ -138,7 +138,7 @@ module Alf
138
138
  f.and(f.comp(:eq, :x => 2), f.comp(:eq, :y => 3))
139
139
  }
140
140
 
141
- it{ should eq("(x == 2) && (y == 3)") }
141
+ it{ should eq("->(t){ (t.x == 2) && (t.y == 3) }") }
142
142
  end
143
143
 
144
144
  describe "or and and" do
@@ -146,7 +146,7 @@ module Alf
146
146
  f.and(f.eq(:x, 2), f.or(true, false))
147
147
  }
148
148
 
149
- it{ should eq("(x == 2) && (true || false)") }
149
+ it{ should eq("->(t){ (t.x == 2) && (true || false) }") }
150
150
  end
151
151
 
152
152
  end