exonware-xwnode 0.0.1.12__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 (132) hide show
  1. exonware/__init__.py +14 -0
  2. exonware/xwnode/__init__.py +127 -0
  3. exonware/xwnode/base.py +676 -0
  4. exonware/xwnode/config.py +178 -0
  5. exonware/xwnode/contracts.py +730 -0
  6. exonware/xwnode/errors.py +503 -0
  7. exonware/xwnode/facade.py +460 -0
  8. exonware/xwnode/strategies/__init__.py +158 -0
  9. exonware/xwnode/strategies/advisor.py +463 -0
  10. exonware/xwnode/strategies/edges/__init__.py +32 -0
  11. exonware/xwnode/strategies/edges/adj_list.py +227 -0
  12. exonware/xwnode/strategies/edges/adj_matrix.py +391 -0
  13. exonware/xwnode/strategies/edges/base.py +169 -0
  14. exonware/xwnode/strategies/flyweight.py +328 -0
  15. exonware/xwnode/strategies/impls/__init__.py +13 -0
  16. exonware/xwnode/strategies/impls/_base_edge.py +403 -0
  17. exonware/xwnode/strategies/impls/_base_node.py +307 -0
  18. exonware/xwnode/strategies/impls/edge_adj_list.py +353 -0
  19. exonware/xwnode/strategies/impls/edge_adj_matrix.py +445 -0
  20. exonware/xwnode/strategies/impls/edge_bidir_wrapper.py +455 -0
  21. exonware/xwnode/strategies/impls/edge_block_adj_matrix.py +539 -0
  22. exonware/xwnode/strategies/impls/edge_coo.py +533 -0
  23. exonware/xwnode/strategies/impls/edge_csc.py +447 -0
  24. exonware/xwnode/strategies/impls/edge_csr.py +492 -0
  25. exonware/xwnode/strategies/impls/edge_dynamic_adj_list.py +503 -0
  26. exonware/xwnode/strategies/impls/edge_flow_network.py +555 -0
  27. exonware/xwnode/strategies/impls/edge_hyperedge_set.py +516 -0
  28. exonware/xwnode/strategies/impls/edge_neural_graph.py +650 -0
  29. exonware/xwnode/strategies/impls/edge_octree.py +574 -0
  30. exonware/xwnode/strategies/impls/edge_property_store.py +655 -0
  31. exonware/xwnode/strategies/impls/edge_quadtree.py +519 -0
  32. exonware/xwnode/strategies/impls/edge_rtree.py +820 -0
  33. exonware/xwnode/strategies/impls/edge_temporal_edgeset.py +558 -0
  34. exonware/xwnode/strategies/impls/edge_tree_graph_basic.py +271 -0
  35. exonware/xwnode/strategies/impls/edge_weighted_graph.py +411 -0
  36. exonware/xwnode/strategies/manager.py +775 -0
  37. exonware/xwnode/strategies/metrics.py +538 -0
  38. exonware/xwnode/strategies/migration.py +432 -0
  39. exonware/xwnode/strategies/nodes/__init__.py +50 -0
  40. exonware/xwnode/strategies/nodes/_base_node.py +307 -0
  41. exonware/xwnode/strategies/nodes/adjacency_list.py +267 -0
  42. exonware/xwnode/strategies/nodes/aho_corasick.py +345 -0
  43. exonware/xwnode/strategies/nodes/array_list.py +209 -0
  44. exonware/xwnode/strategies/nodes/base.py +247 -0
  45. exonware/xwnode/strategies/nodes/deque.py +200 -0
  46. exonware/xwnode/strategies/nodes/hash_map.py +135 -0
  47. exonware/xwnode/strategies/nodes/heap.py +307 -0
  48. exonware/xwnode/strategies/nodes/linked_list.py +232 -0
  49. exonware/xwnode/strategies/nodes/node_aho_corasick.py +520 -0
  50. exonware/xwnode/strategies/nodes/node_array_list.py +175 -0
  51. exonware/xwnode/strategies/nodes/node_avl_tree.py +371 -0
  52. exonware/xwnode/strategies/nodes/node_b_plus_tree.py +542 -0
  53. exonware/xwnode/strategies/nodes/node_bitmap.py +420 -0
  54. exonware/xwnode/strategies/nodes/node_bitset_dynamic.py +513 -0
  55. exonware/xwnode/strategies/nodes/node_bloom_filter.py +347 -0
  56. exonware/xwnode/strategies/nodes/node_btree.py +357 -0
  57. exonware/xwnode/strategies/nodes/node_count_min_sketch.py +470 -0
  58. exonware/xwnode/strategies/nodes/node_cow_tree.py +473 -0
  59. exonware/xwnode/strategies/nodes/node_cuckoo_hash.py +392 -0
  60. exonware/xwnode/strategies/nodes/node_fenwick_tree.py +301 -0
  61. exonware/xwnode/strategies/nodes/node_hash_map.py +269 -0
  62. exonware/xwnode/strategies/nodes/node_heap.py +191 -0
  63. exonware/xwnode/strategies/nodes/node_hyperloglog.py +407 -0
  64. exonware/xwnode/strategies/nodes/node_linked_list.py +409 -0
  65. exonware/xwnode/strategies/nodes/node_lsm_tree.py +400 -0
  66. exonware/xwnode/strategies/nodes/node_ordered_map.py +390 -0
  67. exonware/xwnode/strategies/nodes/node_ordered_map_balanced.py +565 -0
  68. exonware/xwnode/strategies/nodes/node_patricia.py +512 -0
  69. exonware/xwnode/strategies/nodes/node_persistent_tree.py +378 -0
  70. exonware/xwnode/strategies/nodes/node_radix_trie.py +452 -0
  71. exonware/xwnode/strategies/nodes/node_red_black_tree.py +497 -0
  72. exonware/xwnode/strategies/nodes/node_roaring_bitmap.py +570 -0
  73. exonware/xwnode/strategies/nodes/node_segment_tree.py +289 -0
  74. exonware/xwnode/strategies/nodes/node_set_hash.py +354 -0
  75. exonware/xwnode/strategies/nodes/node_set_tree.py +480 -0
  76. exonware/xwnode/strategies/nodes/node_skip_list.py +316 -0
  77. exonware/xwnode/strategies/nodes/node_splay_tree.py +393 -0
  78. exonware/xwnode/strategies/nodes/node_suffix_array.py +487 -0
  79. exonware/xwnode/strategies/nodes/node_treap.py +387 -0
  80. exonware/xwnode/strategies/nodes/node_tree_graph_hybrid.py +1434 -0
  81. exonware/xwnode/strategies/nodes/node_trie.py +252 -0
  82. exonware/xwnode/strategies/nodes/node_union_find.py +187 -0
  83. exonware/xwnode/strategies/nodes/node_xdata_optimized.py +369 -0
  84. exonware/xwnode/strategies/nodes/priority_queue.py +209 -0
  85. exonware/xwnode/strategies/nodes/queue.py +161 -0
  86. exonware/xwnode/strategies/nodes/sparse_matrix.py +206 -0
  87. exonware/xwnode/strategies/nodes/stack.py +152 -0
  88. exonware/xwnode/strategies/nodes/trie.py +274 -0
  89. exonware/xwnode/strategies/nodes/union_find.py +283 -0
  90. exonware/xwnode/strategies/pattern_detector.py +603 -0
  91. exonware/xwnode/strategies/performance_monitor.py +487 -0
  92. exonware/xwnode/strategies/queries/__init__.py +24 -0
  93. exonware/xwnode/strategies/queries/base.py +236 -0
  94. exonware/xwnode/strategies/queries/cql.py +201 -0
  95. exonware/xwnode/strategies/queries/cypher.py +181 -0
  96. exonware/xwnode/strategies/queries/datalog.py +70 -0
  97. exonware/xwnode/strategies/queries/elastic_dsl.py +70 -0
  98. exonware/xwnode/strategies/queries/eql.py +70 -0
  99. exonware/xwnode/strategies/queries/flux.py +70 -0
  100. exonware/xwnode/strategies/queries/gql.py +70 -0
  101. exonware/xwnode/strategies/queries/graphql.py +240 -0
  102. exonware/xwnode/strategies/queries/gremlin.py +181 -0
  103. exonware/xwnode/strategies/queries/hiveql.py +214 -0
  104. exonware/xwnode/strategies/queries/hql.py +70 -0
  105. exonware/xwnode/strategies/queries/jmespath.py +219 -0
  106. exonware/xwnode/strategies/queries/jq.py +66 -0
  107. exonware/xwnode/strategies/queries/json_query.py +66 -0
  108. exonware/xwnode/strategies/queries/jsoniq.py +248 -0
  109. exonware/xwnode/strategies/queries/kql.py +70 -0
  110. exonware/xwnode/strategies/queries/linq.py +238 -0
  111. exonware/xwnode/strategies/queries/logql.py +70 -0
  112. exonware/xwnode/strategies/queries/mql.py +68 -0
  113. exonware/xwnode/strategies/queries/n1ql.py +210 -0
  114. exonware/xwnode/strategies/queries/partiql.py +70 -0
  115. exonware/xwnode/strategies/queries/pig.py +215 -0
  116. exonware/xwnode/strategies/queries/promql.py +70 -0
  117. exonware/xwnode/strategies/queries/sparql.py +220 -0
  118. exonware/xwnode/strategies/queries/sql.py +275 -0
  119. exonware/xwnode/strategies/queries/xml_query.py +66 -0
  120. exonware/xwnode/strategies/queries/xpath.py +223 -0
  121. exonware/xwnode/strategies/queries/xquery.py +258 -0
  122. exonware/xwnode/strategies/queries/xwnode_executor.py +332 -0
  123. exonware/xwnode/strategies/queries/xwquery_strategy.py +424 -0
  124. exonware/xwnode/strategies/registry.py +604 -0
  125. exonware/xwnode/strategies/simple.py +273 -0
  126. exonware/xwnode/strategies/utils.py +532 -0
  127. exonware/xwnode/types.py +912 -0
  128. exonware/xwnode/version.py +78 -0
  129. exonware_xwnode-0.0.1.12.dist-info/METADATA +169 -0
  130. exonware_xwnode-0.0.1.12.dist-info/RECORD +132 -0
  131. exonware_xwnode-0.0.1.12.dist-info/WHEEL +4 -0
  132. exonware_xwnode-0.0.1.12.dist-info/licenses/LICENSE +21 -0
