Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bugfix/issue 820 fix incorrect code name #821

Merged
merged 2 commits into from
Aug 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/Interpreters/Streaming/PartitionByVisitor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ void PartitionByMatcher::visit(ASTPtr & ast, Data & data)

/// Convert function to window function.
/// Always show original function
node_func->code_name = DB::serializeAST(*node_func);
node_func->makeCurrentCodeName();
node_func->window_definition = data.win_define->clone();
node_func->is_window_function = true;
}
Expand Down
3 changes: 1 addition & 2 deletions src/Interpreters/Streaming/SubstituteStreamingFunction.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -146,8 +146,7 @@ void StreamingFunctionData::visit(DB::ASTFunction & func, DB::ASTPtr)
if (!func_alias_name->empty())
{
/// Always show original function
if (func.code_name.empty())
func.code_name = DB::serializeAST(func);
func.makeCurrentCodeName();

func.name = *func_alias_name;
if (!func.arguments)
Expand Down
14 changes: 14 additions & 0 deletions src/Parsers/ASTFunction.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -641,6 +641,20 @@ void ASTFunction::formatImplWithoutAlias(const FormatSettings & settings, Format
}
}

/// proton: starts.
void ASTFunction::makeCurrentCodeName()
{
if (!code_name.empty())
return;

WriteBufferFromOwnString buf;
IAST::FormatSettings settings(buf, /*one_line=*/true);
FormatState state;
formatImplWithoutAlias(settings, state, FormatStateStacked());
code_name = buf.str();
}
/// proton: ends.

String getFunctionName(const IAST * ast)
{
String res;
Expand Down
4 changes: 4 additions & 0 deletions src/Parsers/ASTFunction.h
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,10 @@ class ASTFunction : public ASTWithAlias

std::string getWindowDescription() const;

/// proton: starts. Generates the one-line formatting string (without aliases) for the current function and assigns it to code_name.
void makeCurrentCodeName();
/// proton: ends.

protected:
void formatImplWithoutAlias(const FormatSettings & settings, FormatState & state, FormatStateStacked frame) const override;
void appendColumnNameImpl(WriteBuffer & ostr) const override;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
SELECT
count() OVER (PARTITION BY i) AS x, lag(x)
FROM
changelog(`99005_stream`, i)
GROUP BY
i
6 changes: 6 additions & 0 deletions tests/queries_ported/0_stateless/99005_explain_syntax_bug.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
DROP STREAM IF EXISTS 99005_stream;
CREATE STREAM 99005_stream(i int, v int);

EXPLAIN SYNTAX select count() over (partition by i) as x, lag(x) from changelog(99005_stream, i);

DROP STREAM 99005_stream;
Loading