|
1 | 1 | #include "parser/expression/parsed_expression_visitor.h"
|
2 | 2 |
|
| 3 | +#include "catalog/catalog.h" |
| 4 | +#include "catalog/catalog_entry/function_catalog_entry.h" |
3 | 5 | #include "common/exception/not_implemented.h"
|
4 |
| -#include "function/sequence/sequence_functions.h" |
| 6 | +#include "main/client_context.h" |
5 | 7 | #include "parser/expression/parsed_case_expression.h"
|
6 | 8 | #include "parser/expression/parsed_function_expression.h"
|
7 | 9 | #include "parser/expression/parsed_lambda_expression.h"
|
8 | 10 |
|
9 | 11 | using namespace kuzu::common;
|
| 12 | +using namespace kuzu::catalog; |
10 | 13 |
|
11 | 14 | namespace kuzu {
|
12 | 15 | namespace parser {
|
@@ -141,13 +144,28 @@ void ParsedExpressionVisitor::visitCaseChildrenUnsafe(ParsedExpression& expr) {
|
141 | 144 | }
|
142 | 145 | }
|
143 | 146 |
|
144 |
| -void ParsedSequenceFunctionCollector::visitFunctionExpr(const ParsedExpression* expr) { |
| 147 | +void ReadWriteExprAnalyzer::visitFunctionExpr(const ParsedExpression* expr) { |
145 | 148 | if (expr->getExpressionType() != ExpressionType::FUNCTION) {
|
| 149 | + // Can be AND/OR/... which guarantees to be readonly. |
146 | 150 | return;
|
147 | 151 | }
|
148 |
| - auto funName = expr->constCast<ParsedFunctionExpression>().getFunctionName(); |
149 |
| - if (StringUtils::getUpper(funName) == function::NextValFunction::name) { |
150 |
| - hasSeqUpdate_ = true; |
| 152 | + auto funcName = expr->constCast<ParsedFunctionExpression>().getFunctionName(); |
| 153 | + auto catalog = context->getCatalog(); |
| 154 | + // Assume user cannot add function with sideeffect, i.e. all non-readonly function is |
| 155 | + // registered when database starts. |
| 156 | + auto transaction = &transaction::DUMMY_TRANSACTION; |
| 157 | + if (!catalog->containsFunction(transaction, funcName)) { |
| 158 | + return; |
| 159 | + } |
| 160 | + auto entry = catalog->getFunctionEntry(transaction, funcName); |
| 161 | + if (entry->getType() != CatalogEntryType::SCALAR_FUNCTION_ENTRY) { |
| 162 | + // Can be macro function which guarantees to be readonly. |
| 163 | + return; |
| 164 | + } |
| 165 | + auto& funcSet = entry->constPtrCast<FunctionCatalogEntry>()->getFunctionSet(); |
| 166 | + KU_ASSERT(!funcSet.empty()); |
| 167 | + if (!funcSet[0]->isReadOnly) { |
| 168 | + readOnly = false; |
151 | 169 | }
|
152 | 170 | }
|
153 | 171 |
|
|
0 commit comments