-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
13 changed files
with
212 additions
and
136 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
# cython: language_level=3 | ||
# cython: nonecheck=False | ||
# cython: cdivision=True | ||
# cython: initializedcheck=False | ||
# cython: infer_types=True | ||
# cython: wraparound=False | ||
# cython: boundscheck=False | ||
|
||
from libc.stdint cimport int64_t | ||
|
||
import numpy | ||
cimport numpy | ||
|
||
cdef class IntBuffer: | ||
|
||
cdef public int64_t[::1] _buffer | ||
cdef public int64_t size | ||
cdef public int64_t capacity | ||
|
||
cpdef void append(self, int64_t value) | ||
cpdef void extend(self, iterable) | ||
cpdef numpy.ndarray[int64_t, ndim=1] to_numpy(self) | ||
cpdef buffer(self) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# See the License at http://www.apache.org/licenses/LICENSE-2.0 | ||
# Distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND. | ||
|
||
""" | ||
Inner (Nested Loop) Join Node | ||
This is a SQL Query Execution Plan Node. | ||
This is an implementation of a nested loop join, which is a simple join algorithm, it excels | ||
when one of the relations is very small - in this situation it's many times faster than a hash | ||
join as we don't need to create the hash table. | ||
The Join Order Optimization Strategy will decide if this node should be used, based on the size. | ||
""" | ||
|
||
from threading import Lock | ||
|
||
import numpy | ||
import pyarrow | ||
from pyarrow import Table | ||
|
||
from opteryx import EOS | ||
from opteryx.compiled.joins.inner_join import nested_loop_join | ||
from opteryx.models import QueryProperties | ||
from opteryx.utils.arrow import align_tables | ||
|
||
from . import JoinNode | ||
|
||
|
||
class NestedLoopJoinNode(JoinNode): | ||
join_type = "nested_loop" | ||
|
||
def __init__(self, properties: QueryProperties, **parameters): | ||
JoinNode.__init__(self, properties=properties, **parameters) | ||
|
||
self.left_columns = numpy.array(parameters.get("left_columns"), dtype=numpy.bytes_) | ||
self.right_columns = numpy.array(parameters.get("right_columns"), dtype=numpy.bytes_) | ||
|
||
self.left_relation = None | ||
self.left_buffer = [] | ||
self.lock = Lock() | ||
|
||
@property | ||
def name(self): # pragma: no cover | ||
return "Nested Loop Join" | ||
|
||
@property | ||
def config(self): # pragma: no cover | ||
return "" | ||
|
||
def execute(self, morsel: Table, join_leg: str) -> Table: | ||
with self.lock: | ||
if join_leg == "left": | ||
if morsel == EOS: | ||
self.left_relation = pyarrow.concat_tables( | ||
self.left_buffer, promote_options="none" | ||
) | ||
self.left_buffer.clear() | ||
else: | ||
self.left_buffer.append(morsel) | ||
yield None | ||
return | ||
|
||
if join_leg == "right": | ||
if morsel == EOS: | ||
yield EOS | ||
return | ||
|
||
left_indexes, right_indexes = nested_loop_join( | ||
self.left_relation, morsel, self.left_columns, self.right_columns | ||
) | ||
yield align_tables(self.left_relation, morsel, left_indexes, right_indexes) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.