prograph 1.3.3__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 (237) hide show
  1. prograph/__init__.py +36 -0
  2. prograph/__main__.py +5 -0
  3. prograph/_version.py +375 -0
  4. prograph/cli/__init__.py +1 -0
  5. prograph/cli/_iri_utils.py +124 -0
  6. prograph/cli/emit_genie_space.py +107 -0
  7. prograph/cli/generate_views.py +140 -0
  8. prograph/cli/main.py +420 -0
  9. prograph/cli/schema_inferrer.py +746 -0
  10. prograph/cli/ttl_loader.py +289 -0
  11. prograph/cli/upload_genie_space.py +84 -0
  12. prograph/config/__init__.py +27 -0
  13. prograph/config/yaml_config.py +848 -0
  14. prograph/demos/__init__.py +14 -0
  15. prograph/demos/turbofan/README.md +74 -0
  16. prograph/demos/turbofan/SCENARIO.md +209 -0
  17. prograph/demos/turbofan/__init__.py +75 -0
  18. prograph/demos/turbofan/create_tables.sql +206 -0
  19. prograph/demos/turbofan/data/engine-instances.ttl +1123 -0
  20. prograph/demos/turbofan/data/sensor-timeseries.csv +90 -0
  21. prograph/demos/turbofan/demo.py +162 -0
  22. prograph/demos/turbofan/genie_qa_notebook.py +434 -0
  23. prograph/demos/turbofan/graph.yaml +1098 -0
  24. prograph/demos/turbofan/instance_graph_demo.py +32 -0
  25. prograph/demos/turbofan/load.py +223 -0
  26. prograph/demos/turbofan/mapping.r2rml.ttl +991 -0
  27. prograph/demos/turbofan/ontology/engine-maintenance.ttl +606 -0
  28. prograph/demos/turbofan/payload-shapes.ttl +33 -0
  29. prograph/demos/turbofan/queries/example-queries.sparql +215 -0
  30. prograph/demos/turbofan/shapes.ttl +75 -0
  31. prograph/demos/turbofan/tables.py +106 -0
  32. prograph/demos/turbofan/turbofan_schema.py +393 -0
  33. prograph/demos/turbofan/validation_demo.py +153 -0
  34. prograph/describe.py +231 -0
  35. prograph/endpoint/__init__.py +12 -0
  36. prograph/endpoint/app.py +722 -0
  37. prograph/endpoint/cli.py +280 -0
  38. prograph/endpoint/credentials.py +240 -0
  39. prograph/endpoint/engines.py +418 -0
  40. prograph/endpoint/negotiate.py +101 -0
  41. prograph/endpoint/results.py +181 -0
  42. prograph/endpoint/service.py +31 -0
  43. prograph/engine.py +2718 -0
  44. prograph/execution.py +455 -0
  45. prograph/executors/__init__.py +6 -0
  46. prograph/executors/base.py +11 -0
  47. prograph/executors/databricks_sql_executor.py +51 -0
  48. prograph/executors/duckdb_executor.py +24 -0
  49. prograph/executors/mysql_executor.py +20 -0
  50. prograph/executors/oracle_executor.py +24 -0
  51. prograph/executors/pandas_executor.py +72 -0
  52. prograph/executors/postgresql_executor.py +35 -0
  53. prograph/executors/spark_executor.py +88 -0
  54. prograph/executors/sqlserver_executor.py +35 -0
  55. prograph/extras/__init__.py +1 -0
  56. prograph/extras/graphql/__init__.py +33 -0
  57. prograph/extras/graphql/execute.py +25 -0
  58. prograph/extras/graphql/schema.py +314 -0
  59. prograph/extras/instance_graph.py +559 -0
  60. prograph/genie/__init__.py +83 -0
  61. prograph/genie/databricks_uploader.py +306 -0
  62. prograph/genie/deploy.py +393 -0
  63. prograph/genie/formats.py +414 -0
  64. prograph/genie/instruction_generator.py +375 -0
  65. prograph/genie/sample_query_generator.py +256 -0
  66. prograph/genie/shacl_views.py +318 -0
  67. prograph/genie/space_emitter.py +329 -0
  68. prograph/genie/view_generator.py +628 -0
  69. prograph/genie/view_writer.py +172 -0
  70. prograph/graph/__init__.py +1 -0
  71. prograph/graph/ansi_session.py +348 -0
  72. prograph/graph/databricks_sql_graph.py +300 -0
  73. prograph/graph/drivers.py +143 -0
  74. prograph/graph/duckdb_graph.py +68 -0
  75. prograph/graph/mysql_graph.py +38 -0
  76. prograph/graph/oracle_graph.py +285 -0
  77. prograph/graph/pandas_graph.py +343 -0
  78. prograph/graph/postgresql_graph.py +644 -0
  79. prograph/graph/spark_graph.py +556 -0
  80. prograph/graph/sql_graph.py +83 -0
  81. prograph/graph/sqlserver_graph.py +72 -0
  82. prograph/hints.py +95 -0
  83. prograph/logging.py +550 -0
  84. prograph/mcp/__init__.py +29 -0
  85. prograph/mcp/__main__.py +180 -0
  86. prograph/mcp/bootstrap.py +98 -0
  87. prograph/mcp/server.py +601 -0
  88. prograph/mcp/sparql.py +397 -0
  89. prograph/mcp/tools.py +504 -0
  90. prograph/nlp/__init__.py +79 -0
  91. prograph/nlp/client.py +305 -0
  92. prograph/nlp/databricks_tools.py +369 -0
  93. prograph/nlp/graph_context.py +313 -0
  94. prograph/nlp/interface.py +652 -0
  95. prograph/nlp/prompts/__init__.py +19 -0
  96. prograph/nlp/prompts/examples.py +258 -0
  97. prograph/nlp/prompts/system.py +239 -0
  98. prograph/nlp/providers/__init__.py +14 -0
  99. prograph/nlp/providers/anthropic.py +274 -0
  100. prograph/nlp/providers/databricks.py +312 -0
  101. prograph/nlp/providers/openai.py +203 -0
  102. prograph/nlp/schema_context.py +78 -0
  103. prograph/ontology/__init__.py +53 -0
  104. prograph/ontology/alignment.py +542 -0
  105. prograph/ontology/hierarchy.py +310 -0
  106. prograph/ontology/imports.py +587 -0
  107. prograph/ontology/layer.py +991 -0
  108. prograph/ontology/skos.py +61 -0
  109. prograph/owl/__init__.py +27 -0
  110. prograph/owl/defined_classes.py +323 -0
  111. prograph/parameters.py +242 -0
  112. prograph/parser/__init__.py +1 -0
  113. prograph/parser/cypher/CypherLexer.py +836 -0
  114. prograph/parser/cypher/CypherListener.py +966 -0
  115. prograph/parser/cypher/CypherParser.py +10854 -0
  116. prograph/parser/cypher/CypherVisitor.py +543 -0
  117. prograph/parser/cypher/__init__.py +1 -0
  118. prograph/parser/sparql/SparqlLexer.py +801 -0
  119. prograph/parser/sparql/SparqlParser.py +10146 -0
  120. prograph/parser/sparql/SparqlParserListener.py +1056 -0
  121. prograph/parser/sparql/SparqlParserVisitor.py +593 -0
  122. prograph/parser/sparql/__init__.py +8 -0
  123. prograph/plan/__init__.py +3 -0
  124. prograph/plan/ir/__init__.py +1 -0
  125. prograph/plan/ir/casts.py +338 -0
  126. prograph/plan/ir/consistency.py +397 -0
  127. prograph/plan/ir/construct.py +90 -0
  128. prograph/plan/ir/cost.py +234 -0
  129. prograph/plan/ir/cypher_answer.py +1081 -0
  130. prograph/plan/ir/cypher_apoc.py +717 -0
  131. prograph/plan/ir/cypher_apoc_convert.py +505 -0
  132. prograph/plan/ir/cypher_apoc_date.py +845 -0
  133. prograph/plan/ir/cypher_apoc_map.py +496 -0
  134. prograph/plan/ir/cypher_apoc_meta.py +384 -0
  135. prograph/plan/ir/cypher_apoc_path.py +597 -0
  136. prograph/plan/ir/cypher_apoc_procedures.py +163 -0
  137. prograph/plan/ir/cypher_apoc_text.py +785 -0
  138. prograph/plan/ir/cypher_front.py +5474 -0
  139. prograph/plan/ir/cypher_functions.py +565 -0
  140. prograph/plan/ir/cypher_lists.py +935 -0
  141. prograph/plan/ir/cypher_maps.py +370 -0
  142. prograph/plan/ir/cypher_mixed.py +604 -0
  143. prograph/plan/ir/cypher_ontology.py +226 -0
  144. prograph/plan/ir/cypher_procedures.py +191 -0
  145. prograph/plan/ir/cypher_runtime_errors.py +107 -0
  146. prograph/plan/ir/cypher_temporal.py +1357 -0
  147. prograph/plan/ir/cypher_temporal_arith.py +339 -0
  148. prograph/plan/ir/cypher_values.py +546 -0
  149. prograph/plan/ir/cypher_write.py +612 -0
  150. prograph/plan/ir/dataset.py +643 -0
  151. prograph/plan/ir/dates.py +102 -0
  152. prograph/plan/ir/entry.py +992 -0
  153. prograph/plan/ir/expr.py +260 -0
  154. prograph/plan/ir/facts.py +1171 -0
  155. prograph/plan/ir/fresh.py +291 -0
  156. prograph/plan/ir/freshness.py +625 -0
  157. prograph/plan/ir/identity.py +797 -0
  158. prograph/plan/ir/java_datetime.py +265 -0
  159. prograph/plan/ir/java_regex.py +391 -0
  160. prograph/plan/ir/join_order.py +39 -0
  161. prograph/plan/ir/key_checks.py +433 -0
  162. prograph/plan/ir/keys.py +454 -0
  163. prograph/plan/ir/lower.py +5323 -0
  164. prograph/plan/ir/ops.py +619 -0
  165. prograph/plan/ir/owl_rl.py +1119 -0
  166. prograph/plan/ir/owl_rl_rules.py +725 -0
  167. prograph/plan/ir/profiles.py +694 -0
  168. prograph/plan/ir/ql.py +987 -0
  169. prograph/plan/ir/rdfs.py +342 -0
  170. prograph/plan/ir/rewrite.py +1782 -0
  171. prograph/plan/ir/saturate.py +339 -0
  172. prograph/plan/ir/semantics.py +103 -0
  173. prograph/plan/ir/slot.py +509 -0
  174. prograph/plan/ir/sparql_front.py +3418 -0
  175. prograph/plan/ir/strings.py +534 -0
  176. prograph/plan/ir/term_functions.py +274 -0
  177. prograph/plan/ir/terms.py +84 -0
  178. prograph/plan/ir/xpath_regex.py +264 -0
  179. prograph/plan/run_record.py +65 -0
  180. prograph/plan/sql/__init__.py +21 -0
  181. prograph/plan/sql/dialect.py +3726 -0
  182. prograph/plan/sql/mysql_serializer.py +103 -0
  183. prograph/plan/sql/names.py +65 -0
  184. prograph/plan/sql/oracle_serializer.py +306 -0
  185. prograph/plan/sql/pg_serializer.py +501 -0
  186. prograph/plan/sql/rel_algebra.py +781 -0
  187. prograph/plan/sql/sql_serializer.py +1419 -0
  188. prograph/plan/sql/sqlserver_serializer.py +603 -0
  189. prograph/provenance.py +222 -0
  190. prograph/r2rml/__init__.py +48 -0
  191. prograph/r2rml/catalog.py +259 -0
  192. prograph/r2rml/compile.py +372 -0
  193. prograph/r2rml/direct.py +140 -0
  194. prograph/r2rml/export.py +495 -0
  195. prograph/r2rml/model.py +180 -0
  196. prograph/r2rml/parser.py +546 -0
  197. prograph/r2rml/schema.py +120 -0
  198. prograph/read_only.py +122 -0
  199. prograph/results.py +157 -0
  200. prograph/rules/__init__.py +168 -0
  201. prograph/rules/__main__.py +32 -0
  202. prograph/schema/__init__.py +60 -0
  203. prograph/schema/change_set.py +50 -0
  204. prograph/schema/collations.py +198 -0
  205. prograph/schema/compile_schema.py +388 -0
  206. prograph/schema/context.py +845 -0
  207. prograph/schema/examples.py +234 -0
  208. prograph/schema/iri.py +817 -0
  209. prograph/schema/literals.py +94 -0
  210. prograph/schema/lpg_view.py +617 -0
  211. prograph/schema/mapping.py +1803 -0
  212. prograph/schema/maps_schema.py +40 -0
  213. prograph/schema/naming.py +77 -0
  214. prograph/schema/query_sources.py +59 -0
  215. prograph/schema/rows.py +215 -0
  216. prograph/schema/source_map.py +1103 -0
  217. prograph/schema/store_view.py +459 -0
  218. prograph/schema/types.py +569 -0
  219. prograph/schema/xsd.py +569 -0
  220. prograph/shacl/__init__.py +30 -0
  221. prograph/shacl/dqv.py +58 -0
  222. prograph/shacl/generate.py +255 -0
  223. prograph/shacl/report.py +138 -0
  224. prograph/shacl/validator.py +164 -0
  225. prograph/store.py +1737 -0
  226. prograph/utils/__init__.py +6 -0
  227. prograph/utils/exceptions.py +308 -0
  228. prograph/utils/helpers.py +126 -0
  229. prograph/warnings.py +46 -0
  230. prograph/writes.py +369 -0
  231. prograph-1.3.3.dist-info/METADATA +281 -0
  232. prograph-1.3.3.dist-info/RECORD +237 -0
  233. prograph-1.3.3.dist-info/WHEEL +5 -0
  234. prograph-1.3.3.dist-info/entry_points.txt +3 -0
  235. prograph-1.3.3.dist-info/licenses/LICENSE +201 -0
  236. prograph-1.3.3.dist-info/licenses/NOTICE +10 -0
  237. prograph-1.3.3.dist-info/top_level.txt +1 -0
