kbforge-sql 0.1.2__tar.gz → 0.1.3__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.
@@ -1,3 +1,30 @@
1
+ Metadata-Version: 2.5
2
+ Name: kbforge-sql
3
+ Version: 0.1.3
4
+ Summary: SQL source connector for kbforge
5
+ Project-URL: Homepage, https://github.com/flyersworder/kbforge/tree/main/packages/kbforge-sql
6
+ Project-URL: Repository, https://github.com/flyersworder/kbforge
7
+ Project-URL: Issues, https://github.com/flyersworder/kbforge/issues
8
+ Project-URL: Changelog, https://github.com/flyersworder/kbforge/blob/main/CHANGELOG.md
9
+ Author-email: Qing <qingye779@gmail.com>
10
+ License: MIT
11
+ Keywords: connector,database,kbforge,knowledge-base,okf,open-knowledge-format,sql,sqlalchemy
12
+ Classifier: Development Status :: 4 - Beta
13
+ Classifier: Intended Audience :: Developers
14
+ Classifier: License :: OSI Approved :: MIT License
15
+ Classifier: Operating System :: OS Independent
16
+ Classifier: Programming Language :: Python :: 3
17
+ Classifier: Programming Language :: Python :: 3.12
18
+ Classifier: Programming Language :: Python :: 3.13
19
+ Classifier: Programming Language :: Python :: 3.14
20
+ Classifier: Topic :: Database
21
+ Classifier: Topic :: Software Development :: Libraries :: Python Modules
22
+ Requires-Python: >=3.12
23
+ Requires-Dist: kbforge>=0.16.0
24
+ Requires-Dist: pydantic>=2.0
25
+ Requires-Dist: sqlalchemy>=2.0
26
+ Description-Content-Type: text/markdown
27
+
1
28
  # kbforge-sql
2
29
 
