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

support for SELECT special functions #24888

Merged
merged 4 commits into from
Apr 7, 2023
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
Original file line number Diff line number Diff line change
Expand Up @@ -954,7 +954,12 @@ public final ASTNode visitExtractFunction(final ExtractFunctionContext ctx) {
@Override
public final ASTNode visitCharFunction(final CharFunctionContext ctx) {
calculateParameterCount(ctx.expr());
return new FunctionSegment(ctx.getStart().getStartIndex(), ctx.getStop().getStopIndex(), ctx.CHAR().getText(), getOriginalText(ctx));
FunctionSegment result = new FunctionSegment(ctx.getStart().getStartIndex(), ctx.getStop().getStopIndex(), ctx.CHAR().getText(), getOriginalText(ctx));
for (ExprContext each : ctx.expr()) {
ASTNode expr = visit(each);
result.getParameters().add((ExpressionSegment) expr);
}
return result;
}

@Override
Expand All @@ -966,7 +971,9 @@ public final ASTNode visitTrimFunction(final TrimFunctionContext ctx) {
@Override
public final ASTNode visitWeightStringFunction(final WeightStringFunctionContext ctx) {
calculateParameterCount(Collections.singleton(ctx.expr()));
return new FunctionSegment(ctx.getStart().getStartIndex(), ctx.getStop().getStopIndex(), ctx.WEIGHT_STRING().getText(), getOriginalText(ctx));
FunctionSegment result = new FunctionSegment(ctx.getStart().getStartIndex(), ctx.getStop().getStopIndex(), ctx.WEIGHT_STRING().getText(), getOriginalText(ctx));
result.getParameters().add((ExpressionSegment) visit(ctx.expr()));
return result;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,8 @@ private Set<String> getSupportedSQLCaseIDs() {
result.add("select_natural_full_join");
result.add("select_order_by_for_nulls_first");
result.add("select_order_by_for_nulls_last");
result.add("select_char");
result.add("select_weight_string");
return result;
}
// CHECKSTYLE:ON
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,23 @@
<projections start-index="7" stop-index="29">
<expression-projection text="CHAR(77,121,83,81,'76')" start-index="7" stop-index="29">
<expr>
<function function-name="CHAR" start-index="7" stop-index="29" text="CHAR(77,121,83,81,'76')" />
<function function-name="CHAR" start-index="7" stop-index="29" text="CHAR(77,121,83,81,'76')" >
<parameter>
<literal-expression value="77" start-index="12" stop-index="13" />
</parameter>
<parameter>
<literal-expression value="121" start-index="15" stop-index="17" />
</parameter>
<parameter>
<literal-expression value="83" start-index="19" stop-index="20" />
</parameter>
<parameter>
<literal-expression value="81" start-index="22" stop-index="23" />
</parameter>
<parameter>
<literal-expression value="76" start-index="25" stop-index="28" />
</parameter>
</function>
</expr>
</expression-projection>
</projections>
Expand Down Expand Up @@ -170,7 +186,11 @@
<projections start-index="7" stop-index="26">
<expression-projection text="WEIGHT_STRING('bar')" start-index="7" stop-index="26">
<expr>
<function function-name="WEIGHT_STRING" start-index="7" stop-index="26" text="WEIGHT_STRING('bar')" />
<function function-name="WEIGHT_STRING" start-index="7" stop-index="26" text="WEIGHT_STRING('bar')" >
<parameter>
<literal-expression value="bar" start-index="21" stop-index="25" />
</parameter>
</function>
</expr>
</expression-projection>
</projections>
Expand Down