-
Notifications
You must be signed in to change notification settings - Fork 86
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2058 from kuzudb/range
range() function
- Loading branch information
Showing
11 changed files
with
284 additions
and
24 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
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,45 @@ | ||
#pragma once | ||
|
||
#include "common/types/ku_list.h" | ||
|
||
namespace kuzu { | ||
namespace function { | ||
|
||
struct Range { | ||
public: | ||
// range function: | ||
// - include end | ||
// - when start = end: there is only one element in result varlist | ||
// - when end - start are of opposite sign of step, the result will be empty | ||
// - default step = 1 | ||
template<typename T> | ||
static inline void operation(T& start, T& end, common::list_entry_t& result, | ||
common::ValueVector& leftVector, common::ValueVector& rightVector, | ||
common::ValueVector& resultVector) { | ||
T step = 1; | ||
operation(start, end, step, result, leftVector, resultVector); | ||
} | ||
|
||
template<typename T> | ||
static inline void operation(T& start, T& end, T& step, common::list_entry_t& result, | ||
common::ValueVector& inputVector, common::ValueVector& resultVector) { | ||
if (step == 0) { | ||
throw common::RuntimeException("Step of range cannot be 0."); | ||
} | ||
|
||
// start, start + step, start + 2step, ..., end | ||
T number = start; | ||
auto size = (end - start) * 1.0 / step; | ||
size < 0 ? size = 0 : size = (int64_t)(size + 1); | ||
|
||
result = common::ListVector::addList(&resultVector, size); | ||
auto resultDataVector = common::ListVector::getDataVector(&resultVector); | ||
for (auto i = 0u; i < size; i++) { | ||
resultDataVector->setValue(result.offset + i, number); | ||
number += step; | ||
} | ||
} | ||
}; | ||
|
||
} // namespace function | ||
} // namespace kuzu |
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.