relationalai 0.13.0.dev0__py3-none-any.whl → 0.13.1__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (837) hide show
  1. frontend/debugger/dist/.gitignore +2 -0
  2. frontend/debugger/dist/assets/favicon-Dy0ZgA6N.png +0 -0
  3. frontend/debugger/dist/assets/index-Cssla-O7.js +208 -0
  4. frontend/debugger/dist/assets/index-DlHsYx1V.css +9 -0
  5. frontend/debugger/dist/index.html +17 -0
  6. relationalai/__init__.py +256 -1
  7. relationalai/clients/__init__.py +18 -0
  8. relationalai/clients/client.py +912 -0
  9. relationalai/clients/config.py +673 -0
  10. relationalai/clients/direct_access_client.py +118 -0
  11. relationalai/clients/exec_txn_poller.py +91 -0
  12. relationalai/clients/hash_util.py +31 -0
  13. relationalai/clients/local.py +571 -0
  14. relationalai/clients/profile_polling.py +73 -0
  15. relationalai/clients/resources/__init__.py +8 -0
  16. relationalai/clients/resources/azure/azure.py +477 -0
  17. relationalai/clients/resources/snowflake/__init__.py +20 -0
  18. relationalai/clients/resources/snowflake/cli_resources.py +87 -0
  19. relationalai/clients/resources/snowflake/direct_access_resources.py +694 -0
  20. relationalai/clients/resources/snowflake/engine_state_handlers.py +309 -0
  21. relationalai/clients/resources/snowflake/error_handlers.py +199 -0
  22. relationalai/clients/resources/snowflake/export_procedure.py.jinja +249 -0
  23. relationalai/clients/resources/snowflake/resources_factory.py +99 -0
  24. relationalai/clients/resources/snowflake/snowflake.py +3190 -0
  25. relationalai/clients/resources/snowflake/use_index_poller.py +1019 -0
  26. relationalai/clients/resources/snowflake/use_index_resources.py +188 -0
  27. relationalai/clients/resources/snowflake/util.py +387 -0
  28. relationalai/clients/result_helpers.py +420 -0
  29. relationalai/clients/types.py +113 -0
  30. relationalai/clients/util.py +356 -0
  31. relationalai/debugging.py +389 -0
  32. relationalai/dsl.py +1749 -0
  33. relationalai/early_access/builder/__init__.py +30 -0
  34. relationalai/early_access/builder/builder/__init__.py +35 -0
  35. relationalai/early_access/builder/snowflake/__init__.py +12 -0
  36. relationalai/early_access/builder/std/__init__.py +25 -0
  37. relationalai/early_access/builder/std/decimals/__init__.py +12 -0
  38. relationalai/early_access/builder/std/integers/__init__.py +12 -0
  39. relationalai/early_access/builder/std/math/__init__.py +12 -0
  40. relationalai/early_access/builder/std/strings/__init__.py +14 -0
  41. relationalai/early_access/devtools/__init__.py +12 -0
  42. relationalai/early_access/devtools/benchmark_lqp/__init__.py +12 -0
  43. relationalai/early_access/devtools/extract_lqp/__init__.py +12 -0
  44. relationalai/early_access/dsl/adapters/orm/adapter_qb.py +427 -0
  45. relationalai/early_access/dsl/adapters/orm/parser.py +636 -0
  46. relationalai/early_access/dsl/adapters/owl/adapter.py +176 -0
  47. relationalai/early_access/dsl/adapters/owl/parser.py +160 -0
  48. relationalai/early_access/dsl/bindings/common.py +402 -0
  49. relationalai/early_access/dsl/bindings/csv.py +170 -0
  50. relationalai/early_access/dsl/bindings/legacy/binding_models.py +143 -0
  51. relationalai/early_access/dsl/bindings/snowflake.py +64 -0
  52. relationalai/early_access/dsl/codegen/binder.py +411 -0
  53. relationalai/early_access/dsl/codegen/common.py +79 -0
  54. relationalai/early_access/dsl/codegen/helpers.py +23 -0
  55. relationalai/early_access/dsl/codegen/relations.py +700 -0
  56. relationalai/early_access/dsl/codegen/weaver.py +417 -0
  57. relationalai/early_access/dsl/core/builders/__init__.py +47 -0
  58. relationalai/early_access/dsl/core/builders/logic.py +19 -0
  59. relationalai/early_access/dsl/core/builders/scalar_constraint.py +11 -0
  60. relationalai/early_access/dsl/core/constraints/predicate/atomic.py +455 -0
  61. relationalai/early_access/dsl/core/constraints/predicate/universal.py +73 -0
  62. relationalai/early_access/dsl/core/constraints/scalar.py +310 -0
  63. relationalai/early_access/dsl/core/context.py +13 -0
  64. relationalai/early_access/dsl/core/cset.py +132 -0
  65. relationalai/early_access/dsl/core/exprs/__init__.py +116 -0
  66. relationalai/early_access/dsl/core/exprs/relational.py +18 -0
  67. relationalai/early_access/dsl/core/exprs/scalar.py +412 -0
  68. relationalai/early_access/dsl/core/instances.py +44 -0
  69. relationalai/early_access/dsl/core/logic/__init__.py +193 -0
  70. relationalai/early_access/dsl/core/logic/aggregation.py +98 -0
  71. relationalai/early_access/dsl/core/logic/exists.py +223 -0
  72. relationalai/early_access/dsl/core/logic/helper.py +163 -0
  73. relationalai/early_access/dsl/core/namespaces.py +32 -0
  74. relationalai/early_access/dsl/core/relations.py +276 -0
  75. relationalai/early_access/dsl/core/rules.py +112 -0
  76. relationalai/early_access/dsl/core/std/__init__.py +45 -0
  77. relationalai/early_access/dsl/core/temporal/recall.py +6 -0
  78. relationalai/early_access/dsl/core/types/__init__.py +270 -0
  79. relationalai/early_access/dsl/core/types/concepts.py +128 -0
  80. relationalai/early_access/dsl/core/types/constrained/__init__.py +267 -0
  81. relationalai/early_access/dsl/core/types/constrained/nominal.py +143 -0
  82. relationalai/early_access/dsl/core/types/constrained/subtype.py +124 -0
  83. relationalai/early_access/dsl/core/types/standard.py +92 -0
  84. relationalai/early_access/dsl/core/types/unconstrained.py +50 -0
  85. relationalai/early_access/dsl/core/types/variables.py +203 -0
  86. relationalai/early_access/dsl/ir/compiler.py +318 -0
  87. relationalai/early_access/dsl/ir/executor.py +260 -0
  88. relationalai/early_access/dsl/ontologies/constraints.py +88 -0
  89. relationalai/early_access/dsl/ontologies/export.py +30 -0
  90. relationalai/early_access/dsl/ontologies/models.py +453 -0
  91. relationalai/early_access/dsl/ontologies/python_printer.py +303 -0
  92. relationalai/early_access/dsl/ontologies/readings.py +60 -0
  93. relationalai/early_access/dsl/ontologies/relationships.py +322 -0
  94. relationalai/early_access/dsl/ontologies/roles.py +87 -0
  95. relationalai/early_access/dsl/ontologies/subtyping.py +55 -0
  96. relationalai/early_access/dsl/orm/constraints.py +438 -0
  97. relationalai/early_access/dsl/orm/measures/dimensions.py +200 -0
  98. relationalai/early_access/dsl/orm/measures/initializer.py +16 -0
  99. relationalai/early_access/dsl/orm/measures/measure_rules.py +275 -0
  100. relationalai/early_access/dsl/orm/measures/measures.py +299 -0
  101. relationalai/early_access/dsl/orm/measures/role_exprs.py +268 -0
  102. relationalai/early_access/dsl/orm/models.py +256 -0
  103. relationalai/early_access/dsl/orm/object_oriented_printer.py +344 -0
  104. relationalai/early_access/dsl/orm/printer.py +469 -0
  105. relationalai/early_access/dsl/orm/reasoners.py +480 -0
  106. relationalai/early_access/dsl/orm/relations.py +19 -0
  107. relationalai/early_access/dsl/orm/relationships.py +251 -0
  108. relationalai/early_access/dsl/orm/types.py +42 -0
  109. relationalai/early_access/dsl/orm/utils.py +79 -0
  110. relationalai/early_access/dsl/orm/verb.py +204 -0
  111. relationalai/early_access/dsl/physical_metadata/tables.py +133 -0
  112. relationalai/early_access/dsl/relations.py +170 -0
  113. relationalai/early_access/dsl/rulesets.py +69 -0
  114. relationalai/early_access/dsl/schemas/__init__.py +450 -0
  115. relationalai/early_access/dsl/schemas/builder.py +48 -0
  116. relationalai/early_access/dsl/schemas/comp_names.py +51 -0
  117. relationalai/early_access/dsl/schemas/components.py +203 -0
  118. relationalai/early_access/dsl/schemas/contexts.py +156 -0
  119. relationalai/early_access/dsl/schemas/exprs.py +89 -0
  120. relationalai/early_access/dsl/schemas/fragments.py +464 -0
  121. relationalai/early_access/dsl/serialization.py +79 -0
  122. relationalai/early_access/dsl/serialize/exporter.py +163 -0
  123. relationalai/early_access/dsl/snow/api.py +105 -0
  124. relationalai/early_access/dsl/snow/common.py +76 -0
  125. relationalai/early_access/dsl/state_mgmt/__init__.py +129 -0
  126. relationalai/early_access/dsl/state_mgmt/state_charts.py +125 -0
  127. relationalai/early_access/dsl/state_mgmt/transitions.py +130 -0
  128. relationalai/early_access/dsl/types/__init__.py +40 -0
  129. relationalai/early_access/dsl/types/concepts.py +12 -0
  130. relationalai/early_access/dsl/types/entities.py +135 -0
  131. relationalai/early_access/dsl/types/values.py +17 -0
  132. relationalai/early_access/dsl/utils.py +102 -0
  133. relationalai/early_access/graphs/__init__.py +13 -0
  134. relationalai/early_access/lqp/__init__.py +12 -0
  135. relationalai/early_access/lqp/compiler/__init__.py +12 -0
  136. relationalai/early_access/lqp/constructors/__init__.py +18 -0
  137. relationalai/early_access/lqp/executor/__init__.py +12 -0
  138. relationalai/early_access/lqp/ir/__init__.py +12 -0
  139. relationalai/early_access/lqp/passes/__init__.py +12 -0
  140. relationalai/early_access/lqp/pragmas/__init__.py +12 -0
  141. relationalai/early_access/lqp/primitives/__init__.py +12 -0
  142. relationalai/early_access/lqp/types/__init__.py +12 -0
  143. relationalai/early_access/lqp/utils/__init__.py +12 -0
  144. relationalai/early_access/lqp/validators/__init__.py +12 -0
  145. relationalai/early_access/metamodel/__init__.py +58 -0
  146. relationalai/early_access/metamodel/builtins/__init__.py +12 -0
  147. relationalai/early_access/metamodel/compiler/__init__.py +12 -0
  148. relationalai/early_access/metamodel/dependency/__init__.py +12 -0
  149. relationalai/early_access/metamodel/factory/__init__.py +17 -0
  150. relationalai/early_access/metamodel/helpers/__init__.py +12 -0
  151. relationalai/early_access/metamodel/ir/__init__.py +14 -0
  152. relationalai/early_access/metamodel/rewrite/__init__.py +7 -0
  153. relationalai/early_access/metamodel/typer/__init__.py +3 -0
  154. relationalai/early_access/metamodel/typer/typer/__init__.py +12 -0
  155. relationalai/early_access/metamodel/types/__init__.py +15 -0
  156. relationalai/early_access/metamodel/util/__init__.py +15 -0
  157. relationalai/early_access/metamodel/visitor/__init__.py +12 -0
  158. relationalai/early_access/rel/__init__.py +12 -0
  159. relationalai/early_access/rel/executor/__init__.py +12 -0
  160. relationalai/early_access/rel/rel_utils/__init__.py +12 -0
  161. relationalai/early_access/rel/rewrite/__init__.py +7 -0
  162. relationalai/early_access/solvers/__init__.py +19 -0
  163. relationalai/early_access/sql/__init__.py +11 -0
  164. relationalai/early_access/sql/executor/__init__.py +3 -0
  165. relationalai/early_access/sql/rewrite/__init__.py +3 -0
  166. relationalai/early_access/tests/logging/__init__.py +12 -0
  167. relationalai/early_access/tests/test_snapshot_base/__init__.py +12 -0
  168. relationalai/early_access/tests/utils/__init__.py +12 -0
  169. relationalai/environments/__init__.py +35 -0
  170. relationalai/environments/base.py +381 -0
  171. relationalai/environments/colab.py +14 -0
  172. relationalai/environments/generic.py +71 -0
  173. relationalai/environments/ipython.py +68 -0
  174. relationalai/environments/jupyter.py +9 -0
  175. relationalai/environments/snowbook.py +169 -0
  176. relationalai/errors.py +2496 -0
  177. relationalai/experimental/SF.py +38 -0
  178. relationalai/experimental/inspect.py +47 -0
  179. relationalai/experimental/pathfinder/__init__.py +158 -0
  180. relationalai/experimental/pathfinder/api.py +160 -0
  181. relationalai/experimental/pathfinder/automaton.py +584 -0
  182. relationalai/experimental/pathfinder/bridge.py +226 -0
  183. relationalai/experimental/pathfinder/compiler.py +416 -0
  184. relationalai/experimental/pathfinder/datalog.py +214 -0
  185. relationalai/experimental/pathfinder/diagnostics.py +56 -0
  186. relationalai/experimental/pathfinder/filter.py +236 -0
  187. relationalai/experimental/pathfinder/glushkov.py +439 -0
  188. relationalai/experimental/pathfinder/options.py +265 -0
  189. relationalai/experimental/pathfinder/pathfinder-v0.7.0.rel +1951 -0
  190. relationalai/experimental/pathfinder/rpq.py +344 -0
  191. relationalai/experimental/pathfinder/transition.py +200 -0
  192. relationalai/experimental/pathfinder/utils.py +26 -0
  193. relationalai/experimental/paths/README.md +107 -0
  194. relationalai/experimental/paths/api.py +143 -0
  195. relationalai/experimental/paths/benchmarks/grid_graph.py +37 -0
  196. relationalai/experimental/paths/code_organization.md +2 -0
  197. relationalai/experimental/paths/examples/Movies.ipynb +16328 -0
  198. relationalai/experimental/paths/examples/basic_example.py +40 -0
  199. relationalai/experimental/paths/examples/minimal_engine_warmup.py +3 -0
  200. relationalai/experimental/paths/examples/movie_example.py +77 -0
  201. relationalai/experimental/paths/examples/movies_data/actedin.csv +193 -0
  202. relationalai/experimental/paths/examples/movies_data/directed.csv +45 -0
  203. relationalai/experimental/paths/examples/movies_data/follows.csv +7 -0
  204. relationalai/experimental/paths/examples/movies_data/movies.csv +39 -0
  205. relationalai/experimental/paths/examples/movies_data/person.csv +134 -0
  206. relationalai/experimental/paths/examples/movies_data/produced.csv +16 -0
  207. relationalai/experimental/paths/examples/movies_data/ratings.csv +10 -0
  208. relationalai/experimental/paths/examples/movies_data/wrote.csv +11 -0
  209. relationalai/experimental/paths/examples/paths_benchmark.py +115 -0
  210. relationalai/experimental/paths/examples/paths_example.py +116 -0
  211. relationalai/experimental/paths/examples/pattern_to_automaton.py +28 -0
  212. relationalai/experimental/paths/find_paths_via_automaton.py +85 -0
  213. relationalai/experimental/paths/graph.py +185 -0
  214. relationalai/experimental/paths/path_algorithms/find_paths.py +280 -0
  215. relationalai/experimental/paths/path_algorithms/one_sided_ball_repetition.py +26 -0
  216. relationalai/experimental/paths/path_algorithms/one_sided_ball_upto.py +111 -0
  217. relationalai/experimental/paths/path_algorithms/single.py +59 -0
  218. relationalai/experimental/paths/path_algorithms/two_sided_balls_repetition.py +39 -0
  219. relationalai/experimental/paths/path_algorithms/two_sided_balls_upto.py +103 -0
  220. relationalai/experimental/paths/path_algorithms/usp-old.py +130 -0
  221. relationalai/experimental/paths/path_algorithms/usp-tuple.py +183 -0
  222. relationalai/experimental/paths/path_algorithms/usp.py +150 -0
  223. relationalai/experimental/paths/product_graph.py +93 -0
  224. relationalai/experimental/paths/rpq/automaton.py +584 -0
  225. relationalai/experimental/paths/rpq/diagnostics.py +56 -0
  226. relationalai/experimental/paths/rpq/rpq.py +378 -0
  227. relationalai/experimental/paths/tests/tests_limit_sp_max_length.py +90 -0
  228. relationalai/experimental/paths/tests/tests_limit_sp_multiple.py +119 -0
  229. relationalai/experimental/paths/tests/tests_limit_sp_single.py +104 -0
  230. relationalai/experimental/paths/tests/tests_limit_walks_multiple.py +113 -0
  231. relationalai/experimental/paths/tests/tests_limit_walks_single.py +149 -0
  232. relationalai/experimental/paths/tests/tests_one_sided_ball_repetition_multiple.py +70 -0
  233. relationalai/experimental/paths/tests/tests_one_sided_ball_repetition_single.py +64 -0
  234. relationalai/experimental/paths/tests/tests_one_sided_ball_upto_multiple.py +115 -0
  235. relationalai/experimental/paths/tests/tests_one_sided_ball_upto_single.py +75 -0
  236. relationalai/experimental/paths/tests/tests_single_paths.py +152 -0
  237. relationalai/experimental/paths/tests/tests_single_walks.py +208 -0
  238. relationalai/experimental/paths/tests/tests_single_walks_undirected.py +297 -0
  239. relationalai/experimental/paths/tests/tests_two_sided_balls_repetition_multiple.py +107 -0
  240. relationalai/experimental/paths/tests/tests_two_sided_balls_repetition_single.py +76 -0
  241. relationalai/experimental/paths/tests/tests_two_sided_balls_upto_multiple.py +76 -0
  242. relationalai/experimental/paths/tests/tests_two_sided_balls_upto_single.py +110 -0
  243. relationalai/experimental/paths/tests/tests_usp_nsp_multiple.py +229 -0
  244. relationalai/experimental/paths/tests/tests_usp_nsp_single.py +108 -0
  245. relationalai/experimental/paths/tree_agg.py +168 -0
  246. relationalai/experimental/paths/utilities/iterators.py +27 -0
  247. relationalai/experimental/paths/utilities/prefix_sum.py +91 -0
  248. relationalai/experimental/solvers.py +1087 -0
  249. relationalai/loaders/csv.py +195 -0
  250. relationalai/loaders/loader.py +177 -0
  251. relationalai/loaders/types.py +23 -0
  252. relationalai/rel_emitter.py +373 -0
  253. relationalai/rel_utils.py +185 -0
  254. relationalai/semantics/__init__.py +22 -146
  255. relationalai/semantics/designs/query_builder/identify_by.md +106 -0
  256. relationalai/semantics/devtools/benchmark_lqp.py +535 -0
  257. relationalai/semantics/devtools/compilation_manager.py +294 -0
  258. relationalai/semantics/devtools/extract_lqp.py +110 -0
  259. relationalai/semantics/internal/internal.py +3785 -0
  260. relationalai/semantics/internal/snowflake.py +325 -0
  261. relationalai/semantics/lqp/README.md +34 -0
  262. relationalai/semantics/lqp/builtins.py +16 -0
  263. relationalai/semantics/lqp/compiler.py +22 -0
  264. relationalai/semantics/lqp/constructors.py +68 -0
  265. relationalai/semantics/lqp/executor.py +469 -0
  266. relationalai/semantics/lqp/intrinsics.py +24 -0
  267. relationalai/semantics/lqp/model2lqp.py +877 -0
  268. relationalai/semantics/lqp/passes.py +680 -0
  269. relationalai/semantics/lqp/primitives.py +252 -0
  270. relationalai/semantics/lqp/result_helpers.py +202 -0
  271. relationalai/semantics/lqp/rewrite/annotate_constraints.py +57 -0
  272. relationalai/semantics/lqp/rewrite/cdc.py +216 -0
  273. relationalai/semantics/lqp/rewrite/extract_common.py +338 -0
  274. relationalai/semantics/lqp/rewrite/extract_keys.py +512 -0
  275. relationalai/semantics/lqp/rewrite/function_annotations.py +114 -0
  276. relationalai/semantics/lqp/rewrite/functional_dependencies.py +314 -0
  277. relationalai/semantics/lqp/rewrite/quantify_vars.py +296 -0
  278. relationalai/semantics/lqp/rewrite/splinter.py +76 -0
  279. relationalai/semantics/lqp/types.py +101 -0
  280. relationalai/semantics/lqp/utils.py +160 -0
  281. relationalai/semantics/lqp/validators.py +57 -0
  282. relationalai/semantics/metamodel/__init__.py +40 -6
  283. relationalai/semantics/metamodel/builtins.py +771 -205
  284. relationalai/semantics/metamodel/compiler.py +133 -0
  285. relationalai/semantics/metamodel/dependency.py +862 -0
  286. relationalai/semantics/metamodel/executor.py +61 -0
  287. relationalai/semantics/metamodel/factory.py +287 -0
  288. relationalai/semantics/metamodel/helpers.py +361 -0
  289. relationalai/semantics/metamodel/rewrite/discharge_constraints.py +39 -0
  290. relationalai/semantics/metamodel/rewrite/dnf_union_splitter.py +210 -0
  291. relationalai/semantics/metamodel/rewrite/extract_nested_logicals.py +78 -0
  292. relationalai/semantics/metamodel/rewrite/flatten.py +554 -0
  293. relationalai/semantics/metamodel/rewrite/format_outputs.py +165 -0
  294. relationalai/semantics/metamodel/typer/checker.py +353 -0
  295. relationalai/semantics/metamodel/typer/typer.py +1395 -0
  296. relationalai/semantics/metamodel/util.py +506 -0
  297. relationalai/semantics/reasoners/__init__.py +10 -0
  298. relationalai/semantics/reasoners/graph/README.md +620 -0
  299. relationalai/semantics/reasoners/graph/__init__.py +37 -0
  300. relationalai/semantics/reasoners/graph/core.py +9019 -0
  301. relationalai/semantics/reasoners/graph/design/beyond_demand_transform.md +797 -0
  302. relationalai/semantics/reasoners/graph/tests/README.md +21 -0
  303. relationalai/semantics/reasoners/optimization/__init__.py +68 -0
  304. relationalai/semantics/reasoners/optimization/common.py +88 -0
  305. relationalai/semantics/reasoners/optimization/solvers_dev.py +568 -0
  306. relationalai/semantics/reasoners/optimization/solvers_pb.py +1414 -0
  307. relationalai/semantics/rel/builtins.py +40 -0
  308. relationalai/semantics/rel/compiler.py +989 -0
  309. relationalai/semantics/rel/executor.py +362 -0
  310. relationalai/semantics/rel/rel.py +482 -0
  311. relationalai/semantics/rel/rel_utils.py +276 -0
  312. relationalai/semantics/snowflake/__init__.py +3 -0
  313. relationalai/semantics/sql/compiler.py +2503 -0
  314. relationalai/semantics/sql/executor/duck_db.py +52 -0
  315. relationalai/semantics/sql/executor/result_helpers.py +64 -0
  316. relationalai/semantics/sql/executor/snowflake.py +149 -0
  317. relationalai/semantics/sql/rewrite/denormalize.py +222 -0
  318. relationalai/semantics/sql/rewrite/double_negation.py +49 -0
  319. relationalai/semantics/sql/rewrite/recursive_union.py +127 -0
  320. relationalai/semantics/sql/rewrite/sort_output_query.py +246 -0
  321. relationalai/semantics/sql/sql.py +504 -0
  322. relationalai/semantics/std/__init__.py +40 -60
  323. relationalai/semantics/std/constraints.py +43 -37
  324. relationalai/semantics/std/datetime.py +135 -246
  325. relationalai/semantics/std/decimals.py +52 -45
  326. relationalai/semantics/std/floats.py +5 -13
  327. relationalai/semantics/std/integers.py +11 -26
  328. relationalai/semantics/std/math.py +112 -183
  329. relationalai/semantics/std/pragmas.py +11 -0
  330. relationalai/semantics/std/re.py +62 -80
  331. relationalai/semantics/std/std.py +14 -0
  332. relationalai/semantics/std/strings.py +60 -117
  333. relationalai/semantics/tests/test_snapshot_abstract.py +143 -0
  334. relationalai/semantics/tests/test_snapshot_base.py +9 -0
  335. relationalai/semantics/tests/utils.py +46 -0
  336. relationalai/std/__init__.py +70 -0
  337. relationalai/tools/cli.py +1936 -0
  338. relationalai/tools/cli_controls.py +1826 -0
  339. relationalai/tools/cli_helpers.py +398 -0
  340. relationalai/tools/debugger.py +183 -289
  341. relationalai/tools/debugger_client.py +109 -0
  342. relationalai/tools/debugger_server.py +302 -0
  343. relationalai/tools/dev.py +685 -0
  344. relationalai/tools/notes +7 -0
  345. relationalai/tools/qb_debugger.py +425 -0
  346. relationalai/util/clean_up_databases.py +95 -0
  347. relationalai/util/format.py +106 -48
  348. relationalai/util/list_databases.py +9 -0
  349. relationalai/util/otel_configuration.py +26 -0
  350. relationalai/util/otel_handler.py +484 -0
  351. relationalai/util/snowflake_handler.py +88 -0
  352. relationalai/util/span_format_test.py +43 -0
  353. relationalai/util/span_tracker.py +207 -0
  354. relationalai/util/spans_file_handler.py +72 -0
  355. relationalai/util/tracing_handler.py +34 -0
  356. relationalai-0.13.1.dist-info/METADATA +74 -0
  357. relationalai-0.13.1.dist-info/RECORD +459 -0
  358. relationalai-0.13.1.dist-info/WHEEL +4 -0
  359. relationalai-0.13.1.dist-info/entry_points.txt +3 -0
  360. relationalai-0.13.1.dist-info/licenses/LICENSE +202 -0
  361. relationalai_test_util/__init__.py +4 -0
  362. relationalai_test_util/fixtures.py +233 -0
  363. relationalai_test_util/snapshot.py +252 -0
  364. relationalai_test_util/traceback.py +118 -0
  365. relationalai/config/__init__.py +0 -56
  366. relationalai/config/config.py +0 -289
  367. relationalai/config/config_fields.py +0 -86
  368. relationalai/config/connections/__init__.py +0 -46
  369. relationalai/config/connections/base.py +0 -23
  370. relationalai/config/connections/duckdb.py +0 -29
  371. relationalai/config/connections/snowflake.py +0 -243
  372. relationalai/config/external/__init__.py +0 -17
  373. relationalai/config/external/dbt_converter.py +0 -101
  374. relationalai/config/external/dbt_models.py +0 -93
  375. relationalai/config/external/snowflake_converter.py +0 -41
  376. relationalai/config/external/snowflake_models.py +0 -85
  377. relationalai/config/external/utils.py +0 -19
  378. relationalai/semantics/backends/lqp/annotations.py +0 -11
  379. relationalai/semantics/backends/sql/sql_compiler.py +0 -327
  380. relationalai/semantics/frontend/base.py +0 -1707
  381. relationalai/semantics/frontend/core.py +0 -179
  382. relationalai/semantics/frontend/front_compiler.py +0 -1313
  383. relationalai/semantics/frontend/pprint.py +0 -408
  384. relationalai/semantics/metamodel/metamodel.py +0 -437
  385. relationalai/semantics/metamodel/metamodel_analyzer.py +0 -519
  386. relationalai/semantics/metamodel/metamodel_compiler.py +0 -0
  387. relationalai/semantics/metamodel/pprint.py +0 -412
  388. relationalai/semantics/metamodel/rewriter.py +0 -266
  389. relationalai/semantics/metamodel/typer.py +0 -1378
  390. relationalai/semantics/std/aggregates.py +0 -149
  391. relationalai/semantics/std/common.py +0 -44
  392. relationalai/semantics/std/numbers.py +0 -86
  393. relationalai/shims/executor.py +0 -147
  394. relationalai/shims/helpers.py +0 -126
  395. relationalai/shims/hoister.py +0 -221
  396. relationalai/shims/mm2v0.py +0 -1290
  397. relationalai/tools/cli/__init__.py +0 -6
  398. relationalai/tools/cli/cli.py +0 -90
  399. relationalai/tools/cli/components/__init__.py +0 -5
  400. relationalai/tools/cli/components/progress_reader.py +0 -1524
  401. relationalai/tools/cli/components/utils.py +0 -58
  402. relationalai/tools/cli/config_template.py +0 -45
  403. relationalai/tools/cli/dev.py +0 -19
  404. relationalai/tools/typer_debugger.py +0 -93
  405. relationalai/util/dataclasses.py +0 -43
  406. relationalai/util/docutils.py +0 -40
  407. relationalai/util/error.py +0 -199
  408. relationalai/util/naming.py +0 -145
  409. relationalai/util/python.py +0 -35
  410. relationalai/util/runtime.py +0 -156
  411. relationalai/util/schema.py +0 -197
  412. relationalai/util/source.py +0 -185
  413. relationalai/util/structures.py +0 -163
  414. relationalai/util/tracing.py +0 -261
  415. relationalai-0.13.0.dev0.dist-info/METADATA +0 -46
  416. relationalai-0.13.0.dev0.dist-info/RECORD +0 -488
  417. relationalai-0.13.0.dev0.dist-info/WHEEL +0 -5
  418. relationalai-0.13.0.dev0.dist-info/entry_points.txt +0 -3
  419. relationalai-0.13.0.dev0.dist-info/top_level.txt +0 -2
  420. v0/relationalai/__init__.py +0 -216
  421. v0/relationalai/clients/__init__.py +0 -5
  422. v0/relationalai/clients/azure.py +0 -477
  423. v0/relationalai/clients/client.py +0 -912
  424. v0/relationalai/clients/config.py +0 -673
  425. v0/relationalai/clients/direct_access_client.py +0 -118
  426. v0/relationalai/clients/hash_util.py +0 -31
  427. v0/relationalai/clients/local.py +0 -571
  428. v0/relationalai/clients/profile_polling.py +0 -73
  429. v0/relationalai/clients/result_helpers.py +0 -420
  430. v0/relationalai/clients/snowflake.py +0 -3869
  431. v0/relationalai/clients/types.py +0 -113
  432. v0/relationalai/clients/use_index_poller.py +0 -980
  433. v0/relationalai/clients/util.py +0 -356
  434. v0/relationalai/debugging.py +0 -389
  435. v0/relationalai/dsl.py +0 -1749
  436. v0/relationalai/early_access/builder/__init__.py +0 -30
  437. v0/relationalai/early_access/builder/builder/__init__.py +0 -35
  438. v0/relationalai/early_access/builder/snowflake/__init__.py +0 -12
  439. v0/relationalai/early_access/builder/std/__init__.py +0 -25
  440. v0/relationalai/early_access/builder/std/decimals/__init__.py +0 -12
  441. v0/relationalai/early_access/builder/std/integers/__init__.py +0 -12
  442. v0/relationalai/early_access/builder/std/math/__init__.py +0 -12
  443. v0/relationalai/early_access/builder/std/strings/__init__.py +0 -14
  444. v0/relationalai/early_access/devtools/__init__.py +0 -12
  445. v0/relationalai/early_access/devtools/benchmark_lqp/__init__.py +0 -12
  446. v0/relationalai/early_access/devtools/extract_lqp/__init__.py +0 -12
  447. v0/relationalai/early_access/dsl/adapters/orm/adapter_qb.py +0 -427
  448. v0/relationalai/early_access/dsl/adapters/orm/parser.py +0 -636
  449. v0/relationalai/early_access/dsl/adapters/owl/adapter.py +0 -176
  450. v0/relationalai/early_access/dsl/adapters/owl/parser.py +0 -160
  451. v0/relationalai/early_access/dsl/bindings/common.py +0 -402
  452. v0/relationalai/early_access/dsl/bindings/csv.py +0 -170
  453. v0/relationalai/early_access/dsl/bindings/legacy/binding_models.py +0 -143
  454. v0/relationalai/early_access/dsl/bindings/snowflake.py +0 -64
  455. v0/relationalai/early_access/dsl/codegen/binder.py +0 -411
  456. v0/relationalai/early_access/dsl/codegen/common.py +0 -79
  457. v0/relationalai/early_access/dsl/codegen/helpers.py +0 -23
  458. v0/relationalai/early_access/dsl/codegen/relations.py +0 -700
  459. v0/relationalai/early_access/dsl/codegen/weaver.py +0 -417
  460. v0/relationalai/early_access/dsl/core/builders/__init__.py +0 -47
  461. v0/relationalai/early_access/dsl/core/builders/logic.py +0 -19
  462. v0/relationalai/early_access/dsl/core/builders/scalar_constraint.py +0 -11
  463. v0/relationalai/early_access/dsl/core/constraints/predicate/atomic.py +0 -455
  464. v0/relationalai/early_access/dsl/core/constraints/predicate/universal.py +0 -73
  465. v0/relationalai/early_access/dsl/core/constraints/scalar.py +0 -310
  466. v0/relationalai/early_access/dsl/core/context.py +0 -13
  467. v0/relationalai/early_access/dsl/core/cset.py +0 -132
  468. v0/relationalai/early_access/dsl/core/exprs/__init__.py +0 -116
  469. v0/relationalai/early_access/dsl/core/exprs/relational.py +0 -18
  470. v0/relationalai/early_access/dsl/core/exprs/scalar.py +0 -412
  471. v0/relationalai/early_access/dsl/core/instances.py +0 -44
  472. v0/relationalai/early_access/dsl/core/logic/__init__.py +0 -193
  473. v0/relationalai/early_access/dsl/core/logic/aggregation.py +0 -98
  474. v0/relationalai/early_access/dsl/core/logic/exists.py +0 -223
  475. v0/relationalai/early_access/dsl/core/logic/helper.py +0 -163
  476. v0/relationalai/early_access/dsl/core/namespaces.py +0 -32
  477. v0/relationalai/early_access/dsl/core/relations.py +0 -276
  478. v0/relationalai/early_access/dsl/core/rules.py +0 -112
  479. v0/relationalai/early_access/dsl/core/std/__init__.py +0 -45
  480. v0/relationalai/early_access/dsl/core/temporal/recall.py +0 -6
  481. v0/relationalai/early_access/dsl/core/types/__init__.py +0 -270
  482. v0/relationalai/early_access/dsl/core/types/concepts.py +0 -128
  483. v0/relationalai/early_access/dsl/core/types/constrained/__init__.py +0 -267
  484. v0/relationalai/early_access/dsl/core/types/constrained/nominal.py +0 -143
  485. v0/relationalai/early_access/dsl/core/types/constrained/subtype.py +0 -124
  486. v0/relationalai/early_access/dsl/core/types/standard.py +0 -92
  487. v0/relationalai/early_access/dsl/core/types/unconstrained.py +0 -50
  488. v0/relationalai/early_access/dsl/core/types/variables.py +0 -203
  489. v0/relationalai/early_access/dsl/ir/compiler.py +0 -318
  490. v0/relationalai/early_access/dsl/ir/executor.py +0 -260
  491. v0/relationalai/early_access/dsl/ontologies/constraints.py +0 -88
  492. v0/relationalai/early_access/dsl/ontologies/export.py +0 -30
  493. v0/relationalai/early_access/dsl/ontologies/models.py +0 -453
  494. v0/relationalai/early_access/dsl/ontologies/python_printer.py +0 -303
  495. v0/relationalai/early_access/dsl/ontologies/readings.py +0 -60
  496. v0/relationalai/early_access/dsl/ontologies/relationships.py +0 -322
  497. v0/relationalai/early_access/dsl/ontologies/roles.py +0 -87
  498. v0/relationalai/early_access/dsl/ontologies/subtyping.py +0 -55
  499. v0/relationalai/early_access/dsl/orm/constraints.py +0 -438
  500. v0/relationalai/early_access/dsl/orm/measures/dimensions.py +0 -200
  501. v0/relationalai/early_access/dsl/orm/measures/initializer.py +0 -16
  502. v0/relationalai/early_access/dsl/orm/measures/measure_rules.py +0 -275
  503. v0/relationalai/early_access/dsl/orm/measures/measures.py +0 -299
  504. v0/relationalai/early_access/dsl/orm/measures/role_exprs.py +0 -268
  505. v0/relationalai/early_access/dsl/orm/models.py +0 -256
  506. v0/relationalai/early_access/dsl/orm/object_oriented_printer.py +0 -344
  507. v0/relationalai/early_access/dsl/orm/printer.py +0 -469
  508. v0/relationalai/early_access/dsl/orm/reasoners.py +0 -480
  509. v0/relationalai/early_access/dsl/orm/relations.py +0 -19
  510. v0/relationalai/early_access/dsl/orm/relationships.py +0 -251
  511. v0/relationalai/early_access/dsl/orm/types.py +0 -42
  512. v0/relationalai/early_access/dsl/orm/utils.py +0 -79
  513. v0/relationalai/early_access/dsl/orm/verb.py +0 -204
  514. v0/relationalai/early_access/dsl/physical_metadata/tables.py +0 -133
  515. v0/relationalai/early_access/dsl/relations.py +0 -170
  516. v0/relationalai/early_access/dsl/rulesets.py +0 -69
  517. v0/relationalai/early_access/dsl/schemas/__init__.py +0 -450
  518. v0/relationalai/early_access/dsl/schemas/builder.py +0 -48
  519. v0/relationalai/early_access/dsl/schemas/comp_names.py +0 -51
  520. v0/relationalai/early_access/dsl/schemas/components.py +0 -203
  521. v0/relationalai/early_access/dsl/schemas/contexts.py +0 -156
  522. v0/relationalai/early_access/dsl/schemas/exprs.py +0 -89
  523. v0/relationalai/early_access/dsl/schemas/fragments.py +0 -464
  524. v0/relationalai/early_access/dsl/serialization.py +0 -79
  525. v0/relationalai/early_access/dsl/serialize/exporter.py +0 -163
  526. v0/relationalai/early_access/dsl/snow/api.py +0 -104
  527. v0/relationalai/early_access/dsl/snow/common.py +0 -76
  528. v0/relationalai/early_access/dsl/state_mgmt/__init__.py +0 -129
  529. v0/relationalai/early_access/dsl/state_mgmt/state_charts.py +0 -125
  530. v0/relationalai/early_access/dsl/state_mgmt/transitions.py +0 -130
  531. v0/relationalai/early_access/dsl/types/__init__.py +0 -40
  532. v0/relationalai/early_access/dsl/types/concepts.py +0 -12
  533. v0/relationalai/early_access/dsl/types/entities.py +0 -135
  534. v0/relationalai/early_access/dsl/types/values.py +0 -17
  535. v0/relationalai/early_access/dsl/utils.py +0 -102
  536. v0/relationalai/early_access/graphs/__init__.py +0 -13
  537. v0/relationalai/early_access/lqp/__init__.py +0 -12
  538. v0/relationalai/early_access/lqp/compiler/__init__.py +0 -12
  539. v0/relationalai/early_access/lqp/constructors/__init__.py +0 -18
  540. v0/relationalai/early_access/lqp/executor/__init__.py +0 -12
  541. v0/relationalai/early_access/lqp/ir/__init__.py +0 -12
  542. v0/relationalai/early_access/lqp/passes/__init__.py +0 -12
  543. v0/relationalai/early_access/lqp/pragmas/__init__.py +0 -12
  544. v0/relationalai/early_access/lqp/primitives/__init__.py +0 -12
  545. v0/relationalai/early_access/lqp/types/__init__.py +0 -12
  546. v0/relationalai/early_access/lqp/utils/__init__.py +0 -12
  547. v0/relationalai/early_access/lqp/validators/__init__.py +0 -12
  548. v0/relationalai/early_access/metamodel/__init__.py +0 -58
  549. v0/relationalai/early_access/metamodel/builtins/__init__.py +0 -12
  550. v0/relationalai/early_access/metamodel/compiler/__init__.py +0 -12
  551. v0/relationalai/early_access/metamodel/dependency/__init__.py +0 -12
  552. v0/relationalai/early_access/metamodel/factory/__init__.py +0 -17
  553. v0/relationalai/early_access/metamodel/helpers/__init__.py +0 -12
  554. v0/relationalai/early_access/metamodel/ir/__init__.py +0 -14
  555. v0/relationalai/early_access/metamodel/rewrite/__init__.py +0 -7
  556. v0/relationalai/early_access/metamodel/typer/__init__.py +0 -3
  557. v0/relationalai/early_access/metamodel/typer/typer/__init__.py +0 -12
  558. v0/relationalai/early_access/metamodel/types/__init__.py +0 -15
  559. v0/relationalai/early_access/metamodel/util/__init__.py +0 -15
  560. v0/relationalai/early_access/metamodel/visitor/__init__.py +0 -12
  561. v0/relationalai/early_access/rel/__init__.py +0 -12
  562. v0/relationalai/early_access/rel/executor/__init__.py +0 -12
  563. v0/relationalai/early_access/rel/rel_utils/__init__.py +0 -12
  564. v0/relationalai/early_access/rel/rewrite/__init__.py +0 -7
  565. v0/relationalai/early_access/solvers/__init__.py +0 -19
  566. v0/relationalai/early_access/sql/__init__.py +0 -11
  567. v0/relationalai/early_access/sql/executor/__init__.py +0 -3
  568. v0/relationalai/early_access/sql/rewrite/__init__.py +0 -3
  569. v0/relationalai/early_access/tests/logging/__init__.py +0 -12
  570. v0/relationalai/early_access/tests/test_snapshot_base/__init__.py +0 -12
  571. v0/relationalai/early_access/tests/utils/__init__.py +0 -12
  572. v0/relationalai/environments/__init__.py +0 -35
  573. v0/relationalai/environments/base.py +0 -381
  574. v0/relationalai/environments/colab.py +0 -14
  575. v0/relationalai/environments/generic.py +0 -71
  576. v0/relationalai/environments/ipython.py +0 -68
  577. v0/relationalai/environments/jupyter.py +0 -9
  578. v0/relationalai/environments/snowbook.py +0 -169
  579. v0/relationalai/errors.py +0 -2455
  580. v0/relationalai/experimental/SF.py +0 -38
  581. v0/relationalai/experimental/inspect.py +0 -47
  582. v0/relationalai/experimental/pathfinder/__init__.py +0 -158
  583. v0/relationalai/experimental/pathfinder/api.py +0 -160
  584. v0/relationalai/experimental/pathfinder/automaton.py +0 -584
  585. v0/relationalai/experimental/pathfinder/bridge.py +0 -226
  586. v0/relationalai/experimental/pathfinder/compiler.py +0 -416
  587. v0/relationalai/experimental/pathfinder/datalog.py +0 -214
  588. v0/relationalai/experimental/pathfinder/diagnostics.py +0 -56
  589. v0/relationalai/experimental/pathfinder/filter.py +0 -236
  590. v0/relationalai/experimental/pathfinder/glushkov.py +0 -439
  591. v0/relationalai/experimental/pathfinder/options.py +0 -265
  592. v0/relationalai/experimental/pathfinder/rpq.py +0 -344
  593. v0/relationalai/experimental/pathfinder/transition.py +0 -200
  594. v0/relationalai/experimental/pathfinder/utils.py +0 -26
  595. v0/relationalai/experimental/paths/api.py +0 -143
  596. v0/relationalai/experimental/paths/benchmarks/grid_graph.py +0 -37
  597. v0/relationalai/experimental/paths/examples/basic_example.py +0 -40
  598. v0/relationalai/experimental/paths/examples/minimal_engine_warmup.py +0 -3
  599. v0/relationalai/experimental/paths/examples/movie_example.py +0 -77
  600. v0/relationalai/experimental/paths/examples/paths_benchmark.py +0 -115
  601. v0/relationalai/experimental/paths/examples/paths_example.py +0 -116
  602. v0/relationalai/experimental/paths/examples/pattern_to_automaton.py +0 -28
  603. v0/relationalai/experimental/paths/find_paths_via_automaton.py +0 -85
  604. v0/relationalai/experimental/paths/graph.py +0 -185
  605. v0/relationalai/experimental/paths/path_algorithms/find_paths.py +0 -280
  606. v0/relationalai/experimental/paths/path_algorithms/one_sided_ball_repetition.py +0 -26
  607. v0/relationalai/experimental/paths/path_algorithms/one_sided_ball_upto.py +0 -111
  608. v0/relationalai/experimental/paths/path_algorithms/single.py +0 -59
  609. v0/relationalai/experimental/paths/path_algorithms/two_sided_balls_repetition.py +0 -39
  610. v0/relationalai/experimental/paths/path_algorithms/two_sided_balls_upto.py +0 -103
  611. v0/relationalai/experimental/paths/path_algorithms/usp-old.py +0 -130
  612. v0/relationalai/experimental/paths/path_algorithms/usp-tuple.py +0 -183
  613. v0/relationalai/experimental/paths/path_algorithms/usp.py +0 -150
  614. v0/relationalai/experimental/paths/product_graph.py +0 -93
  615. v0/relationalai/experimental/paths/rpq/automaton.py +0 -584
  616. v0/relationalai/experimental/paths/rpq/diagnostics.py +0 -56
  617. v0/relationalai/experimental/paths/rpq/rpq.py +0 -378
  618. v0/relationalai/experimental/paths/tests/tests_limit_sp_max_length.py +0 -90
  619. v0/relationalai/experimental/paths/tests/tests_limit_sp_multiple.py +0 -119
  620. v0/relationalai/experimental/paths/tests/tests_limit_sp_single.py +0 -104
  621. v0/relationalai/experimental/paths/tests/tests_limit_walks_multiple.py +0 -113
  622. v0/relationalai/experimental/paths/tests/tests_limit_walks_single.py +0 -149
  623. v0/relationalai/experimental/paths/tests/tests_one_sided_ball_repetition_multiple.py +0 -70
  624. v0/relationalai/experimental/paths/tests/tests_one_sided_ball_repetition_single.py +0 -64
  625. v0/relationalai/experimental/paths/tests/tests_one_sided_ball_upto_multiple.py +0 -115
  626. v0/relationalai/experimental/paths/tests/tests_one_sided_ball_upto_single.py +0 -75
  627. v0/relationalai/experimental/paths/tests/tests_single_paths.py +0 -152
  628. v0/relationalai/experimental/paths/tests/tests_single_walks.py +0 -208
  629. v0/relationalai/experimental/paths/tests/tests_single_walks_undirected.py +0 -297
  630. v0/relationalai/experimental/paths/tests/tests_two_sided_balls_repetition_multiple.py +0 -107
  631. v0/relationalai/experimental/paths/tests/tests_two_sided_balls_repetition_single.py +0 -76
  632. v0/relationalai/experimental/paths/tests/tests_two_sided_balls_upto_multiple.py +0 -76
  633. v0/relationalai/experimental/paths/tests/tests_two_sided_balls_upto_single.py +0 -110
  634. v0/relationalai/experimental/paths/tests/tests_usp_nsp_multiple.py +0 -229
  635. v0/relationalai/experimental/paths/tests/tests_usp_nsp_single.py +0 -108
  636. v0/relationalai/experimental/paths/tree_agg.py +0 -168
  637. v0/relationalai/experimental/paths/utilities/iterators.py +0 -27
  638. v0/relationalai/experimental/paths/utilities/prefix_sum.py +0 -91
  639. v0/relationalai/experimental/solvers.py +0 -1087
  640. v0/relationalai/loaders/csv.py +0 -195
  641. v0/relationalai/loaders/loader.py +0 -177
  642. v0/relationalai/loaders/types.py +0 -23
  643. v0/relationalai/rel_emitter.py +0 -373
  644. v0/relationalai/rel_utils.py +0 -185
  645. v0/relationalai/semantics/__init__.py +0 -29
  646. v0/relationalai/semantics/devtools/benchmark_lqp.py +0 -536
  647. v0/relationalai/semantics/devtools/compilation_manager.py +0 -294
  648. v0/relationalai/semantics/devtools/extract_lqp.py +0 -110
  649. v0/relationalai/semantics/internal/internal.py +0 -3785
  650. v0/relationalai/semantics/internal/snowflake.py +0 -324
  651. v0/relationalai/semantics/lqp/builtins.py +0 -16
  652. v0/relationalai/semantics/lqp/compiler.py +0 -22
  653. v0/relationalai/semantics/lqp/constructors.py +0 -68
  654. v0/relationalai/semantics/lqp/executor.py +0 -469
  655. v0/relationalai/semantics/lqp/intrinsics.py +0 -24
  656. v0/relationalai/semantics/lqp/model2lqp.py +0 -839
  657. v0/relationalai/semantics/lqp/passes.py +0 -680
  658. v0/relationalai/semantics/lqp/primitives.py +0 -252
  659. v0/relationalai/semantics/lqp/result_helpers.py +0 -202
  660. v0/relationalai/semantics/lqp/rewrite/annotate_constraints.py +0 -57
  661. v0/relationalai/semantics/lqp/rewrite/cdc.py +0 -216
  662. v0/relationalai/semantics/lqp/rewrite/extract_common.py +0 -338
  663. v0/relationalai/semantics/lqp/rewrite/extract_keys.py +0 -449
  664. v0/relationalai/semantics/lqp/rewrite/function_annotations.py +0 -114
  665. v0/relationalai/semantics/lqp/rewrite/functional_dependencies.py +0 -314
  666. v0/relationalai/semantics/lqp/rewrite/quantify_vars.py +0 -296
  667. v0/relationalai/semantics/lqp/rewrite/splinter.py +0 -76
  668. v0/relationalai/semantics/lqp/types.py +0 -101
  669. v0/relationalai/semantics/lqp/utils.py +0 -160
  670. v0/relationalai/semantics/lqp/validators.py +0 -57
  671. v0/relationalai/semantics/metamodel/__init__.py +0 -40
  672. v0/relationalai/semantics/metamodel/builtins.py +0 -774
  673. v0/relationalai/semantics/metamodel/compiler.py +0 -133
  674. v0/relationalai/semantics/metamodel/dependency.py +0 -862
  675. v0/relationalai/semantics/metamodel/executor.py +0 -61
  676. v0/relationalai/semantics/metamodel/factory.py +0 -287
  677. v0/relationalai/semantics/metamodel/helpers.py +0 -361
  678. v0/relationalai/semantics/metamodel/rewrite/discharge_constraints.py +0 -39
  679. v0/relationalai/semantics/metamodel/rewrite/dnf_union_splitter.py +0 -210
  680. v0/relationalai/semantics/metamodel/rewrite/extract_nested_logicals.py +0 -78
  681. v0/relationalai/semantics/metamodel/rewrite/flatten.py +0 -549
  682. v0/relationalai/semantics/metamodel/rewrite/format_outputs.py +0 -165
  683. v0/relationalai/semantics/metamodel/typer/checker.py +0 -353
  684. v0/relationalai/semantics/metamodel/typer/typer.py +0 -1395
  685. v0/relationalai/semantics/metamodel/util.py +0 -505
  686. v0/relationalai/semantics/reasoners/__init__.py +0 -10
  687. v0/relationalai/semantics/reasoners/graph/__init__.py +0 -37
  688. v0/relationalai/semantics/reasoners/graph/core.py +0 -9020
  689. v0/relationalai/semantics/reasoners/optimization/__init__.py +0 -68
  690. v0/relationalai/semantics/reasoners/optimization/common.py +0 -88
  691. v0/relationalai/semantics/reasoners/optimization/solvers_dev.py +0 -568
  692. v0/relationalai/semantics/reasoners/optimization/solvers_pb.py +0 -1163
  693. v0/relationalai/semantics/rel/builtins.py +0 -40
  694. v0/relationalai/semantics/rel/compiler.py +0 -989
  695. v0/relationalai/semantics/rel/executor.py +0 -359
  696. v0/relationalai/semantics/rel/rel.py +0 -482
  697. v0/relationalai/semantics/rel/rel_utils.py +0 -276
  698. v0/relationalai/semantics/snowflake/__init__.py +0 -3
  699. v0/relationalai/semantics/sql/compiler.py +0 -2503
  700. v0/relationalai/semantics/sql/executor/duck_db.py +0 -52
  701. v0/relationalai/semantics/sql/executor/result_helpers.py +0 -64
  702. v0/relationalai/semantics/sql/executor/snowflake.py +0 -145
  703. v0/relationalai/semantics/sql/rewrite/denormalize.py +0 -222
  704. v0/relationalai/semantics/sql/rewrite/double_negation.py +0 -49
  705. v0/relationalai/semantics/sql/rewrite/recursive_union.py +0 -127
  706. v0/relationalai/semantics/sql/rewrite/sort_output_query.py +0 -246
  707. v0/relationalai/semantics/sql/sql.py +0 -504
  708. v0/relationalai/semantics/std/__init__.py +0 -54
  709. v0/relationalai/semantics/std/constraints.py +0 -43
  710. v0/relationalai/semantics/std/datetime.py +0 -363
  711. v0/relationalai/semantics/std/decimals.py +0 -62
  712. v0/relationalai/semantics/std/floats.py +0 -7
  713. v0/relationalai/semantics/std/integers.py +0 -22
  714. v0/relationalai/semantics/std/math.py +0 -141
  715. v0/relationalai/semantics/std/pragmas.py +0 -11
  716. v0/relationalai/semantics/std/re.py +0 -83
  717. v0/relationalai/semantics/std/std.py +0 -14
  718. v0/relationalai/semantics/std/strings.py +0 -63
  719. v0/relationalai/semantics/tests/__init__.py +0 -0
  720. v0/relationalai/semantics/tests/test_snapshot_abstract.py +0 -143
  721. v0/relationalai/semantics/tests/test_snapshot_base.py +0 -9
  722. v0/relationalai/semantics/tests/utils.py +0 -46
  723. v0/relationalai/std/__init__.py +0 -70
  724. v0/relationalai/tools/__init__.py +0 -0
  725. v0/relationalai/tools/cli.py +0 -1940
  726. v0/relationalai/tools/cli_controls.py +0 -1826
  727. v0/relationalai/tools/cli_helpers.py +0 -390
  728. v0/relationalai/tools/debugger.py +0 -183
  729. v0/relationalai/tools/debugger_client.py +0 -109
  730. v0/relationalai/tools/debugger_server.py +0 -302
  731. v0/relationalai/tools/dev.py +0 -685
  732. v0/relationalai/tools/qb_debugger.py +0 -425
  733. v0/relationalai/util/clean_up_databases.py +0 -95
  734. v0/relationalai/util/format.py +0 -123
  735. v0/relationalai/util/list_databases.py +0 -9
  736. v0/relationalai/util/otel_configuration.py +0 -25
  737. v0/relationalai/util/otel_handler.py +0 -484
  738. v0/relationalai/util/snowflake_handler.py +0 -88
  739. v0/relationalai/util/span_format_test.py +0 -43
  740. v0/relationalai/util/span_tracker.py +0 -207
  741. v0/relationalai/util/spans_file_handler.py +0 -72
  742. v0/relationalai/util/tracing_handler.py +0 -34
  743. /relationalai/{semantics/frontend → analysis}/__init__.py +0 -0
  744. {v0/relationalai → relationalai}/analysis/mechanistic.py +0 -0
  745. {v0/relationalai → relationalai}/analysis/whynot.py +0 -0
  746. /relationalai/{shims → auth}/__init__.py +0 -0
  747. {v0/relationalai → relationalai}/auth/jwt_generator.py +0 -0
  748. {v0/relationalai → relationalai}/auth/oauth_callback_server.py +0 -0
  749. {v0/relationalai → relationalai}/auth/token_handler.py +0 -0
  750. {v0/relationalai → relationalai}/auth/util.py +0 -0
  751. {v0/relationalai/clients → relationalai/clients/resources/snowflake}/cache_store.py +0 -0
  752. {v0/relationalai → relationalai}/compiler.py +0 -0
  753. {v0/relationalai → relationalai}/dependencies.py +0 -0
  754. {v0/relationalai → relationalai}/docutils.py +0 -0
  755. {v0/relationalai/analysis → relationalai/early_access}/__init__.py +0 -0
  756. {v0/relationalai → relationalai}/early_access/dsl/__init__.py +0 -0
  757. {v0/relationalai/auth → relationalai/early_access/dsl/adapters}/__init__.py +0 -0
  758. {v0/relationalai/early_access → relationalai/early_access/dsl/adapters/orm}/__init__.py +0 -0
  759. {v0/relationalai → relationalai}/early_access/dsl/adapters/orm/model.py +0 -0
  760. {v0/relationalai/early_access/dsl/adapters → relationalai/early_access/dsl/adapters/owl}/__init__.py +0 -0
  761. {v0/relationalai → relationalai}/early_access/dsl/adapters/owl/model.py +0 -0
  762. {v0/relationalai/early_access/dsl/adapters/orm → relationalai/early_access/dsl/bindings}/__init__.py +0 -0
  763. {v0/relationalai/early_access/dsl/adapters/owl → relationalai/early_access/dsl/bindings/legacy}/__init__.py +0 -0
  764. {v0/relationalai/early_access/dsl/bindings → relationalai/early_access/dsl/codegen}/__init__.py +0 -0
  765. {v0/relationalai → relationalai}/early_access/dsl/constants.py +0 -0
  766. {v0/relationalai → relationalai}/early_access/dsl/core/__init__.py +0 -0
  767. {v0/relationalai → relationalai}/early_access/dsl/core/constraints/__init__.py +0 -0
  768. {v0/relationalai → relationalai}/early_access/dsl/core/constraints/predicate/__init__.py +0 -0
  769. {v0/relationalai → relationalai}/early_access/dsl/core/stack.py +0 -0
  770. {v0/relationalai/early_access/dsl/bindings/legacy → relationalai/early_access/dsl/core/temporal}/__init__.py +0 -0
  771. {v0/relationalai → relationalai}/early_access/dsl/core/utils.py +0 -0
  772. {v0/relationalai/early_access/dsl/codegen → relationalai/early_access/dsl/ir}/__init__.py +0 -0
  773. {v0/relationalai/early_access/dsl/core/temporal → relationalai/early_access/dsl/ontologies}/__init__.py +0 -0
  774. {v0/relationalai → relationalai}/early_access/dsl/ontologies/raw_source.py +0 -0
  775. {v0/relationalai/early_access/dsl/ir → relationalai/early_access/dsl/orm}/__init__.py +0 -0
  776. {v0/relationalai/early_access/dsl/ontologies → relationalai/early_access/dsl/orm/measures}/__init__.py +0 -0
  777. {v0/relationalai → relationalai}/early_access/dsl/orm/reasoner_errors.py +0 -0
  778. {v0/relationalai/early_access/dsl/orm → relationalai/early_access/dsl/physical_metadata}/__init__.py +0 -0
  779. {v0/relationalai/early_access/dsl/orm/measures → relationalai/early_access/dsl/serialize}/__init__.py +0 -0
  780. {v0/relationalai → relationalai}/early_access/dsl/serialize/binding_model.py +0 -0
  781. {v0/relationalai → relationalai}/early_access/dsl/serialize/model.py +0 -0
  782. {v0/relationalai/early_access/dsl/physical_metadata → relationalai/early_access/dsl/snow}/__init__.py +0 -0
  783. {v0/relationalai → relationalai}/early_access/tests/__init__.py +0 -0
  784. {v0/relationalai → relationalai}/environments/ci.py +0 -0
  785. {v0/relationalai → relationalai}/environments/hex.py +0 -0
  786. {v0/relationalai → relationalai}/environments/terminal.py +0 -0
  787. {v0/relationalai → relationalai}/experimental/__init__.py +0 -0
  788. {v0/relationalai → relationalai}/experimental/graphs.py +0 -0
  789. {v0/relationalai → relationalai}/experimental/paths/__init__.py +0 -0
  790. {v0/relationalai → relationalai}/experimental/paths/benchmarks/__init__.py +0 -0
  791. {v0/relationalai → relationalai}/experimental/paths/path_algorithms/__init__.py +0 -0
  792. {v0/relationalai → relationalai}/experimental/paths/rpq/__init__.py +0 -0
  793. {v0/relationalai → relationalai}/experimental/paths/rpq/filter.py +0 -0
  794. {v0/relationalai → relationalai}/experimental/paths/rpq/glushkov.py +0 -0
  795. {v0/relationalai → relationalai}/experimental/paths/rpq/transition.py +0 -0
  796. {v0/relationalai → relationalai}/experimental/paths/utilities/__init__.py +0 -0
  797. {v0/relationalai → relationalai}/experimental/paths/utilities/utilities.py +0 -0
  798. {v0/relationalai/early_access/dsl/serialize → relationalai/loaders}/__init__.py +0 -0
  799. {v0/relationalai → relationalai}/metagen.py +0 -0
  800. {v0/relationalai → relationalai}/metamodel.py +0 -0
  801. {v0/relationalai → relationalai}/rel.py +0 -0
  802. {v0/relationalai → relationalai}/semantics/devtools/__init__.py +0 -0
  803. {v0/relationalai → relationalai}/semantics/internal/__init__.py +0 -0
  804. {v0/relationalai → relationalai}/semantics/internal/annotations.py +0 -0
  805. {v0/relationalai → relationalai}/semantics/lqp/__init__.py +0 -0
  806. {v0/relationalai → relationalai}/semantics/lqp/ir.py +0 -0
  807. {v0/relationalai → relationalai}/semantics/lqp/pragmas.py +0 -0
  808. {v0/relationalai → relationalai}/semantics/lqp/rewrite/__init__.py +0 -0
  809. {v0/relationalai → relationalai}/semantics/metamodel/dataflow.py +0 -0
  810. {v0/relationalai → relationalai}/semantics/metamodel/ir.py +0 -0
  811. {v0/relationalai → relationalai}/semantics/metamodel/rewrite/__init__.py +0 -0
  812. {v0/relationalai → relationalai}/semantics/metamodel/typer/__init__.py +0 -0
  813. {v0/relationalai → relationalai}/semantics/metamodel/types.py +0 -0
  814. {v0/relationalai → relationalai}/semantics/metamodel/visitor.py +0 -0
  815. {v0/relationalai → relationalai}/semantics/reasoners/experimental/__init__.py +0 -0
  816. {v0/relationalai → relationalai}/semantics/rel/__init__.py +0 -0
  817. {v0/relationalai → relationalai}/semantics/sql/__init__.py +0 -0
  818. {v0/relationalai → relationalai}/semantics/sql/executor/__init__.py +0 -0
  819. {v0/relationalai → relationalai}/semantics/sql/rewrite/__init__.py +0 -0
  820. {v0/relationalai/early_access/dsl/snow → relationalai/semantics/tests}/__init__.py +0 -0
  821. {v0/relationalai → relationalai}/semantics/tests/logging.py +0 -0
  822. {v0/relationalai → relationalai}/std/aggregates.py +0 -0
  823. {v0/relationalai → relationalai}/std/dates.py +0 -0
  824. {v0/relationalai → relationalai}/std/graphs.py +0 -0
  825. {v0/relationalai → relationalai}/std/inspect.py +0 -0
  826. {v0/relationalai → relationalai}/std/math.py +0 -0
  827. {v0/relationalai → relationalai}/std/re.py +0 -0
  828. {v0/relationalai → relationalai}/std/strings.py +0 -0
  829. {v0/relationalai/loaders → relationalai/tools}/__init__.py +0 -0
  830. {v0/relationalai → relationalai}/tools/cleanup_snapshots.py +0 -0
  831. {v0/relationalai → relationalai}/tools/constants.py +0 -0
  832. {v0/relationalai → relationalai}/tools/query_utils.py +0 -0
  833. {v0/relationalai → relationalai}/tools/snapshot_viewer.py +0 -0
  834. {v0/relationalai → relationalai}/util/__init__.py +0 -0
  835. {v0/relationalai → relationalai}/util/constants.py +0 -0
  836. {v0/relationalai → relationalai}/util/graph.py +0 -0
  837. {v0/relationalai → relationalai}/util/timeout.py +0 -0
