rete-graph 0.4.0__tar.gz → 0.4.2__tar.gz

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 (132) hide show
  1. {rete_graph-0.4.0 → rete_graph-0.4.2}/Cargo.toml +1 -1
  2. {rete_graph-0.4.0 → rete_graph-0.4.2}/PKG-INFO +1 -1
  3. {rete_graph-0.4.0 → rete_graph-0.4.2}/clients/python/Cargo.lock +55 -2
  4. {rete_graph-0.4.0 → rete_graph-0.4.2}/clients/python/Cargo.toml +14 -4
  5. {rete_graph-0.4.0 → rete_graph-0.4.2}/clients/python/src/lib.rs +33 -10
  6. rete_graph-0.4.2/clients/python/src/readers.rs +177 -0
  7. rete_graph-0.4.2/clients/python/tests/test_threads_and_http.py +200 -0
  8. {rete_graph-0.4.0 → rete_graph-0.4.2}/crates/rete-core/Cargo.toml +9 -0
  9. {rete_graph-0.4.0 → rete_graph-0.4.2}/crates/rete-core/src/bgp.rs +15 -2
  10. rete_graph-0.4.2/crates/rete-core/src/build_progress.rs +395 -0
  11. {rete_graph-0.4.0 → rete_graph-0.4.2}/crates/rete-core/src/build_trace.rs +13 -1
  12. {rete_graph-0.4.0 → rete_graph-0.4.2}/crates/rete-core/src/card_derive.rs +16 -0
  13. {rete_graph-0.4.0 → rete_graph-0.4.2}/crates/rete-core/src/dict.rs +59 -9
  14. {rete_graph-0.4.0 → rete_graph-0.4.2}/crates/rete-core/src/dictionary.rs +214 -13
  15. {rete_graph-0.4.0 → rete_graph-0.4.2}/crates/rete-core/src/extbuild.rs +1886 -1049
  16. rete_graph-0.4.2/crates/rete-core/src/extbuild_remap.rs +470 -0
  17. {rete_graph-0.4.0 → rete_graph-0.4.2}/crates/rete-core/src/extbuild_sections.rs +120 -57
  18. rete_graph-0.4.2/crates/rete-core/src/extbuild_spill.rs +1082 -0
  19. {rete_graph-0.4.0 → rete_graph-0.4.2}/crates/rete-core/src/extsort.rs +31 -6
  20. {rete_graph-0.4.0 → rete_graph-0.4.2}/crates/rete-core/src/file.rs +182 -55
  21. rete_graph-0.4.2/crates/rete-core/src/http.rs +1269 -0
  22. {rete_graph-0.4.0 → rete_graph-0.4.2}/crates/rete-core/src/index.rs +125 -24
  23. {rete_graph-0.4.0 → rete_graph-0.4.2}/crates/rete-core/src/ingest.rs +48 -12
  24. {rete_graph-0.4.0 → rete_graph-0.4.2}/crates/rete-core/src/lib.rs +23 -1
  25. {rete_graph-0.4.0 → rete_graph-0.4.2}/crates/rete-core/src/quad.rs +116 -0
  26. rete_graph-0.4.2/crates/rete-core/src/recard.rs +1046 -0
  27. {rete_graph-0.4.0 → rete_graph-0.4.2}/crates/rete-core/src/sparql/eval.rs +498 -104
  28. rete_graph-0.4.2/crates/rete-core/src/sparql/prefetch.rs +173 -0
  29. {rete_graph-0.4.0 → rete_graph-0.4.2}/crates/rete-core/src/sparql.rs +1 -0
  30. rete_graph-0.4.2/crates/rete-core/src/sysmem.rs +267 -0
  31. {rete_graph-0.4.0 → rete_graph-0.4.2}/crates/rete-core/src/text_index.rs +5 -2
  32. {rete_graph-0.4.0 → rete_graph-0.4.2}/crates/rete-core/src/text_index_spill.rs +180 -63
  33. {rete_graph-0.4.0 → rete_graph-0.4.2}/crates/rete-core/src/write_opts.rs +13 -0
  34. rete_graph-0.4.2/crates/rete-core/tests/contains_str_pushdown.rs +433 -0
  35. rete_graph-0.4.2/crates/rete-core/tests/lookup_batch.rs +134 -0
  36. rete_graph-0.4.2/crates/rete-core/tests/text_pushdown_coverage.rs +424 -0
  37. {rete_graph-0.4.0 → rete_graph-0.4.2}/crates/rete-core/tests/write_opts.rs +19 -6
  38. {rete_graph-0.4.0 → rete_graph-0.4.2}/pyproject.toml +1 -1
  39. {rete_graph-0.4.0 → rete_graph-0.4.2}/python/rete_graph/__init__.py +9 -2
  40. rete_graph-0.4.0/clients/python/src/readers.rs +0 -293
  41. rete_graph-0.4.0/crates/rete-core/src/recard.rs +0 -526
  42. {rete_graph-0.4.0 → rete_graph-0.4.2}/README.md +0 -0
  43. {rete_graph-0.4.0 → rete_graph-0.4.2}/clients/python/.gitignore +0 -0
  44. {rete_graph-0.4.0 → rete_graph-0.4.2}/clients/python/README.md +0 -0
  45. {rete_graph-0.4.0 → rete_graph-0.4.2}/clients/python/examples/agents/README.md +0 -0
  46. {rete_graph-0.4.0 → rete_graph-0.4.2}/clients/python/examples/agents/langchain_agent.py +0 -0
  47. {rete_graph-0.4.0 → rete_graph-0.4.2}/clients/python/examples/agents/pydantic_ai_agent.py +0 -0
  48. {rete_graph-0.4.0 → rete_graph-0.4.2}/clients/python/examples/agents/rete_tools.py +0 -0
  49. {rete_graph-0.4.0 → rete_graph-0.4.2}/clients/python/examples/graph-data-science.ipynb +0 -0
  50. {rete_graph-0.4.0 → rete_graph-0.4.2}/clients/python/examples/jupyterlite-build-tutorial.ipynb +0 -0
  51. {rete_graph-0.4.0 → rete_graph-0.4.2}/clients/python/examples/jupyterlite-demo.ipynb +0 -0
  52. {rete_graph-0.4.0 → rete_graph-0.4.2}/clients/python/examples/tutorial.ipynb +0 -0
  53. {rete_graph-0.4.0 → rete_graph-0.4.2}/clients/python/tests/conftest.py +0 -0
  54. {rete_graph-0.4.0 → rete_graph-0.4.2}/clients/python/tests/test_rdf12.py +0 -0
  55. {rete_graph-0.4.0 → rete_graph-0.4.2}/clients/python/tests/test_rete_graph.py +0 -0
  56. {rete_graph-0.4.0 → rete_graph-0.4.2}/clients/python/tests/test_warnings.py +0 -0
  57. {rete_graph-0.4.0 → rete_graph-0.4.2}/crates/rete-core/LICENSE +0 -0
  58. {rete_graph-0.4.0 → rete_graph-0.4.2}/crates/rete-core/README.md +0 -0
  59. {rete_graph-0.4.0 → rete_graph-0.4.2}/crates/rete-core/examples/coherence_bench.rs +0 -0
  60. {rete_graph-0.4.0 → rete_graph-0.4.2}/crates/rete-core/examples/compression_lab.rs +0 -0
  61. {rete_graph-0.4.0 → rete_graph-0.4.2}/crates/rete-core/examples/parallel_bench.rs +0 -0
  62. {rete_graph-0.4.0 → rete_graph-0.4.2}/crates/rete-core/examples/qbench.rs +0 -0
  63. {rete_graph-0.4.0 → rete_graph-0.4.2}/crates/rete-core/src/block_cache.rs +0 -0
  64. {rete_graph-0.4.0 → rete_graph-0.4.2}/crates/rete-core/src/card_input.rs +0 -0
  65. {rete_graph-0.4.0 → rete_graph-0.4.2}/crates/rete-core/src/card_queries.rs +0 -0
  66. {rete_graph-0.4.0 → rete_graph-0.4.2}/crates/rete-core/src/chunk_cache.rs +0 -0
  67. {rete_graph-0.4.0 → rete_graph-0.4.2}/crates/rete-core/src/geo.rs +0 -0
  68. {rete_graph-0.4.0 → rete_graph-0.4.2}/crates/rete-core/src/geo3.rs +0 -0
  69. {rete_graph-0.4.0 → rete_graph-0.4.2}/crates/rete-core/src/header.rs +0 -0
  70. {rete_graph-0.4.0 → rete_graph-0.4.2}/crates/rete-core/src/iri.rs +0 -0
  71. {rete_graph-0.4.0 → rete_graph-0.4.2}/crates/rete-core/src/label_index.rs +0 -0
  72. {rete_graph-0.4.0 → rete_graph-0.4.2}/crates/rete-core/src/manifest.rs +0 -0
  73. {rete_graph-0.4.0 → rete_graph-0.4.2}/crates/rete-core/src/meta.rs +0 -0
  74. {rete_graph-0.4.0 → rete_graph-0.4.2}/crates/rete-core/src/parallel.rs +0 -0
  75. {rete_graph-0.4.0 → rete_graph-0.4.2}/crates/rete-core/src/pyramid.rs +0 -0
  76. {rete_graph-0.4.0 → rete_graph-0.4.2}/crates/rete-core/src/reach.rs +0 -0
  77. {rete_graph-0.4.0 → rete_graph-0.4.2}/crates/rete-core/src/reader.rs +0 -0
  78. {rete_graph-0.4.0 → rete_graph-0.4.2}/crates/rete-core/src/reason.rs +0 -0
  79. {rete_graph-0.4.0 → rete_graph-0.4.2}/crates/rete-core/src/results.rs +0 -0
  80. {rete_graph-0.4.0 → rete_graph-0.4.2}/crates/rete-core/src/row.rs +0 -0
  81. {rete_graph-0.4.0 → rete_graph-0.4.2}/crates/rete-core/src/schema_pyramid.rs +0 -0
  82. {rete_graph-0.4.0 → rete_graph-0.4.2}/crates/rete-core/src/schema_section.rs +0 -0
  83. {rete_graph-0.4.0 → rete_graph-0.4.2}/crates/rete-core/src/service.rs +0 -0
  84. {rete_graph-0.4.0 → rete_graph-0.4.2}/crates/rete-core/src/shacl.rs +0 -0
  85. {rete_graph-0.4.0 → rete_graph-0.4.2}/crates/rete-core/src/sparql/aggregate.rs +0 -0
  86. {rete_graph-0.4.0 → rete_graph-0.4.2}/crates/rete-core/src/sparql/diag.rs +0 -0
  87. {rete_graph-0.4.0 → rete_graph-0.4.2}/crates/rete-core/src/sparql/distinct.rs +0 -0
  88. {rete_graph-0.4.0 → rete_graph-0.4.2}/crates/rete-core/src/sparql/distinct_union.rs +0 -0
  89. {rete_graph-0.4.0 → rete_graph-0.4.2}/crates/rete-core/src/sparql/expr.rs +0 -0
  90. {rete_graph-0.4.0 → rete_graph-0.4.2}/crates/rete-core/src/sparql/lower.rs +0 -0
  91. {rete_graph-0.4.0 → rete_graph-0.4.2}/crates/rete-core/src/sparql/partition.rs +0 -0
  92. {rete_graph-0.4.0 → rete_graph-0.4.2}/crates/rete-core/src/sparql/path.rs +0 -0
  93. {rete_graph-0.4.0 → rete_graph-0.4.2}/crates/rete-core/src/sparql/ql.rs +0 -0
  94. {rete_graph-0.4.0 → rete_graph-0.4.2}/crates/rete-core/src/sparql/sparql12.rs +0 -0
  95. {rete_graph-0.4.0 → rete_graph-0.4.2}/crates/rete-core/src/sparql/value.rs +0 -0
  96. {rete_graph-0.4.0 → rete_graph-0.4.2}/crates/rete-core/src/terms.rs +0 -0
  97. {rete_graph-0.4.0 → rete_graph-0.4.2}/crates/rete-core/src/tiling.rs +0 -0
  98. {rete_graph-0.4.0 → rete_graph-0.4.2}/crates/rete-core/src/triples.rs +0 -0
  99. {rete_graph-0.4.0 → rete_graph-0.4.2}/crates/rete-core/src/varint.rs +0 -0
  100. {rete_graph-0.4.0 → rete_graph-0.4.2}/crates/rete-core/tests/community_eval.rs +0 -0
  101. {rete_graph-0.4.0 → rete_graph-0.4.2}/crates/rete-core/tests/compatibility_v1.rs +0 -0
  102. {rete_graph-0.4.0 → rete_graph-0.4.2}/crates/rete-core/tests/entailment_sets.rs +0 -0
  103. {rete_graph-0.4.0 → rete_graph-0.4.2}/crates/rete-core/tests/fixtures/louvain-hangs/jev-commander-145.nt +0 -0
  104. {rete_graph-0.4.0 → rete_graph-0.4.2}/crates/rete-core/tests/fixtures/louvain-hangs/jev-random30-30.nt +0 -0
  105. {rete_graph-0.4.0 → rete_graph-0.4.2}/crates/rete-core/tests/fixtures/louvain-hangs/jev-random63-63.nt +0 -0
  106. {rete_graph-0.4.0 → rete_graph-0.4.2}/crates/rete-core/tests/fixtures/louvain-hangs/min-15-level0.nt +0 -0
  107. {rete_graph-0.4.0 → rete_graph-0.4.2}/crates/rete-core/tests/fixtures/louvain-hangs/min-18-level1.nt +0 -0
  108. {rete_graph-0.4.0 → rete_graph-0.4.2}/crates/rete-core/tests/fixtures/v1/glue-stub.js +0 -0
  109. {rete_graph-0.4.0 → rete_graph-0.4.2}/crates/rete-core/tests/fixtures/v1/minimal.rete +0 -0
  110. {rete_graph-0.4.0 → rete_graph-0.4.2}/crates/rete-core/tests/fixtures/v1/source.nq +0 -0
  111. {rete_graph-0.4.0 → rete_graph-0.4.2}/crates/rete-core/tests/graph_scope.rs +0 -0
  112. {rete_graph-0.4.0 → rete_graph-0.4.2}/crates/rete-core/tests/iri_differential.rs +0 -0
  113. {rete_graph-0.4.0 → rete_graph-0.4.2}/crates/rete-core/tests/label_schema_sections.rs +0 -0
  114. {rete_graph-0.4.0 → rete_graph-0.4.2}/crates/rete-core/tests/louvain_termination.rs +0 -0
  115. {rete_graph-0.4.0 → rete_graph-0.4.2}/crates/rete-core/tests/polyglot_roundtrip.rs +0 -0
  116. {rete_graph-0.4.0 → rete_graph-0.4.2}/crates/rete-core/tests/properties.proptest-regressions +0 -0
  117. {rete_graph-0.4.0 → rete_graph-0.4.2}/crates/rete-core/tests/properties.rs +0 -0
  118. {rete_graph-0.4.0 → rete_graph-0.4.2}/crates/rete-core/tests/public_api.rs +0 -0
  119. {rete_graph-0.4.0 → rete_graph-0.4.2}/crates/rete-core/tests/quad_index.rs +0 -0
  120. {rete_graph-0.4.0 → rete_graph-0.4.2}/crates/rete-core/tests/ranged.rs +0 -0
  121. {rete_graph-0.4.0 → rete_graph-0.4.2}/crates/rete-core/tests/regex_unicode.rs +0 -0
  122. {rete_graph-0.4.0 → rete_graph-0.4.2}/crates/rete-core/tests/robustness.rs +0 -0
  123. {rete_graph-0.4.0 → rete_graph-0.4.2}/crates/rete-core/tests/roundtrip.rs +0 -0
  124. {rete_graph-0.4.0 → rete_graph-0.4.2}/crates/rete-core/tests/service_federation.rs +0 -0
  125. {rete_graph-0.4.0 → rete_graph-0.4.2}/crates/rete-core/tests/shacl_core.rs +0 -0
  126. {rete_graph-0.4.0 → rete_graph-0.4.2}/crates/rete-core/tests/sparql12_triple_terms.rs +0 -0
  127. {rete_graph-0.4.0 → rete_graph-0.4.2}/crates/rete-core/tests/sparql_integration.rs +0 -0
  128. {rete_graph-0.4.0 → rete_graph-0.4.2}/crates/rete-core/tests/sparql_nondeterministic.rs +0 -0
  129. {rete_graph-0.4.0 → rete_graph-0.4.2}/crates/rete-core/tests/sparql_partition.rs +0 -0
  130. {rete_graph-0.4.0 → rete_graph-0.4.2}/crates/rete-core/tests/sparql_warnings.rs +0 -0
  131. {rete_graph-0.4.0 → rete_graph-0.4.2}/crates/rete-core/tests/string_literals.rs +0 -0
  132. {rete_graph-0.4.0 → rete_graph-0.4.2}/crates/rete-core/tests/text_index_scope.rs +0 -0
