alf-core 0.13.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (789) hide show
  1. data/CHANGELOG.md +4 -0
  2. data/Gemfile +29 -0
  3. data/Gemfile.lock +41 -0
  4. data/LICENCE.md +22 -0
  5. data/Manifest.txt +14 -0
  6. data/README.md +11 -0
  7. data/Rakefile +11 -0
  8. data/TODO.md +23 -0
  9. data/examples/functions-as-values.rb +39 -0
  10. data/examples/memory_database.rb +44 -0
  11. data/examples/operators/autonum.alf +6 -0
  12. data/examples/operators/cities.rash +4 -0
  13. data/examples/operators/clip.alf +3 -0
  14. data/examples/operators/compact.alf +2 -0
  15. data/examples/operators/defaults.alf +3 -0
  16. data/examples/operators/extend.alf +3 -0
  17. data/examples/operators/group.alf +3 -0
  18. data/examples/operators/intersect.alf +4 -0
  19. data/examples/operators/join.alf +2 -0
  20. data/examples/operators/matching.alf +2 -0
  21. data/examples/operators/minus.alf +8 -0
  22. data/examples/operators/not_matching.alf +2 -0
  23. data/examples/operators/nulls.rash +3 -0
  24. data/examples/operators/parts.rash +6 -0
  25. data/examples/operators/project.alf +3 -0
  26. data/examples/operators/pseudo-with.alf +7 -0
  27. data/examples/operators/quota.alf +4 -0
  28. data/examples/operators/rank.alf +4 -0
  29. data/examples/operators/rename.alf +3 -0
  30. data/examples/operators/restrict.alf +2 -0
  31. data/examples/operators/schema.yaml +28 -0
  32. data/examples/operators/sort.alf +4 -0
  33. data/examples/operators/summarize.alf +16 -0
  34. data/examples/operators/suppliers.rash +5 -0
  35. data/examples/operators/supplies.rash +12 -0
  36. data/examples/operators/ungroup.alf +4 -0
  37. data/examples/operators/union.alf +3 -0
  38. data/examples/operators/unwrap.alf +4 -0
  39. data/examples/operators/wrap.alf +2 -0
  40. data/examples/readme.rb +23 -0
  41. data/examples/suppliers_and_parts/cities.rash +4 -0
  42. data/examples/suppliers_and_parts/parts.rash +6 -0
  43. data/examples/suppliers_and_parts/suppliers.rash +5 -0
  44. data/examples/suppliers_and_parts/supplies.rash +12 -0
  45. data/lib/alf-adapter-fs/alf/adapter/folder.rb +22 -0
  46. data/lib/alf-adapter-fs/alf/adapter/folder/connection.rb +39 -0
  47. data/lib/alf-adapter-fs/alf/adapter/fs.rb +1 -0
  48. data/lib/alf-adapter/alf/adapter.rb +95 -0
  49. data/lib/alf-adapter/alf/adapter/connection.rb +88 -0
  50. data/lib/alf-adapter/alf/adapter/connection/schema_cached.rb +34 -0
  51. data/lib/alf-aggregator/alf/aggregator.rb +223 -0
  52. data/lib/alf-aggregator/alf/aggregator/avg.rb +39 -0
  53. data/lib/alf-aggregator/alf/aggregator/collect.rb +32 -0
  54. data/lib/alf-aggregator/alf/aggregator/concat.rb +47 -0
  55. data/lib/alf-aggregator/alf/aggregator/count.rb +32 -0
  56. data/lib/alf-aggregator/alf/aggregator/max.rb +32 -0
  57. data/lib/alf-aggregator/alf/aggregator/min.rb +32 -0
  58. data/lib/alf-aggregator/alf/aggregator/stddev.rb +25 -0
  59. data/lib/alf-aggregator/alf/aggregator/sum.rb +32 -0
  60. data/lib/alf-aggregator/alf/aggregator/variance.rb +45 -0
  61. data/lib/alf-algebra/alf/algebra.rb +13 -0
  62. data/lib/alf-algebra/alf/algebra/operand.rb +54 -0
  63. data/lib/alf-algebra/alf/algebra/operand/fake.rb +61 -0
  64. data/lib/alf-algebra/alf/algebra/operand/named.rb +36 -0
  65. data/lib/alf-algebra/alf/algebra/operand/proxy.rb +25 -0
  66. data/lib/alf-algebra/alf/algebra/operator.rb +134 -0
  67. data/lib/alf-algebra/alf/algebra/operator/autonum.rb +20 -0
  68. data/lib/alf-algebra/alf/algebra/operator/clip.rb +28 -0
  69. data/lib/alf-algebra/alf/algebra/operator/coerce.rb +20 -0
  70. data/lib/alf-algebra/alf/algebra/operator/compact.rb +19 -0
  71. data/lib/alf-algebra/alf/algebra/operator/defaults.rb +24 -0
  72. data/lib/alf-algebra/alf/algebra/operator/extend.rb +23 -0
  73. data/lib/alf-algebra/alf/algebra/operator/generator.rb +21 -0
  74. data/lib/alf-algebra/alf/algebra/operator/group.rb +28 -0
  75. data/lib/alf-algebra/alf/algebra/operator/infer_heading.rb +19 -0
  76. data/lib/alf-algebra/alf/algebra/operator/intersect.rb +24 -0
  77. data/lib/alf-algebra/alf/algebra/operator/join.rb +27 -0
  78. data/lib/alf-algebra/alf/algebra/operator/matching.rb +19 -0
  79. data/lib/alf-algebra/alf/algebra/operator/minus.rb +19 -0
  80. data/lib/alf-algebra/alf/algebra/operator/not_matching.rb +19 -0
  81. data/lib/alf-algebra/alf/algebra/operator/project.rb +36 -0
  82. data/lib/alf-algebra/alf/algebra/operator/quota.rb +22 -0
  83. data/lib/alf-algebra/alf/algebra/operator/rank.rb +28 -0
  84. data/lib/alf-algebra/alf/algebra/operator/rename.rb +24 -0
  85. data/lib/alf-algebra/alf/algebra/operator/restrict.rb +26 -0
  86. data/lib/alf-algebra/alf/algebra/operator/sort.rb +20 -0
  87. data/lib/alf-algebra/alf/algebra/operator/summarize.rb +28 -0
  88. data/lib/alf-algebra/alf/algebra/operator/type_safe.rb +21 -0
  89. data/lib/alf-algebra/alf/algebra/operator/ungroup.rb +31 -0
  90. data/lib/alf-algebra/alf/algebra/operator/union.rb +19 -0
  91. data/lib/alf-algebra/alf/algebra/operator/unwrap.rb +23 -0
  92. data/lib/alf-algebra/alf/algebra/operator/wrap.rb +41 -0
  93. data/lib/alf-algebra/alf/algebra/support.rb +15 -0
  94. data/lib/alf-algebra/alf/algebra/support/binary.rb +51 -0
  95. data/lib/alf-algebra/alf/algebra/support/classification.rb +37 -0
  96. data/lib/alf-algebra/alf/algebra/support/compiler.rb +28 -0
  97. data/lib/alf-algebra/alf/algebra/support/experimental.rb +19 -0
  98. data/lib/alf-algebra/alf/algebra/support/non_relational.rb +16 -0
  99. data/lib/alf-algebra/alf/algebra/support/nullary.rb +25 -0
  100. data/lib/alf-algebra/alf/algebra/support/relational.rb +16 -0
  101. data/lib/alf-algebra/alf/algebra/support/rewriter.rb +32 -0
  102. data/lib/alf-algebra/alf/algebra/support/signature.rb +195 -0
  103. data/lib/alf-algebra/alf/algebra/support/to_dot.rb +196 -0
  104. data/lib/alf-algebra/alf/algebra/support/unary.rb +34 -0
  105. data/lib/alf-algebra/alf/algebra/support/visitor.rb +31 -0
  106. data/lib/alf-core.rb +37 -0
  107. data/lib/alf-core/dsl.rb +22 -0
  108. data/lib/alf-core/errors.rb +16 -0
  109. data/lib/alf-core/ext.rb +1 -0
  110. data/lib/alf-core/ext/domain/heading_based.rb +88 -0
  111. data/lib/alf-core/facade.rb +35 -0
  112. data/lib/alf-core/loader.rb +13 -0
  113. data/lib/alf-core/version.rb +16 -0
  114. data/lib/alf-database/alf/database.rb +46 -0
  115. data/lib/alf-database/alf/database/connection.rb +156 -0
  116. data/lib/alf-database/alf/database/options.rb +25 -0
  117. data/lib/alf-engine/alf/engine.rb +37 -0
  118. data/lib/alf-engine/alf/engine/aggregate.rb +46 -0
  119. data/lib/alf-engine/alf/engine/autonum.rb +46 -0
  120. data/lib/alf-engine/alf/engine/cesure.rb +47 -0
  121. data/lib/alf-engine/alf/engine/clip.rb +54 -0
  122. data/lib/alf-engine/alf/engine/coerce.rb +47 -0
  123. data/lib/alf-engine/alf/engine/cog.rb +27 -0
  124. data/lib/alf-engine/alf/engine/compact.rb +27 -0
  125. data/lib/alf-engine/alf/engine/compact/set.rb +24 -0
  126. data/lib/alf-engine/alf/engine/compact/uniq.rb +24 -0
  127. data/lib/alf-engine/alf/engine/compiler.rb +144 -0
  128. data/lib/alf-engine/alf/engine/concat.rb +26 -0
  129. data/lib/alf-engine/alf/engine/defaults.rb +44 -0
  130. data/lib/alf-engine/alf/engine/filter.rb +42 -0
  131. data/lib/alf-engine/alf/engine/generator.rb +51 -0
  132. data/lib/alf-engine/alf/engine/group.rb +3 -0
  133. data/lib/alf-engine/alf/engine/group/hash.rb +41 -0
  134. data/lib/alf-engine/alf/engine/infer_heading.rb +29 -0
  135. data/lib/alf-engine/alf/engine/join.rb +3 -0
  136. data/lib/alf-engine/alf/engine/join/hash.rb +36 -0
  137. data/lib/alf-engine/alf/engine/leaf.rb +24 -0
  138. data/lib/alf-engine/alf/engine/materialize.rb +4 -0
  139. data/lib/alf-engine/alf/engine/materialize/array.rb +79 -0
  140. data/lib/alf-engine/alf/engine/materialize/hash.rb +123 -0
  141. data/lib/alf-engine/alf/engine/quota.rb +3 -0
  142. data/lib/alf-engine/alf/engine/quota/cesure.rb +48 -0
  143. data/lib/alf-engine/alf/engine/rank.rb +3 -0
  144. data/lib/alf-engine/alf/engine/rank/cesure.rb +48 -0
  145. data/lib/alf-engine/alf/engine/rename.rb +40 -0
  146. data/lib/alf-engine/alf/engine/semi.rb +3 -0
  147. data/lib/alf-engine/alf/engine/semi/hash.rb +40 -0
  148. data/lib/alf-engine/alf/engine/set_attr.rb +47 -0
  149. data/lib/alf-engine/alf/engine/sort.rb +29 -0
  150. data/lib/alf-engine/alf/engine/sort/in_memory.rb +40 -0
  151. data/lib/alf-engine/alf/engine/summarize.rb +4 -0
  152. data/lib/alf-engine/alf/engine/summarize/cesure.rb +54 -0
  153. data/lib/alf-engine/alf/engine/summarize/hash.rb +36 -0
  154. data/lib/alf-engine/alf/engine/to_array.rb +62 -0
  155. data/lib/alf-engine/alf/engine/to_dot.rb +60 -0
  156. data/lib/alf-engine/alf/engine/type_safe.rb +28 -0
  157. data/lib/alf-engine/alf/engine/ungroup.rb +31 -0
  158. data/lib/alf-engine/alf/engine/unwrap.rb +33 -0
  159. data/lib/alf-engine/alf/engine/wrap.rb +40 -0
  160. data/lib/alf-io/alf/io.rb +6 -0
  161. data/lib/alf-io/alf/reader.rb +189 -0
  162. data/lib/alf-io/alf/reader/csv.rb +28 -0
  163. data/lib/alf-io/alf/reader/json.rb +25 -0
  164. data/lib/alf-io/alf/reader/rash.rb +32 -0
  165. data/lib/alf-io/alf/renderer.rb +119 -0
  166. data/lib/alf-io/alf/renderer/csv.rb +30 -0
  167. data/lib/alf-io/alf/renderer/json.rb +33 -0
  168. data/lib/alf-io/alf/renderer/rash.rb +38 -0
  169. data/lib/alf-io/alf/renderer/text.rb +166 -0
  170. data/lib/alf-io/alf/renderer/yaml.rb +25 -0
  171. data/lib/alf-io/alf/support/csv_utils.rb +40 -0
  172. data/lib/alf-lang/alf/lang.rb +4 -0
  173. data/lib/alf-lang/alf/lang/functional.rb +56 -0
  174. data/lib/alf-lang/alf/lang/lispy.rb +53 -0
  175. data/lib/alf-lang/alf/lang/object_oriented.rb +26 -0
  176. data/lib/alf-lang/alf/lang/oo/aggregation_methods.rb +19 -0
  177. data/lib/alf-lang/alf/lang/oo/algebra_methods.rb +72 -0
  178. data/lib/alf-lang/alf/lang/oo/rendering_methods.rb +54 -0
  179. data/lib/alf-lang/alf/lang/predicates.rb +17 -0
  180. data/lib/alf-optimizer/alf/optimizer.rb +38 -0
  181. data/lib/alf-optimizer/alf/optimizer/restrict.rb +169 -0
  182. data/lib/alf-predicate/alf/predicate.rb +110 -0
  183. data/lib/alf-predicate/alf/predicate/factory.rb +104 -0
  184. data/lib/alf-predicate/alf/predicate/grammar.rb +38 -0
  185. data/lib/alf-predicate/alf/predicate/grammar.sexp.yml +54 -0
  186. data/lib/alf-predicate/alf/predicate/nodes/and.rb +25 -0
  187. data/lib/alf-predicate/alf/predicate/nodes/contradiction.rb +36 -0
  188. data/lib/alf-predicate/alf/predicate/nodes/dyadic_comp.rb +28 -0
  189. data/lib/alf-predicate/alf/predicate/nodes/eq.rb +17 -0
  190. data/lib/alf-predicate/alf/predicate/nodes/expr.rb +65 -0
  191. data/lib/alf-predicate/alf/predicate/nodes/gt.rb +12 -0
  192. data/lib/alf-predicate/alf/predicate/nodes/gte.rb +12 -0
  193. data/lib/alf-predicate/alf/predicate/nodes/in.rb +28 -0
  194. data/lib/alf-predicate/alf/predicate/nodes/literal.rb +20 -0
  195. data/lib/alf-predicate/alf/predicate/nodes/lt.rb +12 -0
  196. data/lib/alf-predicate/alf/predicate/nodes/lte.rb +12 -0
  197. data/lib/alf-predicate/alf/predicate/nodes/nadic_bool.rb +18 -0
  198. data/lib/alf-predicate/alf/predicate/nodes/native.rb +20 -0
  199. data/lib/alf-predicate/alf/predicate/nodes/neq.rb +12 -0
  200. data/lib/alf-predicate/alf/predicate/nodes/not.rb +24 -0
  201. data/lib/alf-predicate/alf/predicate/nodes/or.rb +12 -0
  202. data/lib/alf-predicate/alf/predicate/nodes/tautology.rb +32 -0
  203. data/lib/alf-predicate/alf/predicate/nodes/var_ref.rb +20 -0
  204. data/lib/alf-predicate/alf/predicate/parser.rb +12 -0
  205. data/lib/alf-predicate/alf/predicate/processors.rb +3 -0
  206. data/lib/alf-predicate/alf/predicate/processors/renamer.rb +19 -0
  207. data/lib/alf-predicate/alf/predicate/processors/to_proc.rb +35 -0
  208. data/lib/alf-predicate/alf/predicate/processors/to_ruby_code.rb +74 -0
  209. data/lib/alf-relation/alf/relation.rb +123 -0
  210. data/lib/alf-relation/alf/tuple.rb +103 -0
  211. data/lib/alf-relvar/alf/relvar.rb +87 -0
  212. data/lib/alf-relvar/alf/relvar/base.rb +64 -0
  213. data/lib/alf-relvar/alf/relvar/fake.rb +34 -0
  214. data/lib/alf-relvar/alf/relvar/read_only.rb +67 -0
  215. data/lib/alf-relvar/alf/relvar/virtual.rb +62 -0
  216. data/lib/alf-support/alf/support.rb +21 -0
  217. data/lib/alf-support/alf/support/bindable.rb +26 -0
  218. data/lib/alf-support/alf/support/coerce.rb +28 -0
  219. data/lib/alf-support/alf/support/config.rb +62 -0
  220. data/lib/alf-support/alf/support/dot_utils.rb +15 -0
  221. data/lib/alf-support/alf/support/miscellaneous.rb +60 -0
  222. data/lib/alf-support/alf/support/ordered_set.rb +33 -0
  223. data/lib/alf-support/alf/support/registry.rb +52 -0
  224. data/lib/alf-support/alf/support/scope.rb +85 -0
  225. data/lib/alf-support/alf/support/to_lispy.rb +37 -0
  226. data/lib/alf-support/alf/support/to_ruby_literal.rb +33 -0
  227. data/lib/alf-support/alf/support/tuple_scope.rb +72 -0
  228. data/lib/alf-types/alf/types.rb +51 -0
  229. data/lib/alf-types/alf/types/attr_list.rb +154 -0
  230. data/lib/alf-types/alf/types/attr_name.rb +24 -0
  231. data/lib/alf-types/alf/types/boolean.rb +8 -0
  232. data/lib/alf-types/alf/types/heading.rb +189 -0
  233. data/lib/alf-types/alf/types/keys.rb +39 -0
  234. data/lib/alf-types/alf/types/ordering.rb +95 -0
  235. data/lib/alf-types/alf/types/renaming.rb +74 -0
  236. data/lib/alf-types/alf/types/size.rb +15 -0
  237. data/lib/alf-types/alf/types/summarization.rb +101 -0
  238. data/lib/alf-types/alf/types/tuple_computation.rb +104 -0
  239. data/lib/alf-types/alf/types/tuple_expression.rb +132 -0
  240. data/lib/alf-types/alf/types/type_check.rb +58 -0
  241. data/lib/alf-update/alf/update.rb +3 -0
  242. data/lib/alf-update/alf/update/deleter.rb +101 -0
  243. data/lib/alf-update/alf/update/inserter.rb +126 -0
  244. data/lib/alf-update/alf/update/updater.rb +55 -0
  245. data/lib/alf-viewpoint/alf/viewpoint.rb +41 -0
  246. data/spec/integration/__database__/group.alf +3 -0
  247. data/spec/integration/__database__/parts.rash +6 -0
  248. data/spec/integration/__database__/suppliers.rash +5 -0
  249. data/spec/integration/__database__/suppliers_csv.csv +6 -0
  250. data/spec/integration/__database__/supplies.rash +12 -0
  251. data/spec/integration/algebra/test_to_dot.rb +14 -0
  252. data/spec/integration/ext/test_relation.rb +16 -0
  253. data/spec/integration/relation/test_to_array.rb +28 -0
  254. data/spec/integration/relvar/test_type_safe.rb +22 -0
  255. data/spec/integration/test_alf.rb +8 -0
  256. data/spec/integration/test_examples.rb +14 -0
  257. data/spec/optimizer_helper.rb +19 -0
  258. data/spec/regression/heading/test_heading_with_date.rb +12 -0
  259. data/spec/regression/relation/test_coerce.rb +24 -0
  260. data/spec/regression/relation/test_relation_allbut_all.rb +14 -0
  261. data/spec/regression/relation/test_relation_with_date.rb +12 -0
  262. data/spec/regression/relation/test_restrict.rb +21 -0
  263. data/spec/regression/restrict/test_restrict_with_keywords.rb +17 -0
  264. data/spec/shared/a_scope.rb +21 -0
  265. data/spec/shared/a_valid_type_implementation.rb +47 -0
  266. data/spec/shared/a_value.rb +12 -0
  267. data/spec/shared/an_operator_class.rb +49 -0
  268. data/spec/spec_helper.rb +68 -0
  269. data/spec/unit/alf-adapter-fs/folder/fixtures/suppliers.rash +5 -0
  270. data/spec/unit/alf-adapter-fs/folder/test_adapter_class.rb +23 -0
  271. data/spec/unit/alf-adapter-fs/folder/test_adapter_instance.rb +17 -0
  272. data/spec/unit/alf-adapter/adapter/test_factor.rb +20 -0
  273. data/spec/unit/alf-adapter/connection/schema_cached/test_delegate.rb +14 -0
  274. data/spec/unit/alf-adapter/connection/schema_cached/test_heading.rb +12 -0
  275. data/spec/unit/alf-adapter/connection/schema_cached/test_keys.rb +12 -0
  276. data/spec/unit/alf-adapter/connection/schema_cached/test_knows.rb +12 -0
  277. data/spec/unit/alf-adapter/connection/test_lock.rb +16 -0
  278. data/spec/unit/alf-adapter/connection/test_migrate.rb +17 -0
  279. data/spec/unit/alf-adapter/shared_examples/a_cached_connection_method.rb +30 -0
  280. data/spec/unit/alf-adapter/shared_examples/an_adapter.rb +34 -0
  281. data/spec/unit/alf-adapter/shared_examples/an_adapter_class.rb +21 -0
  282. data/spec/unit/alf-adapter/shared_examples/an_adapter_with_readable_cogs.rb +31 -0
  283. data/spec/unit/alf-adapter/shared_examples/an_uncached_connection_method.rb +21 -0
  284. data/spec/unit/alf-aggregator/test_avg.rb +22 -0
  285. data/spec/unit/alf-aggregator/test_collect.rb +25 -0
  286. data/spec/unit/alf-aggregator/test_concat.rb +31 -0
  287. data/spec/unit/alf-aggregator/test_count.rb +17 -0
  288. data/spec/unit/alf-aggregator/test_max.rb +23 -0
  289. data/spec/unit/alf-aggregator/test_min.rb +23 -0
  290. data/spec/unit/alf-aggregator/test_stddev.rb +27 -0
  291. data/spec/unit/alf-aggregator/test_sum.rb +23 -0
  292. data/spec/unit/alf-aggregator/test_variance.rb +29 -0
  293. data/spec/unit/alf-algebra/operand/named/test_keys.rb +22 -0
  294. data/spec/unit/alf-algebra/operand/named/test_to_relvar.rb +18 -0
  295. data/spec/unit/alf-algebra/operand/test_coerce.rb +43 -0
  296. data/spec/unit/alf-algebra/operator/allbut/test_key_preserving.rb +55 -0
  297. data/spec/unit/alf-algebra/operator/allbut/test_keys.rb +52 -0
  298. data/spec/unit/alf-algebra/operator/autonum/test_heading.rb +22 -0
  299. data/spec/unit/alf-algebra/operator/autonum/test_keys.rb +22 -0
  300. data/spec/unit/alf-algebra/operator/clip/test_heading.rb +36 -0
  301. data/spec/unit/alf-algebra/operator/clip/test_keys.rb +48 -0
  302. data/spec/unit/alf-algebra/operator/coerce/test_heading.rb +23 -0
  303. data/spec/unit/alf-algebra/operator/coerce/test_keys.rb +23 -0
  304. data/spec/unit/alf-algebra/operator/commons/test_with_operands.rb +42 -0
  305. data/spec/unit/alf-algebra/operator/compact/test_heading.rb +23 -0
  306. data/spec/unit/alf-algebra/operator/compact/test_keys.rb +38 -0
  307. data/spec/unit/alf-algebra/operator/defaults/test_heading.rb +48 -0
  308. data/spec/unit/alf-algebra/operator/defaults/test_keys.rb +22 -0
  309. data/spec/unit/alf-algebra/operator/extend/test_heading.rb +37 -0
  310. data/spec/unit/alf-algebra/operator/extend/test_keys.rb +30 -0
  311. data/spec/unit/alf-algebra/operator/generator/test_heading.rb +19 -0
  312. data/spec/unit/alf-algebra/operator/generator/test_keys.rb +19 -0
  313. data/spec/unit/alf-algebra/operator/group/test_heading.rb +33 -0
  314. data/spec/unit/alf-algebra/operator/group/test_keys.rb +65 -0
  315. data/spec/unit/alf-algebra/operator/infer_heading/test_keys.rb +23 -0
  316. data/spec/unit/alf-algebra/operator/intersect/test_heading.rb +39 -0
  317. data/spec/unit/alf-algebra/operator/intersect/test_keys.rb +67 -0
  318. data/spec/unit/alf-algebra/operator/join/test_heading.rb +39 -0
  319. data/spec/unit/alf-algebra/operator/join/test_keys.rb +59 -0
  320. data/spec/unit/alf-algebra/operator/matching/test_heading.rb +26 -0
  321. data/spec/unit/alf-algebra/operator/matching/test_keys.rb +43 -0
  322. data/spec/unit/alf-algebra/operator/minus/test_heading.rb +26 -0
  323. data/spec/unit/alf-algebra/operator/minus/test_keys.rb +26 -0
  324. data/spec/unit/alf-algebra/operator/not_matching/test_heading.rb +26 -0
  325. data/spec/unit/alf-algebra/operator/not_matching/test_keys.rb +26 -0
  326. data/spec/unit/alf-algebra/operator/project/test_heading.rb +36 -0
  327. data/spec/unit/alf-algebra/operator/project/test_key_preserving.rb +55 -0
  328. data/spec/unit/alf-algebra/operator/project/test_keys.rb +52 -0
  329. data/spec/unit/alf-algebra/operator/quota/test_heading.rb +23 -0
  330. data/spec/unit/alf-algebra/operator/quota/test_keys.rb +23 -0
  331. data/spec/unit/alf-algebra/operator/rank/test_heading.rb +23 -0
  332. data/spec/unit/alf-algebra/operator/rank/test_keys.rb +36 -0
  333. data/spec/unit/alf-algebra/operator/rename/test_complete_renaming.rb +23 -0
  334. data/spec/unit/alf-algebra/operator/rename/test_heading.rb +23 -0
  335. data/spec/unit/alf-algebra/operator/rename/test_keys.rb +23 -0
  336. data/spec/unit/alf-algebra/operator/restrict/test_heading.rb +23 -0
  337. data/spec/unit/alf-algebra/operator/restrict/test_keys.rb +52 -0
  338. data/spec/unit/alf-algebra/operator/sort/test_heading.rb +23 -0
  339. data/spec/unit/alf-algebra/operator/sort/test_keys.rb +24 -0
  340. data/spec/unit/alf-algebra/operator/summarize/test_heading.rb +36 -0
  341. data/spec/unit/alf-algebra/operator/summarize/test_keys.rb +47 -0
  342. data/spec/unit/alf-algebra/operator/test_autonum.rb +32 -0
  343. data/spec/unit/alf-algebra/operator/test_clip.rb +32 -0
  344. data/spec/unit/alf-algebra/operator/test_coerce.rb +20 -0
  345. data/spec/unit/alf-algebra/operator/test_compact.rb +16 -0
  346. data/spec/unit/alf-algebra/operator/test_defaults.rb +32 -0
  347. data/spec/unit/alf-algebra/operator/test_extend.rb +16 -0
  348. data/spec/unit/alf-algebra/operator/test_generator.rb +23 -0
  349. data/spec/unit/alf-algebra/operator/test_group.rb +31 -0
  350. data/spec/unit/alf-algebra/operator/test_infer_heading.rb +16 -0
  351. data/spec/unit/alf-algebra/operator/test_intersect.rb +16 -0
  352. data/spec/unit/alf-algebra/operator/test_join.rb +16 -0
  353. data/spec/unit/alf-algebra/operator/test_minus.rb +16 -0
  354. data/spec/unit/alf-algebra/operator/test_project.rb +32 -0
  355. data/spec/unit/alf-algebra/operator/test_quota.rb +19 -0
  356. data/spec/unit/alf-algebra/operator/test_rank.rb +16 -0
  357. data/spec/unit/alf-algebra/operator/test_rename.rb +16 -0
  358. data/spec/unit/alf-algebra/operator/test_restrict.rb +16 -0
  359. data/spec/unit/alf-algebra/operator/test_sort.rb +16 -0
  360. data/spec/unit/alf-algebra/operator/test_summarize.rb +36 -0
  361. data/spec/unit/alf-algebra/operator/test_ungroup.rb +16 -0
  362. data/spec/unit/alf-algebra/operator/test_union.rb +16 -0
  363. data/spec/unit/alf-algebra/operator/test_unwrap.rb +16 -0
  364. data/spec/unit/alf-algebra/operator/test_wrap.rb +32 -0
  365. data/spec/unit/alf-algebra/operator/type_safe/test_heading.rb +26 -0
  366. data/spec/unit/alf-algebra/operator/type_safe/test_keys.rb +26 -0
  367. data/spec/unit/alf-algebra/operator/ungroup/test_heading.rb +20 -0
  368. data/spec/unit/alf-algebra/operator/ungroup/test_keys.rb +23 -0
  369. data/spec/unit/alf-algebra/operator/union/test_heading.rb +36 -0
  370. data/spec/unit/alf-algebra/operator/union/test_keys.rb +26 -0
  371. data/spec/unit/alf-algebra/operator/unwrap/test_heading.rb +20 -0
  372. data/spec/unit/alf-algebra/operator/unwrap/test_keys.rb +20 -0
  373. data/spec/unit/alf-algebra/operator/wrap/test_heading.rb +33 -0
  374. data/spec/unit/alf-algebra/operator/wrap/test_keys.rb +49 -0
  375. data/spec/unit/alf-algebra/support/binary/test_with_left.rb +27 -0
  376. data/spec/unit/alf-algebra/support/binary/test_with_right.rb +27 -0
  377. data/spec/unit/alf-algebra/support/signature/test_collect_on.rb +41 -0
  378. data/spec/unit/alf-algebra/support/signature/test_initialize.rb +20 -0
  379. data/spec/unit/alf-algebra/support/signature/test_install.rb +56 -0
  380. data/spec/unit/alf-algebra/support/signature/test_option_parser.rb +36 -0
  381. data/spec/unit/alf-algebra/support/signature/test_parse_args.rb +92 -0
  382. data/spec/unit/alf-algebra/support/signature/test_to_lispy.rb +102 -0
  383. data/spec/unit/alf-algebra/support/test_non_relational.rb +23 -0
  384. data/spec/unit/alf-algebra/support/test_relational.rb +33 -0
  385. data/spec/unit/alf-algebra/support/unary/test_with_operand.rb +28 -0
  386. data/spec/unit/alf-algebra/test_operator.rb +18 -0
  387. data/spec/unit/alf-algebra/test_rewriter.rb +29 -0
  388. data/spec/unit/alf-core/alf/example.rash +1 -0
  389. data/spec/unit/alf-core/alf/test_Relation.rb +28 -0
  390. data/spec/unit/alf-core/alf/test_connect.rb +25 -0
  391. data/spec/unit/alf-core/alf/test_database.rb +21 -0
  392. data/spec/unit/alf-core/alf/test_reader.rb +22 -0
  393. data/spec/unit/alf-core/assumptions/test_file.rb +16 -0
  394. data/spec/unit/alf-core/assumptions/test_instance_eval.rb +15 -0
  395. data/spec/unit/alf-core/assumptions/test_scoping.rb +29 -0
  396. data/spec/unit/alf-core/assumptions/test_set.rb +64 -0
  397. data/spec/unit/alf-core/test_aggregator.rb +59 -0
  398. data/spec/unit/alf-database/connection/test_assert.rb +36 -0
  399. data/spec/unit/alf-database/connection/test_close.rb +28 -0
  400. data/spec/unit/alf-database/connection/test_deny.rb +36 -0
  401. data/spec/unit/alf-database/connection/test_fact.rb +48 -0
  402. data/spec/unit/alf-database/connection/test_lock.rb +19 -0
  403. data/spec/unit/alf-database/connection/test_migrate.rb +27 -0
  404. data/spec/unit/alf-database/connection/test_new.rb +17 -0
  405. data/spec/unit/alf-database/connection/test_options.rb +16 -0
  406. data/spec/unit/alf-database/connection/test_parse.rb +109 -0
  407. data/spec/unit/alf-database/connection/test_query.rb +22 -0
  408. data/spec/unit/alf-database/connection/test_reconnect.rb +41 -0
  409. data/spec/unit/alf-database/connection/test_relvar.rb +42 -0
  410. data/spec/unit/alf-database/connection/test_tuple_extract.rb +38 -0
  411. data/spec/unit/alf-database/database/test_connect.rb +44 -0
  412. data/spec/unit/alf-database/database/test_connection.rb +21 -0
  413. data/spec/unit/alf-database/database/test_default_options.rb +14 -0
  414. data/spec/unit/alf-database/database/test_new.rb +53 -0
  415. data/spec/unit/alf-database/options/test_default_viewpoint.rb +25 -0
  416. data/spec/unit/alf-database/options/test_freeze.rb +20 -0
  417. data/spec/unit/alf-database/options/test_merge.rb +26 -0
  418. data/spec/unit/alf-database/options/test_new.rb +64 -0
  419. data/spec/unit/alf-database/options/test_schema_cache.rb +29 -0
  420. data/spec/unit/alf-database/options/test_viewpoint.rb +25 -0
  421. data/spec/unit/alf-database/shared_examples/a_facade_on_database_options.rb +6 -0
  422. data/spec/unit/alf-engine/compact/test_set.rb +33 -0
  423. data/spec/unit/alf-engine/compact/test_uniq.rb +33 -0
  424. data/spec/unit/alf-engine/group/test_hash.rb +29 -0
  425. data/spec/unit/alf-engine/infer_heading/test_heading.rb +30 -0
  426. data/spec/unit/alf-engine/join/test_hash.rb +55 -0
  427. data/spec/unit/alf-engine/materialize/test_array.rb +28 -0
  428. data/spec/unit/alf-engine/materialize/test_hash.rb +76 -0
  429. data/spec/unit/alf-engine/quota/test_cesure.rb +34 -0
  430. data/spec/unit/alf-engine/rank/test_cesure.rb +47 -0
  431. data/spec/unit/alf-engine/semi/test_hash.rb +58 -0
  432. data/spec/unit/alf-engine/sort/test_in_memory.rb +32 -0
  433. data/spec/unit/alf-engine/summarize/test_cesure.rb +36 -0
  434. data/spec/unit/alf-engine/summarize/test_hash.rb +36 -0
  435. data/spec/unit/alf-engine/test_aggregate.rb +26 -0
  436. data/spec/unit/alf-engine/test_autonum.rb +24 -0
  437. data/spec/unit/alf-engine/test_clip.rb +34 -0
  438. data/spec/unit/alf-engine/test_coerce.rb +35 -0
  439. data/spec/unit/alf-engine/test_compact.rb +33 -0
  440. data/spec/unit/alf-engine/test_concat.rb +38 -0
  441. data/spec/unit/alf-engine/test_defaults.rb +37 -0
  442. data/spec/unit/alf-engine/test_filter.rb +23 -0
  443. data/spec/unit/alf-engine/test_generator.rb +25 -0
  444. data/spec/unit/alf-engine/test_infer_heading.rb +58 -0
  445. data/spec/unit/alf-engine/test_rename.rb +24 -0
  446. data/spec/unit/alf-engine/test_set_attr.rb +38 -0
  447. data/spec/unit/alf-engine/test_sort.rb +32 -0
  448. data/spec/unit/alf-engine/test_to_array.rb +44 -0
  449. data/spec/unit/alf-engine/test_type_safe.rb +33 -0
  450. data/spec/unit/alf-engine/test_ungroup.rb +28 -0
  451. data/spec/unit/alf-engine/test_unwrap.rb +20 -0
  452. data/spec/unit/alf-engine/test_wrap.rb +26 -0
  453. data/spec/unit/alf-io/reader/class/test_by_mime_type.rb +32 -0
  454. data/spec/unit/alf-io/reader/input.csv +3 -0
  455. data/spec/unit/alf-io/reader/input.rb +2 -0
  456. data/spec/unit/alf-io/reader/test_csv.rb +67 -0
  457. data/spec/unit/alf-io/reader/test_initialize.rb +74 -0
  458. data/spec/unit/alf-io/reader/test_json.rb +30 -0
  459. data/spec/unit/alf-io/reader/test_rash.rb +32 -0
  460. data/spec/unit/alf-io/renderer/class/test_by_mime_type.rb +30 -0
  461. data/spec/unit/alf-io/renderer/test_csv.rb +68 -0
  462. data/spec/unit/alf-io/renderer/test_initialize.rb +40 -0
  463. data/spec/unit/alf-io/renderer/test_json.rb +42 -0
  464. data/spec/unit/alf-io/renderer/test_rash.rb +36 -0
  465. data/spec/unit/alf-io/renderer/test_text.rb +47 -0
  466. data/spec/unit/alf-io/renderer/test_yaml.rb +22 -0
  467. data/spec/unit/alf-io/renderer/text/test_cell.rb +35 -0
  468. data/spec/unit/alf-io/renderer/text/test_row.rb +30 -0
  469. data/spec/unit/alf-io/renderer/text/test_table.rb +39 -0
  470. data/spec/unit/alf-io/shared_examples/a_reader_class.rb +19 -0
  471. data/spec/unit/alf-io/shared_examples/a_renderer_class.rb +24 -0
  472. data/spec/unit/alf-io/support/test_proc_io.rb +18 -0
  473. data/spec/unit/alf-io/test_reader.rb +36 -0
  474. data/spec/unit/alf-io/test_renderer.rb +43 -0
  475. data/spec/unit/alf-lang/functional/test_aggregation.rb +26 -0
  476. data/spec/unit/alf-lang/functional/test_relation.rb +21 -0
  477. data/spec/unit/alf-lang/functional/test_tuple.rb +21 -0
  478. data/spec/unit/alf-lang/lispy/test_connection_bang.rb +26 -0
  479. data/spec/unit/alf-lang/lispy/test_parse.rb +38 -0
  480. data/spec/unit/alf-lang/lispy/test_to_s.rb +14 -0
  481. data/spec/unit/alf-lang/object_oriented/test_rendering_methods.rb +38 -0
  482. data/spec/unit/alf-lang/object_oriented/test_to_array.rb +45 -0
  483. data/spec/unit/alf-lang/object_oriented/test_to_rash.rb +34 -0
  484. data/spec/unit/alf-lang/object_oriented/test_tuple_extract.rb +51 -0
  485. data/spec/unit/alf-lang/test_predicates.rb +17 -0
  486. data/spec/unit/alf-optimizer/optimizer/test_optimizer.rb +37 -0
  487. data/spec/unit/alf-optimizer/optimizer/test_search.rb +48 -0
  488. data/spec/unit/alf-optimizer/restrict/test_on_autonum.rb +41 -0
  489. data/spec/unit/alf-optimizer/restrict/test_on_coerce.rb +42 -0
  490. data/spec/unit/alf-optimizer/restrict/test_on_join.rb +107 -0
  491. data/spec/unit/alf-optimizer/restrict/test_on_matching.rb +41 -0
  492. data/spec/unit/alf-optimizer/shared/a_pass_through_expression_for_restrict.rb +36 -0
  493. data/spec/unit/alf-optimizer/shared/a_split_able_expression_for_restrict.rb +46 -0
  494. data/spec/unit/alf-optimizer/shared/an_optimizable_expression_for_restrict.rb +39 -0
  495. data/spec/unit/alf-optimizer/shared/an_unoptimizable_expression_for_restrict.rb +24 -0
  496. data/spec/unit/alf-optimizer/test_autonum.rb +12 -0
  497. data/spec/unit/alf-optimizer/test_clip.rb +10 -0
  498. data/spec/unit/alf-optimizer/test_coerce.rb +12 -0
  499. data/spec/unit/alf-optimizer/test_compact.rb +10 -0
  500. data/spec/unit/alf-optimizer/test_defaults.rb +12 -0
  501. data/spec/unit/alf-optimizer/test_extend.rb +12 -0
  502. data/spec/unit/alf-optimizer/test_generator.rb +9 -0
  503. data/spec/unit/alf-optimizer/test_group.rb +12 -0
  504. data/spec/unit/alf-optimizer/test_infer_heading.rb +9 -0
  505. data/spec/unit/alf-optimizer/test_intersect.rb +10 -0
  506. data/spec/unit/alf-optimizer/test_minus.rb +10 -0
  507. data/spec/unit/alf-optimizer/test_project.rb +10 -0
  508. data/spec/unit/alf-optimizer/test_quota.rb +16 -0
  509. data/spec/unit/alf-optimizer/test_rank.rb +12 -0
  510. data/spec/unit/alf-optimizer/test_rename.rb +19 -0
  511. data/spec/unit/alf-optimizer/test_sort.rb +10 -0
  512. data/spec/unit/alf-optimizer/test_summarize.rb +15 -0
  513. data/spec/unit/alf-optimizer/test_union.rb +10 -0
  514. data/spec/unit/alf-optimizer/test_wrap.rb +12 -0
  515. data/spec/unit/alf-predicate/expr/test_to_proc.rb +20 -0
  516. data/spec/unit/alf-predicate/expr/test_to_ruby_code.rb +154 -0
  517. data/spec/unit/alf-predicate/factory/shared/a_comparison_factory_method.rb +35 -0
  518. data/spec/unit/alf-predicate/factory/shared/a_predicate_ast_node.rb +20 -0
  519. data/spec/unit/alf-predicate/factory/test_and.rb +15 -0
  520. data/spec/unit/alf-predicate/factory/test_between.rb +14 -0
  521. data/spec/unit/alf-predicate/factory/test_comp.rb +37 -0
  522. data/spec/unit/alf-predicate/factory/test_contradiction.rb +13 -0
  523. data/spec/unit/alf-predicate/factory/test_eq.rb +11 -0
  524. data/spec/unit/alf-predicate/factory/test_factor_predicate.rb +52 -0
  525. data/spec/unit/alf-predicate/factory/test_gt.rb +11 -0
  526. data/spec/unit/alf-predicate/factory/test_gte.rb +11 -0
  527. data/spec/unit/alf-predicate/factory/test_in.rb +14 -0
  528. data/spec/unit/alf-predicate/factory/test_literal.rb +15 -0
  529. data/spec/unit/alf-predicate/factory/test_lt.rb +11 -0
  530. data/spec/unit/alf-predicate/factory/test_lte.rb +11 -0
  531. data/spec/unit/alf-predicate/factory/test_native.rb +16 -0
  532. data/spec/unit/alf-predicate/factory/test_neq.rb +11 -0
  533. data/spec/unit/alf-predicate/factory/test_not.rb +15 -0
  534. data/spec/unit/alf-predicate/factory/test_or.rb +15 -0
  535. data/spec/unit/alf-predicate/factory/test_tautology.rb +14 -0
  536. data/spec/unit/alf-predicate/factory/test_var_ref.rb +15 -0
  537. data/spec/unit/alf-predicate/grammar/test_match.rb +95 -0
  538. data/spec/unit/alf-predicate/grammar/test_parse.rb +23 -0
  539. data/spec/unit/alf-predicate/grammar/test_sexpr.rb +105 -0
  540. data/spec/unit/alf-predicate/nodes/and/test_and_split.rb +68 -0
  541. data/spec/unit/alf-predicate/nodes/dyadic_comp/test_and_split.rb +47 -0
  542. data/spec/unit/alf-predicate/nodes/nadic_bool/test_free_variables.rb +16 -0
  543. data/spec/unit/alf-predicate/nodes/var_ref/test_and_split.rb +25 -0
  544. data/spec/unit/alf-predicate/nodes/var_ref/test_free_variables.rb +14 -0
  545. data/spec/unit/alf-predicate/nodes/var_ref/test_var_name.rb +14 -0
  546. data/spec/unit/alf-predicate/predicate/test_and_split.rb +59 -0
  547. data/spec/unit/alf-predicate/predicate/test_bool_and.rb +36 -0
  548. data/spec/unit/alf-predicate/predicate/test_bool_not.rb +70 -0
  549. data/spec/unit/alf-predicate/predicate/test_bool_or.rb +36 -0
  550. data/spec/unit/alf-predicate/predicate/test_coerce.rb +131 -0
  551. data/spec/unit/alf-predicate/predicate/test_constant_variables.rb +54 -0
  552. data/spec/unit/alf-predicate/predicate/test_contradiction.rb +28 -0
  553. data/spec/unit/alf-predicate/predicate/test_evaluate.rb +32 -0
  554. data/spec/unit/alf-predicate/predicate/test_factory_methods.rb +79 -0
  555. data/spec/unit/alf-predicate/predicate/test_free_variables.rb +16 -0
  556. data/spec/unit/alf-predicate/predicate/test_hash_and_equal.rb +28 -0
  557. data/spec/unit/alf-predicate/predicate/test_rename.rb +35 -0
  558. data/spec/unit/alf-predicate/predicate/test_tautology.rb +28 -0
  559. data/spec/unit/alf-predicate/predicate/test_to_proc.rb +16 -0
  560. data/spec/unit/alf-predicate/predicate/test_to_ruby_code.rb +16 -0
  561. data/spec/unit/alf-predicate/predicate/test_to_ruby_literal.rb +16 -0
  562. data/spec/unit/alf-predicate/test_predicate.rb +132 -0
  563. data/spec/unit/alf-relation/relation/class/test_coerce.rb +62 -0
  564. data/spec/unit/alf-relation/relation/class/test_type.rb +31 -0
  565. data/spec/unit/alf-relation/relation/factored-types/test_allbut.rb +34 -0
  566. data/spec/unit/alf-relation/relation/factored-types/test_coerce.rb +45 -0
  567. data/spec/unit/alf-relation/relation/factored-types/test_comparisons.rb +69 -0
  568. data/spec/unit/alf-relation/relation/factored-types/test_equality.rb +28 -0
  569. data/spec/unit/alf-relation/relation/factored-types/test_project.rb +34 -0
  570. data/spec/unit/alf-relation/relation/factored-types/test_rename.rb +12 -0
  571. data/spec/unit/alf-relation/relation/factored-types/test_split.rb +30 -0
  572. data/spec/unit/alf-relation/relation/factored-types/test_to_ruby_literal.rb +18 -0
  573. data/spec/unit/alf-relation/relation/factored-types/test_triple_equal.rb +42 -0
  574. data/spec/unit/alf-relation/relation/test_aggregation.rb +36 -0
  575. data/spec/unit/alf-relation/relation/test_equality.rb +34 -0
  576. data/spec/unit/alf-relation/relation/test_hash.rb +28 -0
  577. data/spec/unit/alf-relation/relation/test_heading.rb +17 -0
  578. data/spec/unit/alf-relation/relation/test_inspect.rb +20 -0
  579. data/spec/unit/alf-relation/relation/test_relation.rb +77 -0
  580. data/spec/unit/alf-relation/relation/test_relops.rb +62 -0
  581. data/spec/unit/alf-relation/relation/test_sugar.rb +40 -0
  582. data/spec/unit/alf-relation/relation/test_to_a.rb +37 -0
  583. data/spec/unit/alf-relation/relation/test_to_relation.rb +14 -0
  584. data/spec/unit/alf-relation/tuple/class/test_coerce.rb +29 -0
  585. data/spec/unit/alf-relation/tuple/class/test_type.rb +27 -0
  586. data/spec/unit/alf-relation/tuple/factored-types/test_allbut.rb +34 -0
  587. data/spec/unit/alf-relation/tuple/factored-types/test_coerce.rb +91 -0
  588. data/spec/unit/alf-relation/tuple/factored-types/test_comparisons.rb +69 -0
  589. data/spec/unit/alf-relation/tuple/factored-types/test_equality.rb +28 -0
  590. data/spec/unit/alf-relation/tuple/factored-types/test_project.rb +34 -0
  591. data/spec/unit/alf-relation/tuple/factored-types/test_rename.rb +12 -0
  592. data/spec/unit/alf-relation/tuple/factored-types/test_split.rb +30 -0
  593. data/spec/unit/alf-relation/tuple/factored-types/test_to_ruby_literal.rb +18 -0
  594. data/spec/unit/alf-relation/tuple/factored-types/test_triple_equal.rb +56 -0
  595. data/spec/unit/alf-relation/tuple/test_allbut.rb +14 -0
  596. data/spec/unit/alf-relation/tuple/test_attribute_accessors.rb +36 -0
  597. data/spec/unit/alf-relation/tuple/test_equality.rb +28 -0
  598. data/spec/unit/alf-relation/tuple/test_extend.rb +30 -0
  599. data/spec/unit/alf-relation/tuple/test_hash.rb +28 -0
  600. data/spec/unit/alf-relation/tuple/test_heading.rb +20 -0
  601. data/spec/unit/alf-relation/tuple/test_merge.rb +24 -0
  602. data/spec/unit/alf-relation/tuple/test_project.rb +18 -0
  603. data/spec/unit/alf-relation/tuple/test_remap.rb +14 -0
  604. data/spec/unit/alf-relation/tuple/test_rename.rb +14 -0
  605. data/spec/unit/alf-relation/tuple/test_split.rb +28 -0
  606. data/spec/unit/alf-relation/tuple/test_to_attr_list.rb +12 -0
  607. data/spec/unit/alf-relation/tuple/test_triple_equal.rb +17 -0
  608. data/spec/unit/alf-relvar/base/test_connection.rb +14 -0
  609. data/spec/unit/alf-relvar/base/test_delete.rb +35 -0
  610. data/spec/unit/alf-relvar/base/test_heading.rb +22 -0
  611. data/spec/unit/alf-relvar/base/test_insert.rb +23 -0
  612. data/spec/unit/alf-relvar/base/test_keys.rb +22 -0
  613. data/spec/unit/alf-relvar/base/test_lock.rb +22 -0
  614. data/spec/unit/alf-relvar/base/test_name.rb +14 -0
  615. data/spec/unit/alf-relvar/base/test_oo_lang.rb +28 -0
  616. data/spec/unit/alf-relvar/base/test_to_cog.rb +22 -0
  617. data/spec/unit/alf-relvar/base/test_to_lispy.rb +14 -0
  618. data/spec/unit/alf-relvar/base/test_to_relvar.rb +14 -0
  619. data/spec/unit/alf-relvar/base/test_to_s.rb +14 -0
  620. data/spec/unit/alf-relvar/base/test_update.rb +24 -0
  621. data/spec/unit/alf-relvar/read_only/test_type.rb +21 -0
  622. data/spec/unit/alf-relvar/shared/test_empty.rb +21 -0
  623. data/spec/unit/alf-relvar/shared/test_empty_bang.rb +31 -0
  624. data/spec/unit/alf-relvar/shared/test_not_empty_bang.rb +31 -0
  625. data/spec/unit/alf-relvar/shared/test_to_relation.rb +45 -0
  626. data/spec/unit/alf-relvar/shared/test_type.rb +21 -0
  627. data/spec/unit/alf-relvar/shared/test_upsert.rb +41 -0
  628. data/spec/unit/alf-relvar/virtual/test_connection.rb +14 -0
  629. data/spec/unit/alf-relvar/virtual/test_delete.rb +41 -0
  630. data/spec/unit/alf-relvar/virtual/test_expr.rb +14 -0
  631. data/spec/unit/alf-relvar/virtual/test_heading.rb +20 -0
  632. data/spec/unit/alf-relvar/virtual/test_insert.rb +28 -0
  633. data/spec/unit/alf-relvar/virtual/test_keys.rb +20 -0
  634. data/spec/unit/alf-relvar/virtual/test_oo_lang.rb +29 -0
  635. data/spec/unit/alf-relvar/virtual/test_to_cog.rb +18 -0
  636. data/spec/unit/alf-relvar/virtual/test_to_lispy.rb +20 -0
  637. data/spec/unit/alf-relvar/virtual/test_to_relvar.rb +14 -0
  638. data/spec/unit/alf-relvar/virtual/test_to_s.rb +15 -0
  639. data/spec/unit/alf-relvar/virtual/test_update.rb +29 -0
  640. data/spec/unit/alf-support/bindable/test_bind.rb +60 -0
  641. data/spec/unit/alf-support/bindable/test_bound.rb +31 -0
  642. data/spec/unit/alf-support/bindable/test_connection.rb +31 -0
  643. data/spec/unit/alf-support/bindable/test_connection_bang.rb +35 -0
  644. data/spec/unit/alf-support/config/test_helpers.rb +33 -0
  645. data/spec/unit/alf-support/config/test_merge.rb +34 -0
  646. data/spec/unit/alf-support/config/test_new.rb +52 -0
  647. data/spec/unit/alf-support/config/test_option.rb +27 -0
  648. data/spec/unit/alf-support/scope/test_branch.rb +28 -0
  649. data/spec/unit/alf-support/scope/test_evaluate.rb +42 -0
  650. data/spec/unit/alf-support/scope/test_initialize.rb +20 -0
  651. data/spec/unit/alf-support/scope/test_respond_to.rb +33 -0
  652. data/spec/unit/alf-support/test_class_name.rb +16 -0
  653. data/spec/unit/alf-support/test_coerce.rb +24 -0
  654. data/spec/unit/alf-support/test_registry.rb +63 -0
  655. data/spec/unit/alf-support/test_ruby_case.rb +16 -0
  656. data/spec/unit/alf-support/test_rubycase_name.rb +24 -0
  657. data/spec/unit/alf-support/test_symbolize_keys.rb +24 -0
  658. data/spec/unit/alf-support/test_to_lispy.rb +142 -0
  659. data/spec/unit/alf-support/test_to_ruby_literal.rb +26 -0
  660. data/spec/unit/alf-support/test_to_tuple.rb +29 -0
  661. data/spec/unit/alf-support/test_tuple_scope.rb +35 -0
  662. data/spec/unit/alf-support/test_unsymbolize_keys.rb +24 -0
  663. data/spec/unit/alf-support/tuple_scope/test_evaluate.rb +37 -0
  664. data/spec/unit/alf-support/tuple_scope/test_respond_to.rb +34 -0
  665. data/spec/unit/alf-types/attr_list/test_allbut.rb +28 -0
  666. data/spec/unit/alf-types/attr_list/test_ampersand.rb +20 -0
  667. data/spec/unit/alf-types/attr_list/test_coerce.rb +68 -0
  668. data/spec/unit/alf-types/attr_list/test_difference.rb +20 -0
  669. data/spec/unit/alf-types/attr_list/test_hash_and_eql.rb +47 -0
  670. data/spec/unit/alf-types/attr_list/test_include.rb +22 -0
  671. data/spec/unit/alf-types/attr_list/test_intersect.rb +36 -0
  672. data/spec/unit/alf-types/attr_list/test_or.rb +20 -0
  673. data/spec/unit/alf-types/attr_list/test_project.rb +52 -0
  674. data/spec/unit/alf-types/attr_list/test_project_tuple.rb +31 -0
  675. data/spec/unit/alf-types/attr_list/test_sameset.rb +36 -0
  676. data/spec/unit/alf-types/attr_list/test_set_compare.rb +59 -0
  677. data/spec/unit/alf-types/attr_list/test_split_tuple.rb +31 -0
  678. data/spec/unit/alf-types/attr_list/test_subset.rb +50 -0
  679. data/spec/unit/alf-types/attr_list/test_superset.rb +50 -0
  680. data/spec/unit/alf-types/attr_list/test_to_a.rb +14 -0
  681. data/spec/unit/alf-types/attr_list/test_to_ordering.rb +19 -0
  682. data/spec/unit/alf-types/attr_name/test_coerce.rb +16 -0
  683. data/spec/unit/alf-types/attr_name/test_triple_equal.rb +27 -0
  684. data/spec/unit/alf-types/heading/class/test_coerce.rb +40 -0
  685. data/spec/unit/alf-types/heading/class/test_infer.rb +26 -0
  686. data/spec/unit/alf-types/heading/test_allbut.rb +12 -0
  687. data/spec/unit/alf-types/heading/test_cardinality.rb +25 -0
  688. data/spec/unit/alf-types/heading/test_coerce.rb +57 -0
  689. data/spec/unit/alf-types/heading/test_comparison.rb +96 -0
  690. data/spec/unit/alf-types/heading/test_intersection.rb +29 -0
  691. data/spec/unit/alf-types/heading/test_merge.rb +25 -0
  692. data/spec/unit/alf-types/heading/test_project.rb +20 -0
  693. data/spec/unit/alf-types/heading/test_split.rb +20 -0
  694. data/spec/unit/alf-types/heading/test_to_h.rb +24 -0
  695. data/spec/unit/alf-types/heading/test_triple_equal.rb +40 -0
  696. data/spec/unit/alf-types/heading/test_union.rb +33 -0
  697. data/spec/unit/alf-types/keys/test_all.rb +17 -0
  698. data/spec/unit/alf-types/keys/test_ampersand.rb +26 -0
  699. data/spec/unit/alf-types/keys/test_any.rb +17 -0
  700. data/spec/unit/alf-types/keys/test_coerce.rb +64 -0
  701. data/spec/unit/alf-types/keys/test_compact.rb +21 -0
  702. data/spec/unit/alf-types/keys/test_empty.rb +20 -0
  703. data/spec/unit/alf-types/keys/test_first.rb +17 -0
  704. data/spec/unit/alf-types/keys/test_hash_and_equal.rb +33 -0
  705. data/spec/unit/alf-types/keys/test_if_empty.rb +40 -0
  706. data/spec/unit/alf-types/keys/test_map.rb +17 -0
  707. data/spec/unit/alf-types/keys/test_plus.rb +26 -0
  708. data/spec/unit/alf-types/keys/test_project.rb +29 -0
  709. data/spec/unit/alf-types/keys/test_reject.rb +17 -0
  710. data/spec/unit/alf-types/keys/test_rename.rb +21 -0
  711. data/spec/unit/alf-types/keys/test_select.rb +17 -0
  712. data/spec/unit/alf-types/ordering/test_coerce.rb +53 -0
  713. data/spec/unit/alf-types/ordering/test_compare.rb +29 -0
  714. data/spec/unit/alf-types/ordering/test_plus.rb +27 -0
  715. data/spec/unit/alf-types/ordering/test_sorter.rb +16 -0
  716. data/spec/unit/alf-types/ordering/test_to_attr_list.rb +14 -0
  717. data/spec/unit/alf-types/renaming/test_coerce.rb +24 -0
  718. data/spec/unit/alf-types/renaming/test_complete.rb +14 -0
  719. data/spec/unit/alf-types/renaming/test_invert.rb +14 -0
  720. data/spec/unit/alf-types/renaming/test_rename_attr_list.rb +24 -0
  721. data/spec/unit/alf-types/renaming/test_rename_tuple.rb +14 -0
  722. data/spec/unit/alf-types/renaming/test_to_attr_list.rb +14 -0
  723. data/spec/unit/alf-types/size/test_coerce.rb +23 -0
  724. data/spec/unit/alf-types/size/test_triple_equal.rb +25 -0
  725. data/spec/unit/alf-types/summarization/test_coerce.rb +31 -0
  726. data/spec/unit/alf-types/summarization/test_least.rb +11 -0
  727. data/spec/unit/alf-types/summarization/test_summarize.rb +15 -0
  728. data/spec/unit/alf-types/test_attr_list.rb +18 -0
  729. data/spec/unit/alf-types/test_class_methods.rb +59 -0
  730. data/spec/unit/alf-types/test_heading.rb +59 -0
  731. data/spec/unit/alf-types/test_ordering.rb +18 -0
  732. data/spec/unit/alf-types/test_renaming.rb +18 -0
  733. data/spec/unit/alf-types/test_summarization.rb +25 -0
  734. data/spec/unit/alf-types/test_tuple_computation.rb +28 -0
  735. data/spec/unit/alf-types/test_tuple_expression.rb +17 -0
  736. data/spec/unit/alf-types/tuple_computation/test_coerce.rb +54 -0
  737. data/spec/unit/alf-types/tuple_computation/test_to_attr_list.rb +15 -0
  738. data/spec/unit/alf-types/tuple_computation/test_to_heading.rb +29 -0
  739. data/spec/unit/alf-types/tuple_expression/test_coerce.rb +44 -0
  740. data/spec/unit/alf-types/tuple_expression/test_to_ruby_literal.rb +16 -0
  741. data/spec/unit/alf-types/type_check/test_triple_equal.rb +58 -0
  742. data/spec/unit/alf-update/deleter/test_autonum.rb +31 -0
  743. data/spec/unit/alf-update/deleter/test_clip.rb +18 -0
  744. data/spec/unit/alf-update/deleter/test_defaults.rb +31 -0
  745. data/spec/unit/alf-update/deleter/test_extend.rb +31 -0
  746. data/spec/unit/alf-update/deleter/test_group.rb +31 -0
  747. data/spec/unit/alf-update/deleter/test_intersect.rb +21 -0
  748. data/spec/unit/alf-update/deleter/test_project.rb +18 -0
  749. data/spec/unit/alf-update/deleter/test_rank.rb +31 -0
  750. data/spec/unit/alf-update/deleter/test_rename.rb +31 -0
  751. data/spec/unit/alf-update/deleter/test_restrict.rb +20 -0
  752. data/spec/unit/alf-update/deleter/test_sort.rb +18 -0
  753. data/spec/unit/alf-update/deleter/test_var_ref.rb +19 -0
  754. data/spec/unit/alf-update/deleter/test_wrap.rb +31 -0
  755. data/spec/unit/alf-update/inserter/test_autonum.rb +19 -0
  756. data/spec/unit/alf-update/inserter/test_clip.rb +21 -0
  757. data/spec/unit/alf-update/inserter/test_compact.rb +19 -0
  758. data/spec/unit/alf-update/inserter/test_defaults.rb +19 -0
  759. data/spec/unit/alf-update/inserter/test_extend.rb +19 -0
  760. data/spec/unit/alf-update/inserter/test_group.rb +26 -0
  761. data/spec/unit/alf-update/inserter/test_intersect.rb +22 -0
  762. data/spec/unit/alf-update/inserter/test_join.rb +21 -0
  763. data/spec/unit/alf-update/inserter/test_matching.rb +19 -0
  764. data/spec/unit/alf-update/inserter/test_minus.rb +19 -0
  765. data/spec/unit/alf-update/inserter/test_not_matching.rb +19 -0
  766. data/spec/unit/alf-update/inserter/test_project.rb +21 -0
  767. data/spec/unit/alf-update/inserter/test_rank.rb +19 -0
  768. data/spec/unit/alf-update/inserter/test_rename.rb +19 -0
  769. data/spec/unit/alf-update/inserter/test_restrict.rb +19 -0
  770. data/spec/unit/alf-update/inserter/test_sort.rb +19 -0
  771. data/spec/unit/alf-update/inserter/test_type_safe.rb +72 -0
  772. data/spec/unit/alf-update/inserter/test_union.rb +22 -0
  773. data/spec/unit/alf-update/inserter/test_var_ref.rb +18 -0
  774. data/spec/unit/alf-update/inserter/test_wrap.rb +25 -0
  775. data/spec/unit/alf-update/updater/test_var_ref.rb +19 -0
  776. data/spec/unit/alf-viewpoint/test_namespace.rb +23 -0
  777. data/spec/unit/alf-viewpoint/test_native.rb +26 -0
  778. data/spec/unit/alf-viewpoint/test_native_const.rb +16 -0
  779. data/spec/unit/alf-viewpoint/test_parse.rb +36 -0
  780. data/spec/unit/alf-viewpoint/test_parser.rb +22 -0
  781. data/spec/update_helper.rb +69 -0
  782. data/tasks/clean.rake +3 -0
  783. data/tasks/gem.rake +73 -0
  784. data/tasks/gh-pages.rake +69 -0
  785. data/tasks/integration_test.rake +43 -0
  786. data/tasks/regression_test.rake +44 -0
  787. data/tasks/unit_test.rake +44 -0
  788. data/tasks/yard.rake +51 -0
  789. metadata +1544 -0