@@ -0,0 +1,604 @@
1
+ """Cypher values of several types (rule cypher-mixed-values; design 41-cypher-mixed-values, the second
2
+ step): where a list holds an integer, a float, a string or a boolean in different places (`[1, 'a',
3
+ 2.0]`), each element is a tagged struct
4
+
5
+ {pg_kind: 'i' | 'f' | 's' | 'b', pg_int, pg_float, pg_str, pg_bool}
6
+
7
+ with the one field its kind names set and a null element a null struct (a Cypher null). The slot of such
8
+ a value is of kind `MIXED`; a list of them has the element type `MIXED_TYPE`. Lists of lists of different
9
+ element types widen their inner lists the same way (`[[1], ['a']]` is a list of lists of mixed values).
10
+ A list or map held among scalars of other types (`[1, [2]]`), a node, a temporal value, and the mixed
11
+ values as a map's field are not built, by name; a grouping key, a DISTINCT or a count(DISTINCT) over them
12
+ only where they cannot hold a float (`refuse_identity`). On PostgreSQL the tagged struct
13
+ is a jsonb object (its `NAMED_STRUCT`), each member typed by its own kind (`to_jsonb(1)` a number,
14
+ `to_jsonb('C-1')` a string): a node property its maps give in several types (`MIXED_OF`) is built
15
+ there, compared, ordered (a row key, `_rank_key`), grouped and answered (the tagged text `answer_text`,
16
+ which the reader makes the struct of, `from_text`); a list of mixed values is not (its arrays hold no
17
+ struct; the jsonb list form is not built).
18
+
19
+ The answer is the struct; the result conversion (`unwrap`, called by `entry.run`) turns it into the
20
+ value, a column or list of several types becoming Arrow's dense union as every Cypher answer of several
21
+ types does (`results.rows_to_arrow`). Equality is Cypher's (`compare`: numbers by value across integer
22
+ and float, `1 = 1.0` true; a number against a string false); ordering is Cypher's orderability across
23
+ types (`sort_key`: strings, booleans, numbers, null last), element by element for a list.
24
+ """
25
+
26
+ from __future__ import annotations
27
+
28
+ import itertools
29
+ from typing import TYPE_CHECKING, Any, Dict, List, Optional
30
+
31
+ from prograph.plan.ir import expr as E # noqa: F401 (kept for type names in docstrings)
32
+ from prograph.plan.ir.facts import NotBuilt
33
+ from prograph.plan.ir.slot import LIST, MIXED, VALUE, Bound, Slot, value_slot
34
+ from prograph.rules import module_home
35
+ from prograph.schema import xsd
36
+
37
+ if TYPE_CHECKING:
38
+ from prograph.plan.sql import rel_algebra as R
39
+
40
+ module_home("cypher-mixed-values", "Cypher's values of several types, in SQL",
41
+ terms=("mixed list", "mixed value", "tagged struct", "values of several types", "orderability",
42
+ "mixed type"))
43
+
44
+ MIXED_TYPE = "urn:prograph:cypher:mixed:"
45
+ """A list's element type when its elements are mixed values (`MIXED` slots): this prefix and the tags the
46
+ values may have, in `TAGS` order (`mixed_type`). A slot of kind `MIXED` records the same tags in its
47
+ `datatypes`."""
48
+ TAGS = "ifsb"
49
+
50
+
51
+ def mixed_type(tags) -> str:
52
+ return MIXED_TYPE + "".join(t for t in TAGS if t in tags)
53
+
54
+
55
+ def is_mixed(datatype: Optional[str]) -> bool:
56
+ return datatype is not None and datatype.startswith(MIXED_TYPE)
57
+
58
+
59
+ def tags_of(datatype: str) -> str:
60
+ return datatype[len(MIXED_TYPE):]
61
+
62
+ KIND, INT, FLOAT, STR, BOOL = "pg_kind", "pg_int", "pg_float", "pg_str", "pg_bool"
63
+ DEC = "pg_dec"
64
+ LIST_FIELD = "pg_list"
65
+ FIELDS = (KIND, INT, FLOAT, STR, BOOL)
66
+ FIELDS_DECIMAL = FIELDS + (DEC,) # a property map holding a decimal (`cypher_answer.properties_map`)
67
+ FIELDS_LIST = FIELDS + (LIST_FIELD,) # a property map holding a list property: one list field, one list type
68
+ FIELDS_DECIMAL_LIST = FIELDS + (DEC, LIST_FIELD)
69
+ _INTEGERS = frozenset({xsd.INTEGER}) | xsd.INTEGER_DATATYPES
70
+
71
+ _LAMBDAS = itertools.count()
72
+
73
+
74
+ def mixed_slot(tags, null: Bound = Bound.MAYBE) -> Slot:
75
+ """The slot of a value that is an integer, float, string or boolean per row: the kinds it may be, as
76
+ their tags (`i`, `f`, `s`, `b`)."""
77
+ return Slot(kinds=frozenset({MIXED}), datatypes=frozenset(tags), bound=Bound.NEVER, null=null)
78
+
79
+
80
+ def mixed_of_slot(inner: Slot) -> Slot:
81
+ """`MIXED_OF(x)`'s slot: a plain scalar `x` as a mixed value of its one tag (a node map's property
82
+ that another map of the node gives in another type, `cypher_front.scan`); a null as a null one."""
83
+ if inner.present is Bound.NEVER:
84
+ return inner
85
+ tag = slot_tags(inner)
86
+ if inner.kinds - {VALUE, MIXED} or not tag:
87
+ raise NotBuilt("a property of several types over its maps holding a value that is not an integer, "
88
+ "float, string or boolean")
89
+ return mixed_slot(tag, inner.null)
90
+
91
+
92
+ def property_tags(slots: List[Slot]) -> Optional[str]:
93
+ """The tags of a property its maps give as plain scalars of two or more kinds (`slots`: one per map,
94
+ a map that gives no value never present), so the node's merged value is a mixed value; None where the
95
+ maps give one type, or a type that is not an integer, float, string or boolean (left to the merge's
96
+ own refusal)."""
97
+ from prograph.plan.ir.cypher_lists import value_type
98
+ types = {value_type(s) for s in slots if s.present is not Bound.NEVER}
99
+ if len(types) < 2 or any(t is None or family(t) is None for t in types):
100
+ return None
101
+ return "".join(t for t in TAGS if t in {family(x) for x in types})
102
+
103
+
104
+ def slot_tags(slot: Slot) -> str:
105
+ """The tags a mixed slot's values may have, or a plain scalar slot's one."""
106
+ if slot.kinds == {MIXED}:
107
+ return "".join(t for t in TAGS if t in slot.datatypes)
108
+ from prograph.plan.ir.cypher_lists import value_type
109
+ return family(value_type(slot)) or ""
110
+
111
+
112
+ def family(datatype: Optional[str]) -> Optional[str]:
113
+ """The kind tag a plain value of `datatype` has: i, f, s or b; None for any other type."""
114
+ if datatype in _INTEGERS:
115
+ return "i"
116
+ if datatype in (xsd.DOUBLE, xsd.FLOAT):
117
+ return "f"
118
+ if datatype == xsd.STRING:
119
+ return "s"
120
+ if datatype == xsd.BOOLEAN:
121
+ return "b"
122
+ return None
123
+
124
+
125
+ def has_mixed(datatype: Optional[str]) -> bool:
126
+ """Whether a type names mixed values somewhere in it (a list's, a map's field's); not a node's or
127
+ relationship's property of several types, which its element type records after a `|` (an element's
128
+ properties are its parts, not a list of mixed values)."""
129
+ return datatype is not None and MIXED_TYPE in datatype.split("|", 1)[0]
130
+
131
+
132
+ def holds_mixed(slot: Slot) -> bool:
133
+ """Whether a slot's values are mixed values or lists of them."""
134
+ return MIXED in slot.kinds or any(has_mixed(d) for d in slot.datatypes)
135
+
136
+
137
+ def refuse_identity(slot: Slot, what: str) -> None:
138
+ """Grouping, DISTINCT and the like read a value's equality as the engine has it: `[1]` and `[1.0]`
139
+ are two structs there but one value in Cypher's equivalence, so they are not built over lists of
140
+ mixed values, nor over a mixed value that may be a float (1 and 1.0; -0.0 and 0.0, two texts in
141
+ PostgreSQL's jsonb object). One that cannot (an integer or a string, a node key of two types) is
142
+ equal in the engine exactly where it is in Cypher: of one kind by value, of two kinds never."""
143
+ if slot.kinds == {MIXED} and "f" not in slot_tags(slot):
144
+ return
145
+ if holds_mixed(slot):
146
+ raise NotBuilt(f"{what} over values of several types")
147
+
148
+
149
+ def engine(scalar: bool = False, what: str = "a list of values of several types") -> None:
150
+ """Refuse a mixed value where the engine has no form for it: on PostgreSQL a list of them (`scalar`
151
+ False; `what` names the form); a single one is its jsonb object there."""
152
+ from prograph.plan.ir.lower import DIALECT
153
+ if DIALECT.get() in ("postgresql", "postgres") and not scalar:
154
+ raise NotBuilt(f"{what} on PostgreSQL (its arrays hold no struct; the jsonb list form is not built)")
155
+
156
+
157
+ def is_postgresql() -> bool:
158
+ from prograph.plan.ir.lower import DIALECT
159
+ return DIALECT.get() in ("postgresql", "postgres")
160
+
161
+
162
+ def widened(a: Optional[str], b: Optional[str]) -> Optional[str]:
163
+ """Two element types as one where they differ: mixed values where both are plain scalars (or already
164
+ mixed), their lists' elements widened where both are lists; None where a list or map would sit among
165
+ scalars of other types, or where the types are a map's, a node's or a temporal value's."""
166
+ from prograph.plan.ir.cypher_lists import element_of, joined, list_type, nested
167
+ same = joined(a, b)
168
+ if same is not None or a == b:
169
+ return same if same is not None else a
170
+ if is_mixed(a) and is_mixed(b) and tags_of(a) == tags_of(b):
171
+ return a
172
+ if nested(a) and nested(b):
173
+ ea, eb = element_of(a), element_of(b)
174
+ if ea is None or eb is None:
175
+ return list_type(ea or eb)
176
+ inner = widened(ea, eb)
177
+ return None if inner is None else list_type(inner)
178
+ plain = lambda t: is_mixed(t) or family(t) is not None # noqa: E731
179
+ if a is not None and b is not None and plain(a) and plain(b):
180
+ return mixed_type(slot_tags_of(a) + slot_tags_of(b))
181
+ return None
182
+
183
+
184
+ def slot_tags_of(datatype: str) -> str:
185
+ return tags_of(datatype) if is_mixed(datatype) else family(datatype)
186
+
187
+
188
+ def element_type(slots: List[Slot], what: str) -> Optional[str]:
189
+ """`cypher_lists.element_type` where elements of different types are allowed to become mixed values
190
+ (a list literal, a concatenation): the one type of `slots`' values, None where every one is null."""
191
+ from prograph.plan.ir.cypher_lists import value_type
192
+ out: Optional[str] = None
193
+ seen = False
194
+ for s in slots:
195
+ if s.present is Bound.NEVER:
196
+ continue
197
+ t = value_type(s)
198
+ if t is None:
199
+ raise NotBuilt(f"{what} of a value that is not one plain type (a list, map, node or mixed)")
200
+ if seen:
201
+ joined = widened(out, t)
202
+ if joined is None:
203
+ raise NotBuilt(f"{what} of values of several types that are not plain scalars (a list or map "
204
+ "among values of other types)")
205
+ out = joined
206
+ else:
207
+ out, seen = t, True
208
+ return out
209
+
210
+
211
+ # -- values ---------------------------------------------------------------------------
212
+
213
+
214
+ def _null_of(datatype: str, L):
215
+ from prograph.plan.ir.cypher_lists import typed_null
216
+ return typed_null(datatype, L)
217
+
218
+
219
+ def null_struct(L) -> "R.Expr":
220
+ """A null of the mixed value's struct type (a false CASE fixes the type on every engine)."""
221
+ return L.case(L.FALSE, struct("i", L, integer=L.integer(0)))
222
+
223
+
224
+ def struct(tag: str, L, *, integer=None, number=None, string=None, boolean=None, decimal=None,
225
+ decimal_like=None, listed=None, list_like=None) -> "R.Expr":
226
+ """The tagged struct of a value of kind `tag`, its one field set and the others typed nulls. With
227
+ `decimal_like` (a decimal expression) the struct has the decimal field `pg_dec` too, a null of that
228
+ expression's type where the value is not a decimal (a false CASE fixes the type on every engine). With
229
+ `list_like` (a list expression) it has the list field `pg_list` too, `listed` where the value is a list,
230
+ else a null of that expression's type."""
231
+ extra = [] if decimal_like is None else [
232
+ L.text(DEC), decimal if decimal is not None else L.case(L.FALSE, decimal_like)]
233
+ if list_like is not None:
234
+ extra += [L.text(LIST_FIELD), listed if listed is not None else L.case(L.FALSE, list_like)]
235
+ if number is not None and is_postgresql():
236
+ # A float as its own text in the jsonb object (`-0`, `NaN`, `Infinity`; a jsonb number has no negative
237
+ # zero), read back by the field's cast to a double.
238
+ number = L.fn("CAST_STRING", number)
239
+ return L.fn("NAMED_STRUCT",
240
+ L.text(KIND), L.text(tag),
241
+ L.text(INT), integer if integer is not None else L.fn("CAST_LONG", L.NULL),
242
+ L.text(FLOAT), number if number is not None else L.fn("CAST_DOUBLE", L.NULL),
243
+ L.text(STR), string if string is not None else L.fn("CAST_STRING", L.NULL),
244
+ L.text(BOOL), boolean if boolean is not None else L.fn("CAST_BOOLEAN", L.NULL),
245
+ *extra)
246
+
247
+
248
+ def wrap_value(value: "R.Expr", datatype: str, L, maybe_null: bool = True, decimal_like=None,
249
+ list_like=None, scalar: bool = False) -> "R.Expr":
250
+ """A plain value of `datatype` (an SQL expression: a column, a lambda variable) as the tagged struct.
251
+ With `decimal_like` the struct carries the decimal field (see `struct`), and an exact decimal is the
252
+ kind `d`; with `list_like` the list field, and a list of the one list type of a property map the
253
+ kind `l`. `scalar`: a value standing alone (not a list's element), which PostgreSQL builds."""
254
+ engine(scalar)
255
+ from prograph.plan.ir.cypher_lists import nested
256
+ if list_like is not None and nested(datatype):
257
+ made = struct("l", L, listed=value, decimal_like=decimal_like, list_like=list_like)
258
+ return L.case(L.is_null(value), L.NULL, made) if maybe_null else made
259
+ tag = family(datatype)
260
+ if datatype == xsd.DECIMAL and decimal_like is not None:
261
+ made = struct("d", L, decimal=value, decimal_like=decimal_like, list_like=list_like)
262
+ return L.case(L.is_null(value), L.NULL, made) if maybe_null else made
263
+ if tag is None:
264
+ raise NotBuilt(f"a value of several types holding a {datatype}")
265
+ made = {"i": lambda: struct("i", L, integer=L.fn("CAST_LONG", value), decimal_like=decimal_like, list_like=list_like),
266
+ "f": lambda: struct("f", L, number=L.fn("CAST_DOUBLE", value), decimal_like=decimal_like, list_like=list_like),
267
+ "s": lambda: struct("s", L, string=L.fn("CAST_STRING", value), decimal_like=decimal_like, list_like=list_like),
268
+ "b": lambda: struct("b", L, boolean=L.fn("CAST_BOOLEAN", value), decimal_like=decimal_like,
269
+ list_like=list_like)}[tag]()
270
+ return L.case(L.is_null(value), L.NULL, made) if maybe_null else made
271
+
272
+
273
+ def wrap(cell: "L.Cell", L, scalar: bool = False) -> "R.Expr":
274
+ """A cell of a plain scalar slot or a mixed one as the tagged struct."""
275
+ from prograph.plan.ir.cypher_lists import value_type
276
+ s = cell.slot
277
+ if s.present is Bound.NEVER:
278
+ engine(scalar)
279
+ return null_struct(L)
280
+ if s.kinds == {MIXED}:
281
+ return cell.value
282
+ t = value_type(s)
283
+ if t is None or (family(t) is None):
284
+ raise NotBuilt("a value of several types holding a value that is not an integer, float, string or boolean")
285
+ return wrap_value(cell.value, t, L, maybe_null=s.present is not Bound.NEVER and s.null is not Bound.NEVER,
286
+ scalar=scalar)
287
+
288
+
289
+ def convert(value: "R.Expr", source: Optional[str], target: Optional[str], L) -> "R.Expr":
290
+ """`value`, an SQL expression of a Cypher type `source`, as one of `target` where `target` is the
291
+ widening of it (`widened`): a plain scalar as the tagged struct, a list element by element."""
292
+ from prograph.plan.ir.cypher_lists import element_of, nested
293
+ from prograph.plan.sql import rel_algebra as R
294
+ if source == target or (is_mixed(source) and is_mixed(target)):
295
+ return value # the struct type is one whatever kinds the values may have
296
+ if is_mixed(target) and source is not None:
297
+ return wrap_value(value, source, L)
298
+ if nested(source) and nested(target):
299
+ es, et = element_of(source), element_of(target)
300
+ if es is None:
301
+ raise NotBuilt("a list of no element type widened")
302
+ name = f"_mw{next(_LAMBDAS)}"
303
+ var = R.LitExpr(value=name, sql=name)
304
+ return L.fn("LIST_TRANSFORM", value, var, convert(var, es, et, L))
305
+ raise NotBuilt("a value widened to a type it does not widen to")
306
+
307
+
308
+ def convert_elements(value: "R.Expr", source: Optional[str], target: Optional[str], L) -> "R.Expr":
309
+ """A list `value` of elements of type `source` as a list of elements of type `target`."""
310
+ from prograph.plan.ir.cypher_lists import list_type
311
+ return convert(value, list_type(source), list_type(target), L)
312
+
313
+
314
+ def converted_cell(cell: "L.Cell", target: Optional[str], L, literal: Optional["E.Expr"] = None) -> "R.Expr":
315
+ """A list literal's or concatenation's element, as an SQL value of the element type `target`: a null
316
+ typed, an empty list typed, a plain value or list widened."""
317
+ from prograph.plan.ir.cypher_lists import typed_empty, typed_null, value_type
318
+ s = cell.slot
319
+ if target is None or not has_mixed(target):
320
+ return cell.value
321
+ if s.present is Bound.NEVER:
322
+ return typed_null(target, L)
323
+ if s.kinds == {LIST} and not s.datatypes:
324
+ return typed_empty(_element(target), L) if target.startswith("urn:prograph:cypher:list:") else cell.value
325
+ t = value_type(s)
326
+ return convert(cell.value, t, target, L)
327
+
328
+
329
+ def _element(target: str) -> Optional[str]:
330
+ from prograph.plan.ir.cypher_lists import element_of
331
+ return element_of(target)
332
+
333
+
334
+ def field(struct_value: "R.Expr", name: str, L) -> "R.Expr":
335
+ fn = {KIND: "CYPHER_FIELD_STRING", INT: "CYPHER_FIELD_LONG", FLOAT: "CYPHER_FIELD_DOUBLE",
336
+ STR: "CYPHER_FIELD_STRING", BOOL: "CYPHER_FIELD_BOOLEAN"}[name]
337
+ return L.fn(fn, struct_value, L.text(name))
338
+
339
+
340
+ # -- equality and comparison -----------------------------------------------------------------
341
+
342
+
343
+ def compare(op: str, a: "L.Cell", b: "L.Cell") -> "R.Expr":
344
+ """`a op b` where a side is a mixed value (Cypher 9, "Comparability and equality"): null where either
345
+ is null; two numbers by value (integer against float exactly, a NaN unequal and unordered); two
346
+ strings by code point; two booleans false before true; values of two kinds are not equal (`=` false,
347
+ `<>` true) and not ordered (null). The other side is a plain scalar, wrapped, or a mixed value."""
348
+ from prograph.plan.ir import lower as L
349
+ engine(scalar=True) # a mixed value compared is one value (a list's elements are compared one by one)
350
+ if a.slot.present is Bound.NEVER or b.slot.present is Bound.NEVER:
351
+ return L.NULL_BOOLEAN
352
+ for c in (a, b):
353
+ if c.slot.kinds != {MIXED} and (c.slot.kinds - {VALUE} and not _boolean_condition(c.slot)):
354
+ if c.slot.kinds & {LIST}:
355
+ # A mixed value is never a list (a list among scalars is not built): unequal, not ordered.
356
+ differ = {"=": L.FALSE, "!=": L.TRUE}.get(op, L.NULL_BOOLEAN)
357
+ return L.case(L.any_of([L.is_null(a.value), L.is_null(b.value)]), L.NULL_BOOLEAN, differ)
358
+ raise NotBuilt("a comparison of a value of several types with a map, node or relationship")
359
+ sa, sb = wrap(a, L, scalar=True), wrap(b, L, scalar=True)
360
+ ka, kb = field(sa, KIND, L), field(sb, KIND, L)
361
+ is_ = lambda k, tag: L.eq(k, L.text(tag)) # noqa: E731
362
+
363
+ def typed(s, tag):
364
+ if tag == "i":
365
+ return L.Cell(value_slot(xsd.INTEGER, Bound.NEVER), field(s, INT, L))
366
+ if tag == "f":
367
+ return L.Cell(value_slot(xsd.DOUBLE, Bound.NEVER), field(s, FLOAT, L))
368
+ if tag == "s":
369
+ return L.Cell(value_slot(xsd.STRING, Bound.NEVER), field(s, STR, L))
370
+ return L.Cell(value_slot(xsd.BOOLEAN, Bound.NEVER), field(s, BOOL, L))
371
+ parts: List[Any] = [L.any_of([L.is_null(sa), L.is_null(sb)]), L.NULL_BOOLEAN]
372
+ for ta in slot_tags(a.slot):
373
+ for tb in slot_tags(b.slot):
374
+ same_kind = (ta in "if" and tb in "if") or ta == tb
375
+ if not same_kind:
376
+ continue
377
+ parts += [L.all_of([is_(ka, ta), is_(kb, tb)]),
378
+ L.cypher_compare(op, typed(sa, ta), typed(sb, tb))]
379
+ differ = {"=": L.FALSE, "!=": L.TRUE}.get(op, L.NULL_BOOLEAN)
380
+ parts.append(differ)
381
+ return L.case(*parts)
382
+
383
+
384
+ def _boolean_condition(slot: Slot) -> bool:
385
+ return slot.datatypes == {xsd.BOOLEAN} and slot.native == xsd.BOOLEAN
386
+
387
+
388
+ # -- ordering -------------------------------------------------------------------------------
389
+
390
+
391
+ def _rank_key(tag_struct: "R.Expr", L) -> "R.Expr":
392
+ """The sort key of a mixed value's struct (Cypher's orderability across types, ascending: string,
393
+ boolean, number, null; `r`), a number as its double (`d`), a float at or past 2^63 flagged (`o`: above the
394
+ integer 2^63 - 1, whose double it shares), then its exact integer part (`x`: two integers past 2^53
395
+ stay apart), a string by code point (`s`); every field present."""
396
+ k = field(tag_struct, KIND, L)
397
+ is_ = lambda tag: L.eq(k, L.text(tag)) # noqa: E731
398
+ zero_f, zero_i = L.fn("CAST_DOUBLE", L.text("0")), L.integer(0)
399
+ f = field(tag_struct, FLOAT, L)
400
+ two63 = L._TWO_TO_63 # 2^63: a double at or past it is above every integer, though its double is the integer 2^63 - 1's
401
+ cmp = L.R.CompareExpr
402
+ inside = L.all_of([cmp(left=f, op=">=", right=L.fn("-", zero_f, two63)), cmp(left=f, op="<", right=two63)])
403
+ over = cmp(left=f, op=">=", right=two63)
404
+ rank = L.case(is_("s"), L.integer(0), is_("b"), L.integer(1), L.integer(2))
405
+ d = L.case(is_("i"), L.fn("CAST_DOUBLE", field(tag_struct, INT, L)), is_("f"), f,
406
+ is_("b"), L.case(field(tag_struct, BOOL, L), L.fn("CAST_DOUBLE", L.text("1")), zero_f), zero_f)
407
+ x = L.case(is_("i"), field(tag_struct, INT, L), L.all_of([is_("f"), inside]),
408
+ L.fn("DOUBLE_TO_BIGINT", f), zero_i)
409
+ o = L.case(L.all_of([is_("f"), over]), L.integer(1), zero_i)
410
+ s = L.codepoint(L.case(is_("s"), field(tag_struct, STR, L), L.text("")))
411
+ return _key(L, rank, d, o, x, s)
412
+
413
+
414
+ def _key(L, rank, d, o, x, s) -> "R.Expr":
415
+ """The five parts of a sort key as one value the engine orders part by part: a struct on DuckDB, Spark and
416
+ Databricks; a row on PostgreSQL (a jsonb object orders by its keys' lengths and texts first, and its
417
+ strings by the database's collation; a row compares field by field, each by its own collation)."""
418
+ if is_postgresql():
419
+ return L.fn("CYPHER_ORDER_ROW", rank, d, o, x, s)
420
+ return L.fn("NAMED_STRUCT", L.text("r"), rank, L.text("d"), d, L.text("o"), o, L.text("x"), x, L.text("s"), s)
421
+
422
+
423
+ def _null_key(L) -> "R.Expr":
424
+ zero = L.fn("CAST_DOUBLE", L.text("0"))
425
+ # The empty text typed: PostgreSQL compares two null keys' last fields, and an untyped '' has no comparison.
426
+ return _key(L, L.integer(3), zero, L.integer(0), L.integer(0), L.codepoint(L.fn("CAST_STRING", L.text(""))))
427
+
428
+
429
+ def _element_key(tag_struct: "R.Expr", L) -> "R.Expr":
430
+ return L.case(L.is_null(tag_struct), _null_key(L), _rank_key(tag_struct, L))
431
+
432
+
433
+ def needs_key(slot: Slot) -> bool:
434
+ """Whether ORDER BY over a column of `slot` is by a computed key here: a mixed value, or a list of
435
+ plain scalars or mixed values (one type or several)."""
436
+ from prograph.plan.ir.cypher_lists import nested
437
+ if slot.present is Bound.NEVER:
438
+ return False
439
+ if slot.kinds == {MIXED}:
440
+ return True
441
+ if slot.kinds == {LIST} and len(slot.datatypes) == 1:
442
+ t = slot.datatype
443
+ return (is_mixed(t) or family(t) is not None) and not nested(t)
444
+ return False
445
+
446
+
447
+ def sort_key(cell: "L.Cell") -> "R.Expr":
448
+ """The one SQL value to ORDER BY for a mixed value or a list of scalars (ascending, nulls by the
449
+ caller): the value's rank key, or the list of its elements' (the engines order arrays element by
450
+ element, a shorter list before a longer one it is a prefix of: Cypher's list order)."""
451
+ from prograph.plan.ir import lower as L
452
+ from prograph.plan.ir.cypher_lists import value_type
453
+ from prograph.plan.sql import rel_algebra as R
454
+ s = cell.slot
455
+ engine(scalar=s.kinds == {MIXED})
456
+ if s.kinds == {MIXED}:
457
+ return _element_key(cell.value, L)
458
+ element = s.datatype
459
+ name = f"_mk{next(_LAMBDAS)}"
460
+ var = R.LitExpr(value=name, sql=name)
461
+ inner = var if is_mixed(element) else wrap_value(var, element, L)
462
+ return L.fn("LIST_TRANSFORM", cell.value, var, _element_key(inner, L))
463
+
464
+
465
+ # -- aggregates ---------------------------------------------------------------------------
466
+
467
+
468
+ def extreme(name: str, arg: "L.Cell") -> "R.Expr":
469
+ """min() or max() of mixed values, or of lists of scalars, by orderability (`sort_key`: a list element by
470
+ element, a null element after every value, a prefix first): the value of the least or greatest key, its
471
+ original carried beside the key so it comes back as it was (`1` before `1.0` where they tie)."""
472
+ from prograph.plan.ir import lower as L
473
+ engine(scalar=arg.slot.kinds == {MIXED}, what="min() or max() of lists")
474
+ if arg.slot.kinds == {MIXED} and is_postgresql():
475
+ # PostgreSQL has no min() of a row: the first value in the key's order (ties in the jsonb's own order),
476
+ # nulls skipped.
477
+ return L.fn("CYPHER_FIRST_BY" if name == "MIN" else "CYPHER_FIRST_BY_DESC", arg.value,
478
+ _element_key(arg.value, L))
479
+ key = _element_key(arg.value, L) if arg.slot.kinds == {MIXED} else sort_key(arg)
480
+ packed = L.fn("NAMED_STRUCT", L.text("k"), key, L.text("v"), arg.value)
481
+ # The aggregate skips null elements (their key is not null, so filter): a null packs to null.
482
+ packed = L.case(L.is_null(arg.value), L.NULL, packed)
483
+ return L.fn("CYPHER_FIELD_VALUE", L.fn(name, packed), L.text("v"))
484
+
485
+
486
+ # -- the answer ---------------------------------------------------------------------------
487
+
488
+
489
+ def answer_text(value: "R.Expr", L) -> "R.Expr":
490
+ """PostgreSQL's answer of a mixed value (its jsonb tagged struct `value`): one text column, the kind's
491
+ tag then the value's own text (`i1`, `sC-1`, `f0.5`, `btrue`; a float's shortest round-trip text, `NaN`
492
+ and `Infinity` as PostgreSQL writes them), null for a null value. The reader makes the tagged struct of
493
+ it column-wise (`from_text`), so no cell is read in Python and no value goes through a float."""
494
+ return L.fn("CYPHER_MIXED_TEXT", value)
495
+
496
+
497
+ def from_text(texts: Any) -> Any:
498
+ """The tagged struct array of `answer_text`'s column (`FIELDS`), by Arrow compute alone: the first code
499
+ unit the kind, the rest cast to the kind's type where the row is of it."""
500
+ import pyarrow as pa
501
+ import pyarrow.compute as pc
502
+ texts = pc.cast(texts, pa.string())
503
+ kind = pc.utf8_slice_codeunits(texts, 0, 1)
504
+ rest = pc.utf8_slice_codeunits(texts, 1)
505
+
506
+ def member(tag, kind_type):
507
+ mine = pc.if_else(pc.fill_null(pc.equal(kind, tag), False), rest, pa.scalar(None, pa.string()))
508
+ if kind_type == pa.bool_():
509
+ return pc.equal(mine, "true")
510
+ return pc.cast(mine, kind_type)
511
+ arrays = [kind, member("i", pa.int64()), member("f", pa.float64()), member("s", pa.string()),
512
+ member("b", pa.bool_())]
513
+ return pa.StructArray.from_arrays(arrays, names=list(FIELDS), mask=pc.is_null(texts))
514
+
515
+
516
+
517
+
518
+ def _is_tag_type(t: Any) -> bool:
519
+ import pyarrow as pa
520
+ return pa.types.is_struct(t) and {t.field(i).name for i in range(t.num_fields)} in (
521
+ set(FIELDS), set(FIELDS_DECIMAL), set(FIELDS_LIST), set(FIELDS_DECIMAL_LIST))
522
+
523
+
524
+ def _has_tag_type(t: Any) -> bool:
525
+ import pyarrow as pa
526
+ if _is_tag_type(t):
527
+ return True
528
+ if pa.types.is_list(t) or pa.types.is_large_list(t):
529
+ return _has_tag_type(t.value_type)
530
+ if pa.types.is_map(t):
531
+ return _has_tag_type(t.item_type)
532
+ if pa.types.is_struct(t):
533
+ return any(_has_tag_type(t.field(i).type) for i in range(t.num_fields))
534
+ return False
535
+
536
+
537
+ def _union(tagged: Any) -> Any:
538
+ """An array of tagged structs as a dense union, by Arrow compute alone: `pg_kind` picks each row's
539
+ member, each member holds the rows of its kind (`results.MIXED_MEMBERS`, the four always, in the one
540
+ order), a null struct a null in the first. No cell is read in Python."""
541
+ import pyarrow as pa
542
+ import pyarrow.compute as pc
543
+ from prograph import results
544
+ flat = dict(zip((tagged.type.field(i).name for i in range(tagged.type.num_fields)), tagged.flatten()))
545
+ kind = flat[KIND] # flatten applies the struct's own nulls
546
+ by_member = {"bool": ("b", flat[BOOL]), "int": ("i", flat[INT]), "float": ("f", flat[FLOAT]),
547
+ "str": ("s", flat[STR])}
548
+ members = results.MIXED_MEMBERS
549
+ if LIST_FIELD in flat: # a property map holding a list property: a `list` member, at the list type
550
+ by_member["list"] = ("l", flat[LIST_FIELD])
551
+ members = members + ("list",)
552
+ if DEC in flat: # a property map holding an exact decimal: a member, at the columns' type
553
+ by_member[results.DECIMAL_MEMBER] = ("d", flat[DEC])
554
+ members = members + (results.DECIMAL_MEMBER,)
555
+ type_ids = pa.array([0] * len(tagged), type=pa.int8())
556
+ offsets = pa.array([0] * len(tagged), type=pa.int32())
557
+ children = []
558
+ for position, member in enumerate(members):
559
+ tag, values = by_member[member]
560
+ mask = pc.fill_null(pc.equal(kind, tag), False)
561
+ if position == 0:
562
+ mask = pc.or_(mask, pc.is_null(kind))
563
+ here = pc.subtract(pc.cumulative_sum(pc.cast(mask, pa.int32())), 1)
564
+ code = results._KINDS.index(member)
565
+ type_ids = pc.if_else(mask, pa.scalar(code, pa.int8()), type_ids)
566
+ offsets = pc.if_else(mask, here, offsets)
567
+ children.append(pc.filter(values, mask))
568
+ return results.dense_union(list(members), pc.cast(type_ids, pa.int8()),
569
+ pc.cast(offsets, pa.int32()), children)
570
+
571
+
572
+ def _converted(array: Any) -> Any:
573
+ import pyarrow as pa
574
+ t = array.type
575
+ if _is_tag_type(t):
576
+ return _union(array)
577
+ if pa.types.is_list(t) or pa.types.is_large_list(t):
578
+ # Tagged structs inside a list: the list over the converted values, its own offsets and nulls.
579
+ made = pa.ListArray if pa.types.is_list(t) else pa.LargeListArray
580
+ return made.from_arrays(array.offsets, _converted(array.values), mask=array.is_null())
581
+ if pa.types.is_map(t):
582
+ # A node's or relationship's properties: the keys and offsets as they are, the values converted.
583
+ return pa.MapArray.from_arrays(array.offsets, array.keys, _converted(array.items), mask=array.is_null())
584
+ if pa.types.is_struct(t):
585
+ fields = [(t.field(i).name, _converted(array.field(i)) if _has_tag_type(t.field(i).type) else array.field(i))
586
+ for i in range(t.num_fields)]
587
+ return pa.StructArray.from_arrays([a for _, a in fields], names=[n for n, _ in fields], mask=array.is_null())
588
+ raise NotBuilt("a value of several types inside a nested value in an answer")
589
+
590
+
591
+ def unwrap_table(table: Any) -> Any:
592
+ """`table` with each column of tagged structs, or of lists of them (to any depth), as the dense union
593
+ of its values (`_union`); other columns as they are. The union's members are fixed, so every batch of
594
+ an answer has one type."""
595
+ import pyarrow as pa
596
+ columns = []
597
+ for i, f in enumerate(table.schema):
598
+ column = table.column(i)
599
+ if not _has_tag_type(f.type):
600
+ columns.append(column)
601
+ continue
602
+ chunks = [_converted(c) for c in column.chunks] or [_converted(pa.array([], type=f.type))]
603
+ columns.append(pa.chunked_array(chunks))
604
+ return pa.Table.from_arrays(columns, names=table.column_names)