-
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 #1731 from kuzudb/table-func
Implement table function framework
- Loading branch information
Showing
51 changed files
with
5,602 additions
and
2,372 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
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,24 @@ | ||
#include "function/built_in_table_operations.h" | ||
|
||
#include "common/expression_type.h" | ||
#include "common/string_utils.h" | ||
|
||
namespace kuzu { | ||
namespace function { | ||
|
||
void BuiltInTableOperations::registerTableOperations() { | ||
tableOperations.insert({common::TABLE_INFO_FUNC_NAME, TableInfoOperation::getDefinitions()}); | ||
} | ||
|
||
TableOperationDefinition* BuiltInTableOperations::mathTableOperation(const std::string& name) { | ||
auto upperName = name; | ||
common::StringUtils::toUpper(upperName); | ||
if (!tableOperations.contains(upperName)) { | ||
throw common::BinderException{ | ||
"Cannot match a built-in function for given function " + name + "."}; | ||
} | ||
return tableOperations.at(upperName).get(); | ||
} | ||
|
||
} // 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
#include "function/table_operations.h" | ||
|
||
#include "catalog/catalog.h" | ||
|
||
namespace kuzu { | ||
namespace function { | ||
|
||
std::unique_ptr<TableInfoBindData> TableInfoOperation::bindFunc( | ||
kuzu::function::TableFuncBindInput input, catalog::CatalogContent* catalog) { | ||
std::vector<std::string> returnColumnNames; | ||
std::vector<common::LogicalType> returnTypes; | ||
auto tableName = input.inputs[0].getValue<std::string>(); | ||
auto tableID = catalog->getTableID(tableName); | ||
auto schema = catalog->getTableSchema(tableID); | ||
returnColumnNames.emplace_back("property id"); | ||
returnTypes.emplace_back(common::LogicalTypeID::INT64); | ||
returnColumnNames.emplace_back("name"); | ||
returnTypes.emplace_back(common::LogicalTypeID::STRING); | ||
returnColumnNames.emplace_back("type"); | ||
returnTypes.emplace_back(common::LogicalTypeID::STRING); | ||
if (schema->isNodeTable) { | ||
returnColumnNames.emplace_back("primary key"); | ||
returnTypes.emplace_back(common::LogicalTypeID::BOOL); | ||
} | ||
return std::make_unique<TableInfoBindData>( | ||
schema, std::move(returnTypes), std::move(returnColumnNames), schema->getNumProperties()); | ||
} | ||
|
||
void TableInfoOperation::tableFunc(std::pair<common::offset_t, common::offset_t> morsel, | ||
function::TableFuncBindData* bindData, std::vector<common::ValueVector*> outputVectors) { | ||
auto tableSchema = reinterpret_cast<function::TableInfoBindData*>(bindData)->tableSchema; | ||
auto numPropertiesToOutput = morsel.second - morsel.first; | ||
auto outVectorPos = 0; | ||
for (auto i = 0u; i < numPropertiesToOutput; i++) { | ||
auto property = tableSchema->properties[morsel.first + i]; | ||
if (!tableSchema->isNodeTable && property.name == common::InternalKeyword::ID) { | ||
continue; | ||
} | ||
outputVectors[0]->setValue(outVectorPos, (int64_t)property.propertyID); | ||
outputVectors[1]->setValue(outVectorPos, property.name); | ||
outputVectors[2]->setValue( | ||
outVectorPos, common::LogicalTypeUtils::dataTypeToString(property.dataType)); | ||
if (tableSchema->isNodeTable && | ||
reinterpret_cast<catalog::NodeTableSchema*>(tableSchema)->primaryKeyPropertyID == | ||
property.propertyID) { | ||
outputVectors[3]->setValue(outVectorPos, true /* isPrimaryKey */); | ||
} | ||
outVectorPos++; | ||
} | ||
for (auto& outputVector : outputVectors) { | ||
outputVector->state->selVector->selectedSize = outVectorPos; | ||
} | ||
} | ||
|
||
} // 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
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,27 @@ | ||
#pragma once | ||
|
||
#include "binder/expression/expression.h" | ||
#include "function/table_operations.h" | ||
|
||
namespace kuzu { | ||
namespace binder { | ||
|
||
class BoundCallTableFunc : public BoundStatement { | ||
public: | ||
BoundCallTableFunc(function::table_func_t tableFunc, | ||
std::unique_ptr<function::TableFuncBindData> bindData, | ||
std::unique_ptr<BoundStatementResult> statementResult) | ||
: BoundStatement{common::StatementType::CALL_TABLE_FUNC, std::move(statementResult)}, | ||
tableFunc{std::move(tableFunc)}, bindData{std::move(bindData)} {} | ||
|
||
inline function::table_func_t getTableFunc() const { return tableFunc; } | ||
|
||
inline function::TableFuncBindData* getBindData() const { return bindData.get(); } | ||
|
||
private: | ||
function::table_func_t tableFunc; | ||
std::unique_ptr<function::TableFuncBindData> bindData; | ||
}; | ||
|
||
} // namespace binder | ||
} // 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
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,24 @@ | ||
#pragma once | ||
|
||
#include "table_operations.h" | ||
|
||
namespace kuzu { | ||
namespace function { | ||
|
||
class BuiltInTableOperations { | ||
|
||
public: | ||
BuiltInTableOperations() { registerTableOperations(); } | ||
|
||
TableOperationDefinition* mathTableOperation(const std::string& name); | ||
|
||
private: | ||
void registerTableOperations(); | ||
|
||
private: | ||
// TODO(Ziyi): Refactor vectorOperation/tableOperation to inherit from the same base class. | ||
std::unordered_map<std::string, std::unique_ptr<TableOperationDefinition>> tableOperations; | ||
}; | ||
|
||
} // 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
Oops, something went wrong.