@@ -0,0 +1,332 @@
1
+ #!/usr/bin/env python3
2
+ """
3
+ XWNode Query Action Executor
4
+
5
+ This module implements the XWNode query action executor that provides
6
+ a unified interface for executing queries across all supported query types
7
+ using the existing XWNode strategy system.
8
+
9
+ Company: eXonware.com
10
+ Author: Eng. Muhammad AlShehri
11
+ Email: connect@exonware.com
12
+ Version: 0.0.1.12
13
+ Generation Date: January 2, 2025
14
+ """
15
+
16
+ from typing import Any, Dict, List, Optional, Type
17
+ from datetime import datetime
18
+
19
+ from .base import AQueryActionExecutor
20
+ from .xwquery_strategy import XWQueryScriptStrategy
21
+ from ...base import XWNodeBase
22
+ from ...contracts import QueryMode, QueryTrait
23
+ from ...errors import XWNodeTypeError, XWNodeValueError
24
+
25
+
26
+ class XWNodeQueryActionExecutor(AQueryActionExecutor):
27
+ """
28
+ XWNode implementation of query action executor.
29
+
30
+ This executor provides a unified interface for executing queries across
31
+ all 35+ supported query types using the existing XWNode strategy system.
32
+ """
33
+
34
+ def __init__(self):
35
+ super().__init__()
36
+ self._mode = QueryMode.AUTO
37
+ self._traits = QueryTrait.STRUCTURED | QueryTrait.ANALYTICAL | QueryTrait.BATCH
38
+
39
+ # All supported query types from XWNode
40
+ self._supported_queries = [
41
+ # Structured & Document Query Languages
42
+ "SQL", "HIVEQL", "PIG", "CQL", "N1QL", "KQL", "DATALOG",
43
+ "MQL", "PARTIQL",
44
+
45
+ # Search Query Languages
46
+ "ELASTIC_DSL", "EQL", "LUCENE",
47
+
48
+ # Time Series & Monitoring
49
+ "FLUX", "PROMQL",
50
+
51
+ # Data Streaming
52
+ "KSQL",
53
+
54
+ # Graph Query Languages
55
+ "GRAPHQL", "SPARQL", "GREMLIN", "CYPHER", "GQL",
56
+
57
+ # ORM / Integrated Query
58
+ "LINQ", "HQL",
59
+
60
+ # Markup & Document Structure
61
+ "JSONIQ", "JMESPATH", "JQ", "XQUERY", "XPATH",
62
+
63
+ # Logs & Analytics
64
+ "LOGQL", "SPL",
65
+
66
+ # SQL Engines
67
+ "TRINO_SQL", "BIGQUERY_SQL", "SNOWFLAKE_SQL",
68
+
69
+ # Generic Query Languages
70
+ "XML_QUERY", "JSON_QUERY"
71
+ ]
72
+
73
+ self._strategy_cache = {}
74
+ self._execution_stats = {
75
+ "total_queries": 0,
76
+ "successful_queries": 0,
77
+ "failed_queries": 0,
78
+ "execution_times": []
79
+ }
80
+
81
+ def execute_query(self, query: str, query_type: str, **kwargs) -> Any:
82
+ """Execute a query using the appropriate XWNode strategy."""
83
+ if not self.validate_query(query, query_type):
84
+ raise XWNodeValueError(f"Invalid {query_type} query: {query}")
85
+
86
+ start_time = datetime.now()
87
+ self._execution_stats["total_queries"] += 1
88
+
89
+ try:
90
+ # Get or create strategy instance
91
+ strategy = self._get_strategy(query_type)
92
+
93
+ # Execute the query
94
+ result = strategy.execute(query, **kwargs)
95
+
96
+ # Update stats
97
+ execution_time = (datetime.now() - start_time).total_seconds()
98
+ self._execution_stats["successful_queries"] += 1
99
+ self._execution_stats["execution_times"].append(execution_time)
100
+
101
+ return {
102
+ "result": result,
103
+ "query_type": query_type,
104
+ "execution_time": f"{execution_time:.3f}s",
105
+ "backend": "XWNODE",
106
+ "strategy_used": strategy.__class__.__name__
107
+ }
108
+
109
+ except Exception as e:
110
+ self._execution_stats["failed_queries"] += 1
111
+ raise XWNodeValueError(f"Query execution failed: {e}")
112
+
113
+ def validate_query(self, query: str, query_type: str) -> bool:
114
+ """Validate if XWNode can handle this query type."""
115
+ if query_type.upper() not in self._supported_queries:
116
+ return False
117
+
118
+ try:
119
+ strategy = self._get_strategy(query_type)
120
+ return strategy.validate_query(query)
121
+ except Exception:
122
+ return False
123
+
124
+ def get_supported_query_types(self) -> List[str]:
125
+ """Get list of query types supported by XWNode."""
126
+ return self._supported_queries.copy()
127
+
128
+ def _get_strategy(self, query_type: str) -> Any:
129
+ """Get or create strategy instance for query type."""
130
+ query_type_upper = query_type.upper()
131
+
132
+ if query_type_upper in self._strategy_cache:
133
+ return self._strategy_cache[query_type_upper]
134
+
135
+ # Import and create strategy instance
136
+ strategy_class = self._get_strategy_class(query_type_upper)
137
+ if not strategy_class:
138
+ raise XWNodeValueError(f"No strategy available for query type: {query_type}")
139
+
140
+ strategy = strategy_class()
141
+ self._strategy_cache[query_type_upper] = strategy
142
+ return strategy
143
+
144
+ def _get_strategy_class(self, query_type: str) -> Optional[Type]:
145
+ """Get strategy class for query type."""
146
+ strategy_map = {
147
+ "SQL": "sql",
148
+ "HIVEQL": "hiveql",
149
+ "PIG": "pig",
150
+ "CQL": "cql",
151
+ "N1QL": "n1ql",
152
+ "KQL": "kql",
153
+ "DATALOG": "datalog",
154
+ "MQL": "mql",
155
+ "PARTIQL": "partiql",
156
+ "ELASTIC_DSL": "elastic_dsl",
157
+ "EQL": "eql",
158
+ "LUCENE": "lucene",
159
+ "FLUX": "flux",
160
+ "PROMQL": "promql",
161
+ "KSQL": "ksql",
162
+ "GRAPHQL": "graphql",
163
+ "SPARQL": "sparql",
164
+ "GREMLIN": "gremlin",
165
+ "CYPHER": "cypher",
166
+ "GQL": "gql",
167
+ "LINQ": "linq",
168
+ "HQL": "hql",
169
+ "JSONIQ": "jsoniq",
170
+ "JMESPATH": "jmespath",
171
+ "JQ": "jq",
172
+ "XQUERY": "xquery",
173
+ "XPATH": "xpath",
174
+ "LOGQL": "logql",
175
+ "SPL": "spl",
176
+ "TRINO_SQL": "trino_sql",
177
+ "BIGQUERY_SQL": "bigquery_sql",
178
+ "SNOWFLAKE_SQL": "snowflake_sql",
179
+ "XML_QUERY": "xml_query",
180
+ "JSON_QUERY": "json_query"
181
+ }
182
+
183
+ module_name = strategy_map.get(query_type)
184
+ if not module_name:
185
+ return None
186
+
187
+ try:
188
+ module = __import__(f'.{module_name}', fromlist=['.'], package=__package__)
189
+ strategy_class_name = f"{query_type.title()}Strategy"
190
+ return getattr(module, strategy_class_name, None)
191
+ except (ImportError, AttributeError):
192
+ return None
193
+
194
+ def to_native(self) -> XWQueryScriptStrategy:
195
+ """Convert to XWQueryScriptStrategy using actions."""
196
+ return XWQueryScriptStrategy()
197
+
198
+ def to_actions_tree(self, query: str) -> XWNodeBase:
199
+ """Convert query to actions tree using XWQuery Script."""
200
+ script_strategy = XWQueryScriptStrategy()
201
+ return script_strategy.parse_script(query).get_actions_tree()
202
+
203
+ def from_actions_tree(self, actions_tree: XWNodeBase) -> str:
204
+ """Convert actions tree to query using XWQuery Script."""
205
+ script_strategy = XWQueryScriptStrategy(actions_tree)
206
+ return script_strategy.to_format("SQL") # Default to SQL
207
+
208
+ def get_execution_stats(self) -> Dict[str, Any]:
209
+ """Get execution statistics."""
210
+ stats = self._execution_stats.copy()
211
+
212
+ if stats["execution_times"]:
213
+ stats["avg_execution_time"] = sum(stats["execution_times"]) / len(stats["execution_times"])
214
+ stats["min_execution_time"] = min(stats["execution_times"])
215
+ stats["max_execution_time"] = max(stats["execution_times"])
216
+ else:
217
+ stats["avg_execution_time"] = 0
218
+ stats["min_execution_time"] = 0
219
+ stats["max_execution_time"] = 0
220
+
221
+ stats["success_rate"] = (
222
+ stats["successful_queries"] / stats["total_queries"]
223
+ if stats["total_queries"] > 0 else 0
224
+ )
225
+
226
+ return stats
227
+
228
+ def clear_cache(self):
229
+ """Clear strategy cache."""
230
+ self._strategy_cache.clear()
231
+
232
+ def reset_stats(self):
233
+ """Reset execution statistics."""
234
+ self._execution_stats = {
235
+ "total_queries": 0,
236
+ "successful_queries": 0,
237
+ "failed_queries": 0,
238
+ "execution_times": []
239
+ }
240
+
241
+ def get_backend_info(self) -> Dict[str, Any]:
242
+ """Get XWNode backend information."""
243
+ return {
244
+ "backend": "XWNODE",
245
+ "version": "0.0.1",
246
+ "capabilities": [
247
+ "multi_language_queries",
248
+ "format_agnostic",
249
+ "strategy_pattern",
250
+ "enterprise_features",
251
+ "xwquery_script_support"
252
+ ],
253
+ "supported_query_types": len(self._supported_queries),
254
+ "performance_class": "high_performance",
255
+ "execution_stats": self.get_execution_stats()
256
+ }
257
+
258
+ def estimate_cost(self, query: str, query_type: str) -> Dict[str, Any]:
259
+ """Estimate execution cost for XWNode."""
260
+ try:
261
+ strategy = self._get_strategy(query_type)
262
+ plan = strategy.get_query_plan(query)
263
+
264
+ return {
265
+ "backend": "XWNODE",
266
+ "complexity": plan.get("complexity", "UNKNOWN"),
267
+ "estimated_cost": plan.get("estimated_cost", 0),
268
+ "execution_time": f"{plan.get('estimated_cost', 0)}ms",
269
+ "memory_usage": "low",
270
+ "strategy_used": strategy.__class__.__name__
271
+ }
272
+ except Exception:
273
+ return {
274
+ "backend": "XWNODE",
275
+ "complexity": "UNKNOWN",
276
+ "estimated_cost": 0,
277
+ "execution_time": "0ms",
278
+ "memory_usage": "low",
279
+ "strategy_used": "Unknown"
280
+ }
281
+
282
+ def execute(self, query: str, context: Dict[str, Any] = None, **kwargs) -> Any:
283
+ """Execute query using XWNode strategies."""
284
+ # Determine query type automatically if not specified
285
+ query_type = kwargs.get('query_type', self._detect_query_type(query))
286
+ return self.execute_query(query, query_type, **kwargs)
287
+
288
+ def get_query_plan(self, query: str) -> Dict[str, Any]:
289
+ """Get query execution plan."""
290
+ query_type = self._detect_query_type(query)
291
+ try:
292
+ strategy = self._get_strategy(query_type)
293
+ return strategy.get_query_plan(query)
294
+ except Exception:
295
+ return {
296
+ "query_type": query_type,
297
+ "complexity": "UNKNOWN",
298
+ "estimated_cost": 0,
299
+ "backend": "XWNODE"
300
+ }
301
+
302
+ def can_handle(self, query_string: str) -> bool:
303
+ """Check if XWNode can handle this query."""
304
+ query_type = self._detect_query_type(query_string)
305
+ return query_type in self._supported_queries
306
+
307
+ def get_supported_operations(self) -> List[str]:
308
+ """Get list of supported operations."""
309
+ return self._supported_queries.copy()
310
+
311
+ def estimate_complexity(self, query_string: str) -> Dict[str, Any]:
312
+ """Estimate query complexity."""
313
+ query_type = self._detect_query_type(query_string)
314
+ return self.estimate_cost(query_string, query_type)
315
+
316
+ def _detect_query_type(self, query: str) -> str:
317
+ """Detect query type from query string."""
318
+ query_upper = query.upper()
319
+
320
+ # Simple detection logic
321
+ if any(keyword in query_upper for keyword in ['SELECT', 'INSERT', 'UPDATE', 'DELETE', 'CREATE', 'DROP']):
322
+ return "SQL"
323
+ elif 'MATCH' in query_upper and ('(' in query or ')' in query):
324
+ return "CYPHER"
325
+ elif 'PREFIX' in query_upper or 'SELECT' in query_upper and 'WHERE' in query_upper:
326
+ return "SPARQL"
327
+ elif query.strip().startswith('{') and 'query' in query_upper:
328
+ return "GRAPHQL"
329
+ elif 'FROM' in query_upper and 'WHERE' in query_upper:
330
+ return "KQL"
331
+ else:
332
+ return "SQL" # Default fallback