Skip to content

Commit

Permalink
finish adding tests for select (#4208)
Browse files Browse the repository at this point in the history
  • Loading branch information
tristaZero committed Feb 8, 2020
1 parent 38f77a6 commit a0a91df
Show file tree
Hide file tree
Showing 2 changed files with 116 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -332,6 +332,10 @@ public ASTNode visitProjection(final ProjectionContext ctx) {
((AggregationProjectionSegment) projection).setAlias(alias);
return projection;
}
if (projection instanceof ExpressionProjectionSegment) {
((ExpressionProjectionSegment) projection).setAlias(alias);
return projection;
}
LiteralExpressionSegment column = (LiteralExpressionSegment) projection;
ExpressionProjectionSegment result = Strings.isNullOrEmpty(alias) ? new ExpressionProjectionSegment(column.getStartIndex(), column.getStopIndex(), String.valueOf(column.getLiterals()))
: new ExpressionProjectionSegment(column.getStartIndex(), ctx.alias().stop.getStopIndex(), String.valueOf(column.getLiterals()));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -675,4 +675,116 @@
<!-- FIXME cannot parse subquery's predicate -->
</where>
</select>

<select sql-case-id="select_with_interval_function" parameters="12, 1000">
<table name="t_order" start-index="45" stop-index="51" />
<projections start-index="7" stop-index="38">
<expression-projection alias="func_status" start-index="7" stop-index="26" />
</projections>
<where parameters-count="2" start-index="53" stop-index="86" literal-stop-index="90">
<and-predicate>
<predicate start-index="59" stop-index="69" literal-stop-index="70">
<column-left-value name="user_id" start-index="59" stop-index="65" />
<operator type="=" />
<compare-right-value>
<parameter-marker-expression value="0" />
<literal-expression value="12" />
</compare-right-value>
</predicate>
<predicate start-index="75" stop-index="86" literal-start-index="76" literal-stop-index="90">
<column-left-value name="order_id" start-index="75" stop-index="82" literal-start-index="76" literal-stop-index="83" />
<operator type="=" />
<compare-right-value>
<parameter-marker-expression value="1" />
<literal-expression value="1000" />
</compare-right-value>
</predicate>
</and-predicate>
</where>
</select>

<select sql-case-id="select_with_left_function">
<table name="t_order_item" start-index="44" stop-index="55" />
<projections start-index="7" stop-index="37">
<expression-projection start-index="7" stop-index="37" />
</projections>
<where parameters-count="0" start-index="57" stop-index="74">
<and-predicate>
<predicate start-index="63" stop-index="74">
<column-left-value name="user_id" start-index="63" stop-index="69" />
<operator type="=" />
<compare-right-value>
<literal-expression value="10" />
</compare-right-value>
</predicate>
</and-predicate>
</where>
</select>

<select sql-case-id="select_for_update" parameters="10">
<table name="t_order" start-index="14" stop-index="20" />
<projections start-index="7" stop-index="7">
<shorthand-projection start-index="7" stop-index="7" />
</projections>
<where parameters-count="1" start-index="22" stop-index="38" literal-stop-index="39">
<and-predicate>
<predicate start-index="28" stop-index="38" literal-stop-index="39">
<column-left-value name="user_id" start-index="28" stop-index="34" literal-stop-index="34" />
<operator type="=" />
<compare-right-value>
<parameter-marker-expression value="0" />
<literal-expression value="10" />
</compare-right-value>
</predicate>
</and-predicate>
</where>
</select>

<select sql-case-id="select_database">
<projections start-index="7" stop-index="16">
<expression-projection start-index="7" stop-index="16" />
</projections>
</select>

<select sql-case-id="select_with_mod_function">
<table name="t_order" start-index="14" stop-index="20" />
<projections start-index="7" stop-index="7">
<shorthand-projection start-index="7" stop-index="7" />
</projections>
<where parameters-count="0" start-index="22" stop-index="47">
<!-- FIXME cannot parse expr in left value -->
</where>
</select>

<select sql-case-id="select_with_date_format_function">
<table name="t_order" start-index="14" stop-index="20" />
<projections start-index="7" stop-index="7">
<shorthand-projection start-index="7" stop-index="7" />
</projections>
<where parameters-count="0" start-index="22" stop-index="79">
<!-- FIXME cannot parse expr in left value for predicate -->
<!--<and-predicate>-->
<!--<predicate start-index="28" stop-index="79" />-->
<!--</and-predicate>-->
</where>
</select>

<select sql-case-id="select_with_spatial_function">
<table name="t_order" start-index="14" stop-index="20" />
<projections start-index="7" stop-index="7">
<shorthand-projection start-index="7" stop-index="7" />
</projections>
<where parameters-count="0" start-index="22" stop-index="106">
<!-- FIXME cannot parse expr in left value -->
<!--<and-predicate>-->
<!--<predicate start-index="28" stop-index="106" />-->
<!--</and-predicate>-->
</where>
</select>

<select sql-case-id="select_current_user">
<projections start-index="7" stop-index="18">
<expression-projection start-index="7" stop-index="18" />
</projections>
</select>
</sql-parser-test-cases>

0 comments on commit a0a91df

Please sign in to comment.