Skip to content

Commit 21af545

Browse files
committed
improve errors for source-only functions
1 parent 301360c commit 21af545

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
@@ -6758,11 +6758,24 @@ Y_UNIT_TEST_SUITE(TViewSyntaxTest) {
67586758
}
67596759

67606760
Y_UNIT_TEST_SUITE(CompactNamedExprs) {
6761-
Y_UNIT_TEST(TableRowInWrongContext) {
6762-
ExpectFailWithError(
6763-
"pragma CompactNamedExprs;\n"
6764-
"$foo = TableRow();\n"
6765-
"select $foo from plato.Input;\n",
6766-
"<main>:2:8: Error: TableRow requires data source\n");
6761+
Y_UNIT_TEST(SourceCallablesInWrongContext) {
6762+
TString query = R"(
6763+
pragma CompactNamedExprs;
6764+
$foo = %s();
6765+
select $foo from plato.Input;
6766+
)";
6767+
6768+
THashMap<TString, TString> errs = {
6769+
{"TableRow", "<main>:3:20: Error: TableRow requires data source\n"},
6770+
{"JoinTableRow", "<main>:3:20: Error: JoinTableRow requires data source\n"},
6771+
{"TableRecordIndex", "<main>:3:20: Error: Unable to use function: TableRecord without source\n"},
6772+
{"TablePath", "<main>:3:20: Error: Unable to use function: TablePath without source\n"},
6773+
{"SystemMetadata", "<main>:3:20: Error: Unable to use function: SystemMetadata without source\n"},
6774+
};
6775+
6776+
for (TString callable : { "TableRow", "JoinTableRow", "TableRecordIndex", "TablePath", "SystemMetadata"}) {
6777+
auto req = Sprintf(query.c_str(), callable.c_str());
6778+
ExpectFailWithError(req, errs[callable]);
6779+
}
67676780
}
67686781
}

0 commit comments

Comments
 (0)