Skip to content

Commit 69aeecb

Browse files
committed
improve errors for source-only functions
1 parent bc0eb1d commit 69aeecb

File tree

3 files changed

+21
-8
lines changed

3 files changed

+21
-8
lines changed

ydb/library/yql/sql/v1/builtin.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1838,7 +1838,7 @@ class TTableRow final : public INode {
18381838

18391839
bool DoInit(TContext& ctx, ISource* src) override {
18401840
if (!src || src->IsFake()) {
1841-
ctx.Error(Pos) << "TableRow requires data source";
1841+
ctx.Error(Pos) << TStringBuilder() << (Join ? "Join" : "") << "TableRow requires data source";
18421842
return false;
18431843
}
18441844

ydb/library/yql/sql/v1/node.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -967,7 +967,7 @@ TCallDirectRow::TCallDirectRow(TPosition pos, const TString& opName, const TVect
967967
{}
968968

969969
bool TCallDirectRow::DoInit(TContext& ctx, ISource* src) {
970-
if (!src) {
970+
if (!src || (ctx.CompactNamedExprs && src->IsFake())) {
971971
ctx.Error(Pos) << "Unable to use function: " << OpName << " without source";
972972
return false;
973973
}

ydb/library/yql/sql/v1/sql_ut.cpp

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6773,11 +6773,24 @@ Y_UNIT_TEST_SUITE(TViewSyntaxTest) {
67736773
}
67746774

67756775
Y_UNIT_TEST_SUITE(CompactNamedExprs) {
6776-
Y_UNIT_TEST(TableRowInWrongContext) {
6777-
ExpectFailWithError(
6778-
"pragma CompactNamedExprs;\n"
6779-
"$foo = TableRow();\n"
6780-
"select $foo from plato.Input;\n",
6781-
"<main>:2:8: Error: TableRow requires data source\n");
6776+
Y_UNIT_TEST(SourceCallablesInWrongContext) {
6777+
TString query = R"(
6778+
pragma CompactNamedExprs;
6779+
$foo = %s();
6780+
select $foo from plato.Input;
6781+
)";
6782+
6783+
THashMap<TString, TString> errs = {
6784+
{"TableRow", "<main>:3:20: Error: TableRow requires data source\n"},
6785+
{"JoinTableRow", "<main>:3:20: Error: JoinTableRow requires data source\n"},
6786+
{"TableRecordIndex", "<main>:3:20: Error: Unable to use function: TableRecord without source\n"},
6787+
{"TablePath", "<main>:3:20: Error: Unable to use function: TablePath without source\n"},
6788+
{"SystemMetadata", "<main>:3:20: Error: Unable to use function: SystemMetadata without source\n"},
6789+
};
6790+
6791+
for (TString callable : { "TableRow", "JoinTableRow", "TableRecordIndex", "TablePath", "SystemMetadata"}) {
6792+
auto req = Sprintf(query.c_str(), callable.c_str());
6793+
ExpectFailWithError(req, errs[callable]);
6794+
}
67826795
}
67836796
}

0 commit comments

Comments
 (0)