strongduanmu commented on code in PR #34384:
URL: https://github.com/apache/shardingsphere/pull/34384#discussion_r1924600963
##########
test/it/binder/src/test/resources/cases/dml/select.xml:
##########
@@ -478,6 +478,109 @@
</projections>
</select>
+ <select sql-case-id="select_with_with_clause_with_column_definition">
+ <with start-index="0" stop-index="81">
+ <common-table-expression name="t_order_tmp" start-index="5"
stop-index="81">
+ <subquery-expression start-index="5" stop-index="81">
+ <select>
+ <projections start-index="65" stop-index="65">
+ <shorthand-projection start-index="65"
stop-index="65">
+ <actual-projections>
+ <column-projection name="order_id"
start-index="0" stop-index="0" start-delimiter="`" end-delimiter="`">
+ <owner name="o" start-index="0"
stop-index="0" />
+ <column-bound>
+ <original-database name="foo_db_1"
/>
+ <original-schema name="foo_db_1" />
+ <original-table name="t_order" />
+ <original-column name="order_id"
start-delimiter="`" end-delimiter="`" />
+ </column-bound>
+ </column-projection>
+ <column-projection name="user_id"
start-index="0" stop-index="0" start-delimiter="`" end-delimiter="`">
+ <owner name="o" start-index="0"
stop-index="0" />
+ <column-bound>
+ <original-database name="foo_db_1"
/>
+ <original-schema name="foo_db_1" />
+ <original-table name="t_order" />
+ <original-column name="user_id"
start-delimiter="`" end-delimiter="`" />
+ </column-bound>
+ </column-projection>
+ <column-projection name="status"
start-index="0" stop-index="0" start-delimiter="`" end-delimiter="`">
+ <owner name="o" start-index="0"
stop-index="0" />
+ <column-bound>
+ <original-database name="foo_db_1"
/>
+ <original-schema name="foo_db_1" />
+ <original-table name="t_order" />
+ <original-column name="status"
start-delimiter="`" end-delimiter="`" />
+ </column-bound>
+ </column-projection>
+ <column-projection name="merchant_id"
start-index="0" stop-index="0" start-delimiter="`" end-delimiter="`">
+ <owner name="o" start-index="0"
stop-index="0" />
+ <column-bound>
+ <original-database name="foo_db_1"
/>
+ <original-schema name="foo_db_1" />
+ <original-table name="t_order" />
+ <original-column
name="merchant_id" start-delimiter="`" end-delimiter="`" />
+ </column-bound>
+ </column-projection>
+ <column-projection name="remark"
start-index="0" stop-index="0" start-delimiter="`" end-delimiter="`">
+ <owner name="o" start-index="0"
stop-index="0" />
+ <column-bound>
+ <original-database name="foo_db_1"
/>
+ <original-schema name="foo_db_1" />
+ <original-table name="t_order" />
+ <original-column name="remark"
start-delimiter="`" end-delimiter="`" />
+ </column-bound>
+ </column-projection>
+ <column-projection name="creation_date"
start-index="0" stop-index="0" start-delimiter="`" end-delimiter="`">
+ <owner name="o" start-index="0"
stop-index="0" />
+ <column-bound>
+ <original-database name="foo_db_1"
/>
+ <original-schema name="foo_db_1" />
+ <original-table name="t_order" />
+ <original-column
name="creation_date" start-delimiter="`" end-delimiter="`" />
+ </column-bound>
+ </column-projection>
+ </actual-projections>
+ </shorthand-projection>
+ </projections>
+ <from>
+ <simple-table name="t_order" alias="o"
start-index="72" stop-index="80">
+ <table-bound>
+ <original-database name="foo_db_1" />
+ <original-schema name="foo_db_1" />
+ </table-bound>
+ </simple-table>
+ </from>
+ </select>
+ </subquery-expression>
+ <column name="col1" start-index="18" stop-index="21"/>
Review Comment:
Please add `column-bound` expected result.
##########
infra/binder/src/main/java/org/apache/shardingsphere/infra/binder/engine/segment/dml/with/WithSegmentBinder.java:
##########
@@ -71,18 +74,26 @@ public static WithSegment bind(final WithSegment segment,
final SQLStatementBind
}
private static SimpleTableSegmentBinderContext
createWithTableBinderContext(final CommonTableExpressionSegment
commonTableExpressionSegment) {
- return new
SimpleTableSegmentBinderContext(commonTableExpressionSegment.getSubquery().getSelect().getProjections().getProjections());
+ if (commonTableExpressionSegment.getColumns().isEmpty()) {
+ return new
SimpleTableSegmentBinderContext(commonTableExpressionSegment.getSubquery().getSelect().getProjections().getProjections());
+ } else {
+ Collection<ProjectionSegment> projectionSegments = new
LinkedList<>();
+ commonTableExpressionSegment.getColumns().forEach(each ->
projectionSegments.add(new ColumnProjectionSegment(each)));
Review Comment:
Can you move this logic to CommonTableExpressionSegmentBinder?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]