@@ -18,7 +18,7 @@ members = [
18
18
  exclude = ["fuzz", "clients/python", "clients/r/src/rust", "clients/java/ffi", "clients/tauri/src-tauri"]
19
19
 
20
20
  [workspace.package]
21
- version = "0.4.0"
21
+ version = "0.4.2"
22
22
  edition = "2021"
23
23
  license = "Apache-2.0"
24
24
  repository = "https://github.com/caviri/rete"
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: rete-graph
3
- Version: 0.4.0
3
+ Version: 0.4.2
4
4
  Classifier: Development Status :: 4 - Beta
5
5
  Classifier: Intended Audience :: Developers
6
6
  Classifier: Intended Audience :: Science/Research
@@ -94,6 +94,31 @@ dependencies = [
94
94
  "libc",
95
95
  ]
96
96
 
97
+ [[package]]
98
+ name = "crossbeam-deque"
99
+ version = "0.8.8"
100
+ source = "registry+https://github.com/rust-lang/crates.io-index"
101
+ checksum = "622f3fc73690be383c7214310406f28a90e6edeadc3cea882f9d71e495b9711a"
102
+ dependencies = [
103
+ "crossbeam-epoch",
104
+ "crossbeam-utils",
105
+ ]
106
+
107
+ [[package]]
108
+ name = "crossbeam-epoch"
109
+ version = "0.9.21"
110
+ source = "registry+https://github.com/rust-lang/crates.io-index"
111
+ checksum = "dc74980687109a3b14c72fd458107bf0baa1da1a1a805e178d15501ba9b86d9d"
112
+ dependencies = [
113
+ "crossbeam-utils",
114
+ ]
115
+
116
+ [[package]]
117
+ name = "crossbeam-utils"
118
+ version = "0.8.23"
119
+ source = "registry+https://github.com/rust-lang/crates.io-index"
120
+ checksum = "a31eee39dddec8330830986fcd7625edb5a24ec90ea038215273bbc3adb08ac6"
121
+
97
122
  [[package]]
98
123
  name = "crypto-common"
99
124
  version = "0.1.7"
@@ -125,6 +150,12 @@ dependencies = [
125
150
  "syn 2.0.119",
126
151
  ]
127
152
 
153
+ [[package]]
154
+ name = "either"
155
+ version = "1.19.0"
156
+ source = "registry+https://github.com/rust-lang/crates.io-index"
157
+ checksum = "0e9c71c2167ca323c882b99918929403426e2373ea17242ff5653e0d5e1058be"
158
+
128
159
  [[package]]
129
160
  name = "find-msvc-tools"
130
161
  version = "0.1.9"
@@ -598,6 +629,26 @@ dependencies = [
598
629
  "getrandom 0.2.17",
599
630
  ]
600
631
 
632
+ [[package]]
633
+ name = "rayon"
634
+ version = "1.12.0"
635
+ source = "registry+https://github.com/rust-lang/crates.io-index"
636
+ checksum = "fb39b166781f92d482534ef4b4b1b2568f42613b53e5b6c160e24cfbfa30926d"
637
+ dependencies = [
638
+ "either",
639
+ "rayon-core",
640
+ ]
641
+
642
+ [[package]]
643
+ name = "rayon-core"
644
+ version = "1.13.0"
645
+ source = "registry+https://github.com/rust-lang/crates.io-index"
646
+ checksum = "22e18b0f0062d30d4230b2e85ff77fdfe4326feb054b9783a3460d8435c8ab91"
647
+ dependencies = [
648
+ "crossbeam-deque",
649
+ "crossbeam-utils",
650
+ ]
651
+
601
652
  [[package]]
602
653
  name = "regex"
603
654
  version = "1.13.1"
@@ -635,7 +686,7 @@ checksum = "d6f6ff9a378485b298a5286656da665ba74413d36db0979633275d2e708145d4"
635
686
 
636
687
  [[package]]
637
688
  name = "rete-core"
638
- version = "0.4.0"
689
+ version = "0.4.2"
639
690
  dependencies = [
640
691
  "blake3",
641
692
  "getrandom 0.2.17",
@@ -646,6 +697,7 @@ dependencies = [
646
697
  "oxrdfxml",
647
698
  "oxttl 0.1.8",
648
699
  "oxttl 0.2.4",
700
+ "rayon",
649
701
  "regex",
650
702
  "regex-lite",
651
703
  "ruzstd",
@@ -655,12 +707,13 @@ dependencies = [
655
707
  "sha2",
656
708
  "spargebra",
657
709
  "thiserror",
710
+ "ureq",
658
711
  "zstd",
659
712
  ]
660
713
 
661
714
  [[package]]
662
715
  name = "rete-python"
663
- version = "0.4.0"
716
+ version = "0.4.2"
664
717
  dependencies = [
665
718
  "pyo3",
666
719
  "rete-core",
@@ -6,7 +6,7 @@ name = "rete-python"
6
6
  # Kept in lockstep with pyproject.toml's [project] version, and with the engine's
7
7
  # major.minor, by scripts/sync_versions.py (--check runs in CI). __version__ comes
8
8
  # from here (CARGO_PKG_VERSION), the wheel metadata from pyproject.
9
- version = "0.4.0"
9
+ version = "0.4.2"
10
10
  edition = "2021"
11
11
  license = "Apache-2.0"
12
12
  repository = "https://github.com/caviri/rete"
@@ -34,8 +34,18 @@ serde_json = "1"
34
34
  # Native-only: browsers have no sockets, so the blocking HTTP reader and the
35
35
  # SERVICE client are compiled out on emscripten — there, remote reads route
36
36
  # through the Python-object reader (sync XHR in the pure-Python layer).
37
+ #
38
+ # `parallel` (rayon) is native-only for the same reason: Pyodide has no
39
+ # threads. It spreads a build's sorts, permutations and tile/chunk compression
40
+ # over every core, and a query's dictionary decodes over a small pool; the
41
+ # bytes are the same as the serial build's. `http` is rete-core's range reader,
42
+ # the one the CLI uses (kept-alive, 16 in flight, coalesced, retried, and the
43
+ # bounded whole-body fallback for hosts that ignore Range).
44
+ #
45
+ # Cargo's feature resolver 2 (edition 2021) enables these only when the target
46
+ # matches, so the emscripten build keeps the feature-less base dependency above.
37
47
  [target.'cfg(not(target_os = "emscripten"))'.dependencies]
38
- rete-core = { path = "../../crates/rete-core", features = ["compression"] }
39
- # Blocking HTTP(S) range reads + SERVICE federation, mirroring rete-cli
40
- # (rustls via the `tls` feature — no system OpenSSL anywhere wheels land).
48
+ rete-core = { path = "../../crates/rete-core", features = ["compression", "parallel", "http"] }
49
+ # SERVICE federation's HTTP client, mirroring rete-cli (rustls via the `tls`
50
+ # feature — no system OpenSSL anywhere wheels land).
41
51
  ureq = { version = "2", default-features = false, features = ["tls"] }
@@ -5,8 +5,12 @@
5
5
  //! Python values by the pure-Python `rete_graph` wrapper package.
6
6
  //!
7
7
  //! Every potentially slow call runs inside `Python::detach` (PyO3's name for
8
- //! the old `allow_threads` since 0.26), so remote range fetches (which fan out
9
- //! over a thread pool) never hold the GIL.
8
+ //! the old `allow_threads` since 0.26): opening, querying, dumping, searching,
9
+ //! validating, building and deriving a card never hold the GIL, so other
10
+ //! Python threads keep running. Inside those calls the native wheels use more
11
+ //! than one core: remote range fetches fan out over the HTTP reader's threads,
12
+ //! and rete-core's `parallel` feature (rayon, off on Pyodide) spreads a build's
13
+ //! sorts and compression and a query's dictionary decodes across the machine.
10
14
 
11
15
  mod readers;
12
16
 
@@ -276,12 +280,14 @@ impl Graph {
276
280
  }
277
281
 
278
282
  /// The named-graph IRIs of a dataset.
279
- fn graph_names(&self) -> Vec<String> {
280
- self.rete
281
- .graph_names()
282
- .into_iter()
283
- .map(str::to_owned)
284
- .collect()
283
+ fn graph_names(&self, py: Python<'_>) -> Vec<String> {
284
+ py.detach(|| {
285
+ self.rete
286
+ .graph_names()
287
+ .into_iter()
288
+ .map(str::to_owned)
289
+ .collect()
290
+ })
285
291
  }
286
292
 
287
293
  /// Label prefix search over the pyramid's label index:
@@ -399,7 +405,8 @@ fn open_path(py: Python<'_>, path: String) -> PyResult<Graph> {
399
405
  }
400
406
 
401
407
  /// Open a remote `.rete` over HTTP range requests, lazily. `headers` ride on
402
- /// every request (auth tokens, custom User-Agent). Native-only: the Pyodide
408
+ /// every request (auth tokens, custom User-Agent). The reader is rete-core's,
409
+ /// tuned by the CLI's `RETE_HTTP_*` variables. Native-only: the Pyodide
403
410
  /// build's `open()` routes URLs through the sync-XHR Python reader instead.
404
411
  #[cfg(not(target_os = "emscripten"))]
405
412
  #[pyfunction]
@@ -412,7 +419,9 @@ fn open_url(
412
419
  let headers: Vec<(String, String)> =
413
420
  headers.map(|h| h.into_iter().collect()).unwrap_or_default();
414
421
  py.detach(|| {
415
- let reader = HttpRangeReader::open(&url, headers).map_err(runtime_err)?;
422
+ let policy = rete_core::http::FetchPolicy::from_env();
423
+ let reader =
424
+ HttpRangeReader::open_with_headers(&url, headers, policy).map_err(runtime_err)?;
416
425
  open_lazy(AnyReader::Http(reader))
417
426
  })
418
427
  }
@@ -695,5 +704,19 @@ fn _rete(m: &Bound<'_, PyModule>) -> PyResult<()> {
695
704
  // The binding's version tracks the binding; this reports the engine actually
696
705
  // compiled into the wheel, which is what "does my install support X?" means.
697
706
  m.add("__engine_version__", rete_core::VERSION)?;
707
+ // The rete-core features compiled into this wheel: a native wheel has
708
+ // `parallel` and `http`, a Pyodide one has neither.
709
+ m.add("__engine_features__", engine_features())?;
698
710
  Ok(())
699
711
  }
712
+
713
+ /// The rete-core features this module was built with: the ones a build
714
+ /// record names (`compression`, `parallel`, …), as rete-core reports them, and
715
+ /// `http` when the native range reader (`open_url`) is compiled in.
716
+ fn engine_features() -> Vec<&'static str> {
717
+ let mut f = rete_core::build_trace::enabled_features();
718
+ if cfg!(not(target_os = "emscripten")) {
719
+ f.push("http");
720
+ }
721
+ f
722
+ }
@@ -0,0 +1,177 @@
1
+ //! The [`RangeReader`] implementations behind `rete_graph.open()`: a local
2
+ //! file (positional reads), an HTTP(S) client (`Range` requests: rete-core's
3
+ //! shared reader, the one the CLI uses), and an adapter over a user-supplied Python
4
+ //! object — the escape hatch that lets fsspec/s3fs-style storage back a graph
5
+ //! without any auth code on this side.
6
+
7
+ use std::fs::File;
8
+ use std::io;
9
+
10
+ use pyo3::prelude::*;
11
+ use rete_core::RangeReader;
12
+
13
+ /// The one reader type the open path stores: dispatch instead of generics so
14
+ /// [`crate::Graph`] stays a single non-generic pyclass. The HTTP variant is
15
+ /// native-only — on emscripten (Pyodide) remote reads come in as a
16
+ /// [`PyRangeReader`] over the pure-Python sync-XHR reader.
17
+ pub enum AnyReader {
18
+ Local(LocalRangeReader),
19
+ #[cfg(not(target_os = "emscripten"))]
20
+ Http(HttpRangeReader),
21
+ Py(PyRangeReader),
22
+ }
23
+
24
+ impl RangeReader for AnyReader {
25
+ fn len(&self) -> u64 {
26
+ match self {
27
+ Self::Local(r) => r.len(),
28
+ #[cfg(not(target_os = "emscripten"))]
29
+ Self::Http(r) => r.len(),
30
+ Self::Py(r) => r.len(),
31
+ }
32
+ }
33
+
34
+ fn read_at(&self, offset: u64, len: u64) -> io::Result<Vec<u8>> {
35
+ match self {
36
+ Self::Local(r) => r.read_at(offset, len),
37
+ #[cfg(not(target_os = "emscripten"))]
38
+ Self::Http(r) => r.read_at(offset, len),
39
+ Self::Py(r) => r.read_at(offset, len),
40
+ }
41
+ }
42
+
43
+ fn read_many(&self, ranges: &[(u64, u64)]) -> io::Result<Vec<Vec<u8>>> {
44
+ match self {
45
+ Self::Local(r) => r.read_many(ranges),
46
+ #[cfg(not(target_os = "emscripten"))]
47
+ Self::Http(r) => r.read_many(ranges),
48
+ Self::Py(r) => r.read_many(ranges),
49
+ }
50
+ }
51
+
52
+ // Forwarded, or the trait default (1) tells the planner every reader is
53
+ // serial: it would then size its probe-vs-scan decisions for one request
54
+ // at a time while the HTTP reader really keeps 16 in flight.
55
+ fn concurrency(&self) -> usize {
56
+ match self {
57
+ Self::Local(r) => r.concurrency(),
58
+ #[cfg(not(target_os = "emscripten"))]
59
+ Self::Http(r) => r.concurrency(),
60
+ Self::Py(r) => r.concurrency(),
61
+ }
62
+ }
63
+ }
64
+
65
+ /// Positional reads against a local file (no mmap, no whole-file load), so a
66
+ /// multi-GB `.rete` on disk opens as lazily as a remote one.
67
+ pub struct LocalRangeReader {
68
+ file: File,
69
+ len: u64,
70
+ }
71
+
72
+ impl LocalRangeReader {
73
+ pub fn open(path: &str) -> io::Result<Self> {
74
+ let file = File::open(path)?;
75
+ let len = file.metadata()?.len();
76
+ Ok(Self { file, len })
77
+ }
78
+ }
79
+
80
+ impl RangeReader for LocalRangeReader {
81
+ fn len(&self) -> u64 {
82
+ self.len
83
+ }
84
+
85
+ fn read_at(&self, offset: u64, len: u64) -> io::Result<Vec<u8>> {
86
+ offset
87
+ .checked_add(len)
88
+ .filter(|end| *end <= self.len)
89
+ .ok_or_else(|| io::Error::new(io::ErrorKind::UnexpectedEof, "range out of bounds"))?;
90
+ let size = usize::try_from(len).map_err(|_| {
91
+ io::Error::new(io::ErrorKind::InvalidInput, "range too large for memory")
92
+ })?;
93
+ let mut buf = vec![0u8; size];
94
+ read_exact_at(&self.file, &mut buf, offset)?;
95
+ Ok(buf)
96
+ }
97
+ }
98
+
99
+ #[cfg(unix)]
100
+ fn read_some_at(file: &File, buf: &mut [u8], offset: u64) -> io::Result<usize> {
101
+ use std::os::unix::fs::FileExt;
102
+ file.read_at(buf, offset)
103
+ }
104
+
105
+ #[cfg(windows)]
106
+ fn read_some_at(file: &File, buf: &mut [u8], offset: u64) -> io::Result<usize> {
107
+ use std::os::windows::fs::FileExt;
108
+ file.seek_read(buf, offset)
109
+ }
110
+
111
+ fn read_exact_at(file: &File, mut buf: &mut [u8], mut offset: u64) -> io::Result<()> {
112
+ while !buf.is_empty() {
113
+ let n = read_some_at(file, buf, offset)?;
114
+ if n == 0 {
115
+ return Err(io::Error::new(
116
+ io::ErrorKind::UnexpectedEof,
117
+ "range out of bounds",
118
+ ));
119
+ }
120
+ offset += n as u64;
121
+ let tmp = buf;
122
+ buf = &mut tmp[n..];
123
+ }
124
+ Ok(())
125
+ }
126
+
127
+ /// HTTP(S) `Range` reader: rete-core's, the one the CLI uses — kept-alive
128
+ /// connections, the engine's batches 16 in flight and coalesced, transient
129
+ /// failures retried, a short body a hard error, and a host that ignores `Range`
130
+ /// served from its whole body up to 256 MiB (refused by name above that).
131
+ /// Extra request headers (auth tokens, custom UA) ride on every request.
132
+ /// Native-only: browsers have no sockets (see [`AnyReader`]).
133
+ #[cfg(not(target_os = "emscripten"))]
134
+ pub use rete_core::http::HttpRangeReader;
135
+
136
+ /// A reader backed by a Python object exposing `read_at(offset, length) ->
137
+ /// bytes` and a length (a `len()` method, or `__len__`). Each call re-acquires
138
+ /// the GIL, which is safe here: the engine only calls readers from inside
139
+ /// `detach` sections, where the GIL is free to take.
140
+ pub struct PyRangeReader {
141
+ obj: Py<PyAny>,
142
+ len: u64,
143
+ }
144
+
145
+ impl PyRangeReader {
146
+ pub fn new(py: Python<'_>, obj: Py<PyAny>) -> PyResult<Self> {
147
+ let bound = obj.bind(py);
148
+ let len: u64 = match bound.call_method0("len") {
149
+ Ok(v) => v.extract()?,
150
+ Err(_) => bound.len()? as u64,
151
+ };
152
+ Ok(Self { obj, len })
153
+ }
154
+ }
155
+
156
+ impl RangeReader for PyRangeReader {
157
+ fn len(&self) -> u64 {
158
+ self.len
159
+ }
160
+
161
+ fn read_at(&self, offset: u64, len: u64) -> io::Result<Vec<u8>> {
162
+ let buf: Vec<u8> = Python::attach(|py| {
163
+ self.obj
164
+ .bind(py)
165
+ .call_method1("read_at", (offset, len))?
166
+ .extract()
167
+ })
168
+ .map_err(|e: PyErr| io::Error::other(format!("python reader failed: {e}")))?;
169
+ if buf.len() as u64 != len {
170
+ return Err(io::Error::other(format!(
171
+ "python reader returned {} of {len} bytes at offset {offset}",
172
+ buf.len()
173
+ )));
174
+ }
175
+ Ok(buf)
176
+ }
177
+ }
@@ -0,0 +1,200 @@
1
+ """The native wheel's threading and HTTP contract (0.4.2).
2
+
3
+ * It is built with rete-core's ``parallel`` (rayon) and ``http`` features, and a
4
+ parallel build writes the same bytes as a single-threaded one.
5
+ * Engine calls release the GIL: another Python thread runs while a build or a
6
+ query is in Rust.
7
+ * ``open(url)`` uses the CLI's HTTP reader, so a host that ignores ``Range``
8
+ (``200`` + the whole body) is served from that body up to 256 MiB, and
9
+ refused by name above it.
10
+ """
11
+
12
+ from __future__ import annotations
13
+
14
+ import hashlib
15
+ import os
16
+ import subprocess
17
+ import sys
18
+ import threading
19
+ import time
20
+ from http.server import BaseHTTPRequestHandler, ThreadingHTTPServer
21
+
22
+ import pytest
23
+
24
+ import rete_graph as rete
25
+
26
+ native = pytest.mark.skipif(
27
+ sys.platform == "emscripten", reason="the Pyodide wheel has no threads and no sockets"
28
+ )
29
+
30
+
31
+ def _graph_text(subjects: int) -> str:
32
+ """Typed subjects with labels and links: every build phase has work."""
33
+ lines = []
34
+ for s in range(subjects):
35
+ node = f"<http://example.org/n{s}>"
36
+ lines.append(f"{node} <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://example.org/C{s % 7}> .")
37
+ lines.append(f'{node} <http://www.w3.org/2000/01/rdf-schema#label> "node {s} of the test graph" .')
38
+ lines.append(f"{node} <http://example.org/next> <http://example.org/n{(s * 7919) % subjects}> .")
39
+ lines.append(f'{node} <http://example.org/n> "{s}"^^<http://www.w3.org/2001/XMLSchema#integer> .')
40
+ return "\n".join(lines) + "\n"
41
+
42
+
43
+ COUNT_Q = "SELECT (COUNT(*) AS ?n) WHERE { ?s ?p ?o }"
44
+
45
+
46
+ @native
47
+ def test_the_native_wheel_has_parallel_and_http():
48
+ assert {"parallel", "http"} <= set(rete.__engine_features__), rete.__engine_features__
49
+
50
+
51
+ @native
52
+ def test_a_parallel_build_is_byte_identical_to_a_single_threaded_one(tmp_path):
53
+ text = _graph_text(20_000)
54
+ src = tmp_path / "g.nt"
55
+ src.write_text(text)
56
+ here = rete.build(text)
57
+ # A fresh interpreter whose rayon pool has one thread: the serial schedule.
58
+ script = (
59
+ "import hashlib, sys, rete_graph as rete; "
60
+ "print(hashlib.sha256(rete.build(open(sys.argv[1]).read())).hexdigest())"
61
+ )
62
+ env = dict(os.environ, RAYON_NUM_THREADS="1")
63
+ one = subprocess.run(
64
+ [sys.executable, "-c", script, str(src)], env=env, capture_output=True, text=True, check=True
65
+ ).stdout.strip()
66
+ assert hashlib.sha256(here).hexdigest() == one
67
+ (row,) = rete.open(here).query(COUNT_Q)
68
+ assert row["n"].to_python() == 80_000
69
+
70
+
71
+ def _ticks_during(call) -> tuple[int, float]:
72
+ """Run ``call`` while a second thread counts; return (ticks, seconds)."""
73
+ ticks = 0
74
+ stop = threading.Event()
75
+
76
+ def ticker():
77
+ nonlocal ticks
78
+ while not stop.is_set():
79
+ ticks += 1
80
+ time.sleep(0.001)
81
+
82
+ t = threading.Thread(target=ticker, daemon=True)
83
+ t.start()
84
+ time.sleep(0.02) # let it start ticking
85
+ before = ticks
86
+ t0 = time.perf_counter()
87
+ call()
88
+ took = time.perf_counter() - t0
89
+ during = ticks - before
90
+ stop.set()
91
+ t.join()
92
+ return during, took
93
+
94
+
95
+ @native
96
+ def test_engine_calls_release_the_gil():
97
+ text = _graph_text(60_000)
98
+ built = {}
99
+ during, took = _ticks_during(lambda: built.setdefault("b", rete.build(text)))
100
+ # Holding the GIL for the whole call would leave the ticker at ~0. The
101
+ # bound is loose (a 1 ms sleep ticks far fewer than 1000 times a second on
102
+ # a loaded runner); what matters is that it ran at all, many times.
103
+ assert took > 0.05, f"the build was too quick ({took:.3f} s) to tell"
104
+ assert during >= 10, f"{during} ticks in {took:.3f} s: the build held the GIL"
105
+
106
+ g = rete.open(built["b"])
107
+ q = (
108
+ "SELECT ?c (COUNT(?s) AS ?n) WHERE { ?s a ?c . ?s <http://example.org/next> ?t . "
109
+ "?t <http://www.w3.org/2000/01/rdf-schema#label> ?l } GROUP BY ?c"
110
+ )
111
+ during, took = _ticks_during(lambda: g.query(q))
112
+ if took > 0.05: # only meaningful when the query takes a while
113
+ assert during >= 5, f"{during} ticks in {took:.3f} s: the query held the GIL"
114
+
115
+
116
+ class _IgnoreRange(BaseHTTPRequestHandler):
117
+ """A plain static host: every GET is ``200`` with the whole body."""
118
+
119
+ payload = b""
120
+ gets = 0
121
+
122
+ def log_message(self, *args):
123
+ pass
124
+
125
+ def do_HEAD(self):
126
+ self.send_response(200)
127
+ self.send_header("Content-Length", str(len(self.payload)))
128
+ self.end_headers()
129
+
130
+ def do_GET(self):
131
+ type(self).gets += 1
132
+ self.send_response(200)
133
+ self.send_header("Content-Length", str(len(self.payload)))
134
+ self.end_headers()
135
+ self.wfile.write(self.payload)
136
+
137
+
138
+ class _HugeIgnoreRange(BaseHTTPRequestHandler):
139
+ """Claims a 300 MiB file and ignores ``Range``; streams zeros until the
140
+ client hangs up (it should refuse on the length, unread)."""
141
+
142
+ size = 300 << 20
143
+
144
+ def log_message(self, *args):
145
+ pass
146
+
147
+ def do_HEAD(self):
148
+ self.send_response(200)
149
+ self.send_header("Content-Length", str(self.size))
150
+ self.end_headers()
151
+
152
+ def do_GET(self):
153
+ self.send_response(200)
154
+ self.send_header("Content-Length", str(self.size))
155
+ self.end_headers()
156
+ chunk = b"\0" * 65536
157
+ try:
158
+ for _ in range(self.size // len(chunk)):
159
+ self.wfile.write(chunk)
160
+ except OSError:
161
+ pass # the client refused and closed: expected
162
+
163
+
164
+ @pytest.fixture
165
+ def serve_handler():
166
+ servers = []
167
+
168
+ def _serve(handler) -> str:
169
+ srv = ThreadingHTTPServer(("127.0.0.1", 0), handler)
170
+ srv.daemon_threads = True
171
+ threading.Thread(target=srv.serve_forever, daemon=True).start()
172
+ servers.append(srv)
173
+ return f"http://127.0.0.1:{srv.server_address[1]}/graph.rete"
174
+
175
+ yield _serve
176
+ for srv in servers:
177
+ srv.shutdown()
178
+ srv.server_close()
179
+
180
+
181
+ @native
182
+ def test_a_host_that_ignores_range_is_served_from_its_whole_body(serve_handler):
183
+ data = rete.build(_graph_text(2_000))
184
+ handler = type("H", (_IgnoreRange,), {"payload": data, "gets": 0})
185
+ g = rete.open(serve_handler(handler))
186
+ local = rete.open(data)
187
+ assert g.query(COUNT_Q)[0]["n"].to_python() == 8_000
188
+ label_q = (
189
+ "SELECT ?l WHERE { <http://example.org/n42> "
190
+ "<http://www.w3.org/2000/01/rdf-schema#label> ?l }"
191
+ )
192
+ assert [r["l"].value for r in g.query(label_q)] == ["node 42 of the test graph"]
193
+ assert list(g.iter_quads()) == list(local.iter_quads())
194
+ assert handler.gets == 1, f"{handler.gets} GETs: the whole body was downloaded more than once"
195
+
196
+
197
+ @native
198
+ def test_a_whole_body_over_the_cap_is_refused_by_name(serve_handler):
199
+ with pytest.raises(RuntimeError, match="ignored the Range header.*not kept in memory"):
200
+ rete.open(serve_handler(_HugeIgnoreRange))
@@ -79,6 +79,10 @@ zstd = { workspace = true, optional = true }
79
79
  # Data-parallel query evaluator (prototype). Behind the `parallel` feature so it
80
80
  # is never pulled into wasm (the wasm crate builds with --no-default-features).
81
81
  rayon = { version = "1", optional = true }
82
+ # Blocking HTTP(S) range reads (the `http` feature): the reader the CLI, the
83
+ # Python wheels and the R package share. rustls via `tls`, so no system OpenSSL
84
+ # anywhere a native client lands. Never in a wasm build.
85
+ ureq = { version = "2", optional = true, default-features = false, features = ["tls"] }
82
86
 
83
87
  [dev-dependencies]
84
88
  # Property-based testing (tests only — never shipped, so the dep weight and the
@@ -122,6 +126,11 @@ rdf12-turtle = ["dep:oxttl12", "dep:oxrdf12"]
122
126
  # Prototype data-parallel query evaluator. NOT default; wasm must never enable it
123
127
  # (wasm has no threads). Enables the `parallel` module + `rayon`.
124
128
  parallel = ["dep:rayon"]
129
+ # `rete_core::http::HttpRangeReader`: kept-alive, parallel, coalesced HTTP(S)
130
+ # range reads with retries, and the bounded whole-body fallback for hosts that
131
+ # ignore `Range`. Native only (it opens sockets and spawns threads); the browser
132
+ # engine has its own readers.
133
+ http = ["dep:ureq"]
125
134
  # getrandom's browser backend (crypto.getRandomValues, via js-sys/wasm-bindgen),
126
135
  # for BOTH getrandom lines: 0.2 (SPARQL RAND/UUID/BNODE) and 0.3 (oxrdf 0.3's
127
136
  # blank-node ids, reached only with `rdf12-turtle`). Enable ONLY for a wasm
@@ -656,6 +656,19 @@ fn pattern_slots(t: &(SlotTerm, SlotTerm, SlotTerm)) -> Vec<usize> {
656
656
  slots
657
657
  }
658
658
 
659
+ /// The row value of a matched triple's predicate `p_id`, for a pattern whose
660
+ /// predicate slot is `slot`. Only a variable predicate binds it, so only then
661
+ /// is it canonicalized (a predicate that is also a node becomes the node id):
662
+ /// that is a dictionary lookup of the predicate as a node, memoized per query,
663
+ /// but up to three dependent chunk reads on a lazy open for each new predicate
664
+ /// — reads a constant predicate never needed. Otherwise the value is unused.
665
+ fn pred_val(ctx: &Ctx, slot: &SlotTerm, p_id: u32) -> i64 {
666
+ match slot {
667
+ SlotTerm::Var(_) => ctx.resolver.canon_id(pred_tag(p_id)),
668
+ _ => pred_tag(p_id),
669
+ }
670
+ }
671
+
659
672
  /// Build a solution row for one scanned triple, enforcing repeated variables
660
673
  /// *within* the pattern (e.g. `?x p ?x`). `None` = the triple doesn't satisfy
661
674
  /// a repeated variable.
@@ -666,7 +679,7 @@ fn triple_row(
666
679
  ) -> Option<Row> {
667
680
  let dict = ctx.rete.dictionary();
668
681
  let s_val = dict.subject_node(s_id) as i64;
669
- let p_val = ctx.resolver.canon_id(pred_tag(p_id));
682
+ let p_val = pred_val(ctx, &t.1, p_id);
670
683
  let o_val = dict.object_node(o_id) as i64;
671
684
  let mut row = ctx.slots.empty_row();
672
685
  for (term, val) in [(&t.0, s_val), (&t.1, p_val), (&t.2, o_val)] {
@@ -1535,7 +1548,7 @@ fn probe_rows<'q>(
1535
1548
  .scan_iter((sid, pid, oid))
1536
1549
  .filter_map(move |(s_id, p_id, o_id)| {
1537
1550
  let s_val = dict.subject_node(s_id) as i64;
1538
- let p_val = ctx.resolver.canon_id(pred_tag(p_id));
1551
+ let p_val = pred_val(ctx, &t.1, p_id);
1539
1552
  let o_val = dict.object_node(o_id) as i64;
1540
1553
  let mut row = base.clone();
1541
1554
  for (term, val) in [(&t.0, s_val), (&t.1, p_val), (&t.2, o_val)] {