Skip to content

Commit

Permalink
Bugfix/issue 820 fix incorrect code name (#821)
Browse files Browse the repository at this point in the history
* fix incorrect code name

* add testing
  • Loading branch information
yl-lisen authored Aug 15, 2024
1 parent d52cb5f commit 3ad95c9
Show file tree
Hide file tree
Showing 6 changed files with 32 additions and 3 deletions.
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;

0 comments on commit 3ad95c9

Please sign in to comment.