Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

#1277 #1278

Merged
merged 2 commits into from
Nov 20, 2023
Merged

#1277 #1278

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .github/workflows/regression_suite.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,9 @@ jobs:
regression_matrix:
strategy:
max-parallel: 4
fail-fast: false
matrix:
python-version: ['3.9', '3.10', '3.11']
python-version: ['3.9', '3.10', '3.11', '3.12']
os: [ubuntu-latest]
runs-on: ${{ matrix.os }}
steps:
Expand Down
3 changes: 2 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
lint:
python -m pip install --quiet --upgrade pycln isort black
python -m pip install --quiet --upgrade pycln isort black yamllint
# python -m yamllint .
python -m pycln .
python -m isort .
python -m black .
Expand Down
2 changes: 2 additions & 0 deletions opteryx/components/heuristic_optimizer.py
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,8 @@ def visit(self, parent: str, nid: str, context: HeuristicOptimizerContext):
nodes = heuristic_optimizer.rule_split_conjunctive_predicates(node)
# deduplicate the nodes - note this 'randomizes' the order
nodes = _unique_nodes(nodes)
# order the predicates
nodes = heuristic_optimizer.rule_order_predicates(nodes)

previous = parent
for predicate_node in nodes:
Expand Down
1 change: 1 addition & 0 deletions opteryx/components/rules/heuristic_optimizer/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
from .order_predicates import rule_order_predicates
from .split_conjuctive_predicates import rule_split_conjunctive_predicates
63 changes: 63 additions & 0 deletions opteryx/components/rules/heuristic_optimizer/order_predicates.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

"""
Optimization Rule - Order Predicates

Type: Heuristic
Goal: Reduce rows
"""

from opteryx.managers.expression import NodeType

NODE_ORDER = {
"Eq": 1,
"NotEq": 1,
"Gt": 2,
"GtEq": 2,
"Lt": 2,
"LtEq": 2,
"Like": 4,
"ILike": 4,
"NotLike": 4,
"NotILike": 4,
}


def rule_order_predicates(nodes):
"""
Ordering of predicates based on rules, this is mostly useful for situations where
we do not have statistics to make cost-based decisions.

We're going to start with arbitrary numbers, we need to find a way to refine these
over time.
"""

for node in nodes:
if not node.node_type == NodeType.COMPARISON_OPERATOR:
node.score = 25
continue
node.score = NODE_ORDER.get(node.value, 12)
if node.left.node_type == NodeType.LITERAL:
node.score += 1
elif node.left.node_type == NodeType.IDENTIFIER:
node.score += 3
else:
node.score += 10
if node.right.node_type == NodeType.LITERAL:
node.score += 1
elif node.right.node_type == NodeType.IDENTIFIER:
node.score += 3
else:
node.score += 10

return sorted(nodes, key=lambda node: node.score)
Loading