Skip to content

Commit

Permalink
Run clang-format
Browse files Browse the repository at this point in the history
  • Loading branch information
andyfengHKU committed Jan 17, 2025
1 parent f381df2 commit 55b864a
Show file tree
Hide file tree
Showing 16 changed files with 60 additions and 36 deletions.
3 changes: 2 additions & 1 deletion src/binder/bind/bind_standalone_call_function.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ std::unique_ptr<BoundStatement> Binder::bindStandaloneCallFunction(
auto& funcExpr =
callStatement.getFunctionExpression()->constCast<parser::ParsedFunctionExpression>();
auto funcName = funcExpr.getFunctionName();
auto entry = clientContext->getCatalog()->getFunctionEntry(clientContext->getTransaction(), funcName);
auto entry =
clientContext->getCatalog()->getFunctionEntry(clientContext->getTransaction(), funcName);
if (entry->getType() != catalog::CatalogEntryType::STANDALONE_TABLE_FUNCTION_ENTRY) {
throw common::BinderException(
"Only standalone table functions can be called without return statement.");
Expand Down
6 changes: 4 additions & 2 deletions src/binder/bind/bind_table_function.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ static void validateParameterType(const expression_vector& positionalParams) {

BoundTableFunction Binder::bindTableFunc(std::string tableFuncName,
const parser::ParsedExpression& expr, expression_vector& columns) {
auto entry = clientContext->getCatalog()->getFunctionEntry(clientContext->getTransaction(), tableFuncName);
auto entry = clientContext->getCatalog()->getFunctionEntry(clientContext->getTransaction(),
tableFuncName);
expression_vector positionalParams;
std::vector<LogicalType> positionalParamTypes;
optional_params_t optionalParams;
Expand All @@ -36,7 +37,8 @@ BoundTableFunction Binder::bindTableFunc(std::string tableFuncName,
optionalParams.emplace(childExpr.getAlias(), literalExpr->getValue());
}
}
auto func = BuiltInFunctionsUtils::matchFunction(tableFuncName, positionalParamTypes, entry->ptrCast<catalog::FunctionCatalogEntry>());
auto func = BuiltInFunctionsUtils::matchFunction(tableFuncName, positionalParamTypes,
entry->ptrCast<catalog::FunctionCatalogEntry>());
validateParameterType(positionalParams);
auto tableFunc = func->constPtrCast<TableFunction>();
for (auto i = 0u; i < positionalParams.size(); ++i) {
Expand Down
6 changes: 4 additions & 2 deletions src/binder/bind/copy/bind_copy_to.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,10 @@ std::unique_ptr<BoundStatement> Binder::bindCopyToClause(const Statement& statem
auto columns = query->getStatementResult()->getColumns();
auto fileTypeStr = fileTypeInfo.fileTypeStr;
auto name = common::stringFormat("COPY_{}", fileTypeStr);
auto entry = clientContext->getCatalog()->getFunctionEntry(clientContext->getTransaction(), name);
auto exportFunc = function::BuiltInFunctionsUtils::matchFunction(name, entry->ptrCast<catalog::FunctionCatalogEntry>())
auto entry =
clientContext->getCatalog()->getFunctionEntry(clientContext->getTransaction(), name);
auto exportFunc = function::BuiltInFunctionsUtils::matchFunction(name,
entry->ptrCast<catalog::FunctionCatalogEntry>())
->constPtrCast<function::ExportFunction>();
for (auto& column : columns) {
auto columnName = column->hasAlias() ? column->getAlias() : column->toString();
Expand Down
6 changes: 4 additions & 2 deletions src/binder/bind/read/bind_in_query_call.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@ std::unique_ptr<BoundReadingClause> Binder::bindInQueryCall(const ReadingClause&
auto functionName = functionExpr->getFunctionName();
std::unique_ptr<BoundReadingClause> boundReadingClause;
expression_vector columns;
auto entry = clientContext->getCatalog()->getFunctionEntry(clientContext->getTransaction(), functionName);
auto entry = clientContext->getCatalog()->getFunctionEntry(clientContext->getTransaction(),
functionName);
switch (entry->getType()) {
case CatalogEntryType::TABLE_FUNCTION_ENTRY: {
auto boundTableFunction = bindTableFunc(functionName, *functionExpr, columns);
Expand All @@ -49,7 +50,8 @@ std::unique_ptr<BoundReadingClause> Binder::bindInQueryCall(const ReadingClause&
literalExpr->getValue());
}
}
auto func = BuiltInFunctionsUtils::matchFunction(functionName, childrenTypes, entry->ptrCast<FunctionCatalogEntry>());
auto func = BuiltInFunctionsUtils::matchFunction(functionName, childrenTypes,
entry->ptrCast<FunctionCatalogEntry>());
auto gdsFunc = func->constPtrCast<GDSFunction>()->copy();
auto input = GDSBindInput();
input.params = children;
Expand Down
4 changes: 3 additions & 1 deletion src/binder/bind_expression/bind_comparison_expression.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,9 @@ std::shared_ptr<Expression> ExpressionBinder::bindComparisonExpression(
childrenTypes.push_back(combinedType.copy());
}
auto entry = catalog->getFunctionEntry(transaction, functionName);
auto function = BuiltInFunctionsUtils::matchFunction(functionName, childrenTypes, entry->ptrCast<catalog::FunctionCatalogEntry>())->ptrCast<ScalarFunction>();
auto function = BuiltInFunctionsUtils::matchFunction(functionName, childrenTypes,
entry->ptrCast<catalog::FunctionCatalogEntry>())
->ptrCast<ScalarFunction>();
expression_vector childrenAfterCast;
for (auto i = 0u; i < children.size(); ++i) {
if (children[i]->dataType != combinedType) {
Expand Down
12 changes: 8 additions & 4 deletions src/binder/bind_expression/bind_function_expression.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,10 @@ std::shared_ptr<Expression> ExpressionBinder::bindScalarFunctionExpression(

auto entry = catalog->getFunctionEntry(transaction, functionName);

auto function =
BuiltInFunctionsUtils::matchFunction(functionName, childrenTypes, entry->ptrCast<FunctionCatalogEntry>())->ptrCast<ScalarFunction>()->copy();
auto function = BuiltInFunctionsUtils::matchFunction(functionName, childrenTypes,
entry->ptrCast<FunctionCatalogEntry>())
->ptrCast<ScalarFunction>()
->copy();
if (children.size() == 2 && children[1]->expressionType == ExpressionType::LAMBDA) {
if (!function->isListLambda) {
throw BinderException(stringFormat("{} does not support lambda input.", functionName));
Expand Down Expand Up @@ -135,7 +137,8 @@ std::shared_ptr<Expression> ExpressionBinder::bindRewriteFunctionExpression(
auto childrenTypes = getTypes(children);
auto functionName = funcExpr.getNormalizedFunctionName();
auto entry = context->getCatalog()->getFunctionEntry(context->getTransaction(), functionName);
auto match = BuiltInFunctionsUtils::matchFunction(functionName, childrenTypes, entry->ptrCast<FunctionCatalogEntry>());
auto match = BuiltInFunctionsUtils::matchFunction(functionName, childrenTypes,
entry->ptrCast<FunctionCatalogEntry>());
auto function = match->constPtrCast<RewriteFunction>();
KU_ASSERT(function->rewriteFunc != nullptr);
return function->rewriteFunc(children, this);
Expand All @@ -152,7 +155,8 @@ std::shared_ptr<Expression> ExpressionBinder::bindAggregateFunctionExpression(
}
auto entry = context->getCatalog()->getFunctionEntry(context->getTransaction(), functionName);
auto function = BuiltInFunctionsUtils::matchAggregateFunction(functionName, childrenTypes,
isDistinct, entry->ptrCast<FunctionCatalogEntry>())->copy();
isDistinct, entry->ptrCast<FunctionCatalogEntry>())
->copy();
if (function.paramRewriteFunc) {
function.paramRewriteFunc(children);
}
Expand Down
3 changes: 2 additions & 1 deletion src/binder/bind_expression/bind_subquery_expression.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,8 @@ std::shared_ptr<Expression> ExpressionBinder::bindSubqueryExpression(
std::move(boundGraphPattern.queryGraphCollection), uniqueName, std::move(rawName));
boundSubqueryExpr->setWhereExpression(boundGraphPattern.where);
// Bind projection
auto entry = context->getCatalog()->getFunctionEntry(context->getTransaction(), CountStarFunction::name);
auto entry =
context->getCatalog()->getFunctionEntry(context->getTransaction(), CountStarFunction::name);
auto function = BuiltInFunctionsUtils::matchAggregateFunction(CountStarFunction::name,
std::vector<LogicalType>{}, false, entry->ptrCast<catalog::FunctionCatalogEntry>());
auto bindData = std::make_unique<FunctionBindData>(LogicalType(function->returnTypeID));
Expand Down
15 changes: 9 additions & 6 deletions src/binder/binder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -229,8 +229,7 @@ void Binder::restoreScope(BinderScope prevScope) {
scope = std::move(prevScope);
}

TableFunction Binder::getScanFunction(FileTypeInfo typeInfo,
const FileScanInfo& fileScanInfo) {
TableFunction Binder::getScanFunction(FileTypeInfo typeInfo, const FileScanInfo& fileScanInfo) {
Function* func = nullptr;
std::vector<LogicalType> inputTypes;
inputTypes.push_back(LogicalType::STRING());
Expand All @@ -239,23 +238,27 @@ TableFunction Binder::getScanFunction(FileTypeInfo typeInfo,
switch (typeInfo.fileType) {
case FileType::PARQUET: {
auto entry = catalog->getFunctionEntry(transaction, ParquetScanFunction::name);
func = BuiltInFunctionsUtils::matchFunction(ParquetScanFunction::name, inputTypes, entry->ptrCast<FunctionCatalogEntry>());
func = BuiltInFunctionsUtils::matchFunction(ParquetScanFunction::name, inputTypes,
entry->ptrCast<FunctionCatalogEntry>());
} break;
case FileType::NPY: {
auto entry = catalog->getFunctionEntry(transaction, NpyScanFunction::name);
func = BuiltInFunctionsUtils::matchFunction(NpyScanFunction::name, inputTypes, entry->ptrCast<FunctionCatalogEntry>());
func = BuiltInFunctionsUtils::matchFunction(NpyScanFunction::name, inputTypes,
entry->ptrCast<FunctionCatalogEntry>());
} break;
case FileType::CSV: {
auto csvConfig = CSVReaderConfig::construct(fileScanInfo.options);
auto name = csvConfig.parallel ? ParallelCSVScan::name : SerialCSVScan::name;
auto entry = catalog->getFunctionEntry(transaction, name);
func = BuiltInFunctionsUtils::matchFunction(name, inputTypes, entry->ptrCast<FunctionCatalogEntry>());
func = BuiltInFunctionsUtils::matchFunction(name, inputTypes,
entry->ptrCast<FunctionCatalogEntry>());
} break;
case FileType::UNKNOWN: {
try {
auto name = common::stringFormat("{}_SCAN", typeInfo.fileTypeStr);
auto entry = catalog->getFunctionEntry(transaction, name);
func = BuiltInFunctionsUtils::matchFunction(name, inputTypes, entry->ptrCast<FunctionCatalogEntry>());
func = BuiltInFunctionsUtils::matchFunction(name, inputTypes,
entry->ptrCast<FunctionCatalogEntry>());
} catch (...) {
if (typeInfo.fileTypeStr == "") {
throw common::BinderException{
Expand Down
5 changes: 2 additions & 3 deletions src/catalog/catalog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,11 @@
#include "common/serializer/serializer.h"
#include "common/string_format.h"
#include "function/built_in_function_utils.h"
#include "function/function_collection.h"
#include "main/db_config.h"
#include "storage/storage_utils.h"
#include "storage/storage_version_info.h"
#include "transaction/transaction.h"
#include "function/function_collection.h"

using namespace kuzu::binder;
using namespace kuzu::common;
Expand Down Expand Up @@ -401,8 +401,7 @@ function::ScalarMacroFunction* Catalog::getScalarMacroFunction(const Transaction
// addScalarMacroFunction
void Catalog::addScalarMacroFunction(Transaction* transaction, std::string name,
std::unique_ptr<function::ScalarMacroFunction> macro) {
auto entry =
std::make_unique<ScalarMacroCatalogEntry>(std::move(name), std::move(macro));
auto entry = std::make_unique<ScalarMacroCatalogEntry>(std::move(name), std::move(macro));
functions->createEntry(transaction, std::move(entry));
}

Expand Down
6 changes: 4 additions & 2 deletions src/function/built_in_function_utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@ static void validateNonEmptyCandidateFunctions(std::vector<Function*>& candidate
const function::function_set& set);

Function* BuiltInFunctionsUtils::matchFunction(const std::string& name,
const std::vector<LogicalType>& inputTypes, const catalog::FunctionCatalogEntry* functionEntry) {
const std::vector<LogicalType>& inputTypes,
const catalog::FunctionCatalogEntry* functionEntry) {
auto& functionSet = functionEntry->getFunctionSet();
std::vector<Function*> candidateFunctions;
uint32_t minCost = UINT32_MAX;
Expand All @@ -51,7 +52,8 @@ Function* BuiltInFunctionsUtils::matchFunction(const std::string& name,
}

AggregateFunction* BuiltInFunctionsUtils::matchAggregateFunction(const std::string& name,
const std::vector<common::LogicalType>& inputTypes, bool isDistinct, const catalog::FunctionCatalogEntry* functionEntry) {
const std::vector<common::LogicalType>& inputTypes, bool isDistinct,
const catalog::FunctionCatalogEntry* functionEntry) {
auto& functionSet = functionEntry->getFunctionSet();
std::vector<AggregateFunction*> candidateFunctions;
for (auto& function : functionSet) {
Expand Down
7 changes: 4 additions & 3 deletions src/function/vector_cast_functions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1058,9 +1058,10 @@ static std::unique_ptr<FunctionBindData> castBindFunc(ScalarBindFuncInput input)
std::vector<LogicalType> typeVec;
typeVec.push_back(input.arguments[0]->getDataType().copy());
try {
auto entry = input.context->getCatalog()->getFunctionEntry(input.context->getTransaction(), func->name);
auto match = BuiltInFunctionsUtils::matchFunction(
func->name, typeVec, entry->ptrCast<catalog::FunctionCatalogEntry>());
auto entry = input.context->getCatalog()->getFunctionEntry(
input.context->getTransaction(), func->name);
auto match = BuiltInFunctionsUtils::matchFunction(func->name, typeVec,
entry->ptrCast<catalog::FunctionCatalogEntry>());
func->execFunc = match->constPtrCast<ScalarFunction>()->execFunc;
return std::make_unique<function::CastFunctionBindData>(targetType.copy());
} catch (...) { // NOLINT
Expand Down
3 changes: 1 addition & 2 deletions src/include/catalog/catalog.h
Original file line number Diff line number Diff line change
Expand Up @@ -147,8 +147,7 @@ class KUZU_API Catalog {
// ----------------------------- Functions ----------------------------

// Check if function exists.
bool containsFunction(const transaction::Transaction* transaction,
const std::string& name);
bool containsFunction(const transaction::Transaction* transaction, const std::string& name);
// Get function entry by name.
// Note we cannot cast to FunctionEntry here because result could also be a MacroEntry.
CatalogEntry* getFunctionEntry(const transaction::Transaction* transaction,
Expand Down
6 changes: 4 additions & 2 deletions src/include/function/built_in_function_utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,12 @@ class BuiltInFunctionsUtils {
public:
// TODO(Ziyi): We should have a unified interface for matching table, aggregate and scalar
// functions.
static Function* matchFunction(const std::string& name, const catalog::FunctionCatalogEntry* catalogEntry) {
static Function* matchFunction(const std::string& name,
const catalog::FunctionCatalogEntry* catalogEntry) {
return matchFunction(name, {}, catalogEntry);
}
static Function* matchFunction(const std::string& name, const std::vector<common::LogicalType>& inputTypes,
static Function* matchFunction(const std::string& name,
const std::vector<common::LogicalType>& inputTypes,
const catalog::FunctionCatalogEntry* functionEntry);

static AggregateFunction* matchAggregateFunction(const std::string& name,
Expand Down
2 changes: 1 addition & 1 deletion src/main/database.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ void Database::addTableFunction(std::string name, function::function_set functio
void Database::addStandaloneCallFunction(std::string name,
std::vector<std::unique_ptr<function::Function>> functionSet) {
catalog->addFunction(&DUMMY_TRANSACTION, CatalogEntryType::STANDALONE_TABLE_FUNCTION_ENTRY,
std::move(name), std::move(functionSet));
std::move(name), std::move(functionSet));
}

void Database::registerFileSystem(std::unique_ptr<FileSystem> fs) {
Expand Down
6 changes: 4 additions & 2 deletions src/planner/plan/plan_port_db.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,10 @@ std::unique_ptr<LogicalPlan> Planner::planExportDatabase(const BoundStatement& s
StringUtils::toLower(fileTypeStr);
auto copyToSuffix = "." + fileTypeStr;
std::string name = common::stringFormat("COPY_{}", FileTypeUtils::toString(fileType));
auto entry = clientContext->getCatalog()->getFunctionEntry(clientContext->getTransaction(), name);
auto func = function::BuiltInFunctionsUtils::matchFunction(name, entry->ptrCast<FunctionCatalogEntry>());
auto entry =
clientContext->getCatalog()->getFunctionEntry(clientContext->getTransaction(), name);
auto func = function::BuiltInFunctionsUtils::matchFunction(name,
entry->ptrCast<FunctionCatalogEntry>());
KU_ASSERT(func != nullptr);
auto exportFunc = *func->constPtrCast<function::ExportFunction>();
for (auto& exportTableData : *exportData) {
Expand Down
6 changes: 4 additions & 2 deletions src/processor/map/create_factorized_table_scan.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,10 @@ std::unique_ptr<PhysicalOperator> PlanMapper::createFTableScan(const expression_
}
auto bindData =
std::make_unique<FTableScanBindData>(table, std::move(colIndices), maxMorselSize);
auto functionEntry = clientContext->getCatalog()->getFunctionEntry(clientContext->getTransaction(), FTableScan::name);
auto function = function::BuiltInFunctionsUtils::matchFunction(FTableScan::name, functionEntry->ptrCast<catalog::FunctionCatalogEntry>());
auto functionEntry = clientContext->getCatalog()->getFunctionEntry(
clientContext->getTransaction(), FTableScan::name);
auto function = function::BuiltInFunctionsUtils::matchFunction(FTableScan::name,
functionEntry->ptrCast<catalog::FunctionCatalogEntry>());
auto info = TableFunctionCallInfo();
info.function = *ku_dynamic_cast<TableFunction*>(function);
info.bindData = std::move(bindData);
Expand Down

0 comments on commit 55b864a

Please sign in to comment.