@@ -0,0 +1,34 @@
1
+ module Alf
2
+ module Algebra
3
+ #
4
+ # Specialization of Operator for operators that work on a unary input
5
+ #
6
+ module Unary
7
+
8
+ # Class-level methods
9
+ module ClassMethods
10
+
11
+ # (see Operator::ClassMethods#arity)
12
+ def arity
13
+ 1
14
+ end
15
+
16
+ end # module ClassMethods
17
+
18
+ def self.included(mod)
19
+ super
20
+ mod.extend(ClassMethods)
21
+ end
22
+
23
+ # Simply returns the first operand
24
+ def operand
25
+ operands.first
26
+ end
27
+
28
+ def with_operand(operand)
29
+ with_operands(operand)
30
+ end
31
+
32
+ end # module Unary
33
+ end # module Algebra
34
+ end # module Alf
@@ -0,0 +1,31 @@
1
+ module Alf
2
+ module Algebra
3
+ module Visitor
4
+
5
+ def copy_and_apply(expr)
6
+ if expr.is_a?(Algebra::Operator)
7
+ expr.with_operands(*expr.operands.map{|op| apply(op) })
8
+ else
9
+ expr
10
+ end
11
+ end
12
+
13
+ private
14
+
15
+ def to_method_name(expr, prefix = "on_")
16
+ case expr
17
+ when Algebra::Operator
18
+ name = Support.ruby_case(Support.class_name(expr.class))
19
+ meth = :"#{prefix}#{name}"
20
+ meth = :"#{prefix}missing" unless respond_to?(meth)
21
+ meth
22
+ when Algebra::Operand
23
+ :on_leaf_operand
24
+ else
25
+ :not_supported
26
+ end
27
+ end
28
+
29
+ end # module Visitor
30
+ end # module Algebra
31
+ end # module Alf
@@ -0,0 +1,37 @@
1
+ require_relative 'alf-core/loader'
2
+ require_relative 'alf-core/version'
3
+ require_relative 'alf-core/errors'
4
+ require_relative 'alf-core/ext'
5
+ require_relative 'alf-core/facade'
6
+
7
+ module Alf
8
+ TupleLike = lambda{|t| t.is_a?(Hash) || t.is_a?(Tuple) }
9
+ RelationLike = lambda{|r| Relation===r || Engine::Cog===r || Reader===r || Relvar===r }
10
+ end
11
+
12
+ require_relative 'alf-predicate/alf/predicate'
13
+ require_relative 'alf-support/alf/support'
14
+ require_relative 'alf-types/alf/types'
15
+ require_relative 'alf-aggregator/alf/aggregator'
16
+ require_relative 'alf-algebra/alf/algebra'
17
+ require_relative "alf-engine/alf/engine"
18
+ require_relative 'alf-io/alf/io'
19
+ require_relative 'alf-lang/alf/lang'
20
+ require_relative 'alf-relation/alf/relation'
21
+ require_relative 'alf-relvar/alf/relvar'
22
+ require_relative 'alf-optimizer/alf/optimizer'
23
+ require_relative 'alf-update/alf/update'
24
+ require_relative 'alf-adapter/alf/adapter'
25
+ require_relative 'alf-viewpoint/alf/viewpoint'
26
+ require_relative 'alf-database/alf/database'
27
+ require_relative 'alf-adapter-fs/alf/adapter/fs'
28
+
29
+ module Alf
30
+ extend Facade
31
+
32
+ DUM = Relation::DUM
33
+ DEE = Relation::DEE
34
+ end
35
+
36
+ require_relative 'alf-core/dsl'
37
+ include Alf::Dsl unless defined?(ALF_NO_CORE_EXTENSIONS)
@@ -0,0 +1,22 @@
1
+ module Alf
2
+ module Dsl
3
+
4
+ Tuple = Alf::Tuple
5
+ Relation = Alf::Relation
6
+ DUM = Alf::Relation::DUM
7
+ DEE = Alf::Relation::DEE
8
+
9
+ def Relation(*args, &bl)
10
+ Alf::Relation(*args, &bl)
11
+ end
12
+
13
+ def Tuple(*args, &bl)
14
+ Alf::Tuple(*args, &bl)
15
+ end
16
+
17
+ def Heading(*args, &bl)
18
+ Alf::Heading(*args, &bl)
19
+ end
20
+
21
+ end # module Dsl
22
+ end # module Alf
@@ -0,0 +1,16 @@
1
+ module Alf
2
+ class Error < StandardError; end
3
+ class ConfigError < Alf::Error; end
4
+ class UnboundError < StandardError; end
5
+ class NotSupportedError < Error; end
6
+ class NoSuchRelvarError < Error; end
7
+ class NoSuchTupleError < Error; end
8
+ class FactAssertionError < Error; end
9
+ class CoercionError < Error; end
10
+ class ReadOnlyError < Error; end
11
+ class TypeCheckError < Error; end
12
+ class IllegalStateError < Error; end
13
+
14
+ # deprecated
15
+ class UnsupportedError < Error; end
16
+ end
@@ -0,0 +1 @@
1
+ require_relative 'ext/domain/heading_based'
@@ -0,0 +1,88 @@
1
+ module Domain
2
+ class HeadingBased < Module
3
+
4
+ def initialize(master_class)
5
+ define_method(:new){|*args|
6
+ raise "#{master_class}.new may not be called directly" if master_class==self
7
+ super(*args)
8
+ }
9
+ define_method(:type){|generating_type|
10
+ meths = [
11
+ DomainMethods.new(master_class, generating_type),
12
+ AlgebraMethods.new(master_class, generating_type),
13
+ Domain::Comparisons,
14
+ ]
15
+ Class.new(master_class).extend(*meths).heading_based_factored
16
+ }
17
+ alias_method :[], :type
18
+ define_method(:heading_based_factored) do
19
+ self
20
+ end
21
+ end
22
+
23
+ class DomainMethods < Module
24
+
25
+ def initialize(master_class, gt)
26
+ define_method(:generating_type){
27
+ gt
28
+ }
29
+ define_method(:<=>){|other|
30
+ return nil unless other.ancestors.include?(master_class)
31
+ return -1 if other == master_class
32
+ to_heading <=> other.to_heading
33
+ }
34
+ define_method(:===){|value|
35
+ super(value) || (value.is_a?(master_class) && self >= value.class)
36
+ }
37
+ define_method(:hash){
38
+ @hash ||= 37*master_class.hash + generating_type.hash
39
+ }
40
+ define_method(:==){|other|
41
+ other.is_a?(Class) &&
42
+ other.superclass==master_class &&
43
+ other.to_heading==to_heading
44
+ }
45
+ define_method(:coerce){|arg|
46
+ master_class.coercions.apply(arg, self)
47
+ }
48
+ define_method(:to_heading){
49
+ @heading ||= Alf::Heading.coerce(generating_type)
50
+ }
51
+ define_method(:to_ruby_literal){
52
+ "#{master_class.name}[#{Alf::Support.to_ruby_literal(to_heading.to_hash)}]"
53
+ }
54
+ alias_method :name, :to_ruby_literal
55
+ alias_method :to_s, :to_ruby_literal
56
+ alias_method :inspect, :to_ruby_literal
57
+ end
58
+ end # module DomainMethods
59
+
60
+ class AlgebraMethods < Module
61
+
62
+ def initialize(master_class, generating_type)
63
+ define_method(:heading){
64
+ @heading ||= Alf::Heading.coerce(generating_type)
65
+ }
66
+ define_method(:split){|attr_list|
67
+ if attr_list.empty?
68
+ [ master_class::DUM.class, self ]
69
+ elsif attr_list==heading.to_attr_list
70
+ [ self, master_class::DUM.class ]
71
+ else
72
+ heading.split(attr_list).map{|h| master_class[h]}
73
+ end
74
+ }
75
+ define_method(:project){|attr_list|
76
+ split(attr_list).first
77
+ }
78
+ define_method(:allbut){|attr_list|
79
+ split(attr_list).last
80
+ }
81
+ define_method(:rename){|renaming|
82
+ master_class[heading.rename(renaming)]
83
+ }
84
+ end
85
+ end
86
+
87
+ end # module HeadingBased
88
+ end # module Domain
@@ -0,0 +1,35 @@
1
+ module Alf
2
+ module Facade
3
+
4
+ def database(*args, &bl)
5
+ Alf::Database.new(*args, &bl)
6
+ end
7
+
8
+ def connect(*args, &bl)
9
+ Alf::Database.connect(*args, &bl)
10
+ end
11
+
12
+ def examples(&bl)
13
+ Alf::Database.connect Path.backfind('examples/suppliers_and_parts'), &bl
14
+ end
15
+
16
+ def reader(source, *args)
17
+ Alf::Reader.reader(source, *args)
18
+ end
19
+
20
+ def Relation(*args, &bl)
21
+ Alf::Relation.coerce(*args, &bl)
22
+ end
23
+
24
+ def Tuple(*args, &bl)
25
+ tuple = Alf::Tuple.coerce(*args)
26
+ tuple = tuple.remap(&bl) if bl
27
+ tuple
28
+ end
29
+
30
+ def Heading(*args, &bl)
31
+ Alf::Heading.coerce(*args, &bl)
32
+ end
33
+
34
+ end
35
+ end
@@ -0,0 +1,13 @@
1
+ # Standard library
2
+ require "enumerator"
3
+ require "stringio"
4
+ require "set"
5
+ require "forwardable"
6
+ require 'time'
7
+
8
+ # Third party gems
9
+ require "path"
10
+ require "sexpr"
11
+ require "myrrha"
12
+ require 'myrrha/to_ruby_literal'
13
+ require 'myrrha/coerce'
@@ -0,0 +1,16 @@
1
+ module Alf
2
+ module Core
3
+ module Version
4
+
5
+ MAJOR = 0
6
+ MINOR = 13
7
+ TINY = 0
8
+
9
+ def self.to_s
10
+ [ MAJOR, MINOR, TINY ].join('.')
11
+ end
12
+
13
+ end
14
+ VERSION = Version.to_s
15
+ end
16
+ end
@@ -0,0 +1,46 @@
1
+ require_relative 'database/options'
2
+ require_relative 'database/connection'
3
+ module Alf
4
+ class Database
5
+ include Options.helpers(:default_options)
6
+
7
+ def self.new(conn_spec, options = {})
8
+ adapter = Adapter.factor(conn_spec)
9
+ options = Options.new(options)
10
+ yield(options) if block_given?
11
+ super(adapter, options)
12
+ end
13
+
14
+ def self.connect(conn_spec, options = {}, &bl)
15
+ db = new(conn_spec, options)
16
+ bl ? db.connect(&bl) : db.connection
17
+ end
18
+
19
+ def initialize(adapter, options)
20
+ @adapter = adapter
21
+ @default_options = options.freeze
22
+ @schema_cache = Adapter::Connection::SchemaCached.empty_cache
23
+ end
24
+ attr_reader :adapter, :default_options
25
+
26
+ ### connection handling
27
+
28
+ def connection(opts = {})
29
+ Connection.new(self, default_options.merge(opts)) do |conn_opts|
30
+ conn = adapter.connection
31
+ if conn_opts.schema_cache?
32
+ conn = Adapter::Connection::SchemaCached.new(conn, @schema_cache)
33
+ end
34
+ conn
35
+ end
36
+ end
37
+
38
+ def connect(opts = {})
39
+ c = connection(opts)
40
+ yield(c)
41
+ ensure
42
+ c.close if c
43
+ end
44
+
45
+ end # class Database
46
+ end # module Alf
@@ -0,0 +1,156 @@
1
+ module Alf
2
+ class Database
3
+ class Connection
4
+ include Options.helpers(:options)
5
+ extend Forwardable
6
+
7
+ def initialize(db, options = Options.new, &connection_handler)
8
+ @db = db
9
+ @options = options.freeze
10
+ @connection_handler = connection_handler
11
+ open!
12
+ end
13
+ attr_reader :db, :options, :connection_handler
14
+
15
+ ### connection handling
16
+ private :connection_handler
17
+
18
+ def adapter_connection
19
+ @adapter_connection ||= connection_handler.call(options)
20
+ end
21
+ alias_method :open!, :adapter_connection
22
+ private :open!
23
+
24
+ def reconnect(opts = {})
25
+ close unless (opts.keys & [:schema_cache]).empty?
26
+ @options = options.merge(opts)
27
+ open!
28
+ end
29
+
30
+ def closed?
31
+ @adapter_connection.nil?
32
+ end
33
+
34
+ def close
35
+ adapter_connection.close unless closed?
36
+ @adapter_connection = nil
37
+ end
38
+
39
+ ### logical level
40
+
41
+ def parse(*args, &bl)
42
+ parser.parse(*args, &bl)
43
+ end
44
+
45
+ def optimize(*args, &bl)
46
+ optimizer.call(parse(*args, &bl))
47
+ end
48
+
49
+ def relvar(*args, &bl)
50
+ parse(*args, &bl).to_relvar
51
+ end
52
+
53
+ def query(*args, &bl)
54
+ relvar(*args, &bl).to_relation
55
+ end
56
+
57
+ def tuple_extract(*args, &bl)
58
+ relvar(*args, &bl).tuple_extract
59
+ end
60
+
61
+ def assert!(msg = "an assert! assertion failed", &bl)
62
+ relvar(&bl).not_empty!(msg)
63
+ end
64
+
65
+ def deny!(msg = "a deny! assertion failed", &bl)
66
+ relvar(&bl).empty!(msg)
67
+ end
68
+
69
+ def fact!(msg = "a fact! assertion failed", &bl)
70
+ relvar(&bl).tuple_extract
71
+ rescue NoSuchTupleError
72
+ raise FactAssertionError, msg
73
+ end
74
+
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
+ ### physical level
95
+
96
+ def_delegators :adapter_connection, :in_transaction,
97
+ :knows?,
98
+ :heading,
99
+ :keys,
100
+ :insert,
101
+ :delete,
102
+ :update
103
+
104
+ def migrate!
105
+ adapter_connection.migrate!(options)
106
+ end
107
+
108
+ ### others
109
+
110
+ def to_s
111
+ "Alf::Database::Connection(#{adapter_connection})"
112
+ end
113
+
114
+ private
115
+
116
+ def compile(expr)
117
+ if df = options.debug_folder
118
+ where, i = options.debug_naming.call(expr), 1
119
+ debug_dot(expr, df/"#{where}/#{i}-Algebra.dot")
120
+ compilation_chain.inject(expr){|e,c|
121
+ c.call(e).tap{|mid|
122
+ name = "#{i}-#{Alf::Support.class_name(c.class)}"
123
+ debug_dot(mid, df/"#{where}/#{name}.dot")
124
+ i += 1
125
+ }
126
+ }
127
+ else
128
+ compilation_chain.inject(expr){|e,c| c.call(e) }
129
+ end
130
+ end
131
+
132
+ def optimizer
133
+ Optimizer.new.register(Optimizer::Restrict.new, Algebra::Restrict)
134
+ end
135
+
136
+ def compilation_chain
137
+ [ optimizer, adapter_connection.compiler ]
138
+ end
139
+
140
+ def parser
141
+ options.viewpoint.parser(self)
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")
152
+ end
153
+
154
+ end # class Connection
155
+ end # class Database
156
+ end # module Alf