@@ -0,0 +1,1936 @@
1
+ #pyright: reportPrivateImportUsage=false
2
+ from __future__ import annotations
3
+ import os
4
+ import re
5
+ import sys
6
+ import rich
7
+ import json
8
+ import click
9
+ import shlex
10
+ from pathlib import Path
11
+ from rich.table import Table
12
+ from datetime import datetime
13
+ from rich import box as rich_box
14
+ from InquirerPy.base.control import Choice
15
+
16
+ from relationalai.clients.util import IdentityParser
17
+ from .cli_controls import divider, Spinner
18
+ from . import cli_controls as controls
19
+ from typing import Sequence, cast, Any, List, TYPE_CHECKING
20
+
21
+ if TYPE_CHECKING:
22
+ from relationalai.clients import azure
23
+ from relationalai.errors import RAIException
24
+ from relationalai.loaders.types import LoadType, UnsupportedTypeError
25
+ from relationalai.loaders.csv import CSVLoader
26
+ from relationalai.loaders.loader import Loader, rel_schema_to_type
27
+ from ..clients.types import ImportSource, ImportSourceFile, ImportSourceTable
28
+ from ..clients.client import ResourcesBase
29
+ from ..tools import debugger as deb, qb_debugger as qb_deb
30
+ from ..clients import config
31
+ from relationalai.tools.constants import RAI_APP_NAME
32
+ from relationalai.clients.resources.snowflake.cli_resources import CLIResources
33
+ from relationalai.tools.cli_helpers import (
34
+ EMPTY_STRING_REGEX,
35
+ ENGINE_NAME_ERROR,
36
+ ENGINE_NAME_REGEX,
37
+ PASSCODE_REGEX,
38
+ UUID,
39
+ RichGroup,
40
+ account_from_url,
41
+ coming_soon,
42
+ ensure_config,
43
+ exit_with_divider,
44
+ exit_with_error,
45
+ filter_profiles_by_platform,
46
+ format_row,
47
+ get_config, get_resource_provider,
48
+ is_latest_cli_version,
49
+ issue_top_level_profile_warning,
50
+ latest_version,
51
+ show_dictionary_table,
52
+ show_engines,
53
+ show_imports,
54
+ show_transactions,
55
+ supports_platform,
56
+ unexpand_user_path,
57
+ validate_engine_name
58
+ )
59
+ from ..clients.config import (
60
+ FIELD_PLACEHOLDER,
61
+ CONFIG_FILE,
62
+ ConfigStore,
63
+ all_configs_including_legacy,
64
+ get_from_snowflake_connections_toml,
65
+ azure_default_props,
66
+ map_toml_value,
67
+ SNOWFLAKE_AUTHS,
68
+ )
69
+ from relationalai.tools.constants import AZURE, AZURE_ENVS, CONTEXT_SETTINGS, SNOWFLAKE, SNOWFLAKE_AUTHENTICATOR, GlobalProfile
70
+ from relationalai.util.constants import DEFAULT_PROFILE_NAME, PARTIAL_PROFILE_NAME, TOP_LEVEL_PROFILE_NAME
71
+ from packaging.version import Version
72
+
73
+
74
+ #--------------------------------------------------
75
+ # Custom Click Option and Argument Types
76
+ #--------------------------------------------------
77
+
78
+ ImportOption = tuple[list[str], str]
79
+
80
+ class ImportOptionsType(click.ParamType):
81
+ def __init__(self):
82
+ self.options = {}
83
+
84
+ name = "import_options"
85
+ def convert(self, value: Any, param, ctx) -> ImportOption:
86
+ if ':' not in value or '=' not in value:
87
+ self.fail(f"'{value}' is not a valid import option.", param, ctx)
88
+ raw_key, val = value.split('=', 1)
89
+ if len(val) == 2 and val[0] == "\\":
90
+ val = val.encode().decode("unicode_escape")
91
+ return (raw_key.split(":"), val)
92
+
93
+ @classmethod
94
+ def reduce(cls, kvs:Sequence[ImportOption]):
95
+ options = {}
96
+ for (key_parts, val) in kvs:
97
+ cur = options
98
+ for part in key_parts[:-1]:
99
+ cur = cur.setdefault(part, {})
100
+ cur[key_parts[-1]] = val
101
+ return options
102
+
103
+ #--------------------------------------------------
104
+ # Main group
105
+ #--------------------------------------------------
106
+
107
+ @click.group(cls=RichGroup, context_settings=CONTEXT_SETTINGS)
108
+ @click.option("--profile", help="Which config profile to use")
109
+ def cli(profile):
110
+ is_latest, _, latest_ver = is_latest_cli_version()
111
+ if not is_latest:
112
+ rich.print()
113
+ rich.print(f"[yellow]RelationalAI version ({latest_ver}) is the latest. Please consider upgrading.[/yellow]")
114
+ GlobalProfile.set(profile)
115
+
116
+ #--------------------------------------------------
117
+ # Init
118
+ #--------------------------------------------------
119
+
120
+ @cli.command(help="Initialize a new project")
121
+ def init():
122
+ init_flow()
123
+
124
+ #--------------------------------------------------
125
+ # Init flow
126
+ #--------------------------------------------------
127
+
128
+ def azure_flow(cfg:config.Config):
129
+ option_selected = check_original_config_flow(cfg, "azure")
130
+ # get the client id and secret
131
+ client_id = controls.text("Client ID:", default=cfg.get("client_id", "") if option_selected else "")
132
+ client_secret = controls.password("Client Secret:", default=cfg.get("client_secret", "") if option_selected else "")
133
+ host = cfg.get("host", "")
134
+ client_credentials_url = cfg.get("client_credentials_url", "")
135
+ if not host or not client_credentials_url:
136
+ env = controls.fuzzy("Select environment:", [*AZURE_ENVS.keys(), "<custom>"])
137
+ if env == "<custom>":
138
+ host = controls.text("Host:")
139
+ client_credentials_url = controls.text("Client Credentials URL:")
140
+ else:
141
+ host = AZURE_ENVS[env]["host"]
142
+ client_credentials_url = AZURE_ENVS[env]["client_credentials_url"]
143
+ # setup the default config
144
+ cfg.fill_in_with_azure_defaults(
145
+ client_id=client_id,
146
+ client_secret=client_secret,
147
+ host=host if host else None,
148
+ client_credentials_url=client_credentials_url if client_credentials_url else None
149
+ )
150
+
151
+ def snowflake_flow(cfg:config.Config):
152
+ pyrel_config = check_original_config_flow(cfg, "snowflake")
153
+ if not pyrel_config:
154
+ check_snowflake_connections_flow(cfg)
155
+
156
+ provider = get_resource_provider("snowflake", cfg)
157
+
158
+ rich.print('\n Please select your Snowflake authentication method.')
159
+ rich.print('\n If the Snowflake user has Multi-Factor Authentication (MFA) enabled, select "USERNAME & PASSWORD (MFA ENABLED)" to enter the MFA passcode.')
160
+ rich.print(' If your Snowflake account supports Single Sign-On, please select "SINGLE SIGN-ON (SSO)".\n')
161
+
162
+ cfg_auth = cfg.get("authenticator", "snowflake")
163
+ auth_key = next((key for key, value in SNOWFLAKE_AUTHENTICATOR.items() if value == cfg_auth), None)
164
+
165
+ authenticator = SNOWFLAKE_AUTHENTICATOR[controls.fuzzy(
166
+ "Snowflake Authentication:",
167
+ choices=list(SNOWFLAKE_AUTHENTICATOR.keys()),
168
+ default=auth_key
169
+ )]
170
+ cfg.set("authenticator", authenticator)
171
+
172
+ # setup the authenticator default values in the config
173
+ cfg.fill_in_with_snowflake_defaults(authenticator=authenticator)
174
+
175
+ rich.print('\n Note: Account ID should look like: "<my_org_name>-<my_account_name>" e.g. "org-account123"')
176
+ rich.print(" Details: https://docs.snowflake.com/en/user-guide/admin-account-identifier\n")
177
+ rich.print(" Alternatively, you can log in to Snowsight, copy the URL, and paste it here.")
178
+ rich.print(" Example: https://app.snowflake.com/myorg/account123/worksheets\n")
179
+ account_or_url = controls.text(
180
+ "Snowflake account:",
181
+ default=cfg.get("account", ""),
182
+ validator=EMPTY_STRING_REGEX.match,
183
+ invalid_message="Account is required"
184
+ )
185
+ account = account_from_url(account_or_url)
186
+ if "." in account and "privatelink" not in account:
187
+ rich.print("\n[yellow] Your Account ID should not contain a period (.) character.")
188
+ corrected_account = account.replace(".", "-")
189
+ use_replacement = controls.confirm(f"Use '{corrected_account}' instead", default=True)
190
+ if use_replacement:
191
+ account = corrected_account
192
+ if account_or_url != account:
193
+ rich.print(f"\n[dim] Account ID: {account}")
194
+ cfg.set("account", account)
195
+
196
+ user_prompt = "Snowflake user:"
197
+ invalid_message = "User is required"
198
+ validator = EMPTY_STRING_REGEX.match
199
+
200
+ if authenticator == "externalbrowser":
201
+ rich.print('\n Note: For SSO, the user must match the one specified in the Identity Provider.\n')
202
+
203
+ # get account info
204
+ user = controls.text(
205
+ user_prompt,
206
+ default=cfg.get("user", ""),
207
+ validator = validator,
208
+ invalid_message=invalid_message
209
+ )
210
+ cfg.set("user", user)
211
+
212
+ if authenticator != "externalbrowser":
213
+ password = controls.password("SnowSQL password:", default=cfg.get("password", ""))
214
+ cfg.set("password", password)
215
+
216
+ if authenticator == "username_password_mfa":
217
+ rich.print('\n The MFA passcode can be found in your [cyan]Duo mobile[/cyan] app. Make sure you select the correct account passcode.')
218
+ rich.print(' To learn more about MFA: https://docs.snowflake.com/en/user-guide/security-mfa\n')
219
+ passcode = mfa_passcode_flow(cfg)
220
+ cfg.set("passcode", passcode)
221
+
222
+ if authenticator == "externalbrowser":
223
+ rich.print("")
224
+ try:
225
+ is_id_token = provider.is_account_flag_set("ALLOW_ID_TOKEN")
226
+ if not is_id_token:
227
+ rich.print("\nNote: [yellow2]Connection caching is not enabled in your Snowflake account.")
228
+ rich.print("You'll be prompted for SSO account selection for each request to Snowflake.")
229
+ rich.print("To learn more: https://docs.snowflake.com/en/user-guide/admin-security-fed-auth-use#label-browser-based-sso-connection-caching\n")
230
+ except Exception as e:
231
+ if "SAML Identity Provider account parameter" in f"{e}":
232
+ rich.print(f'[yellow2]Single Sign-On is not enabled on[/yellow2] "{account}" [yellow2]account.')
233
+ exit_with_error("Learn more: https://docs.snowflake.com/en/user-guide/admin-security-fed-auth-security-integration")
234
+ else:
235
+ raise e
236
+
237
+
238
+ # this has to be done here because the account ID must be available:
239
+ if not pyrel_config or cfg.get("engine_size", None) is None:
240
+ engine_size = controls.fuzzy(
241
+ "Select an engine size:",
242
+ choices=[size for size in provider.get_engine_sizes()],
243
+ default=cfg.get_default_engine_size()
244
+ )
245
+ cfg.set("engine_size", engine_size)
246
+
247
+ # init SF specific configuration
248
+ if not pyrel_config or cfg.get("data_freshness_mins", None) is None:
249
+ data_freshness_mins = controls.number(
250
+ "How often should data in RAI be refreshed (minutes)?\n(30 minutes recommended for development, otherwise 0 for data to refreshed on each program execution):",
251
+ default=30,
252
+ min_allowed=0,
253
+ float_allowed=False,
254
+ )
255
+ cfg.set("data_freshness_mins", int(data_freshness_mins))
256
+
257
+ return account
258
+
259
+ def mfa_passcode_flow(cfg:config.Config):
260
+ passcode = controls.text(
261
+ "MFA passcode:",
262
+ validator=PASSCODE_REGEX.match,
263
+ invalid_message="Invalid passcode. MFA passcode should be 6 digits.",
264
+ )
265
+ cfg.set("passcode", passcode)
266
+
267
+ provider = get_resource_provider("snowflake", cfg)
268
+
269
+ is_mfa_cached = False
270
+ try:
271
+ # Run a dummy query to check if the passcode is correct
272
+ is_mfa_cached = provider.is_account_flag_set("ALLOW_CLIENT_MFA_CACHING")
273
+ except Exception as e:
274
+ if "Incorrect passcode was specified" in f"{e}":
275
+ rich.print("")
276
+ rich.print("[yellow]Provided MFA passcode was incorrect")
277
+ rich.print("")
278
+ redo = controls.confirm("Enter fresh passcode from the Duo app?", default=True)
279
+ if redo:
280
+ rich.print("")
281
+ return mfa_passcode_flow(cfg)
282
+ else:
283
+ return ""
284
+ else:
285
+ raise e
286
+
287
+ if not is_mfa_cached:
288
+ rich.print("\nNote: [yellow2]MFA caching is not enabled in your Snowflake account.")
289
+ rich.print("You'll be prompted for approval in the Duo app for each request to Snowflake.")
290
+ rich.print("To learn more: https://docs.snowflake.com/en/user-guide/security-mfa#using-mfa-token-caching-to-minimize-the-number-of-prompts-during-authentication-optional")
291
+ # If MFA caching is not enabled, clear the passcode so that the user is prompted in the Duo app
292
+ passcode = ""
293
+
294
+ return passcode
295
+
296
+ def check_original_config_flow(cfg:config.Config, platform:str):
297
+ all_profiles = {}
298
+ for config_file in all_configs_including_legacy():
299
+ file_path = config_file.path
300
+ plt_config = filter_profiles_by_platform(config_file, platform)
301
+ for profile, props in plt_config.items():
302
+ profile_id = (profile, file_path)
303
+ all_profiles[profile_id] = props
304
+ if platform == "snowflake":
305
+ sf_config = get_from_snowflake_connections_toml()
306
+ if sf_config:
307
+ file_path = os.path.expanduser("~/.snowflake/connections.toml")
308
+ for profile, props in sf_config.items():
309
+ profile_id = (profile, file_path)
310
+ all_profiles[profile_id] = props
311
+ if len(all_profiles) == 0:
312
+ return
313
+ max_profile_name_len = max(len(profile) for profile, _ in all_profiles.keys())
314
+ profile_options: List[Choice] = []
315
+ for profile, props in all_profiles.items():
316
+ formatted_name = f"{profile[0]:<{max_profile_name_len}} {unexpand_user_path(profile[1])}"
317
+ profile_options.append(Choice(value=profile, name=formatted_name))
318
+ selected_profile = controls.select("Start from an existing profile", list(profile_options), None, mandatory=False)
319
+ if not selected_profile:
320
+ return
321
+ cfg.profile = selected_profile[0]
322
+ if cfg.profile == PARTIAL_PROFILE_NAME:
323
+ cfg.profile = TOP_LEVEL_PROFILE_NAME
324
+ cfg.update(all_profiles[selected_profile])
325
+ return True
326
+
327
+ def check_snowflake_connections_flow(cfg:config.Config):
328
+ sf_config = get_from_snowflake_connections_toml()
329
+ if not sf_config or len(sf_config) == 0:
330
+ return
331
+ profiles = list(sf_config.keys())
332
+ if len(profiles) == 0:
333
+ return
334
+ profile = controls.fuzzy("Import a profile from ~/.snowflake/connections.toml", profiles, mandatory=False)
335
+ if not profile:
336
+ return
337
+ cfg.profile = profile
338
+ cfg.update(sf_config[profile])
339
+ return True
340
+
341
+ def role_flow(provider:ResourcesBase, cfg:config.Config):
342
+ roles = cast(CLIResources, provider).list_roles()
343
+ result = controls.fuzzy_with_refetch(
344
+ "Select a role:",
345
+ "roles",
346
+ lambda: [r["name"] for r in roles],
347
+ default=cfg.get("role", None),
348
+ )
349
+ if isinstance(result, Exception):
350
+ return
351
+ else:
352
+ role = result
353
+ cfg.set("role", role or FIELD_PLACEHOLDER)
354
+ provider.reset()
355
+
356
+ def warehouse_flow(provider:ResourcesBase, cfg:config.Config):
357
+ result = controls.fuzzy_with_refetch(
358
+ "Select a warehouse:",
359
+ "warehouses",
360
+ lambda: [w["name"] for w in cast(CLIResources, provider).list_warehouses()],
361
+ default=cfg.get("warehouse", None),
362
+ )
363
+ if not result or isinstance(result, Exception):
364
+ return
365
+ else:
366
+ warehouse = result
367
+ cfg.set("warehouse", warehouse or FIELD_PLACEHOLDER)
368
+
369
+ def rai_app_flow(provider:ResourcesBase, cfg:config.Config):
370
+ auto_select = None
371
+ if provider.config.get("platform") == "snowflake":
372
+ auto_select=RAI_APP_NAME
373
+
374
+ result = controls.fuzzy_with_refetch(
375
+ "Select RelationalAI app name:",
376
+ "apps",
377
+ lambda: [w["name"] for w in cast(CLIResources, provider).list_apps()],
378
+ default=cfg.get("rai_app_name", None),
379
+ auto_select=auto_select
380
+ )
381
+ if not result or isinstance(result, Exception):
382
+ return
383
+ else:
384
+ app = result
385
+ cfg.set("rai_app_name", app or FIELD_PLACEHOLDER)
386
+ provider.reset()
387
+
388
+ def spcs_flow(provider: ResourcesBase, cfg: config.Config):
389
+ role_flow(provider, cfg)
390
+ warehouse_flow(provider, cfg)
391
+ rai_app_flow(provider, cfg)
392
+
393
+ def create_engine(cfg:config.Config, **kwargs):
394
+ provider = get_resource_provider(None, cfg)
395
+ prompt = kwargs.get("prompt", "Select an engine:")
396
+ result = controls.fuzzy_with_refetch(
397
+ prompt,
398
+ "engines",
399
+ lambda: ["[CREATE A NEW ENGINE]"] + [engine.get("name") for engine in provider.list_engines()],
400
+ default=cfg.get("engine", None),
401
+ )
402
+ if not result or isinstance(result, Exception):
403
+ raise Exception("Error fetching engines")
404
+ else:
405
+ engine = result
406
+ if result == "[CREATE A NEW ENGINE]":
407
+ engine = create_engine_flow(cfg)
408
+ rich.print("")
409
+ return engine
410
+
411
+ def engine_flow(provider:ResourcesBase, cfg:config.Config, **kwargs):
412
+ if provider.config.get("platform") == "snowflake":
413
+ app_name = cfg.get("rai_app_name", None)
414
+ if not app_name:
415
+ rich.print("[yellow]App name is required for engine selection. Skipping step.\n")
416
+ raise Exception("App name is required for engine selection")
417
+ warehouse = cfg.get("warehouse", None)
418
+ if not warehouse:
419
+ rich.print("[yellow]Warehouse is required for engine selection. Skipping step.\n")
420
+ raise Exception("Warehouse is required for engine selection")
421
+ prompt = kwargs.get("prompt", "Select an engine:")
422
+ engine = create_engine(cfg, prompt=prompt)
423
+ cfg.set("engine", engine or FIELD_PLACEHOLDER)
424
+
425
+ def gitignore_flow():
426
+ current_dir = Path.cwd()
427
+ prev_dir = None
428
+ while current_dir != prev_dir:
429
+ gitignore_path = current_dir / '.gitignore'
430
+ if gitignore_path.exists():
431
+ # if there is, check to see if raiconfig.toml is in it
432
+ with open(gitignore_path, 'r') as gitignore_file:
433
+ if CONFIG_FILE in gitignore_file.read():
434
+ return
435
+ else:
436
+ # if it's not, ask to add it
437
+ add_to_gitignore = controls.confirm(f"Add {CONFIG_FILE} to .gitignore?", default=True)
438
+ if add_to_gitignore:
439
+ with open(gitignore_path, 'a') as gitignore_file:
440
+ gitignore_file.write(f"\n{CONFIG_FILE}")
441
+ return
442
+ prev_dir = current_dir
443
+ current_dir = current_dir.parent
444
+
445
+ def is_valid_bare_toml_key(key):
446
+ pattern = re.compile(r'^[A-Za-z_][A-Za-z0-9_-]*$')
447
+ return bool(pattern.match(key))
448
+
449
+ def name_profile_flow(cfg: config.Config):
450
+ if cfg.profile != TOP_LEVEL_PROFILE_NAME:
451
+ return
452
+ profile = controls.text("New name for this profile:", default=DEFAULT_PROFILE_NAME)
453
+ if not is_valid_bare_toml_key(profile):
454
+ rich.print(
455
+ "[yellow]Invalid profile name: should contain only alphanumeric characters, dashes, and hyphens"
456
+ )
457
+ return name_profile_flow(cfg)
458
+ config_store = ConfigStore()
459
+ profiles = config_store.get_profiles() or {}
460
+ if profile in profiles:
461
+ overwrite = controls.confirm(f"[yellow]Overwrite existing {profile} profile?")
462
+ if overwrite:
463
+ return profile
464
+ else:
465
+ return name_profile_flow(cfg)
466
+ return profile
467
+
468
+ def save_flow(cfg:config.Config):
469
+ config_store = ConfigStore()
470
+ profiles = config_store.get_profiles() or {}
471
+ if cfg.profile != PARTIAL_PROFILE_NAME and cfg.profile in profiles:
472
+ if not controls.confirm(f"Overwrite existing {cfg.profile} profile"):
473
+ rich.print()
474
+ profile_name = controls.text("Profile name:")
475
+ if profile_name:
476
+ cfg.profile = profile_name
477
+ else:
478
+ save_flow(cfg)
479
+ return
480
+ config_store.add_profile(cfg)
481
+ if cfg.profile != PARTIAL_PROFILE_NAME:
482
+ rich.print()
483
+ if config_store.num_profiles() == 1 or controls.confirm("Activate this profile?"):
484
+ config_store.change_active_profile(cfg.profile)
485
+ config_store.save()
486
+
487
+ def init_flow():
488
+ cfg = config.Config(fetch=False)
489
+ account = None
490
+ try:
491
+ cfg.clone_profile()
492
+ rich.print("\n[dim]---------------------------------------------------\n")
493
+ rich.print("[bold]Welcome to [green]RelationalAI!\n")
494
+ rich.print("Note: [yellow2]To skip a non-mandatory prompt press [bold]Control-S[/bold]\n")
495
+
496
+ if ConfigStore().get("platform"):
497
+ issue_top_level_profile_warning()
498
+
499
+ platform = controls.fuzzy("Host platform:", choices=[SNOWFLAKE, AZURE])
500
+ cfg.set("platform", {
501
+ SNOWFLAKE: "snowflake",
502
+ AZURE: "azure"
503
+ }[platform])
504
+
505
+ if platform == SNOWFLAKE:
506
+ account = snowflake_flow(cfg)
507
+ elif platform == AZURE:
508
+ azure_flow(cfg)
509
+ elif platform:
510
+ rich.print("[yellow]Initialization aborted!")
511
+ rich.print(f"[yellow]Unknown platform: {platform}")
512
+ return
513
+
514
+ provider = get_resource_provider(None, cfg)
515
+
516
+ rich.print()
517
+ if platform == SNOWFLAKE:
518
+ spcs_flow(provider, cfg)
519
+ else: # We auto create engines in SPCS flow so no need to do it here
520
+ engine_flow(provider, cfg)
521
+ profile = name_profile_flow(cfg)
522
+ if profile:
523
+ cfg.profile = profile
524
+ save_flow(cfg)
525
+
526
+ gitignore_flow()
527
+ rich.print("")
528
+ rich.print(f"[green]✓ {CONFIG_FILE} saved!")
529
+ rich.print("\n[dim]---------------------------------------------------\n")
530
+ except Exception as e:
531
+ msg = "[yellow bold]Initialization aborted!\n"
532
+ rich.print("")
533
+ if ("Incorrect passcode was specified" in f"{e}"):
534
+ rich.print("[yellow]Incorrect MFA passcode specified. Please provide a fresh passcode from the Duo app.")
535
+ rich.print('Note: Check if "MFA caching" is enabled in your Snowflake account if this error occurs frequently.\n')
536
+ if ("250001: Could not connect to Snowflake backend" in f"{e}"):
537
+ rich.print("[yellow]Failed to establish connection to the provided account. Please verify the account name.")
538
+ if account and "." in account and "privatelink" not in account:
539
+ corrected_account = account.replace(".", "-")
540
+ rich.print(f"\n[yellow]Note: the account ID format that Snowflake expects in this context uses a dash (-) \nrather than a period (.) to separate the org name and account name. \n\nConsider using {corrected_account} instead.")
541
+ else:
542
+ rich.print(msg)
543
+ print(e.with_traceback(None))
544
+ rich.print("")
545
+
546
+ save = controls.confirm("Save partial config?")
547
+ if save:
548
+ cfg.profile = PARTIAL_PROFILE_NAME
549
+ rich.print("")
550
+ cfg.fill_in_with_defaults()
551
+ save_flow(cfg)
552
+ gitignore_flow()
553
+ rich.print(f"[yellow bold]✓ Saved partial {CONFIG_FILE} ({os.path.abspath(CONFIG_FILE)})")
554
+
555
+ divider()
556
+
557
+ #--------------------------------------------------
558
+ # Profile switcher
559
+ #--------------------------------------------------
560
+
561
+ @cli.command(
562
+ name="profile:switch",
563
+ help="Switch to a different profile",
564
+ )
565
+ @click.option("--profile", help="Profile to switch to")
566
+ def profile_switch(profile:str|None=None):
567
+ config_store = ConfigStore()
568
+ current_profile = None
569
+ try:
570
+ config = config_store.get_config()
571
+ if config.profile != TOP_LEVEL_PROFILE_NAME:
572
+ current_profile = config.profile
573
+ except Exception as e:
574
+ rich.print(f"\n[yellow]Error: {e}")
575
+ pass
576
+
577
+ profiles = list((config_store.get_profiles() or {}).keys())
578
+ divider()
579
+ if not profile:
580
+ if len(profiles) == 0:
581
+ exit_with_error("[yellow]No profiles found")
582
+ profile = controls.fuzzy("Select a profile:", profiles, default=current_profile)
583
+ divider()
584
+ else:
585
+ if profile not in profiles:
586
+ exit_with_error(f"[yellow]Profile '{profile}' not found")
587
+ config_store.change_active_profile(profile)
588
+ config_store.save()
589
+ rich.print(f"[green]✓ Switched to profile '{profile}'")
590
+ divider()
591
+
592
+ #--------------------------------------------------
593
+ # Print config file
594
+ #--------------------------------------------------
595
+ @cli.command(
596
+ name="config:print",
597
+ help="Print the config file contents with secrets masked",
598
+ )
599
+ def config_print():
600
+ divider()
601
+ cfg = ensure_config()
602
+ rich.print(f"[bold green]{cfg.file_path}\n")
603
+ if cfg.file_path is None:
604
+ rich.print("[yellow]No configuration file found. To create one, run: [green]rai init")
605
+ divider()
606
+ return
607
+ with open(cfg.file_path, "r") as f:
608
+ content = f.read()
609
+ for line in content.split("\n"):
610
+ if "client_secret" in line or "password" in line:
611
+ chars = []
612
+ equals_found = False
613
+ for char in line:
614
+ if char == "=":
615
+ equals_found = True
616
+ chars.append(char)
617
+ continue
618
+ if equals_found and char != "\"" and char != " ":
619
+ chars.append("*")
620
+ else:
621
+ chars.append(char)
622
+ line = "".join(chars)
623
+ print(line)
624
+ divider()
625
+
626
+ #--------------------------------------------------
627
+ # Explain config
628
+ #--------------------------------------------------
629
+
630
+ @cli.command(
631
+ name="config:explain",
632
+ help="Inspect config status",
633
+ )
634
+ @click.option(
635
+ "--profile",
636
+ help="Profile to inspect",
637
+ )
638
+ @click.option(
639
+ "--all-profiles",
640
+ help="Whether to show all profiles in config file",
641
+ is_flag=True,
642
+ )
643
+ def config_explain(profile:str|None=None, all_profiles:bool=False):
644
+ divider()
645
+ cfg = ensure_config(profile)
646
+ config_store = ConfigStore()
647
+
648
+ if config_store.get("platform"):
649
+ issue_top_level_profile_warning()
650
+
651
+ rich.print(f"[bold green]{cfg.file_path}")
652
+ if os.getenv("RAI_PROFILE"):
653
+ rich.print(f"[yellow]Environment variable [bold]RAI_PROFILE = {os.getenv('RAI_PROFILE')}[/bold]")
654
+ rich.print("")
655
+ if cfg.profile != TOP_LEVEL_PROFILE_NAME:
656
+ rich.print(f"[bold]\\[{cfg.profile}]")
657
+
658
+ for key, value in cfg.items_with_dots():
659
+ if key == "active_profile" and cfg.profile != TOP_LEVEL_PROFILE_NAME:
660
+ continue
661
+ rich.print(f"{key} = [cyan bold]{map_toml_value(mask(key, value))}")
662
+
663
+ platform = cfg.get("platform", "snowflake")
664
+ authenticator = cfg.get("authenticator", "snowflake")
665
+ assert isinstance(authenticator, str), f"authenticator should be a string, not {type(authenticator)}"
666
+ defaults = {}
667
+ if platform == "snowflake":
668
+ defaults = {k: v["value"] for k, v in SNOWFLAKE_AUTHS[authenticator].items()}
669
+ else:
670
+ defaults = azure_default_props
671
+
672
+ for key, value in defaults.items():
673
+ if key not in cfg:
674
+ rich.print(f"[yellow bold]{key}[/yellow bold] = ?" + (
675
+ f" (default: {value})" if value and value != FIELD_PLACEHOLDER else ""
676
+ ))
677
+
678
+ if all_profiles:
679
+ profiles = config_store.get_profiles() or {}
680
+ for profile, props in profiles.items():
681
+ if profile == cfg.profile:
682
+ continue
683
+ if len(props):
684
+ rich.print()
685
+ rich.print(f"[bold]\\[{profile}][/bold]")
686
+ for key, value in props.items():
687
+ rich.print(f"{key} = [cyan bold]{map_toml_value(mask(key, value))}")
688
+
689
+ divider()
690
+
691
+ def mask(key: str, value: Any):
692
+ if key in ["client_secret", "password"]:
693
+ return "*" * len(str(value))
694
+ return value
695
+
696
+ #--------------------------------------------------
697
+ # Check config
698
+ #--------------------------------------------------
699
+
700
+ @cli.command(
701
+ name="config:check",
702
+ help="Check whether config is valid",
703
+ )
704
+ def config_check(all_profiles:bool=False):
705
+ error = None
706
+ divider()
707
+ if ConfigStore().get("platform"):
708
+ issue_top_level_profile_warning()
709
+
710
+ cfg = ensure_config()
711
+
712
+ with Spinner("Connecting to platform...", "Connection successful!", "Error:"):
713
+ try:
714
+ provider = get_resource_provider(None, cfg)
715
+ # Engine is required by both clients if it is not configured check would fail already
716
+ engine_name = cfg.get("engine")
717
+ assert isinstance(engine_name, str), f"Engine name must be a string, not {type(engine_name)}"
718
+ # This essentially checks if the profile is valid since we are connecting to get the engine
719
+ engine = provider.get_engine(engine_name)
720
+ if not engine or (engine and not provider.is_valid_engine_state(engine.get("state"))):
721
+ provider.auto_create_engine_async(engine_name)
722
+ except Exception as e:
723
+ error = e
724
+ if error:
725
+ raise error
726
+ if error:
727
+ exit_with_divider(1)
728
+ divider()
729
+
730
+ #--------------------------------------------------
731
+ # Version
732
+ #--------------------------------------------------
733
+
734
+ @cli.command(help="Print version info")
735
+ def version():
736
+ from .. import __version__
737
+ try:
738
+ from railib import __version__ as railib_version
739
+ except Exception:
740
+ railib_version = None
741
+
742
+ table = Table(show_header=False, border_style="dim", header_style="bold", box=rich_box.SIMPLE)
743
+ def print_version(name, version, latest=None):
744
+ if latest is not None and Version(version) < Version(latest):
745
+ table.add_row(f"[bold]{name}[red]", f"[red bold]{version} (yours) → {latest} (latest)")
746
+ else:
747
+ table.add_row(f"[bold]{name}", f"[green]{version} (latest)")
748
+
749
+ divider()
750
+ print_version("RelationalAI", __version__, latest_version("relationalai"))
751
+ if railib_version is not None:
752
+ print_version("Rai-sdk", railib_version, latest_version("rai-sdk"))
753
+ print_version("Python", sys.version.split()[0])
754
+
755
+ app_version = None
756
+
757
+ try:
758
+ cfg = get_config()
759
+ if not cfg.file_path:
760
+ table.add_row("[bold]App", "No configuration file found. To create one, run: [green]rai init")
761
+ else:
762
+ platform = cfg.get("platform", None)
763
+ if platform == "snowflake":
764
+ with Spinner("Checking app version"):
765
+ try:
766
+ app_version = get_resource_provider().get_version()
767
+ except Exception as e:
768
+ error_str = str(e).lower()
769
+ prefix = "Unable to acquire app version.\n"
770
+ if "unknown user-defined function" in error_str:
771
+ app_version = Exception(f"{prefix}Application not found. Please make sure you have set a valid Snowflake native application name in your configuration and your app is up and running.")
772
+ elif "404 not found" in error_str:
773
+ app_version = Exception(f"{prefix}Account not found. Please make sure you have set a valid Snowflake account name in your configuration.")
774
+ elif "role" in error_str:
775
+ app_version = Exception(f"{prefix}Please make sure you have a valid role set in your configuration.")
776
+ elif "failed to connect" in error_str:
777
+ app_version = Exception(f"{prefix}Please check your Snowflake connection settings.")
778
+ elif "no active warehouse" in error_str:
779
+ app_version = Exception(f"{prefix}No active warehouse found. Please make sure you have a valid warehouse name set in your configuration.")
780
+ else:
781
+ app_version = e
782
+
783
+ if not isinstance(app_version, Exception):
784
+ print_version("App", app_version)
785
+
786
+ except Exception as e:
787
+ rich.print(f"[yellow]Error checking app version: {e}")
788
+ exit_with_divider(1)
789
+
790
+ rich.print(table)
791
+
792
+ if isinstance(app_version, Exception):
793
+ error_table = Table(show_header=False, border_style="dim", header_style="bold", box=rich_box.SIMPLE)
794
+ error_table.add_row("App", f"[yellow]{app_version}")
795
+ rich.print(error_table)
796
+
797
+ divider()
798
+
799
+ #--------------------------------------------------
800
+ # Debugger
801
+ #--------------------------------------------------
802
+
803
+ @cli.command(help="Open the RAI debugger")
804
+ @click.option("--host", help="Host to use", default="localhost")
805
+ @click.option("--port", type=int, help="Port to use", default=None)
806
+ @click.option("--old", help="Use the legacy debugger", is_flag=True, default=False)
807
+ @click.option("--qb", help="Query builder debugger", is_flag=True, default=None)
808
+ @click.option("--profile", help="Profile to use", default=None)
809
+
810
+ def debugger(host, port, old, qb, profile):
811
+ if old:
812
+ deb.main(host, port)
813
+ elif qb:
814
+ qb_deb.main(host, port)
815
+ else:
816
+ from relationalai.tools import debugger_server
817
+ debugger_server.start_server(host, port, profile)
818
+
819
+
820
+ #--------------------------------------------------
821
+ # Engine list
822
+ #--------------------------------------------------
823
+
824
+ @cli.command(name="engines:list", help="List all engines")
825
+ @click.option("--state", help="Filter by engine state")
826
+ def engines_list(state:str|None=None):
827
+ divider(flush=True)
828
+ ensure_config()
829
+ rich.print("Note: [cyan]Engine names are case sensitive")
830
+ rich.print("")
831
+ with Spinner("Fetching engines"):
832
+ try:
833
+ engines = get_resource_provider().list_engines(state)
834
+ except Exception as e:
835
+ return exit_with_error(f"\n\n[yellow]Error fetching engines: {e}")
836
+
837
+ if len(engines):
838
+ show_engines(engines)
839
+ else:
840
+ exit_with_error("[yellow]No engines found")
841
+ divider()
842
+
843
+ @cli.command(name="engines:get", help="Get engine details")
844
+ @click.option("--name", help="Name of the engine")
845
+ def engines_get(name:str|None=None):
846
+ divider(flush=True)
847
+ ensure_config()
848
+
849
+ rich.print("Note: [cyan]Engine names are case sensitive")
850
+ rich.print("")
851
+
852
+ if not name:
853
+ name = controls.text("Engine name:", validator=ENGINE_NAME_REGEX.match, invalid_message=ENGINE_NAME_ERROR)
854
+ rich.print("")
855
+
856
+ with Spinner("Fetching engine"):
857
+ try:
858
+ engine = get_resource_provider().get_engine(name)
859
+ except Exception as e:
860
+ return exit_with_error(f"\n\n[yellow]Error fetching engine: {e}")
861
+
862
+ if engine:
863
+ table = Table(show_header=True, border_style="dim", header_style="bold", box=rich_box.SIMPLE_HEAD)
864
+ table.add_column("Name")
865
+ table.add_column("Size")
866
+ table.add_column("State")
867
+ table.add_row(engine.get("name"), engine.get("size"), engine.get("state"))
868
+ rich.print(table)
869
+ else:
870
+ exit_with_error(f'[yellow]Engine "{name}" not found')
871
+ divider()
872
+
873
+ #--------------------------------------------------
874
+ # Engine create
875
+ #--------------------------------------------------
876
+
877
+ def create_engine_flow(cfg:config.Config, name=None, size=None, auto_suspend_mins=None):
878
+ provider = get_resource_provider(None, cfg)
879
+ engine = None
880
+ is_engine_present = False
881
+ is_engine_suspended = False
882
+ is_interactive = name is None or size is None
883
+ auto_suspend_mins = cfg.get("auto_suspend_mins", None) if auto_suspend_mins is None else auto_suspend_mins
884
+ if is_interactive:
885
+ rich.print("Note: [cyan]Engine names are case sensitive")
886
+ rich.print("")
887
+
888
+ if not name:
889
+ name = controls.prompt(
890
+ "Engine name:",
891
+ name,
892
+ validator=ENGINE_NAME_REGEX.match,
893
+ invalid_message=ENGINE_NAME_ERROR,
894
+ newline=True
895
+ )
896
+
897
+ if auto_suspend_mins is not None:
898
+ error_msg = f"[yellow]Error: auto_suspend_mins must be an integer instead of {type(auto_suspend_mins)}"
899
+ try:
900
+ auto_suspend_mins = int(auto_suspend_mins)
901
+ except ValueError:
902
+ exit_with_error(error_msg)
903
+ assert isinstance(auto_suspend_mins, int), error_msg
904
+
905
+ is_name_valid, msg = validate_engine_name(name)
906
+ if not is_name_valid:
907
+ rich.print("")
908
+ rich.print(f"[yellow]{msg}")
909
+ if is_interactive:
910
+ rich.print("")
911
+ return create_engine_flow(cfg)
912
+ else:
913
+ exit_with_divider(1)
914
+
915
+ with Spinner(f"Validating engine '{name}' name", "Engine name validated", "Error:"):
916
+ try:
917
+ engine = provider.get_engine(name)
918
+ is_engine_present = engine and engine is not None
919
+ is_engine_suspended = engine and engine.get("state", None) == "SUSPENDED"
920
+ except Exception as e:
921
+ if "already exists" in f"{e}":
922
+ is_engine_present = True
923
+ elif "Not Found" in f"{e}":
924
+ is_engine_present = False
925
+ else:
926
+ raise e
927
+ if is_engine_suspended:
928
+ rich.print("")
929
+ with Spinner(f"Resuming engine '{name}'", f"Engine '{name}' resumed", "Error:"):
930
+ provider.resume_engine(name)
931
+ return name
932
+ if is_engine_present:
933
+ rich.print("")
934
+ if is_interactive:
935
+ rich.print(f"Engine '{name}' already exists")
936
+ rich.print("")
937
+ return create_engine_flow(cfg)
938
+ else:
939
+ exit_with_error(f"[yellow]Engine '{name}' already exists")
940
+
941
+ # If no size is provided via the params and no size is set in the config,
942
+ if not size and not cfg.get("engine_size", None):
943
+ rich.print("")
944
+ cloud_provider = provider.get_cloud_provider()
945
+ choices = provider.get_engine_sizes(cloud_provider)
946
+ size = controls.fuzzy(f"Engine size ({cloud_provider.upper()}):", choices=choices)
947
+ # If a size is provided via the params or the config, validate it
948
+ elif size or cfg.get("engine_size", None):
949
+ # If size is None but config has engine_size, use config value
950
+ if size is None:
951
+ size = cfg.get("engine_size", None)
952
+ valid_sizes = provider.get_engine_sizes()
953
+ if not isinstance(size, str) or size not in valid_sizes:
954
+ exit_with_error(f"\nInvalid engine size [yellow]{size}[/yellow] provided. Please check your config.\n\nValid sizes: [green]{valid_sizes}[/green]")
955
+ assert isinstance(size, str), "engine_size must be a string"
956
+
957
+ rich.print("")
958
+
959
+ with Spinner(
960
+ f"Creating '{name}' engine with size {size}... (this may take several minutes)",
961
+ f"Engine '{name}' created!",
962
+ failed_message="Error:"
963
+ ):
964
+ provider.create_engine(name, size, auto_suspend_mins)
965
+ return name
966
+
967
+ @cli.command(name="engines:create", help="Create a new engine")
968
+ @click.option("--name", help="Name of the engine")
969
+ @click.option("--size", help="Size of the engine")
970
+ @click.option("--auto_suspend_mins", help="Suspend the engine after this many minutes of inactivity", default=None)
971
+ def engines_create(name, size, auto_suspend_mins):
972
+ divider(flush=True)
973
+ cfg = ensure_config()
974
+ create_engine_flow(cfg, name, size, auto_suspend_mins)
975
+ divider()
976
+
977
+ #--------------------------------------------------
978
+ # Engine delete
979
+ #--------------------------------------------------
980
+
981
+ @cli.command(name="engines:delete", help="Delete an engine")
982
+ @click.option("--name", help="Name of the engine")
983
+ @click.option("--force", help="Force delete the engine", is_flag=True)
984
+ def engines_delete(name, force=False):
985
+ divider(flush=True)
986
+ ensure_config()
987
+ provider = get_resource_provider()
988
+ if not name:
989
+ name = controls.fuzzy_with_refetch(
990
+ "Select an engine:",
991
+ "engines",
992
+ lambda: [engine["name"] for engine in provider.list_engines()],
993
+ )
994
+ if not name or isinstance(name, Exception):
995
+ return
996
+ else:
997
+ try:
998
+ engine = provider.get_engine(name)
999
+ if not engine:
1000
+ exit_with_error(f"[yellow]Engine '{name}' not found")
1001
+ except Exception as e:
1002
+ exit_with_error(f"[yellow]Error fetching engine: {e}")
1003
+
1004
+ del_err = None
1005
+ with Spinner(f"Deleting '{name}' engine", f"Engine '{name}' deleted!", "Error:"):
1006
+ try:
1007
+ provider.delete_engine(name, force)
1008
+ except Exception as e:
1009
+ if "SETUP_CDC" in f"{e}":
1010
+ del_err = Exception("[yellow]Imports are setup to utilize this engine.\nUse '[cyan]rai engines:delete --force[/cyan]' to force delete engines.")
1011
+ else:
1012
+ del_err = e
1013
+ raise del_err
1014
+ if isinstance(del_err, Exception):
1015
+ exit_with_divider(1)
1016
+ divider()
1017
+
1018
+ #--------------------------------------------------
1019
+ # Engine resume
1020
+ #--------------------------------------------------
1021
+
1022
+ @cli.command(name="engines:resume", help="Resume an engine")
1023
+ @click.option("--name", help="Name of the engine")
1024
+ def engines_resume(name):
1025
+ divider(flush=True)
1026
+ ensure_config()
1027
+ provider = get_resource_provider()
1028
+ if not name:
1029
+ name = controls.fuzzy_with_refetch(
1030
+ "Select a suspended engine to resume:",
1031
+ "engines",
1032
+ lambda: [engine["name"] for engine in provider.list_engines('SUSPENDED')],
1033
+ )
1034
+ if not name or isinstance(name, Exception):
1035
+ return
1036
+ else:
1037
+ try:
1038
+ engine = provider.get_engine(name)
1039
+ if not engine:
1040
+ exit_with_error(f"[yellow]Engine '{name}' not found")
1041
+ if engine and engine.get("state") != "SUSPENDED":
1042
+ exit_with_error(f"[yellow]Engine '{name}' not in 'SUSPENDED' state")
1043
+ except Exception as e:
1044
+ exit_with_error(f"[yellow]Error fetching engine: {e}")
1045
+
1046
+ with Spinner(f"Resuming '{name}' engine", f"Engine '{name}' resumed", "Error:"):
1047
+ try:
1048
+ provider.resume_engine(name)
1049
+ except Exception as e:
1050
+ rich.print(f"[yellow]Error resuming engine: {e}")
1051
+ exit_with_divider(1)
1052
+ divider()
1053
+
1054
+ #--------------------------------------------------
1055
+ # Engine suspend
1056
+ #--------------------------------------------------
1057
+
1058
+ @cli.command(name="engines:suspend", help="Suspend an engine")
1059
+ @click.option("--name", help="Name of the engine")
1060
+ def engines_suspend(name):
1061
+ divider(flush=True)
1062
+ ensure_config()
1063
+ provider = get_resource_provider()
1064
+ if not name:
1065
+ name = controls.fuzzy_with_refetch(
1066
+ "Select an active engine to suspend:",
1067
+ "engines",
1068
+ lambda: [engine["name"] for engine in provider.list_engines('READY')],
1069
+ )
1070
+ if not name or isinstance(name, Exception):
1071
+ return
1072
+ else:
1073
+ try:
1074
+ engine = provider.get_engine(name)
1075
+ if not engine:
1076
+ exit_with_error(f"[yellow]Engine '{name}' not found")
1077
+ if engine and engine.get("state") != "READY":
1078
+ exit_with_error(f"[yellow]Engine '{name}' must be in 'READY' state to be suspended")
1079
+ except Exception as e:
1080
+ exit_with_error(f"[yellow]Error fetching engine: {e}")
1081
+
1082
+ with Spinner(f"Suspending '{name}' engine", f"Engine '{name}' suspended", "Error:"):
1083
+ try:
1084
+ provider.suspend_engine(name)
1085
+ except Exception as e:
1086
+ rich.print(f"[yellow]Error suspending engine: {e}")
1087
+ exit_with_divider(1)
1088
+ divider()
1089
+
1090
+ #--------------------------------------------------
1091
+ # Engine alter engine pool
1092
+ #--------------------------------------------------
1093
+
1094
+ @cli.command(name="engines:alter_pool", help="Alter the engine pool size")
1095
+ @click.option("--size", help="Engine size")
1096
+ @click.option("--min", help="Minimum number of engines")
1097
+ @click.option("--max", help="Maximum number of engines")
1098
+ def engines_alter_pool(size:str|None=None, min:int|None=None, max:int|None=None):
1099
+ divider(flush=True)
1100
+ ensure_config()
1101
+ provider = get_resource_provider()
1102
+
1103
+ if provider.platform != "snowflake":
1104
+ exit_with_error("Engine pool alteration is only supported for Snowflake")
1105
+
1106
+ # Ask for engine size if not provided
1107
+ if not size:
1108
+ valid_sizes = provider.get_engine_sizes()
1109
+ size = controls.fuzzy(
1110
+ "Select engine size:",
1111
+ choices=valid_sizes,
1112
+ mandatory=True
1113
+ )
1114
+
1115
+ # Validate engine size
1116
+ valid_sizes = provider.get_engine_sizes()
1117
+ if size not in valid_sizes:
1118
+ exit_with_error(f"Invalid engine size '{size}'. Valid sizes: {valid_sizes}")
1119
+
1120
+ # Ask for minimum number of engines
1121
+ if min is None:
1122
+ min_str = controls.text(
1123
+ "Enter minimum number of engines:",
1124
+ validator=lambda x: x.isdigit() and int(x) > 0,
1125
+ invalid_message="Please enter a valid non-negative integer"
1126
+ )
1127
+ min = int(min_str)
1128
+ else:
1129
+ # Convert string to int if it came from command line
1130
+ min = int(min)
1131
+
1132
+ # Ask for maximum number of engines
1133
+ if max is None:
1134
+ max_str = controls.text(
1135
+ "Enter maximum number of engines:",
1136
+ validator=lambda x: x.isdigit() and int(x) >= min,
1137
+ invalid_message=f"Please enter a valid integer greater than or equal to {min}"
1138
+ )
1139
+ max = int(max_str)
1140
+ else:
1141
+ # Convert string to int if it came from command line
1142
+ max = int(max)
1143
+
1144
+ # Validate that range is valid
1145
+ if max < min:
1146
+ exit_with_error(f"Maximum number of engines ({max}) must be greater than or equal to minimum ({min})")
1147
+
1148
+ rich.print()
1149
+
1150
+ # Call the API method
1151
+ with Spinner("Altering engine pool", "Engine pool altered", "Error:"):
1152
+ # Type cast to ensure type checker recognizes the method
1153
+ cast(ResourcesBase, provider).alter_engine_pool(size, min, max)
1154
+ divider()
1155
+
1156
+ #--------------------------------------------------
1157
+ # Import Source flows
1158
+ #--------------------------------------------------
1159
+
1160
+ def import_source_flow(provider: ResourcesBase) -> Sequence[ImportSource]:
1161
+ provider_type = type(provider)
1162
+
1163
+ if isinstance(provider, CLIResources):
1164
+ return snowflake_import_source_flow(provider)
1165
+ else:
1166
+ # Lazy import for azure to avoid optional dependency issues
1167
+ try:
1168
+ from relationalai.clients.resources.azure.azure import Resources as AzureResources
1169
+ if isinstance(provider, AzureResources):
1170
+ return azure_import_source_flow(provider)
1171
+ except ImportError:
1172
+ pass
1173
+ raise Exception(f"No import source flow available for {provider_type.__module__}.{provider_type.__name__}")
1174
+
1175
+ def snowflake_import_source_flow(provider: CLIResources) -> Sequence[ImportSource]:
1176
+ with Spinner("Fetching databases", "Databases fetched"):
1177
+ try:
1178
+ dbs = provider.list_databases()
1179
+ except Exception as e:
1180
+ rich.print(f"\n\n[yellow]Error fetching databases: {e}", file=sys.stderr)
1181
+ dbs = []
1182
+ if len(dbs) == 0:
1183
+ exit_with_error("[yellow]No databases found")
1184
+ rich.print()
1185
+ db = controls.fuzzy("Select a database:", [db["name"] for db in dbs])
1186
+ rich.print()
1187
+
1188
+ with Spinner("Fetching schemas", "Schemas fetched"):
1189
+ try:
1190
+ schemas = provider.list_sf_schemas(db)
1191
+ except Exception as e:
1192
+ rich.print(f"\n\n[yellow]Error fetching schemas: {e}")
1193
+ schemas = []
1194
+ if len(schemas) == 0:
1195
+ exit_with_error("[yellow]No schemas found")
1196
+ rich.print()
1197
+ schema = controls.fuzzy("Select a schema:", [s["name"] for s in schemas])
1198
+ rich.print()
1199
+
1200
+ with Spinner("Fetching tables", "Tables fetched"):
1201
+ try:
1202
+ tables = provider.list_tables(db, schema)
1203
+ except Exception as e:
1204
+ rich.print(f"\n\n[yellow]Error fetching tables: {e}")
1205
+ tables = []
1206
+ if len(tables) == 0:
1207
+ exit_with_error("[yellow]No tables found")
1208
+ rich.print()
1209
+ if tables:
1210
+ tables = controls.fuzzy_multiselect("Select tables (tab for multiple):", [t["name"] for t in tables])
1211
+ else:
1212
+ rich.print("[yellow]No tables found")
1213
+ tables = ""
1214
+ rich.print()
1215
+ if isinstance(tables, list):
1216
+ return [ImportSourceTable(db, schema, table) for table in tables]
1217
+ else:
1218
+ return [ImportSourceTable(db, schema, tables)]
1219
+
1220
+ def azure_import_source_flow(provider: azure.Resources) -> Sequence[ImportSource]:
1221
+ result = controls.file("Select a file:", allow_freeform=True)
1222
+ return [ImportSourceFile(result)] if result else []
1223
+
1224
+ def import_source_options_flow(provider: ResourcesBase, source: ImportSource, default_options:dict) -> dict:
1225
+ if isinstance(source, ImportSourceFile):
1226
+ type: LoadType | None = default_options.get("type", None)
1227
+ if type is None or type == "auto":
1228
+ type = Loader.get_type_for(source)
1229
+ if type == "csv":
1230
+ return import_source_csv_options_flow(provider, source, default_options)
1231
+
1232
+ return default_options
1233
+
1234
+ def import_source_csv_options_flow(provider: ResourcesBase, source: ImportSourceFile, default_options:dict) -> dict:
1235
+ user_specified_schema = {k.strip(): rel_schema_to_type(v.lower()) for k, v in default_options.get("schema", {}).items()}
1236
+ user_specified_syntax = default_options.get("syntax", {})
1237
+
1238
+ if source.is_url():
1239
+ # @FIXME: Should maybe prompt user to provide a schema manually for urls?
1240
+ return {**default_options, "schema": user_specified_schema}
1241
+
1242
+ # Syntax inference + confirmation for local files ==========================
1243
+
1244
+ syntax = CSVLoader.guess_syntax(source.raw_path)
1245
+ syntax.update(user_specified_syntax)
1246
+
1247
+ syntax_table = Table(show_header=True, border_style="dim", header_style="bold", box=rich_box.SIMPLE_HEAD)
1248
+ for k in syntax.keys():
1249
+ syntax_table.add_column(k)
1250
+ syntax_table.add_row(*[
1251
+ repr(v)[1:-1] if isinstance(v, str) else
1252
+ "[dim]<default>[/dim]" if v is None else
1253
+ str(v)
1254
+ for v in syntax.values()])
1255
+
1256
+ rich.print(syntax_table)
1257
+
1258
+ if not controls.confirm(f"Use this dialect for {source.name}:", True):
1259
+ fail_import_options_flow(
1260
+ source,
1261
+ "You can manually specify the CSV dialectusing syntax arguments. For example, to set the [cyan]delimiter[/cyan] to [green]tab[/green], run:",
1262
+ 'syntax:[cyan]delim[/cyan]="[green]\\t[/green]"'
1263
+ )
1264
+
1265
+ # Schema inference + confirmation for local files ==========================
1266
+
1267
+ schema, csv_chunk = CSVLoader.guess_schema(source.raw_path, syntax)
1268
+ schema.update(user_specified_schema)
1269
+
1270
+ schema_table = Table(show_header=True, border_style="dim", header_style="bold", box=rich_box.SIMPLE_HEAD)
1271
+ schema_table.add_column("Field")
1272
+ schema_table.add_column("Type")
1273
+ schema_table.add_column("Ex.")
1274
+ for field, type in schema.items():
1275
+ schema_table.add_row(field, type.name, f"[dim]{csv_chunk[field][0]}")
1276
+
1277
+ rich.print(schema_table)
1278
+
1279
+ if not controls.confirm(f"Use this schema for {source.name}:", True):
1280
+ field = next(iter(schema.keys()))
1281
+ fail_import_options_flow(
1282
+ source,
1283
+ f"You can manually specify column types using schema arguments. For example, to load the column [cyan]{field}[/cyan] as a [green]string[/green], run:",
1284
+ f"schema:[cyan]{field}[/cyan]=[green]string[/green]"
1285
+ )
1286
+
1287
+ return {**default_options, "schema": schema, "syntax": syntax}
1288
+
1289
+ def fail_import_options_flow(source: ImportSourceFile, message: str, solution_args: str):
1290
+ prev_cmd_args = " ".join(shlex.quote(arg) for arg in sys.argv[1:])
1291
+ saved_args = []
1292
+ if "--source" not in sys.argv:
1293
+ saved_args.append(f"--source {shlex.quote(source.raw_path)}")
1294
+ if "--name" not in sys.argv:
1295
+ saved_args.append(f"--name {shlex.quote(source.name)}")
1296
+
1297
+ saved_args = " " + " ".join(saved_args) if saved_args else ""
1298
+ print()
1299
+ rich.print(message)
1300
+ print()
1301
+ rich.get_console().print(f"[dim] rai {prev_cmd_args}{saved_args}[/dim] {solution_args}", highlight=False)
1302
+ divider()
1303
+ exit(0)
1304
+
1305
+
1306
+ def parse_source(provider: ResourcesBase, raw: str) -> ImportSource:
1307
+ if provider.platform == "azure":
1308
+ return ImportSourceFile(raw)
1309
+ elif provider.platform == "snowflake":
1310
+ parser = IdentityParser(raw)
1311
+ assert parser.is_complete, "Snowflake table imports must be in `database.schema.table` format"
1312
+ return ImportSourceTable(*parser.to_list())
1313
+ else:
1314
+ raise Exception(f"Unsupported platform: {provider.platform}")
1315
+
1316
+ #--------------------------------------------------
1317
+ # Imports
1318
+ #--------------------------------------------------
1319
+
1320
+ @supports_platform("snowflake")
1321
+ @cli.command(name="imports:setup", help="Modify and view imports setup")
1322
+ @click.option("--engine_size", help="Engine size")
1323
+ @click.option("--resume", help="Resume imports", is_flag=True)
1324
+ @click.option("--suspend", help="Suspend imports", is_flag=True)
1325
+ def imports_setup(engine_size:str|None=None, resume:bool=False, suspend:bool=False):
1326
+ divider(flush=True)
1327
+ ensure_config()
1328
+ provider = cast(CLIResources, get_resource_provider())
1329
+ data = None
1330
+
1331
+ if resume or suspend:
1332
+ if resume:
1333
+ with Spinner("Resuming imports", "Imports resumed", "Error:"):
1334
+ provider.change_imports_status(suspend=False)
1335
+ if suspend:
1336
+ with Spinner("Suspending imports", "Imports suspended", "Error:"):
1337
+ provider.change_imports_status(suspend=True)
1338
+ exit_with_divider()
1339
+
1340
+ if engine_size:
1341
+ if engine_size in provider.get_engine_sizes():
1342
+ with Spinner("Setting imports engine size", "Imports engine size set", "Error:"):
1343
+ provider.set_imports_engine_size(engine_size)
1344
+ exit_with_divider()
1345
+ else:
1346
+ rich.print("[yellow]Invalid engine size.\n")
1347
+ engine_size = controls.fuzzy("Select engine size for imports:", provider.get_engine_sizes())
1348
+ assert isinstance(engine_size, str), "selected_name should not be None"
1349
+ provider.set_imports_engine_size(engine_size)
1350
+ exit_with_divider()
1351
+
1352
+ # Verify imports setup
1353
+ with Spinner("Fetching imports setup", "Imports setup fetched", "Error:"):
1354
+ try:
1355
+ data = provider.get_imports_status()
1356
+ except Exception as e:
1357
+ raise e
1358
+
1359
+ # Engine is already set for imports
1360
+ if data:
1361
+ rich.print()
1362
+ if data["status"].lower() == "suspended":
1363
+ rich.print("To resume imports, use '[cyan]rai imports:setup --resume[/cyan]'")
1364
+ else:
1365
+ rich.print("To suspend imports, use '[cyan]rai imports:setup --suspend[/cyan]'")
1366
+ try:
1367
+ rich.print()
1368
+ data = {**data, **json.loads(data["info"])}
1369
+ data["status"] = data["status"].upper()
1370
+ data["created_on"] = datetime.strptime(data["createdOn"], '%Y-%m-%d %H:%M:%S.%f %z')
1371
+ data["last_suspended_on"] = datetime.strptime(data["lastSuspendedOn"], '%Y-%m-%d %H:%M:%S.%f %z') if data["lastSuspendedOn"] else "N/A"
1372
+ data["last_suspended_reason"] = data["lastSuspendedReason"] if data["lastSuspendedReason"] else "N/A"
1373
+ del data["info"]
1374
+ del data["state"]
1375
+ del data["createdOn"]
1376
+ del data["lastSuspendedOn"]
1377
+ del data["lastSuspendedReason"]
1378
+ show_dictionary_table(
1379
+ data,
1380
+ lambda k, v: {k: str(v), "style": "red"} if k == "enabled" and not v else format_row(k, v)
1381
+ )
1382
+ except Exception as e:
1383
+ exit_with_error(f"\n\n[yellow]Error fetching imports setup: {e}")
1384
+ divider()
1385
+
1386
+
1387
+ @supports_platform("snowflake")
1388
+ @cli.command(name="imports:get", help="Get specific import details")
1389
+ @click.option("--id", help="Filter by import id")
1390
+ def imports_get(id:str|None=None):
1391
+ divider(flush=True)
1392
+ ensure_config()
1393
+ provider = cast(CLIResources, get_resource_provider())
1394
+ import_streams = []
1395
+ import_response = []
1396
+ with Spinner("Fetching imports", "Imports fetched", "Error:"):
1397
+ import_response = provider.list_imports()
1398
+ if not import_response:
1399
+ exit_with_error("[yellow]No imports found")
1400
+
1401
+ if not id:
1402
+ show_imports(import_response, showId=True)
1403
+ id = controls.fuzzy("Select an import id:", [i["id"] for i in import_response], default=id, show_index=True)
1404
+
1405
+ details_list = [{"name": item['name'], "model": item['model']} for item in import_response if item['id'] == id]
1406
+ if not details_list:
1407
+ rich.print()
1408
+ exit_with_error(f"[yellow]Import '{id}' not found")
1409
+
1410
+ details = details_list[0]
1411
+
1412
+ rich.print()
1413
+ with Spinner("Fetching import details ", "Import details fetched", "Error:"):
1414
+ import_streams = provider.get_import_stream(details.get("name"), details.get("model"))
1415
+ if import_streams and len(import_streams) > 0:
1416
+ rich.print()
1417
+ show_dictionary_table(import_streams[-1], format_row)
1418
+ divider()
1419
+
1420
+ #--------------------------------------------------
1421
+ # Imports list
1422
+ #--------------------------------------------------
1423
+
1424
+ @cli.command(name="imports:list", help="List objects imported into RAI")
1425
+ @click.option("--id", help="Filter by import id")
1426
+ @click.option("--name", help="Filter by import name")
1427
+ @click.option("--model", help="Filter by model")
1428
+ @click.option("--status", help="Filter by import status")
1429
+ @click.option("--creator", help="Filter by import creator")
1430
+ def imports_list(id:str|None=None, name:str|None=None, model:str|None=None, status:str|None=None, creator:str|None=None):
1431
+ divider(flush=True)
1432
+ ensure_config()
1433
+ provider = get_resource_provider()
1434
+ data = None
1435
+ error = None
1436
+ with Spinner("Fetching imports config", "Imports config fetched", "Error:"):
1437
+ try:
1438
+ data = provider.get_imports_status()
1439
+ except Exception as e:
1440
+ error = e
1441
+ raise error
1442
+ if isinstance(error, Exception):
1443
+ exit_with_divider(1)
1444
+
1445
+ if data:
1446
+ rich.print()
1447
+ if data['status'] is None:
1448
+ ds = "[yellow]Not available"
1449
+ elif data['status'].lower() == "suspended":
1450
+ ds = f"[red]{data['status'].upper()}[/red]"
1451
+ else:
1452
+ ds = data["status"].upper()
1453
+ rich.print(f"Imports status: {ds}")
1454
+
1455
+ imports = None
1456
+
1457
+ rich.print()
1458
+ with Spinner("Fetching imports", "Imports fetched", "Error:"):
1459
+ imports = provider.list_imports(id, name, model, status, creator)
1460
+ if len(imports) == 0:
1461
+ exit_with_error("\n[yellow]No imports found")
1462
+
1463
+ rich.print()
1464
+ show_imports(imports)
1465
+ divider()
1466
+
1467
+ #--------------------------------------------------
1468
+ # Imports waiting
1469
+ #--------------------------------------------------
1470
+
1471
+ def poll_imports(provider: ResourcesBase, source:list[str], model:str, no_wait_notice:bool=False):
1472
+ spinner = Spinner(
1473
+ "Waiting for imports to load "
1474
+ "(Ctrl-C to stop waiting - imports will continue loading in the background)",
1475
+ )
1476
+ with spinner:
1477
+ try:
1478
+ provider.poll_imports(source, model)
1479
+ rich.print("\n\n[green]All imports loaded")
1480
+ except KeyboardInterrupt:
1481
+ rich.print("\n\n[yellow]Imports will continue loading in the background")
1482
+ rich.print(f"[yellow]Use [cyan]rai imports:wait --model {model}[/cyan] to resume waiting")
1483
+ if no_wait_notice:
1484
+ rich.print("[yellow]Use [cyan]--no-wait[/cyan] to skip waiting")
1485
+
1486
+ @cli.command(name="imports:wait", help="Wait for a list of imports to load")
1487
+ @click.option("--source", help="Imports to wait for", multiple=True, type=str)
1488
+ @click.option("--model", help="Model", type=str)
1489
+ def imports_wait(source: List[str], model: str):
1490
+ divider(flush=True)
1491
+ ensure_config()
1492
+ provider = get_resource_provider()
1493
+
1494
+ if not model:
1495
+ with Spinner("Fetching models", "Models fetched"):
1496
+ try:
1497
+ models = [model["name"] for model in provider.list_graphs()]
1498
+ except Exception as e:
1499
+ return exit_with_error(f"\n\n[yellow]Error fetching models: {e}")
1500
+ if not models:
1501
+ return exit_with_error("[yellow]No models found")
1502
+ rich.print()
1503
+ model = controls.fuzzy("Select a model:", models)
1504
+ rich.print()
1505
+
1506
+ if not source:
1507
+ with Spinner("Fetching imports", "Imports fetched", "Error:"):
1508
+ imports = provider.list_imports(model=model)
1509
+ if not imports:
1510
+ exit_with_error("[yellow]No imports found")
1511
+ def is_loaded(import_):
1512
+ status = import_["status"]
1513
+ if status is None:
1514
+ return False
1515
+ return status.upper() == "LOADED"
1516
+ loaded_imports = [i for i in imports if is_loaded(i)]
1517
+ other_imports = [i for i in imports if not is_loaded(i)]
1518
+ if loaded_imports:
1519
+ rich.print()
1520
+ rich.print("[yellow]The following imports are already loaded:")
1521
+ show_imports(loaded_imports)
1522
+ if not other_imports:
1523
+ rich.print()
1524
+ exit_with_error("[yellow]No imports to wait for")
1525
+ if not other_imports:
1526
+ exit_with_error("[yellow]No imports found")
1527
+ rich.print()
1528
+ source = controls.fuzzy_multiselect(
1529
+ "Select imports (tab for multiple):",
1530
+ [i["name"] for i in other_imports]
1531
+ )
1532
+ if not source:
1533
+ exit_with_divider()
1534
+
1535
+ rich.print()
1536
+ poll_imports(provider, source, model, no_wait_notice=False)
1537
+
1538
+ divider()
1539
+
1540
+ #--------------------------------------------------
1541
+ # Imports stream
1542
+ #--------------------------------------------------
1543
+
1544
+ @supports_platform("snowflake")
1545
+ @cli.command(name="imports:stream", help="Stream objects into RAI")
1546
+ @click.option("--source", help="Source", multiple=True)
1547
+ @click.option("--model", help="Model")
1548
+ @click.option("--rate", help="Rate")
1549
+ @click.option("--resume", help="Name of the import to resume")
1550
+ @click.option("--suspend", help="Name of the import to suspend")
1551
+ @click.option("--no-wait", help="Don't wait for imports to load", is_flag=True)
1552
+ @click.option("--force", help="Overwrite any existing streams with the same name", is_flag=True)
1553
+ @click.argument('options', nargs=-1, type=ImportOptionsType())
1554
+ def imports_stream(
1555
+ source: Sequence[str],
1556
+ model: str|None,
1557
+ rate: int|None,
1558
+ resume: str|None,
1559
+ suspend: str|None,
1560
+ no_wait: bool|None,
1561
+ force: bool|None,
1562
+ options: Sequence[ImportOption],
1563
+ ):
1564
+ divider(flush=True)
1565
+ ensure_config()
1566
+ provider = cast(CLIResources, get_resource_provider())
1567
+ default_options = ImportOptionsType.reduce(options)
1568
+
1569
+ # Resume or suspend import stream
1570
+ if resume or suspend:
1571
+ import_name = resume if resume else suspend
1572
+ assert import_name
1573
+ is_suspend = True if suspend else False
1574
+ with Spinner("Acquiring import", "Import stream fetched", "Error:"):
1575
+ stream = provider.list_imports(name=import_name)
1576
+ if not stream:
1577
+ rich.print()
1578
+ rich.print(f"[yellow]Import '{import_name}' not found")
1579
+ exit_with_divider()
1580
+ rich.print()
1581
+ with Spinner(
1582
+ f"{'Resume' if resume else 'Suspend'}ing import stream",
1583
+ f"Import stream {'resumed' if resume else 'suspended'}",
1584
+ "Error:"
1585
+ ):
1586
+ provider.change_stream_status(import_name, model=stream[0]["model"], suspend=is_suspend)
1587
+ exit_with_divider()
1588
+
1589
+ # Model/database selection & validation
1590
+ if not model:
1591
+ with Spinner("Fetching models", "Models fetched"):
1592
+ try:
1593
+ models = ["[CREATE MODEL]"] + [model["name"] for model in provider.list_graphs()]
1594
+ except Exception as e:
1595
+ return exit_with_error(f"\n\n[yellow]Error fetching models: {e}")
1596
+
1597
+ rich.print()
1598
+ model = controls.fuzzy("Select a model:", models)
1599
+ if model == "[CREATE MODEL]":
1600
+ model = controls.text("Model name:")
1601
+ rich.print()
1602
+ with Spinner("Creating model", "Model created"):
1603
+ provider.create_graph(model)
1604
+ rich.print()
1605
+ else:
1606
+ db = provider.get_database(model)
1607
+ if not db:
1608
+ rich.print()
1609
+ with Spinner("Creating model", "Model created"):
1610
+ provider.create_graph(model)
1611
+ try:
1612
+ if not source:
1613
+ sources = import_source_flow(provider)
1614
+ else:
1615
+ sources = [parse_source(provider, source_) for source_ in source]
1616
+ except Exception as e:
1617
+ return exit_with_error(f"[yellow]Error: {e}")
1618
+
1619
+ for import_source in sources:
1620
+ try:
1621
+ opts = import_source_options_flow(provider, import_source, default_options)
1622
+ with Spinner(f"Creating stream for {import_source.name}", f"Stream for {import_source.name} created successfully"):
1623
+ if force:
1624
+ provider.delete_import(import_source.name, model, True)
1625
+ provider.create_import_stream(import_source, model, rate, options=opts)
1626
+ except UnsupportedTypeError as err:
1627
+ exit_with_error(f"\n\n[yellow]The [bold]{provider.platform}[/bold] integration doesn't support streaming from [bold]'{err.type}'[/bold] sources.")
1628
+ except Exception as e:
1629
+ if "relations are not empty" in f"{e}":
1630
+ # Handle LeftOverRelationException directly here
1631
+ from relationalai.errors import LeftOverRelationException
1632
+ exception = LeftOverRelationException(import_source.name, model)
1633
+ exception.pprint()
1634
+ sys.exit(1)
1635
+ elif "use setup_cdc()" in f"{e}":
1636
+ exit_with_error("\n\n[yellow]Imports are not configured.\n[yellow]To start use '[cyan]rai imports:setup[/cyan]' to set up imports.")
1637
+ elif "stream already exists" in f"{e}":
1638
+ exit_with_error(f"\n\n[yellow]Stream [cyan]'{import_source.name.upper()}'[/cyan] already exists.")
1639
+ elif "engine not found" in f"{e}":
1640
+ exit_with_error("\n\n[yellow]Stream engine not found. Please use '[cyan]rai imports:setup[/cyan]' to set up imports.")
1641
+ else:
1642
+ rich.print()
1643
+ exit_with_error(f"\n[yellow]Error creating stream: {e}")
1644
+ wait = not no_wait
1645
+ if wait:
1646
+ poll_imports(provider, [source.name for source in sources], model, no_wait_notice=True)
1647
+ else:
1648
+ rich.print(f"\nRun '[cyan]rai imports:list --model {model}[/cyan]' to check import status.")
1649
+ rich.print(f"\nRun '[cyan]rai imports:wait --model {model}[/cyan]' to poll until the imports are loaded.")
1650
+
1651
+ divider()
1652
+
1653
+ #--------------------------------------------------
1654
+ # Imports snapshot
1655
+ #--------------------------------------------------
1656
+
1657
+ @supports_platform("azure")
1658
+ @cli.command(name="imports:snapshot", help="Load an object once into RAI")
1659
+ @click.option("--source", help="Source")
1660
+ @click.option("--model", help="Model")
1661
+ @click.option("--name", help="Import name")
1662
+ @click.option("--type", help="Import as type", default="auto", type=click.Choice(["auto", *Loader.type_to_loader.keys()]))
1663
+ @click.argument('options', nargs=-1, type=ImportOptionsType())
1664
+ def imports_snapshot(source:str|None, model:str|None, name:str|None, type:str|None, options):
1665
+ divider(flush=True)
1666
+ ensure_config()
1667
+ provider = get_resource_provider()
1668
+ default_options = ImportOptionsType.reduce(options)
1669
+ default_options["type"] = type
1670
+
1671
+ if not model:
1672
+ with Spinner("Fetching models", "Models fetched"):
1673
+ try:
1674
+ models = [model["name"] for model in provider.list_graphs()]
1675
+ except Exception as e:
1676
+ return exit_with_error(f"\n\n[yellow]Error fetching models: {e}")
1677
+ if len(models) == 0:
1678
+ exit_with_error("[yellow]No models found")
1679
+ rich.print()
1680
+ model = controls.fuzzy("Select a model:", models)
1681
+ rich.print()
1682
+
1683
+ sources = [parse_source(provider, source)] if source else import_source_flow(provider)
1684
+ for import_source in sources:
1685
+ try:
1686
+ import_source.name = name if name else controls.text("name:", import_source.name)
1687
+ options = import_source_options_flow(provider, import_source, default_options)
1688
+ with Spinner(f"Creating snapshot for {import_source.name}", f"Snapshot for {import_source.name} created"):
1689
+ provider.create_import_snapshot(import_source, model, options=options)
1690
+ except UnsupportedTypeError as err:
1691
+ exit_with_error(f"\n\n[yellow]The [bold]{provider.platform}[/bold] integration doesn't support loading [bold]'{err.type}'[/bold] files.")
1692
+ except RAIException as e:
1693
+ print("\n\n")
1694
+ e.pprint()
1695
+ exit_with_error("\n[yellow]Error creating snapshot, aborting.")
1696
+
1697
+ except Exception as e:
1698
+ exit_with_error(f"\n\n[yellow]Error creating snapshot: {e}")
1699
+ divider()
1700
+
1701
+ #--------------------------------------------------
1702
+ # Imports delete
1703
+ #--------------------------------------------------
1704
+
1705
+ @cli.command(name="imports:delete", help="Delete an import from RAI")
1706
+ @click.option("--object", help="Object")
1707
+ @click.option("--model", help="Model")
1708
+ @click.option("--force", help="Force delete stream and relations", is_flag=True)
1709
+ def imports_delete(object, model, force):
1710
+ divider(flush=True)
1711
+ ensure_config()
1712
+ provider = cast(CLIResources, get_resource_provider())
1713
+ if not model:
1714
+ with Spinner("Fetching models", "Models fetched"):
1715
+ try:
1716
+ models = [model["name"] for model in provider.list_graphs()]
1717
+ except Exception as e:
1718
+ return exit_with_error(f"\n\n[yellow]Error fetching models: {e}")
1719
+ if len(models) == 0:
1720
+ rich.print()
1721
+ exit_with_error("[yellow]No models found")
1722
+ rich.print()
1723
+ model = controls.fuzzy("Select a model:", models)
1724
+ rich.print()
1725
+
1726
+ with Spinner(f"Fetching imports for {model}", "Imports fetched"):
1727
+ try:
1728
+ imports = provider.list_imports(model=model)
1729
+ except Exception as e:
1730
+ return exit_with_error(f"\n\n[yellow]Error fetching imports: {e}")
1731
+
1732
+ if not imports and not force:
1733
+ rich.print()
1734
+ exit_with_error("[yellow]No imports to delete")
1735
+
1736
+ if object:
1737
+ parser = IdentityParser(object)
1738
+ assert parser.identity, "Invalid object provided for deletion"
1739
+ objects = [parser.identity]
1740
+ else:
1741
+ if len(imports) == 0:
1742
+ exit_with_error("[yellow]No imports found")
1743
+ rich.print()
1744
+ objects = controls.fuzzy_multiselect("Select objects (tab for multiple):", [t["name"] for t in imports])
1745
+ rich.print()
1746
+
1747
+ for object in objects:
1748
+ spinner_message = f"Removing {object}" + (" and relations" if force else "")
1749
+ success_message = f"{object}" + (" and relations" if force else "") + " removed successfully"
1750
+ with Spinner(spinner_message, success_message):
1751
+ try:
1752
+ provider.delete_import(object, model, force)
1753
+ except Exception as e:
1754
+ exit_with_error(f"\n\n[yellow]Error deleting import: {e}")
1755
+ divider()
1756
+
1757
+ #--------------------------------------------------
1758
+ # Exports list
1759
+ #--------------------------------------------------
1760
+
1761
+ @supports_platform("snowflake")
1762
+ @cli.command(name="exports:list", help="List objects exported out of RAI")
1763
+ @click.option("--model", help="Model")
1764
+ def exports_list(model):
1765
+ divider(flush=True)
1766
+ ensure_config()
1767
+ provider = cast(CLIResources, get_resource_provider())
1768
+ coming_soon()
1769
+ if not model:
1770
+ with Spinner("Fetching models", "Models fetched"):
1771
+ try:
1772
+ models = [model["name"] for model in provider.list_graphs()]
1773
+ except Exception as e:
1774
+ return exit_with_error(f"\n\n[yellow]Error fetching models: {e}")
1775
+ if len(models) == 0:
1776
+ return exit_with_error("[yellow]No models found")
1777
+ rich.print()
1778
+ model = controls.fuzzy("Select a model:", models)
1779
+ rich.print()
1780
+
1781
+ with Spinner(f"Fetching exports for {model}", "Exports fetched"):
1782
+ try:
1783
+ exports = provider.list_exports(model, "")
1784
+ except Exception as e:
1785
+ return exit_with_error(f"\n\n[yellow]Error fetching exports: {e}")
1786
+
1787
+ rich.print()
1788
+ if len(exports):
1789
+ table = Table(show_header=True, border_style="dim", header_style="bold", box=rich_box.SIMPLE_HEAD)
1790
+ table.add_column("Object")
1791
+ for imp in exports:
1792
+ table.add_row(imp.get("name"))
1793
+ rich.print(table)
1794
+ else:
1795
+ rich.print("[yellow]No exports found")
1796
+ divider()
1797
+
1798
+ #--------------------------------------------------
1799
+ # Exports delete
1800
+ #--------------------------------------------------
1801
+
1802
+ @supports_platform("snowflake")
1803
+ @cli.command(name="exports:delete", help="Delete an export from RAI")
1804
+ @click.option("--export", help="export")
1805
+ @click.option("--model", help="Model")
1806
+ def exports_delete(export, model):
1807
+ divider(flush=True)
1808
+ ensure_config()
1809
+ provider = cast(CLIResources, get_resource_provider())
1810
+ coming_soon()
1811
+ if not model:
1812
+ with Spinner("Fetching models", "Models fetched"):
1813
+ try:
1814
+ models = [model["name"] for model in provider.list_graphs()]
1815
+ except Exception as e:
1816
+ return exit_with_error(f"\n\n[yellow]Error fetching models: {e}")
1817
+ if len(models) == 0:
1818
+ exit_with_error("[yellow]No models found")
1819
+ rich.print()
1820
+ model = controls.fuzzy("Select a model:", models)
1821
+ rich.print()
1822
+
1823
+ # @FIXME It seems like we should just fuzzy list exports but this was the original behavior
1824
+ source_names = [export] if export else [source.name for source in import_source_flow(provider)]
1825
+ for source_name in source_names:
1826
+ with Spinner(f"Removing {source_name}", f"{source_name} removed"):
1827
+ try:
1828
+ provider.delete_export(model, "", source_name)
1829
+ except Exception as e:
1830
+ rich.print(f"\n\n[yellow]Error deleting export: {e}")
1831
+ divider()
1832
+
1833
+ #--------------------------------------------------
1834
+ # Transactions get
1835
+ #--------------------------------------------------
1836
+
1837
+ @cli.command(name="transactions:get", help="Get transaction details")
1838
+ @click.option("--id", help="Transaction id")
1839
+ def transactions_get(id):
1840
+ divider()
1841
+ ensure_config()
1842
+ provider = get_resource_provider()
1843
+ transaction = None
1844
+ if not id:
1845
+ id = controls.text("Transaction id:", mandatory=True, validator=UUID.match, invalid_message="Invalid transaction id")
1846
+ rich.print("")
1847
+
1848
+ with Spinner("Fetching transaction", "Transaction fetched"):
1849
+ try:
1850
+ transaction = provider.get_transaction(id)
1851
+ except Exception as e:
1852
+ exit_with_error(f"\n\n[yellow]Error fetching transaction: {e}")
1853
+ rich.print()
1854
+ if transaction:
1855
+ show_dictionary_table(transaction, format_row)
1856
+ divider()
1857
+
1858
+ #--------------------------------------------------
1859
+ # Transactions list
1860
+ #--------------------------------------------------
1861
+
1862
+ @cli.command(name="transactions:list", help="List transactions")
1863
+ @click.option("--id", help="Filter by transaction id", type=str)
1864
+ @click.option("--state", help="Filter by transaction state", type=str)
1865
+ @click.option("--engine", help="Filter by transaction engine", type=str)
1866
+ @click.option("--limit", default=20, help="Limit", type=int)
1867
+ @click.option("--all-users", is_flag=True, default=False, help="Show transactions from all users")
1868
+ def transactions_list(id, state, engine, limit, all_users):
1869
+ divider()
1870
+ cfg = ensure_config()
1871
+ provider = get_resource_provider()
1872
+ with Spinner("Fetching transactions", "Transactions fetched"):
1873
+ try:
1874
+ transactions = provider.list_transactions(
1875
+ id=id,
1876
+ state=state,
1877
+ engine=engine,
1878
+ limit=max(limit, 100),
1879
+ all_users=all_users,
1880
+ created_by=cfg.get("user", None),
1881
+ )
1882
+ except Exception as e:
1883
+ rich.print()
1884
+ return exit_with_error(f"\n\n[yellow]Error fetching transactions: {e}\n")
1885
+
1886
+ if len(transactions) == 0:
1887
+ rich.print()
1888
+ exit_with_error("[yellow]No transactions found")
1889
+
1890
+ rich.print()
1891
+ show_transactions(transactions, limit)
1892
+ divider()
1893
+
1894
+ #--------------------------------------------------
1895
+ # Transaction cancel
1896
+ #--------------------------------------------------
1897
+
1898
+ @cli.command(name="transactions:cancel", help="Cancel a transaction")
1899
+ @click.option("--id", help="Transaction ID")
1900
+ @click.option("--all-users", is_flag=True, help="Show transactions from all users")
1901
+ def transactions_cancel(id, all_users):
1902
+ divider()
1903
+ cfg = ensure_config()
1904
+ provider = get_resource_provider()
1905
+ if id is None:
1906
+ with Spinner("Fetching transactions", "Transactions fetched"):
1907
+ try:
1908
+ transactions = provider.list_transactions(
1909
+ limit=20,
1910
+ only_active=True,
1911
+ all_users=all_users,
1912
+ created_by=cfg.get("user", None),
1913
+ )
1914
+ except Exception as e:
1915
+ return exit_with_error(f"\n\n[yellow]Error fetching transactions: {e}")
1916
+
1917
+ if not transactions:
1918
+ exit_with_error("\n[yellow]No active transactions found")
1919
+
1920
+ show_transactions(transactions, 20)
1921
+
1922
+ id = controls.fuzzy("Select a transaction to cancel:", [t["id"] for t in transactions])
1923
+ print()
1924
+
1925
+ with Spinner("Cancelling transaction", "Transaction cancelled", "Error:"):
1926
+ provider.cancel_transaction(id)
1927
+ divider()
1928
+
1929
+ #--------------------------------------------------
1930
+ # Main
1931
+ #--------------------------------------------------
1932
+
1933
+ if __name__ == "__main__":
1934
+ # app = EventApp()
1935
+ # app.run()
1936
+ cli()