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.
- exonware/__init__.py +14 -0
- exonware/xwnode/__init__.py +127 -0
- exonware/xwnode/base.py +676 -0
- exonware/xwnode/config.py +178 -0
- exonware/xwnode/contracts.py +730 -0
- exonware/xwnode/errors.py +503 -0
- exonware/xwnode/facade.py +460 -0
- exonware/xwnode/strategies/__init__.py +158 -0
- exonware/xwnode/strategies/advisor.py +463 -0
- exonware/xwnode/strategies/edges/__init__.py +32 -0
- exonware/xwnode/strategies/edges/adj_list.py +227 -0
- exonware/xwnode/strategies/edges/adj_matrix.py +391 -0
- exonware/xwnode/strategies/edges/base.py +169 -0
- exonware/xwnode/strategies/flyweight.py +328 -0
- exonware/xwnode/strategies/impls/__init__.py +13 -0
- exonware/xwnode/strategies/impls/_base_edge.py +403 -0
- exonware/xwnode/strategies/impls/_base_node.py +307 -0
- exonware/xwnode/strategies/impls/edge_adj_list.py +353 -0
- exonware/xwnode/strategies/impls/edge_adj_matrix.py +445 -0
- exonware/xwnode/strategies/impls/edge_bidir_wrapper.py +455 -0
- exonware/xwnode/strategies/impls/edge_block_adj_matrix.py +539 -0
- exonware/xwnode/strategies/impls/edge_coo.py +533 -0
- exonware/xwnode/strategies/impls/edge_csc.py +447 -0
- exonware/xwnode/strategies/impls/edge_csr.py +492 -0
- exonware/xwnode/strategies/impls/edge_dynamic_adj_list.py +503 -0
- exonware/xwnode/strategies/impls/edge_flow_network.py +555 -0
- exonware/xwnode/strategies/impls/edge_hyperedge_set.py +516 -0
- exonware/xwnode/strategies/impls/edge_neural_graph.py +650 -0
- exonware/xwnode/strategies/impls/edge_octree.py +574 -0
- exonware/xwnode/strategies/impls/edge_property_store.py +655 -0
- exonware/xwnode/strategies/impls/edge_quadtree.py +519 -0
- exonware/xwnode/strategies/impls/edge_rtree.py +820 -0
- exonware/xwnode/strategies/impls/edge_temporal_edgeset.py +558 -0
- exonware/xwnode/strategies/impls/edge_tree_graph_basic.py +271 -0
- exonware/xwnode/strategies/impls/edge_weighted_graph.py +411 -0
- exonware/xwnode/strategies/manager.py +775 -0
- exonware/xwnode/strategies/metrics.py +538 -0
- exonware/xwnode/strategies/migration.py +432 -0
- exonware/xwnode/strategies/nodes/__init__.py +50 -0
- exonware/xwnode/strategies/nodes/_base_node.py +307 -0
- exonware/xwnode/strategies/nodes/adjacency_list.py +267 -0
- exonware/xwnode/strategies/nodes/aho_corasick.py +345 -0
- exonware/xwnode/strategies/nodes/array_list.py +209 -0
- exonware/xwnode/strategies/nodes/base.py +247 -0
- exonware/xwnode/strategies/nodes/deque.py +200 -0
- exonware/xwnode/strategies/nodes/hash_map.py +135 -0
- exonware/xwnode/strategies/nodes/heap.py +307 -0
- exonware/xwnode/strategies/nodes/linked_list.py +232 -0
- exonware/xwnode/strategies/nodes/node_aho_corasick.py +520 -0
- exonware/xwnode/strategies/nodes/node_array_list.py +175 -0
- exonware/xwnode/strategies/nodes/node_avl_tree.py +371 -0
- exonware/xwnode/strategies/nodes/node_b_plus_tree.py +542 -0
- exonware/xwnode/strategies/nodes/node_bitmap.py +420 -0
- exonware/xwnode/strategies/nodes/node_bitset_dynamic.py +513 -0
- exonware/xwnode/strategies/nodes/node_bloom_filter.py +347 -0
- exonware/xwnode/strategies/nodes/node_btree.py +357 -0
- exonware/xwnode/strategies/nodes/node_count_min_sketch.py +470 -0
- exonware/xwnode/strategies/nodes/node_cow_tree.py +473 -0
- exonware/xwnode/strategies/nodes/node_cuckoo_hash.py +392 -0
- exonware/xwnode/strategies/nodes/node_fenwick_tree.py +301 -0
- exonware/xwnode/strategies/nodes/node_hash_map.py +269 -0
- exonware/xwnode/strategies/nodes/node_heap.py +191 -0
- exonware/xwnode/strategies/nodes/node_hyperloglog.py +407 -0
- exonware/xwnode/strategies/nodes/node_linked_list.py +409 -0
- exonware/xwnode/strategies/nodes/node_lsm_tree.py +400 -0
- exonware/xwnode/strategies/nodes/node_ordered_map.py +390 -0
- exonware/xwnode/strategies/nodes/node_ordered_map_balanced.py +565 -0
- exonware/xwnode/strategies/nodes/node_patricia.py +512 -0
- exonware/xwnode/strategies/nodes/node_persistent_tree.py +378 -0
- exonware/xwnode/strategies/nodes/node_radix_trie.py +452 -0
- exonware/xwnode/strategies/nodes/node_red_black_tree.py +497 -0
- exonware/xwnode/strategies/nodes/node_roaring_bitmap.py +570 -0
- exonware/xwnode/strategies/nodes/node_segment_tree.py +289 -0
- exonware/xwnode/strategies/nodes/node_set_hash.py +354 -0
- exonware/xwnode/strategies/nodes/node_set_tree.py +480 -0
- exonware/xwnode/strategies/nodes/node_skip_list.py +316 -0
- exonware/xwnode/strategies/nodes/node_splay_tree.py +393 -0
- exonware/xwnode/strategies/nodes/node_suffix_array.py +487 -0
- exonware/xwnode/strategies/nodes/node_treap.py +387 -0
- exonware/xwnode/strategies/nodes/node_tree_graph_hybrid.py +1434 -0
- exonware/xwnode/strategies/nodes/node_trie.py +252 -0
- exonware/xwnode/strategies/nodes/node_union_find.py +187 -0
- exonware/xwnode/strategies/nodes/node_xdata_optimized.py +369 -0
- exonware/xwnode/strategies/nodes/priority_queue.py +209 -0
- exonware/xwnode/strategies/nodes/queue.py +161 -0
- exonware/xwnode/strategies/nodes/sparse_matrix.py +206 -0
- exonware/xwnode/strategies/nodes/stack.py +152 -0
- exonware/xwnode/strategies/nodes/trie.py +274 -0
- exonware/xwnode/strategies/nodes/union_find.py +283 -0
- exonware/xwnode/strategies/pattern_detector.py +603 -0
- exonware/xwnode/strategies/performance_monitor.py +487 -0
- exonware/xwnode/strategies/queries/__init__.py +24 -0
- exonware/xwnode/strategies/queries/base.py +236 -0
- exonware/xwnode/strategies/queries/cql.py +201 -0
- exonware/xwnode/strategies/queries/cypher.py +181 -0
- exonware/xwnode/strategies/queries/datalog.py +70 -0
- exonware/xwnode/strategies/queries/elastic_dsl.py +70 -0
- exonware/xwnode/strategies/queries/eql.py +70 -0
- exonware/xwnode/strategies/queries/flux.py +70 -0
- exonware/xwnode/strategies/queries/gql.py +70 -0
- exonware/xwnode/strategies/queries/graphql.py +240 -0
- exonware/xwnode/strategies/queries/gremlin.py +181 -0
- exonware/xwnode/strategies/queries/hiveql.py +214 -0
- exonware/xwnode/strategies/queries/hql.py +70 -0
- exonware/xwnode/strategies/queries/jmespath.py +219 -0
- exonware/xwnode/strategies/queries/jq.py +66 -0
- exonware/xwnode/strategies/queries/json_query.py +66 -0
- exonware/xwnode/strategies/queries/jsoniq.py +248 -0
- exonware/xwnode/strategies/queries/kql.py +70 -0
- exonware/xwnode/strategies/queries/linq.py +238 -0
- exonware/xwnode/strategies/queries/logql.py +70 -0
- exonware/xwnode/strategies/queries/mql.py +68 -0
- exonware/xwnode/strategies/queries/n1ql.py +210 -0
- exonware/xwnode/strategies/queries/partiql.py +70 -0
- exonware/xwnode/strategies/queries/pig.py +215 -0
- exonware/xwnode/strategies/queries/promql.py +70 -0
- exonware/xwnode/strategies/queries/sparql.py +220 -0
- exonware/xwnode/strategies/queries/sql.py +275 -0
- exonware/xwnode/strategies/queries/xml_query.py +66 -0
- exonware/xwnode/strategies/queries/xpath.py +223 -0
- exonware/xwnode/strategies/queries/xquery.py +258 -0
- exonware/xwnode/strategies/queries/xwnode_executor.py +332 -0
- exonware/xwnode/strategies/queries/xwquery_strategy.py +424 -0
- exonware/xwnode/strategies/registry.py +604 -0
- exonware/xwnode/strategies/simple.py +273 -0
- exonware/xwnode/strategies/utils.py +532 -0
- exonware/xwnode/types.py +912 -0
- exonware/xwnode/version.py +78 -0
- exonware_xwnode-0.0.1.12.dist-info/METADATA +169 -0
- exonware_xwnode-0.0.1.12.dist-info/RECORD +132 -0
- exonware_xwnode-0.0.1.12.dist-info/WHEEL +4 -0
- exonware_xwnode-0.0.1.12.dist-info/licenses/LICENSE +21 -0
@@ -0,0 +1,604 @@
|
|
1
|
+
"""
|
2
|
+
#exonware/xwnode/src/exonware/xwnode/strategies/registry.py
|
3
|
+
|
4
|
+
Strategy Registry
|
5
|
+
|
6
|
+
This module provides the StrategyRegistry class for managing strategy registration,
|
7
|
+
discovery, and instantiation in the strategy system.
|
8
|
+
"""
|
9
|
+
|
10
|
+
import threading
|
11
|
+
from typing import Dict, Type, List, Optional, Any, Callable
|
12
|
+
from exonware.xwsystem import get_logger
|
13
|
+
|
14
|
+
logger = get_logger(__name__)
|
15
|
+
|
16
|
+
from ..types import NodeMode, EdgeMode, NodeTrait, EdgeTrait, NODE_STRATEGY_METADATA, EDGE_STRATEGY_METADATA, QueryMode, QueryTrait
|
17
|
+
from ..errors import XWNodeStrategyError, XWNodeError
|
18
|
+
|
19
|
+
|
20
|
+
class StrategyRegistry:
|
21
|
+
"""
|
22
|
+
Central registry for managing strategy implementations.
|
23
|
+
|
24
|
+
This class provides thread-safe registration and discovery of strategy
|
25
|
+
implementations for both nodes and edges in the strategy system.
|
26
|
+
"""
|
27
|
+
|
28
|
+
def __init__(self):
|
29
|
+
"""Initialize the strategy registry."""
|
30
|
+
self._node_strategies: Dict[NodeMode, Type] = {}
|
31
|
+
self._edge_strategies: Dict[EdgeMode, Type] = {}
|
32
|
+
self._query_strategies: Dict[str, Type] = {}
|
33
|
+
self._node_factories: Dict[NodeMode, Callable] = {}
|
34
|
+
self._edge_factories: Dict[EdgeMode, Callable] = {}
|
35
|
+
self._query_factories: Dict[str, Callable] = {}
|
36
|
+
self._lock = threading.RLock()
|
37
|
+
|
38
|
+
# Register default strategies
|
39
|
+
self._register_default_strategies()
|
40
|
+
self._register_default_query_strategies()
|
41
|
+
|
42
|
+
def _register_default_strategies(self):
|
43
|
+
"""Register default strategy implementations."""
|
44
|
+
# Import default strategies
|
45
|
+
from .impls.edge_adj_list import xAdjListStrategy
|
46
|
+
from .impls.edge_adj_matrix import xAdjMatrixStrategy
|
47
|
+
from .impls.edge_csr import xCSRStrategy
|
48
|
+
from .impls.edge_dynamic_adj_list import xDynamicAdjListStrategy
|
49
|
+
from .impls.edge_temporal_edgeset import xTemporalEdgeSetStrategy
|
50
|
+
from .impls.edge_hyperedge_set import xHyperEdgeSetStrategy
|
51
|
+
from .impls.edge_rtree import xRTreeStrategy
|
52
|
+
from .impls.edge_flow_network import xFlowNetworkStrategy
|
53
|
+
from .impls.edge_neural_graph import xNeuralGraphStrategy
|
54
|
+
from .impls.edge_csc import xCSCStrategy
|
55
|
+
from .impls.edge_bidir_wrapper import xBidirWrapperStrategy
|
56
|
+
from .impls.edge_quadtree import xQuadtreeStrategy
|
57
|
+
from .impls.edge_coo import xCOOStrategy
|
58
|
+
from .impls.edge_octree import xOctreeStrategy
|
59
|
+
from .impls.edge_property_store import xEdgePropertyStoreStrategy
|
60
|
+
from .impls.edge_tree_graph_basic import xTreeGraphBasicStrategy
|
61
|
+
from .impls.edge_weighted_graph import xWeightedGraphStrategy
|
62
|
+
|
63
|
+
# Import new strategy implementations
|
64
|
+
from .nodes.node_hash_map import xHashMapStrategy
|
65
|
+
from .nodes.node_array_list import xArrayListStrategy
|
66
|
+
from .nodes.node_trie import xTrieStrategy
|
67
|
+
from .nodes.node_heap import xHeapStrategy
|
68
|
+
from .nodes.node_btree import xBTreeStrategy
|
69
|
+
from .nodes.node_union_find import xUnionFindStrategy
|
70
|
+
from .nodes.node_segment_tree import xSegmentTreeStrategy
|
71
|
+
from .nodes.node_lsm_tree import xLSMTreeStrategy
|
72
|
+
from .nodes.node_fenwick_tree import xFenwickTreeStrategy
|
73
|
+
from .nodes.node_set_hash import xSetHashStrategy
|
74
|
+
from .nodes.node_bloom_filter import xBloomFilterStrategy
|
75
|
+
from .nodes.node_cuckoo_hash import xCuckooHashStrategy
|
76
|
+
from .nodes.node_bitmap import xBitmapStrategy
|
77
|
+
from .nodes.node_roaring_bitmap import xRoaringBitmapStrategy
|
78
|
+
from .nodes.node_suffix_array import xSuffixArrayStrategy
|
79
|
+
from .nodes.node_aho_corasick import xAhoCorasickStrategy
|
80
|
+
from .nodes.node_count_min_sketch import xCountMinSketchStrategy
|
81
|
+
from .nodes.node_hyperloglog import xHyperLogLogStrategy
|
82
|
+
from .nodes.node_set_tree import xSetTreeStrategy
|
83
|
+
from .nodes.node_linked_list import xLinkedListStrategy
|
84
|
+
from .nodes.node_ordered_map import xOrderedMapStrategy
|
85
|
+
from .nodes.node_radix_trie import xRadixTrieStrategy
|
86
|
+
from .nodes.node_patricia import xPatriciaStrategy
|
87
|
+
from .nodes.node_b_plus_tree import xBPlusTreeStrategy
|
88
|
+
from .nodes.node_persistent_tree import xPersistentTreeStrategy
|
89
|
+
from .nodes.node_cow_tree import xCOWTreeStrategy
|
90
|
+
from .nodes.node_skip_list import xSkipListStrategy
|
91
|
+
from .nodes.node_red_black_tree import xRedBlackTreeStrategy
|
92
|
+
from .nodes.node_avl_tree import xAVLTreeStrategy
|
93
|
+
from .nodes.node_treap import xTreapStrategy
|
94
|
+
from .nodes.node_splay_tree import xSplayTreeStrategy
|
95
|
+
from .nodes.node_ordered_map_balanced import xOrderedMapBalancedStrategy
|
96
|
+
from .nodes.node_bitset_dynamic import xBitsetDynamicStrategy
|
97
|
+
from .impls.edge_block_adj_matrix import xBlockAdjMatrixStrategy
|
98
|
+
|
99
|
+
# Import data interchange optimized strategy
|
100
|
+
from .nodes.node_xdata_optimized import DataInterchangeOptimizedStrategy
|
101
|
+
|
102
|
+
# Register tree-graph hybrid strategies
|
103
|
+
from .nodes.node_tree_graph_hybrid import TreeGraphHybridStrategy
|
104
|
+
self.register_node_strategy(NodeMode.TREE_GRAPH_HYBRID, TreeGraphHybridStrategy)
|
105
|
+
|
106
|
+
# Register edge strategies
|
107
|
+
self.register_edge_strategy(EdgeMode.ADJ_LIST, xAdjListStrategy)
|
108
|
+
self.register_edge_strategy(EdgeMode.ADJ_MATRIX, xAdjMatrixStrategy)
|
109
|
+
self.register_edge_strategy(EdgeMode.CSR, xCSRStrategy)
|
110
|
+
self.register_edge_strategy(EdgeMode.DYNAMIC_ADJ_LIST, xDynamicAdjListStrategy)
|
111
|
+
self.register_edge_strategy(EdgeMode.TEMPORAL_EDGESET, xTemporalEdgeSetStrategy)
|
112
|
+
self.register_edge_strategy(EdgeMode.HYPEREDGE_SET, xHyperEdgeSetStrategy)
|
113
|
+
self.register_edge_strategy(EdgeMode.R_TREE, xRTreeStrategy)
|
114
|
+
self.register_edge_strategy(EdgeMode.FLOW_NETWORK, xFlowNetworkStrategy)
|
115
|
+
self.register_edge_strategy(EdgeMode.NEURAL_GRAPH, xNeuralGraphStrategy)
|
116
|
+
self.register_edge_strategy(EdgeMode.CSC, xCSCStrategy)
|
117
|
+
self.register_edge_strategy(EdgeMode.BIDIR_WRAPPER, xBidirWrapperStrategy)
|
118
|
+
self.register_edge_strategy(EdgeMode.QUADTREE, xQuadtreeStrategy)
|
119
|
+
self.register_edge_strategy(EdgeMode.COO, xCOOStrategy)
|
120
|
+
self.register_edge_strategy(EdgeMode.OCTREE, xOctreeStrategy)
|
121
|
+
self.register_edge_strategy(EdgeMode.EDGE_PROPERTY_STORE, xEdgePropertyStoreStrategy)
|
122
|
+
self.register_edge_strategy(EdgeMode.TREE_GRAPH_BASIC, xTreeGraphBasicStrategy)
|
123
|
+
self.register_edge_strategy(EdgeMode.WEIGHTED_GRAPH, xWeightedGraphStrategy)
|
124
|
+
|
125
|
+
# Register new node strategies
|
126
|
+
self.register_node_strategy(NodeMode.HASH_MAP, xHashMapStrategy)
|
127
|
+
self.register_node_strategy(NodeMode.ARRAY_LIST, xArrayListStrategy)
|
128
|
+
self.register_node_strategy(NodeMode.TRIE, xTrieStrategy)
|
129
|
+
self.register_node_strategy(NodeMode.HEAP, xHeapStrategy)
|
130
|
+
self.register_node_strategy(NodeMode.B_TREE, xBTreeStrategy)
|
131
|
+
self.register_node_strategy(NodeMode.UNION_FIND, xUnionFindStrategy)
|
132
|
+
self.register_node_strategy(NodeMode.SEGMENT_TREE, xSegmentTreeStrategy)
|
133
|
+
self.register_node_strategy(NodeMode.LSM_TREE, xLSMTreeStrategy)
|
134
|
+
self.register_node_strategy(NodeMode.FENWICK_TREE, xFenwickTreeStrategy)
|
135
|
+
self.register_node_strategy(NodeMode.SET_HASH, xSetHashStrategy)
|
136
|
+
self.register_node_strategy(NodeMode.BLOOM_FILTER, xBloomFilterStrategy)
|
137
|
+
self.register_node_strategy(NodeMode.CUCKOO_HASH, xCuckooHashStrategy)
|
138
|
+
self.register_node_strategy(NodeMode.BITMAP, xBitmapStrategy)
|
139
|
+
self.register_node_strategy(NodeMode.ROARING_BITMAP, xRoaringBitmapStrategy)
|
140
|
+
self.register_node_strategy(NodeMode.SUFFIX_ARRAY, xSuffixArrayStrategy)
|
141
|
+
self.register_node_strategy(NodeMode.AHO_CORASICK, xAhoCorasickStrategy)
|
142
|
+
self.register_node_strategy(NodeMode.COUNT_MIN_SKETCH, xCountMinSketchStrategy)
|
143
|
+
self.register_node_strategy(NodeMode.HYPERLOGLOG, xHyperLogLogStrategy)
|
144
|
+
self.register_node_strategy(NodeMode.SET_TREE, xSetTreeStrategy)
|
145
|
+
self.register_node_strategy(NodeMode.LINKED_LIST, xLinkedListStrategy)
|
146
|
+
self.register_node_strategy(NodeMode.ORDERED_MAP, xOrderedMapStrategy)
|
147
|
+
self.register_node_strategy(NodeMode.RADIX_TRIE, xRadixTrieStrategy)
|
148
|
+
self.register_node_strategy(NodeMode.PATRICIA, xPatriciaStrategy)
|
149
|
+
self.register_node_strategy(NodeMode.B_PLUS_TREE, xBPlusTreeStrategy)
|
150
|
+
self.register_node_strategy(NodeMode.PERSISTENT_TREE, xPersistentTreeStrategy)
|
151
|
+
self.register_node_strategy(NodeMode.COW_TREE, xCOWTreeStrategy)
|
152
|
+
self.register_node_strategy(NodeMode.SKIP_LIST, xSkipListStrategy)
|
153
|
+
self.register_node_strategy(NodeMode.RED_BLACK_TREE, xRedBlackTreeStrategy)
|
154
|
+
self.register_node_strategy(NodeMode.AVL_TREE, xAVLTreeStrategy)
|
155
|
+
self.register_node_strategy(NodeMode.TREAP, xTreapStrategy)
|
156
|
+
self.register_node_strategy(NodeMode.SPLAY_TREE, xSplayTreeStrategy)
|
157
|
+
self.register_node_strategy(NodeMode.ORDERED_MAP_BALANCED, xOrderedMapBalancedStrategy)
|
158
|
+
self.register_node_strategy(NodeMode.BITSET_DYNAMIC, xBitsetDynamicStrategy)
|
159
|
+
|
160
|
+
# Edge strategies
|
161
|
+
self.register_edge_strategy(EdgeMode.BLOCK_ADJ_MATRIX, xBlockAdjMatrixStrategy)
|
162
|
+
|
163
|
+
# Register data interchange optimized strategy factory
|
164
|
+
# Note: This will be used by strategy manager when DATA_INTERCHANGE_OPTIMIZED preset is detected
|
165
|
+
self.register_data_interchange_optimized_factory()
|
166
|
+
|
167
|
+
logger.info("✅ Registered default strategies")
|
168
|
+
|
169
|
+
def _register_default_query_strategies(self):
|
170
|
+
"""Register default query strategy implementations."""
|
171
|
+
# Import query strategies
|
172
|
+
from .queries.sql import SQLStrategy
|
173
|
+
from .queries.graphql import GraphQLStrategy
|
174
|
+
from .queries.cypher import CypherStrategy
|
175
|
+
from .queries.sparql import SPARQLStrategy
|
176
|
+
from .queries.json_query import JSONQueryStrategy
|
177
|
+
from .queries.xml_query import XMLQueryStrategy
|
178
|
+
from .queries.xpath import XPathStrategy
|
179
|
+
from .queries.xquery import XQueryStrategy
|
180
|
+
from .queries.jq import JQStrategy
|
181
|
+
from .queries.jmespath import JMESPathStrategy
|
182
|
+
from .queries.jsoniq import JSONiqStrategy
|
183
|
+
from .queries.gremlin import GremlinStrategy
|
184
|
+
from .queries.elastic_dsl import ElasticDSLStrategy
|
185
|
+
from .queries.eql import EQLStrategy
|
186
|
+
from .queries.flux import FluxStrategy
|
187
|
+
from .queries.promql import PromQLStrategy
|
188
|
+
from .queries.logql import LogQLStrategy
|
189
|
+
# from .queries.spl import SPLStrategy # TODO: Implement SPL strategy
|
190
|
+
from .queries.kql import KQLStrategy
|
191
|
+
from .queries.cql import CQLStrategy
|
192
|
+
from .queries.n1ql import N1QLStrategy
|
193
|
+
from .queries.hiveql import HiveQLStrategy
|
194
|
+
from .queries.pig import PigStrategy
|
195
|
+
from .queries.mql import MQLStrategy
|
196
|
+
from .queries.partiql import PartiQLStrategy
|
197
|
+
from .queries.linq import LINQStrategy
|
198
|
+
from .queries.hql import HQLStrategy
|
199
|
+
from .queries.datalog import DatalogStrategy
|
200
|
+
# from .queries.ksql import KSQLStrategy # TODO: Implement KSQL strategy
|
201
|
+
from .queries.gql import GQLStrategy
|
202
|
+
# from .queries.trino_sql import TrinoSQLStrategy # TODO: Implement TrinoSQL strategy
|
203
|
+
# from .queries.bigquery_sql import BigQuerySQLStrategy # TODO: Implement BigQuerySQL strategy
|
204
|
+
# from .queries.snowflake_sql import SnowflakeSQLStrategy # TODO: Implement SnowflakeSQL strategy
|
205
|
+
# from .queries.lucene import LuceneStrategy # TODO: Implement Lucene strategy
|
206
|
+
|
207
|
+
# Register query strategies
|
208
|
+
self.register_query_strategy("SQL", SQLStrategy)
|
209
|
+
self.register_query_strategy("GRAPHQL", GraphQLStrategy)
|
210
|
+
self.register_query_strategy("CYPHER", CypherStrategy)
|
211
|
+
self.register_query_strategy("SPARQL", SPARQLStrategy)
|
212
|
+
self.register_query_strategy("JSON_QUERY", JSONQueryStrategy)
|
213
|
+
self.register_query_strategy("XML_QUERY", XMLQueryStrategy)
|
214
|
+
self.register_query_strategy("XPATH", XPathStrategy)
|
215
|
+
self.register_query_strategy("XQUERY", XQueryStrategy)
|
216
|
+
self.register_query_strategy("JQ", JQStrategy)
|
217
|
+
self.register_query_strategy("JMESPATH", JMESPathStrategy)
|
218
|
+
self.register_query_strategy("JSONIQ", JSONiqStrategy)
|
219
|
+
self.register_query_strategy("GREMLIN", GremlinStrategy)
|
220
|
+
self.register_query_strategy("ELASTIC_DSL", ElasticDSLStrategy)
|
221
|
+
self.register_query_strategy("EQL", EQLStrategy)
|
222
|
+
self.register_query_strategy("FLUX", FluxStrategy)
|
223
|
+
self.register_query_strategy("PROMQL", PromQLStrategy)
|
224
|
+
self.register_query_strategy("LOGQL", LogQLStrategy)
|
225
|
+
# self.register_query_strategy("SPL", SPLStrategy) # TODO: Implement SPL strategy
|
226
|
+
self.register_query_strategy("KQL", KQLStrategy)
|
227
|
+
self.register_query_strategy("CQL", CQLStrategy)
|
228
|
+
self.register_query_strategy("N1QL", N1QLStrategy)
|
229
|
+
self.register_query_strategy("HIVEQL", HiveQLStrategy)
|
230
|
+
self.register_query_strategy("PIG", PigStrategy)
|
231
|
+
self.register_query_strategy("MQL", MQLStrategy)
|
232
|
+
self.register_query_strategy("PARTIQL", PartiQLStrategy)
|
233
|
+
self.register_query_strategy("LINQ", LINQStrategy)
|
234
|
+
self.register_query_strategy("HQL", HQLStrategy)
|
235
|
+
self.register_query_strategy("DATALOG", DatalogStrategy)
|
236
|
+
# self.register_query_strategy("KSQL", KSQLStrategy) # TODO: Implement KSQL strategy
|
237
|
+
self.register_query_strategy("GQL", GQLStrategy)
|
238
|
+
# self.register_query_strategy("TRINO_SQL", TrinoSQLStrategy) # TODO: Implement TrinoSQL strategy
|
239
|
+
# self.register_query_strategy("BIGQUERY_SQL", BigQuerySQLStrategy) # TODO: Implement BigQuerySQL strategy
|
240
|
+
# self.register_query_strategy("SNOWFLAKE_SQL", SnowflakeSQLStrategy) # TODO: Implement SnowflakeSQL strategy
|
241
|
+
# self.register_query_strategy("LUCENE", LuceneStrategy) # TODO: Implement Lucene strategy
|
242
|
+
|
243
|
+
logger.info("✅ Registered default query strategies")
|
244
|
+
|
245
|
+
except ImportError as e:
|
246
|
+
logger.warning(f"⚠️ Could not register default query strategies: {e}")
|
247
|
+
|
248
|
+
def register_data_interchange_optimized_factory(self):
|
249
|
+
"""Register special factory for DATA_INTERCHANGE_OPTIMIZED preset handling."""
|
250
|
+
# We'll store this in a special attribute for the strategy manager to use
|
251
|
+
def data_interchange_factory(**options):
|
252
|
+
from .nodes.node_xdata_optimized import DataInterchangeOptimizedStrategy
|
253
|
+
return DataInterchangeOptimizedStrategy(NodeTrait.INDEXED, **options)
|
254
|
+
|
255
|
+
self._data_interchange_optimized_factory = data_interchange_factory
|
256
|
+
logger.debug("📝 Registered data interchange optimized strategy factory")
|
257
|
+
|
258
|
+
def get_data_interchange_optimized_factory(self):
|
259
|
+
"""Get the data interchange optimized strategy factory."""
|
260
|
+
return getattr(self, '_data_interchange_optimized_factory', None)
|
261
|
+
|
262
|
+
def register_node_strategy(self, mode: NodeMode, strategy_class: Type,
|
263
|
+
factory: Optional[Callable] = None) -> None:
|
264
|
+
"""
|
265
|
+
Register a node strategy implementation.
|
266
|
+
|
267
|
+
Args:
|
268
|
+
mode: The node mode to register
|
269
|
+
strategy_class: The strategy implementation class
|
270
|
+
factory: Optional factory function for custom instantiation
|
271
|
+
"""
|
272
|
+
with self._lock:
|
273
|
+
self._node_strategies[mode] = strategy_class
|
274
|
+
if factory:
|
275
|
+
self._node_factories[mode] = factory
|
276
|
+
|
277
|
+
logger.debug(f"📝 Registered node strategy: {mode.name} -> {strategy_class.__name__}")
|
278
|
+
|
279
|
+
def register_edge_strategy(self, mode: EdgeMode, strategy_class: Type,
|
280
|
+
factory: Optional[Callable] = None) -> None:
|
281
|
+
"""
|
282
|
+
Register an edge strategy implementation.
|
283
|
+
|
284
|
+
Args:
|
285
|
+
mode: The edge mode to register
|
286
|
+
strategy_class: The strategy implementation class
|
287
|
+
factory: Optional factory function for custom instantiation
|
288
|
+
"""
|
289
|
+
with self._lock:
|
290
|
+
self._edge_strategies[mode] = strategy_class
|
291
|
+
if factory:
|
292
|
+
self._edge_factories[mode] = factory
|
293
|
+
|
294
|
+
logger.debug(f"📝 Registered edge strategy: {mode.name} -> {strategy_class.__name__}")
|
295
|
+
|
296
|
+
def register_query_strategy(self, query_type: str, strategy_class: Type,
|
297
|
+
factory: Optional[Callable] = None) -> None:
|
298
|
+
"""
|
299
|
+
Register a query strategy implementation.
|
300
|
+
|
301
|
+
Args:
|
302
|
+
query_type: The query type to register (e.g., "SQL", "GRAPHQL")
|
303
|
+
strategy_class: The strategy implementation class
|
304
|
+
factory: Optional factory function for custom instantiation
|
305
|
+
"""
|
306
|
+
with self._lock:
|
307
|
+
self._query_strategies[query_type.upper()] = strategy_class
|
308
|
+
if factory:
|
309
|
+
self._query_factories[query_type.upper()] = factory
|
310
|
+
|
311
|
+
logger.debug(f"📝 Registered query strategy: {query_type.upper()} -> {strategy_class.__name__}")
|
312
|
+
|
313
|
+
def get_node_strategy(self, mode: NodeMode, **kwargs) -> Any:
|
314
|
+
"""
|
315
|
+
Get a node strategy instance.
|
316
|
+
|
317
|
+
Args:
|
318
|
+
mode: The node mode to instantiate
|
319
|
+
**kwargs: Arguments to pass to the strategy constructor
|
320
|
+
|
321
|
+
Returns:
|
322
|
+
Strategy instance
|
323
|
+
|
324
|
+
Raises:
|
325
|
+
StrategyNotFoundError: If the strategy is not registered
|
326
|
+
StrategyInitializationError: If strategy initialization fails
|
327
|
+
"""
|
328
|
+
with self._lock:
|
329
|
+
if mode not in self._node_strategies:
|
330
|
+
raise XWNodeStrategyError(message=f"Strategy '{mode.name}' not found for node")
|
331
|
+
|
332
|
+
strategy_class = self._node_strategies[mode]
|
333
|
+
|
334
|
+
try:
|
335
|
+
if mode in self._node_factories:
|
336
|
+
return self._node_factories[mode](**kwargs)
|
337
|
+
else:
|
338
|
+
# Handle new interface that doesn't accept traits and other arguments
|
339
|
+
if mode == NodeMode.TREE_GRAPH_HYBRID:
|
340
|
+
# For TreeGraphHybridStrategy, ignore traits and other arguments
|
341
|
+
return strategy_class()
|
342
|
+
else:
|
343
|
+
return strategy_class(**kwargs)
|
344
|
+
|
345
|
+
except Exception as e:
|
346
|
+
raise XWNodeError(message=f"Failed to initialize strategy '{mode.name}': {e}", cause=e)
|
347
|
+
|
348
|
+
def get_node_strategy_class(self, mode: NodeMode) -> Type:
|
349
|
+
"""
|
350
|
+
Get the strategy class for the specified mode.
|
351
|
+
|
352
|
+
Args:
|
353
|
+
mode: Node mode
|
354
|
+
|
355
|
+
Returns:
|
356
|
+
Strategy class
|
357
|
+
|
358
|
+
Raises:
|
359
|
+
XWNodeStrategyError: If strategy not found
|
360
|
+
"""
|
361
|
+
with self._lock:
|
362
|
+
if mode not in self._node_strategies:
|
363
|
+
raise XWNodeStrategyError(message=f"Strategy '{mode.name}' not found for node")
|
364
|
+
|
365
|
+
return self._node_strategies[mode]
|
366
|
+
|
367
|
+
def get_edge_strategy(self, mode: EdgeMode, **kwargs) -> Any:
|
368
|
+
"""
|
369
|
+
Get an edge strategy instance.
|
370
|
+
|
371
|
+
Args:
|
372
|
+
mode: The edge mode to instantiate
|
373
|
+
**kwargs: Arguments to pass to the strategy constructor
|
374
|
+
|
375
|
+
Returns:
|
376
|
+
Strategy instance
|
377
|
+
|
378
|
+
Raises:
|
379
|
+
StrategyNotFoundError: If the strategy is not registered
|
380
|
+
StrategyInitializationError: If strategy initialization fails
|
381
|
+
"""
|
382
|
+
with self._lock:
|
383
|
+
if mode not in self._edge_strategies:
|
384
|
+
raise XWNodeStrategyError(message=f"Strategy '{mode.name}' not found for edge")
|
385
|
+
|
386
|
+
strategy_class = self._edge_strategies[mode]
|
387
|
+
|
388
|
+
try:
|
389
|
+
if mode in self._edge_factories:
|
390
|
+
return self._edge_factories[mode](**kwargs)
|
391
|
+
else:
|
392
|
+
return strategy_class(**kwargs)
|
393
|
+
|
394
|
+
except Exception as e:
|
395
|
+
raise XWNodeError(message=f"Failed to initialize strategy '{mode.name}': {e}", cause=e)
|
396
|
+
|
397
|
+
def get_query_strategy(self, query_type: str, **kwargs) -> Any:
|
398
|
+
"""
|
399
|
+
Get a query strategy instance.
|
400
|
+
|
401
|
+
Args:
|
402
|
+
query_type: The query type to instantiate (e.g., "SQL", "GRAPHQL")
|
403
|
+
**kwargs: Arguments to pass to the strategy constructor
|
404
|
+
|
405
|
+
Returns:
|
406
|
+
Strategy instance
|
407
|
+
|
408
|
+
Raises:
|
409
|
+
XWNodeStrategyError: If the strategy is not registered
|
410
|
+
XWNodeError: If strategy initialization fails
|
411
|
+
"""
|
412
|
+
with self._lock:
|
413
|
+
query_type_upper = query_type.upper()
|
414
|
+
if query_type_upper not in self._query_strategies:
|
415
|
+
raise XWNodeStrategyError(message=f"Query strategy '{query_type}' not found")
|
416
|
+
|
417
|
+
strategy_class = self._query_strategies[query_type_upper]
|
418
|
+
|
419
|
+
try:
|
420
|
+
if query_type_upper in self._query_factories:
|
421
|
+
return self._query_factories[query_type_upper](**kwargs)
|
422
|
+
else:
|
423
|
+
return strategy_class(**kwargs)
|
424
|
+
|
425
|
+
except Exception as e:
|
426
|
+
raise XWNodeError(message=f"Failed to initialize query strategy '{query_type}': {e}", cause=e)
|
427
|
+
|
428
|
+
def get_query_strategy_class(self, query_type: str) -> Type:
|
429
|
+
"""
|
430
|
+
Get the query strategy class for the specified type.
|
431
|
+
|
432
|
+
Args:
|
433
|
+
query_type: Query type
|
434
|
+
|
435
|
+
Returns:
|
436
|
+
Strategy class
|
437
|
+
|
438
|
+
Raises:
|
439
|
+
XWNodeStrategyError: If strategy not found
|
440
|
+
"""
|
441
|
+
with self._lock:
|
442
|
+
query_type_upper = query_type.upper()
|
443
|
+
if query_type_upper not in self._query_strategies:
|
444
|
+
raise XWNodeStrategyError(message=f"Query strategy '{query_type}' not found")
|
445
|
+
|
446
|
+
return self._query_strategies[query_type_upper]
|
447
|
+
|
448
|
+
def list_node_modes(self) -> List[NodeMode]:
|
449
|
+
"""List all registered node modes."""
|
450
|
+
with self._lock:
|
451
|
+
return list(self._node_strategies.keys())
|
452
|
+
|
453
|
+
def list_edge_modes(self) -> List[EdgeMode]:
|
454
|
+
"""List all registered edge modes."""
|
455
|
+
with self._lock:
|
456
|
+
return list(self._edge_strategies.keys())
|
457
|
+
|
458
|
+
def list_query_types(self) -> List[str]:
|
459
|
+
"""List all registered query types."""
|
460
|
+
with self._lock:
|
461
|
+
return list(self._query_strategies.keys())
|
462
|
+
|
463
|
+
def get_node_metadata(self, mode: NodeMode) -> Optional[Any]:
|
464
|
+
"""Get metadata for a node mode."""
|
465
|
+
return NODE_STRATEGY_METADATA.get(mode)
|
466
|
+
|
467
|
+
def get_edge_metadata(self, mode: EdgeMode) -> Optional[Any]:
|
468
|
+
"""Get metadata for an edge mode."""
|
469
|
+
return EDGE_STRATEGY_METADATA.get(mode)
|
470
|
+
|
471
|
+
def has_node_strategy(self, mode: NodeMode) -> bool:
|
472
|
+
"""Check if a node strategy is registered."""
|
473
|
+
with self._lock:
|
474
|
+
return mode in self._node_strategies
|
475
|
+
|
476
|
+
def has_edge_strategy(self, mode: EdgeMode) -> bool:
|
477
|
+
"""Check if an edge strategy is registered."""
|
478
|
+
with self._lock:
|
479
|
+
return mode in self._edge_strategies
|
480
|
+
|
481
|
+
def has_query_strategy(self, query_type: str) -> bool:
|
482
|
+
"""Check if a query strategy is registered."""
|
483
|
+
with self._lock:
|
484
|
+
return query_type.upper() in self._query_strategies
|
485
|
+
|
486
|
+
def unregister_node_strategy(self, mode: NodeMode) -> bool:
|
487
|
+
"""
|
488
|
+
Unregister a node strategy.
|
489
|
+
|
490
|
+
Returns:
|
491
|
+
True if strategy was unregistered, False if not found
|
492
|
+
"""
|
493
|
+
with self._lock:
|
494
|
+
if mode in self._node_strategies:
|
495
|
+
del self._node_strategies[mode]
|
496
|
+
if mode in self._node_factories:
|
497
|
+
del self._node_factories[mode]
|
498
|
+
logger.debug(f"🗑️ Unregistered node strategy: {mode.name}")
|
499
|
+
return True
|
500
|
+
return False
|
501
|
+
|
502
|
+
def unregister_edge_strategy(self, mode: EdgeMode) -> bool:
|
503
|
+
"""
|
504
|
+
Unregister an edge strategy.
|
505
|
+
|
506
|
+
Returns:
|
507
|
+
True if strategy was unregistered, False if not found
|
508
|
+
"""
|
509
|
+
with self._lock:
|
510
|
+
if mode in self._edge_strategies:
|
511
|
+
del self._edge_strategies[mode]
|
512
|
+
if mode in self._edge_factories:
|
513
|
+
del self._edge_factories[mode]
|
514
|
+
logger.debug(f"🗑️ Unregistered edge strategy: {mode.name}")
|
515
|
+
return True
|
516
|
+
return False
|
517
|
+
|
518
|
+
def unregister_query_strategy(self, query_type: str) -> bool:
|
519
|
+
"""
|
520
|
+
Unregister a query strategy.
|
521
|
+
|
522
|
+
Returns:
|
523
|
+
True if strategy was unregistered, False if not found
|
524
|
+
"""
|
525
|
+
with self._lock:
|
526
|
+
query_type_upper = query_type.upper()
|
527
|
+
if query_type_upper in self._query_strategies:
|
528
|
+
del self._query_strategies[query_type_upper]
|
529
|
+
if query_type_upper in self._query_factories:
|
530
|
+
del self._query_factories[query_type_upper]
|
531
|
+
logger.debug(f"🗑️ Unregistered query strategy: {query_type_upper}")
|
532
|
+
return True
|
533
|
+
return False
|
534
|
+
|
535
|
+
def clear_node_strategies(self) -> None:
|
536
|
+
"""Clear all registered node strategies."""
|
537
|
+
with self._lock:
|
538
|
+
self._node_strategies.clear()
|
539
|
+
self._node_factories.clear()
|
540
|
+
logger.info("🗑️ Cleared all node strategies")
|
541
|
+
|
542
|
+
def clear_edge_strategies(self) -> None:
|
543
|
+
"""Clear all registered edge strategies."""
|
544
|
+
with self._lock:
|
545
|
+
self._edge_strategies.clear()
|
546
|
+
self._edge_factories.clear()
|
547
|
+
logger.info("🗑️ Cleared all edge strategies")
|
548
|
+
|
549
|
+
def clear_query_strategies(self) -> None:
|
550
|
+
"""Clear all registered query strategies."""
|
551
|
+
with self._lock:
|
552
|
+
self._query_strategies.clear()
|
553
|
+
self._query_factories.clear()
|
554
|
+
logger.info("🗑️ Cleared all query strategies")
|
555
|
+
|
556
|
+
def get_registry_stats(self) -> Dict[str, Any]:
|
557
|
+
"""Get registry statistics."""
|
558
|
+
with self._lock:
|
559
|
+
return {
|
560
|
+
"node_strategies": len(self._node_strategies),
|
561
|
+
"edge_strategies": len(self._edge_strategies),
|
562
|
+
"query_strategies": len(self._query_strategies),
|
563
|
+
"node_factories": len(self._node_factories),
|
564
|
+
"edge_factories": len(self._edge_factories),
|
565
|
+
"query_factories": len(self._query_factories),
|
566
|
+
"registered_node_modes": [mode.name for mode in self._node_strategies.keys()],
|
567
|
+
"registered_edge_modes": [mode.name for mode in self._edge_strategies.keys()],
|
568
|
+
"registered_query_types": list(self._query_strategies.keys())
|
569
|
+
}
|
570
|
+
|
571
|
+
|
572
|
+
# Global registry instance
|
573
|
+
_registry = None
|
574
|
+
|
575
|
+
|
576
|
+
def get_registry() -> StrategyRegistry:
|
577
|
+
"""Get the global strategy registry instance."""
|
578
|
+
global _registry
|
579
|
+
if _registry is None:
|
580
|
+
_registry = StrategyRegistry()
|
581
|
+
return _registry
|
582
|
+
|
583
|
+
|
584
|
+
def register_node_strategy(mode: NodeMode, strategy_class: Type,
|
585
|
+
factory: Optional[Callable] = None) -> None:
|
586
|
+
"""Register a node strategy with the global registry."""
|
587
|
+
get_registry().register_node_strategy(mode, strategy_class, factory)
|
588
|
+
|
589
|
+
|
590
|
+
def register_edge_strategy(mode: EdgeMode, strategy_class: Type,
|
591
|
+
factory: Optional[Callable] = None) -> None:
|
592
|
+
"""Register an edge strategy with the global registry."""
|
593
|
+
get_registry().register_edge_strategy(mode, strategy_class, factory)
|
594
|
+
|
595
|
+
|
596
|
+
def register_query_strategy(query_type: str, strategy_class: Type,
|
597
|
+
factory: Optional[Callable] = None) -> None:
|
598
|
+
"""Register a query strategy with the global registry."""
|
599
|
+
get_registry().register_query_strategy(query_type, strategy_class, factory)
|
600
|
+
|
601
|
+
|
602
|
+
def get_strategy_registry() -> StrategyRegistry:
|
603
|
+
"""Get the global strategy registry instance (alias for get_registry)."""
|
604
|
+
return get_registry()
|