3
30
  `kbforge-sql` lets any database [SQLAlchemy](https://www.sqlalchemy.org/) can reach be a
@@ -34,13 +61,14 @@ system: products # per-instance identity; prefixes every doc_id
34
61
  url_env: DENODO_URL # env var NAME: denodo://kb_reader@host:9996/product_vdb
35
62
  password_env: DENODO_PASSWORD # optional env var NAME; injected via URL.set()
36
63
  query: |
37
- SELECT product_id, product_name, family, status, description, last_refreshed
64
+ SELECT product_id, product_name, family, status AS product_status,
65
+ description, last_refreshed
38
66
  FROM iv_product
39
67
  WHERE app_id = 'EV-TRACTION'
40
68
  id: [product_id] # one or more columns -> native_id
41
69
  title: product_name
42
70
  text: description # optional free-text column, placed verbatim
43
- facets: [family, status] # scalar columns -> filterable frontmatter
71
+ facets: [family, product_status] # scalar columns -> filterable frontmatter
44
72
  exclude: [last_refreshed] # volatile columns, dropped before hashing
45
73
  type: product # OKF `type` for every concept; default "concept"
46
74
  url_template: https://portal.example/products/{product_id} # optional; {column} fields, id columns only
@@ -71,6 +99,13 @@ group:
71
99
  heading: Products # optional; defaults to the source `system`
72
100
  ```
73
101
 
102
+ A facet cannot take the name of an OKF key kbforge does not emit -- `status`, `resource`,
103
+ `superseded_by`, `verified`, `stale_after`, `usage_window`, or an Attested Computation key
104
+ (`computation`, `runtime`, `parameters`, `executor`, `attester`) -- because consumers act on
105
+ those keys: OKF v0.3 reads a `status` other than `draft`, `stable` or `deprecated` as "not
106
+ current" and hides the concept. Alias the column instead, as `status AS product_status`
107
+ does above; the config check refuses the bare name.
108
+
74
109
  Columns outside `id` and `group.children` must be constant across an entity's rows; a
75
110
  grouped entity whose rows disagree on one is a fetch error naming the id and the column.
76
111
 
@@ -82,11 +117,11 @@ kbforge run --connector sql \
82
117
  --set system=products \
83
118
  --set url_env=DENODO_URL \
84
119
  --set password_env=DENODO_PASSWORD \
85
- --set 'query=SELECT product_id, product_name, family, status, description, last_refreshed FROM iv_product' \
120
+ --set 'query=SELECT product_id, product_name, family, status AS product_status, description, last_refreshed FROM iv_product' \
86
121
  --set 'id=[product_id]' \
87
122
  --set title=product_name \
88
123
  --set text=description \
89
- --set 'facets=[family, status]' \
124
+ --set 'facets=[family, product_status]' \
90
125
  --set 'exclude=[last_refreshed]' \
91
126
  --set type=product \
92
127
  --mirror .kbforge/mirror --out .kbforge/out --state .kbforge/state
@@ -1,15 +1,3 @@
1
- Metadata-Version: 2.5
2
- Name: kbforge-sql
3
- Version: 0.1.2
4
- Summary: SQL source connector for kbforge
5
- Author-email: Qing <qingye779@gmail.com>
6
- License: MIT
7
- Requires-Python: >=3.12
8
- Requires-Dist: kbforge>=0.14.1
9
- Requires-Dist: pydantic>=2.0
10
- Requires-Dist: sqlalchemy>=2.0
11
- Description-Content-Type: text/markdown
12
-
13
1
  # kbforge-sql
14
2
 
15
3
  `kbforge-sql` lets any database [SQLAlchemy](https://www.sqlalchemy.org/) can reach be a
@@ -46,13 +34,14 @@ system: products # per-instance identity; prefixes every doc_id
46
34
  url_env: DENODO_URL # env var NAME: denodo://kb_reader@host:9996/product_vdb
47
35
  password_env: DENODO_PASSWORD # optional env var NAME; injected via URL.set()
48
36
  query: |
49
- SELECT product_id, product_name, family, status, description, last_refreshed
37
+ SELECT product_id, product_name, family, status AS product_status,
38
+ description, last_refreshed
50
39
  FROM iv_product
51
40
  WHERE app_id = 'EV-TRACTION'
52
41
  id: [product_id] # one or more columns -> native_id
53
42
  title: product_name
54
43
  text: description # optional free-text column, placed verbatim
55
- facets: [family, status] # scalar columns -> filterable frontmatter
44
+ facets: [family, product_status] # scalar columns -> filterable frontmatter
56
45
  exclude: [last_refreshed] # volatile columns, dropped before hashing
57
46
  type: product # OKF `type` for every concept; default "concept"
58
47
  url_template: https://portal.example/products/{product_id} # optional; {column} fields, id columns only
@@ -83,6 +72,13 @@ group:
83
72
  heading: Products # optional; defaults to the source `system`
84
73
  ```
85
74
 
75
+ A facet cannot take the name of an OKF key kbforge does not emit -- `status`, `resource`,
76
+ `superseded_by`, `verified`, `stale_after`, `usage_window`, or an Attested Computation key
77
+ (`computation`, `runtime`, `parameters`, `executor`, `attester`) -- because consumers act on
78
+ those keys: OKF v0.3 reads a `status` other than `draft`, `stable` or `deprecated` as "not
79
+ current" and hides the concept. Alias the column instead, as `status AS product_status`
80
+ does above; the config check refuses the bare name.
81
+
86
82
  Columns outside `id` and `group.children` must be constant across an entity's rows; a
87
83
  grouped entity whose rows disagree on one is a fetch error naming the id and the column.
88
84
 
@@ -94,11 +90,11 @@ kbforge run --connector sql \
94
90
  --set system=products \
95
91
  --set url_env=DENODO_URL \
96
92
  --set password_env=DENODO_PASSWORD \
97
- --set 'query=SELECT product_id, product_name, family, status, description, last_refreshed FROM iv_product' \
93
+ --set 'query=SELECT product_id, product_name, family, status AS product_status, description, last_refreshed FROM iv_product' \
98
94
  --set 'id=[product_id]' \
99
95
  --set title=product_name \
100
96
  --set text=description \
101
- --set 'facets=[family, status]' \
97
+ --set 'facets=[family, product_status]' \
102
98
  --set 'exclude=[last_refreshed]' \
103
99
  --set type=product \
104
100
  --mirror .kbforge/mirror --out .kbforge/out --state .kbforge/state
@@ -0,0 +1,44 @@
1
+ [project]
2
+ name = "kbforge-sql"
3
+ version = "0.1.3"
4
+ description = "SQL source connector for kbforge"
5
+ readme = "README.md"
6
+ requires-python = ">=3.12"
7
+ authors = [{ name = "Qing", email = "qingye779@gmail.com" }]
8
+ license = { text = "MIT" }
9
+ keywords = ["kbforge", "sql", "sqlalchemy", "database", "okf", "open-knowledge-format", "connector", "knowledge-base"]
10
+ classifiers = [
11
+ "Development Status :: 4 - Beta",
12
+ "Intended Audience :: Developers",
13
+ "License :: OSI Approved :: MIT License",
14
+ "Operating System :: OS Independent",
15
+ "Programming Language :: Python :: 3",
16
+ "Programming Language :: Python :: 3.12",
17
+ "Programming Language :: Python :: 3.13",
18
+ "Programming Language :: Python :: 3.14",
19
+ "Topic :: Database",
20
+ "Topic :: Software Development :: Libraries :: Python Modules",
21
+ ]
22
+ dependencies = [
23
+ # 0.8.0: cursor slots keyed per config instance, so two `sql` sources never
24
+ # share a manifest; `synthesize.OKF_OWNED` and `canonical.is_blank` exist.
25
+ "kbforge>=0.16.0",
26
+ "pydantic>=2.0",
27
+ "sqlalchemy>=2.0",
28
+ ]
29
+
30
+ [project.urls]
31
+ Homepage = "https://github.com/flyersworder/kbforge/tree/main/packages/kbforge-sql"
32
+ Repository = "https://github.com/flyersworder/kbforge"
33
+ Issues = "https://github.com/flyersworder/kbforge/issues"
34
+ Changelog = "https://github.com/flyersworder/kbforge/blob/main/CHANGELOG.md"
35
+
36
+ [project.entry-points."kbforge.connectors"]
37
+ sql = "kbforge_sql.connector:CONNECTOR"
38
+
39
+ [build-system]
40
+ requires = ["hatchling"]
41
+ build-backend = "hatchling.build"
42
+
43
+ [tool.hatch.build.targets.wheel]
44
+ packages = ["src/kbforge_sql"]
@@ -137,7 +137,8 @@ def problems_for(config: dict) -> list[str]:
137
137
  if owned := sorted(set(cfg.facets) & ((OKF_OWNED - {"tags"}) | OKF_RESERVED)):
138
138
  problems.append(
139
139
  f"config 'facets' must not use OKF-owned key(s) {owned}: the emitter "
140
- "drops them, so the facet would silently never appear"
140
+ "drops them, so the facet would silently never appear; alias the "
141
+ f"column in 'query' instead (`{owned[0]} AS <name>`)"
141
142
  )
142
143
 
143
144
  if cfg.group is not None:
@@ -51,13 +51,13 @@ def flat_cfg(**over) -> dict:
51
51
  "system": "products",
52
52
  "url_env": URL_ENV,
53
53
  "query": (
54
- "SELECT product_id, product_name, family, status, description, "
55
- "last_refreshed FROM product"
54
+ "SELECT product_id, product_name, family, status AS product_status, "
55
+ "description, last_refreshed FROM product"
56
56
  ),
57
57
  "id": ["product_id"],
58
58
  "title": "product_name",
59
59
  "text": "description",
60
- "facets": ["family", "status"],
60
+ "facets": ["family", "product_status"],
61
61
  "exclude": ["last_refreshed"],
62
62
  "type": "product",
63
63
  "url_template": "https://portal.example/products/{product_id}",
@@ -98,19 +98,23 @@ def test_group_columns_must_not_be_excluded():
98
98
 
99
99
 
100
100
  def test_a_facet_named_like_an_okf_key_is_rejected():
101
- problems = problems_for(_cfg(facets=["type", "status"]))
101
+ problems = problems_for(_cfg(facets=["type", "family"]))
102
102
  assert any(
103
103
  p.startswith("config 'facets' must not use OKF-owned key(s) ['type']")
104
104
  for p in problems
105
105
  )
106
106
 
107
107
 
108
- def test_a_facet_named_like_a_reserved_okf_key_is_rejected():
109
- # The emitter drops `stale_after` like an owned key, so the config must
110
- # refuse it for the same reason: the facet would silently never appear.
111
- problems = problems_for(_cfg(facets=["family", "stale_after"]))
108
+ @pytest.mark.parametrize(
109
+ "key", ["stale_after", "status", "superseded_by", "resource", "computation"]
110
+ )
111
+ def test_a_facet_named_like_a_reserved_okf_key_is_rejected(key):
112
+ # The emitter drops these like an owned key, so the config must refuse
113
+ # them for the same reason: the facet would silently never appear.
114
+ problems = problems_for(_cfg(facets=["family", key]))
112
115
  assert any(
113
- p.startswith("config 'facets' must not use OKF-owned key(s) ['stale_after']")
116
+ p.startswith(f"config 'facets' must not use OKF-owned key(s) [{key!r}]")
117
+ and p.endswith(f"alias the column in 'query' instead (`{key} AS <name>`)")
114
118
  for p in problems
115
119
  ), problems
116
120
 
@@ -28,7 +28,11 @@ def test_a_flat_source_yields_one_document_per_row(tmp_path, monkeypatch):
28
28
  assert sorted(docs) == ["products:IMC300", "products:TLE9", "products:XDP1"]
29
29
  doc = docs["products:IMC300"]
30
30
  assert doc.title == "IMC300 motor controller"
31
- assert doc.structured == {"family": "MOTIX", "status": "active", "type": "product"}
31
+ assert doc.structured == {
32
+ "family": "MOTIX",
33
+ "product_status": "active",
34
+ "type": "product",
35
+ }
32
36
  assert doc.anchor.url == "https://portal.example/products/IMC300"
33
37
  assert doc.text == (
34
38
  "Motor controller for EV pumps.\n"
@@ -36,7 +40,7 @@ def test_a_flat_source_yields_one_document_per_row(tmp_path, monkeypatch):
36
40
  "## Attributes\n"
37
41
  "- **product_id:** IMC300\n"
38
42
  "- **family:** MOTIX\n"
39
- "- **status:** active"
43
+ "- **product_status:** active"
40
44
  )
41
45
  assert "last_refreshed" not in doc.text
42
46
  assert_fetch_contract(list(docs.values()), complete=True)
@@ -55,10 +59,10 @@ def test_a_tags_facet_ships_as_the_concept_top_level_tags(tmp_path, monkeypatch)
55
59
  make_db(tmp_path, monkeypatch)
56
60
  cfg = flat_cfg(
57
61
  query=(
58
- "SELECT product_id, product_name, family AS tags, status, "
59
- "description, last_refreshed FROM product"
62
+ "SELECT product_id, product_name, family AS tags, "
63
+ "status AS product_status, description, last_refreshed FROM product"
60
64
  ),
61
- facets=["tags", "status"],
65
+ facets=["tags", "product_status"],
62
66
  )
63
67
  _, docs = _docs(cfg)
64
68
  doc = docs["products:IMC300"]
@@ -263,8 +267,8 @@ def test_the_query_cannot_write(tmp_path, monkeypatch):
263
267
  cfg = flat_cfg(
264
268
  query=(
265
269
  "INSERT INTO product VALUES ('NEW', 'n', 'f', 's', 'd', 'x') "
266
- "RETURNING product_id, product_name, family, status, description, "
267
- "last_refreshed"
270
+ "RETURNING product_id, product_name, family, status AS product_status, "
271
+ "description, last_refreshed"
268
272
  )
269
273
  )
270
274
  CONNECTOR.kbforge_fetch(cfg, None)
@@ -1,25 +0,0 @@
1
- [project]
2
- name = "kbforge-sql"
3
- version = "0.1.2"
4
- description = "SQL source connector for kbforge"
5
- readme = "README.md"
6
- requires-python = ">=3.12"
7
- authors = [{ name = "Qing", email = "qingye779@gmail.com" }]
8
- license = { text = "MIT" }
9
- dependencies = [
10
- # 0.8.0: cursor slots keyed per config instance, so two `sql` sources never
11
- # share a manifest; `synthesize.OKF_OWNED` and `canonical.is_blank` exist.
12
- "kbforge>=0.14.1",
13
- "pydantic>=2.0",
14
- "sqlalchemy>=2.0",
15
- ]
16
-
17
- [project.entry-points."kbforge.connectors"]
18
- sql = "kbforge_sql.connector:CONNECTOR"
19
-
20
- [build-system]
21
- requires = ["hatchling"]
22
- build-backend = "hatchling.build"
23
-
24
- [tool.hatch.build.targets.wheel]
25
- packages = ["src/kbforge_sql"]
File without changes