You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@shardingsphere.apache.org by "Yash-cor (via GitHub)" <gi...@apache.org> on 2025/01/17 10:59:22 UTC

[PR] Column bind update in with segment bind [shardingsphere]

Yash-cor opened a new pull request, #34384:
URL: https://github.com/apache/shardingsphere/pull/34384

   Fixes #ISSUSE_ID.
   
   Changes proposed in this pull request:
     -
   Added DifferenceInColumnCountOfSelectListAndColumnNameListException to handle difference in Column counts.
   While using With Clause when Column definition is added it caused Column not found exception.
   Made correction in column bind and externalTableBinderContext.
   ---
   
   Before committing this PR, I'm sure that I have checked the following options:
   - [ ] My code follows the [code of conduct](https://shardingsphere.apache.org/community/en/involved/conduct/code/) of this project.
   - [ ] I have self-reviewed the commit code.
   - [ ] I have (or in comment I request) added corresponding labels for the pull request.
   - [ ] I have passed maven check locally : `./mvnw clean install -B -T1C -Dmaven.javadoc.skip -Dmaven.jacoco.skip -e`.
   - [ ] I have made corresponding changes to the documentation.
   - [ ] I have added corresponding unit tests for my changes.
   - [ ] I have updated the Release Notes of the current development version. For more details, see [Update Release Note](https://shardingsphere.apache.org/community/en/involved/contribute/contributor/)
   


-- 
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: notifications-unsubscribe@shardingsphere.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Column bind update in with segment bind [shardingsphere]

Posted by "Yash-cor (via GitHub)" <gi...@apache.org>.
Yash-cor commented on PR #34384:
URL: https://github.com/apache/shardingsphere/pull/34384#issuecomment-2642034246

   I think the label should be bug as it causes ColumnNotFoundException when we define column names while using with segment.


-- 
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: notifications-unsubscribe@shardingsphere.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Column bind update in with segment bind [shardingsphere]

Posted by "strongduanmu (via GitHub)" <gi...@apache.org>.
strongduanmu commented on PR #34384:
URL: https://github.com/apache/shardingsphere/pull/34384#issuecomment-2599665358

   Hi @Yash-cor, can you update release note?


-- 
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: notifications-unsubscribe@shardingsphere.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Column bind update in with segment bind [shardingsphere]

Posted by "Yash-cor (via GitHub)" <gi...@apache.org>.
Yash-cor commented on code in PR #34384:
URL: https://github.com/apache/shardingsphere/pull/34384#discussion_r1925019454


##########
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?
   
   I have added this logic in CommonTableExpressionSegmentBinder inside the recursion condition.



-- 
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: notifications-unsubscribe@shardingsphere.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Column bind update in with segment bind [shardingsphere]

Posted by "Yash-cor (via GitHub)" <gi...@apache.org>.
Yash-cor commented on code in PR #34384:
URL: https://github.com/apache/shardingsphere/pull/34384#discussion_r1946274746


##########
infra/binder/src/main/java/org/apache/shardingsphere/infra/binder/engine/segment/dml/with/CommonTableExpressionSegmentBinder.java:
##########
@@ -54,16 +71,102 @@ public static CommonTableExpressionSegment bind(final CommonTableExpressionSegme
         }
         if (recursive && segment.getAliasName().isPresent()) {
             binderContext.getExternalTableBinderContexts().put(new CaseInsensitiveString(segment.getAliasName().get()),
-                    new SimpleTableSegmentBinderContext(segment.getColumns().stream().map(ColumnProjectionSegment::new).collect(Collectors.toList())));
+                    createWithTableBinderContext(segment, binderContext));
         }
         SubqueryTableSegment subqueryTableSegment = new SubqueryTableSegment(segment.getStartIndex(), segment.getStopIndex(), segment.getSubquery());
         subqueryTableSegment.setAlias(segment.getAliasSegment());
         SubqueryTableSegment boundSubquerySegment =
                 SubqueryTableSegmentBinder.bind(subqueryTableSegment, binderContext, LinkedHashMultimap.create(), binderContext.getExternalTableBinderContexts());
         CommonTableExpressionSegment result = new CommonTableExpressionSegment(
                 segment.getStartIndex(), segment.getStopIndex(), boundSubquerySegment.getAliasSegment().orElse(null), boundSubquerySegment.getSubquery());
-        // TODO bind with columns
         result.getColumns().addAll(segment.getColumns());
+        if (result.getAliasName().isPresent()) {
+            binderContext.getExternalTableBinderContexts().removeAll(new CaseInsensitiveString(result.getAliasName().get()));
+            binderContext.getExternalTableBinderContexts().put(new CaseInsensitiveString(result.getAliasName().get()),
+                    createWithTableBinderContext(result, binderContext));
+        }
+        result.getColumns().clear();

Review Comment:
   Thanks for reply @strongduanmu 
   This segment `result.getColumns().addAll(segment.getColumns());` and `result.getColumns().clear();` are needed for creating ExternalTableBinderContexts.
   ExternalTableBinderContexts need the result with Column Segment and  binded SubqueryTableSegment.
   And in order to perform column bind for CommonTableExpressionSegment we need the updated ExternalTableBinderContexts.



-- 
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: notifications-unsubscribe@shardingsphere.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Column bind update in with segment bind [shardingsphere]

Posted by "strongduanmu (via GitHub)" <gi...@apache.org>.
strongduanmu commented on code in PR #34384:
URL: https://github.com/apache/shardingsphere/pull/34384#discussion_r1925126292


##########
infra/binder/src/main/java/org/apache/shardingsphere/infra/binder/engine/segment/dml/with/CommonTableExpressionSegmentBinder.java:
##########
@@ -66,4 +67,14 @@ public static CommonTableExpressionSegment bind(final CommonTableExpressionSegme
         result.getColumns().addAll(segment.getColumns());

Review Comment:
   Please check it again, these columns need call ColumnSegmentBinder



##########
test/it/binder/src/test/resources/cases/dml/select.xml:
##########
@@ -478,6 +478,151 @@
         </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">
+                    <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>
+                <column name="col2" start-index="24" stop-index="27">
+                    <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>
+                <column name="col3" start-index="30" stop-index="33">
+                    <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>
+                <column name="col4" start-index="36" stop-index="39">
+                    <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>
+                <column name="col5" start-index="42" stop-index="45">
+                    <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>
+                <column name="col6" start-index="48" stop-index="51">

Review Comment:
   Can you check SQLStatementAssert to confirm whether these columns have been asserted?



-- 
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: notifications-unsubscribe@shardingsphere.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Column bind update in with segment bind [shardingsphere]

Posted by "strongduanmu (via GitHub)" <gi...@apache.org>.
strongduanmu commented on code in PR #34384:
URL: https://github.com/apache/shardingsphere/pull/34384#discussion_r1946132275


##########
infra/binder/src/main/java/org/apache/shardingsphere/infra/binder/engine/segment/dml/with/CommonTableExpressionSegmentBinder.java:
##########
@@ -54,16 +71,102 @@ public static CommonTableExpressionSegment bind(final CommonTableExpressionSegme
         }
         if (recursive && segment.getAliasName().isPresent()) {
             binderContext.getExternalTableBinderContexts().put(new CaseInsensitiveString(segment.getAliasName().get()),
-                    new SimpleTableSegmentBinderContext(segment.getColumns().stream().map(ColumnProjectionSegment::new).collect(Collectors.toList())));
+                    createWithTableBinderContext(segment, binderContext));
         }
         SubqueryTableSegment subqueryTableSegment = new SubqueryTableSegment(segment.getStartIndex(), segment.getStopIndex(), segment.getSubquery());
         subqueryTableSegment.setAlias(segment.getAliasSegment());
         SubqueryTableSegment boundSubquerySegment =
                 SubqueryTableSegmentBinder.bind(subqueryTableSegment, binderContext, LinkedHashMultimap.create(), binderContext.getExternalTableBinderContexts());
         CommonTableExpressionSegment result = new CommonTableExpressionSegment(
                 segment.getStartIndex(), segment.getStopIndex(), boundSubquerySegment.getAliasSegment().orElse(null), boundSubquerySegment.getSubquery());
-        // TODO bind with columns
         result.getColumns().addAll(segment.getColumns());
+        if (result.getAliasName().isPresent()) {
+            binderContext.getExternalTableBinderContexts().removeAll(new CaseInsensitiveString(result.getAliasName().get()));
+            binderContext.getExternalTableBinderContexts().put(new CaseInsensitiveString(result.getAliasName().get()),
+                    createWithTableBinderContext(result, binderContext));
+        }
+        result.getColumns().clear();

Review Comment:
   Please remove `result.getColumns().addAll(segment.getColumns());` and `result.getColumns().clear();`, they seem meaningless.



-- 
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: notifications-unsubscribe@shardingsphere.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Column bind update in with segment bind [shardingsphere]

Posted by "Yash-cor (via GitHub)" <gi...@apache.org>.
Yash-cor commented on code in PR #34384:
URL: https://github.com/apache/shardingsphere/pull/34384#discussion_r1924692680


##########
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:
   Along with this should we also move the bindWithColumns to  CommonTableExpressionBinder.



##########
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?
   
   Along with this should we also move the bindWithColumns to CommonTableExpressionBinder.



-- 
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: notifications-unsubscribe@shardingsphere.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Column bind update in with segment bind [shardingsphere]

Posted by "strongduanmu (via GitHub)" <gi...@apache.org>.
strongduanmu commented on PR #34384:
URL: https://github.com/apache/shardingsphere/pull/34384#issuecomment-2642220060

   > @strongduanmu I think the label should be bug as it causes ColumnNotFoundException when we define column names while using with segment.
   
   Obviously, the SQL Bind logic of the WITH statement is still under development, and setting the label to enhancement is more in line with the actual situation.


-- 
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: notifications-unsubscribe@shardingsphere.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Column bind update in with segment bind [shardingsphere]

Posted by "strongduanmu (via GitHub)" <gi...@apache.org>.
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: notifications-unsubscribe@shardingsphere.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Column bind update in with segment bind [shardingsphere]

Posted by "Yash-cor (via GitHub)" <gi...@apache.org>.
Yash-cor commented on code in PR #34384:
URL: https://github.com/apache/shardingsphere/pull/34384#discussion_r1925042119


##########
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:
   I have added the column-bound info



-- 
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: notifications-unsubscribe@shardingsphere.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Column bind update in with segment bind [shardingsphere]

Posted by "Yash-cor (via GitHub)" <gi...@apache.org>.
Yash-cor commented on code in PR #34384:
URL: https://github.com/apache/shardingsphere/pull/34384#discussion_r1924692680


##########
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:
   Along with this should we also move the bindWithColumns to  CommonTableExpressionBinder.



-- 
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: notifications-unsubscribe@shardingsphere.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Column bind update in with segment bind [shardingsphere]

Posted by "Yash-cor (via GitHub)" <gi...@apache.org>.
Yash-cor commented on code in PR #34384:
URL: https://github.com/apache/shardingsphere/pull/34384#discussion_r1924987094


##########
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:
   Hello @strongduanmu while changing the logic I found Error in the way WithSegment is handling Recursive segment of with clause.
   
   - Recursive segment allows user to use the same common table expression ( cte  ) name in cte's  subquery
   Example - 
       ```
        WITH RECURSIVE cte  AS
       (
          SELECT 1 as (n)
          UNION ALL
          SELECT n + 1 FROM cte WHERE n < 5
       )
      SELECT * FROM cte;
      ```
   
      or similarly can be written as
   
      ```
      WITH RECURSIVE cte (n) AS
      (
         SELECT 1
         UNION ALL
         SELECT n + 1 FROM cte WHERE n < 5
      )
      SELECT * FROM cte;
      ```
   
   -  The WITH clause must begin with WITH RECURSIVE if any CTE in the WITH clause refers to itself. (If no CTE refers to itself, RECURSIVE is permitted but not required.) We have to include a check for it.
   
   - The recursive CTE subquery has two parts, separated by UNION ALL or UNION DISTINCT. Thus, a recursive CTE consists of a non-recursive SELECT part followed by a recursive SELECT part. Should i include a check for it as this check happens when the query hits the MySQL database. 
   
   
   
   



##########
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?
   
   Along with this should we also move the bindWithColumns to CommonTableExpressionBinder.



-- 
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: notifications-unsubscribe@shardingsphere.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Column bind update in with segment bind [shardingsphere]

Posted by "Yash-cor (via GitHub)" <gi...@apache.org>.
Yash-cor commented on PR #34384:
URL: https://github.com/apache/shardingsphere/pull/34384#issuecomment-2603611804

   > Hi @Yash-cor, can you update release note?
   
   Hello @strongduanmu I have updated the release notes.


-- 
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: notifications-unsubscribe@shardingsphere.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Column bind update in with segment bind [shardingsphere]

Posted by "Yash-cor (via GitHub)" <gi...@apache.org>.
Yash-cor commented on code in PR #34384:
URL: https://github.com/apache/shardingsphere/pull/34384#discussion_r1940509218


##########
test/it/binder/src/test/resources/cases/dml/select.xml:
##########
@@ -478,6 +478,151 @@
         </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">
+                    <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>
+                <column name="col2" start-index="24" stop-index="27">
+                    <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>
+                <column name="col3" start-index="30" stop-index="33">
+                    <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>
+                <column name="col4" start-index="36" stop-index="39">
+                    <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>
+                <column name="col5" start-index="42" stop-index="45">
+                    <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>
+                <column name="col6" start-index="48" stop-index="51">

Review Comment:
   Hello @strongduanmu  could you Please review this PR.



##########
test/it/binder/src/test/resources/cases/dml/select.xml:
##########
@@ -478,6 +478,151 @@
         </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">
+                    <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>
+                <column name="col2" start-index="24" stop-index="27">
+                    <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>
+                <column name="col3" start-index="30" stop-index="33">
+                    <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>
+                <column name="col4" start-index="36" stop-index="39">
+                    <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>
+                <column name="col5" start-index="42" stop-index="45">
+                    <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>
+                <column name="col6" start-index="48" stop-index="51">

Review Comment:
   Hello @strongduanmu  could you please review this PR.



-- 
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: notifications-unsubscribe@shardingsphere.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Column bind update in with segment bind [shardingsphere]

Posted by "Yash-cor (via GitHub)" <gi...@apache.org>.
Yash-cor commented on code in PR #34384:
URL: https://github.com/apache/shardingsphere/pull/34384#discussion_r1946274746


##########
infra/binder/src/main/java/org/apache/shardingsphere/infra/binder/engine/segment/dml/with/CommonTableExpressionSegmentBinder.java:
##########
@@ -54,16 +71,102 @@ public static CommonTableExpressionSegment bind(final CommonTableExpressionSegme
         }
         if (recursive && segment.getAliasName().isPresent()) {
             binderContext.getExternalTableBinderContexts().put(new CaseInsensitiveString(segment.getAliasName().get()),
-                    new SimpleTableSegmentBinderContext(segment.getColumns().stream().map(ColumnProjectionSegment::new).collect(Collectors.toList())));
+                    createWithTableBinderContext(segment, binderContext));
         }
         SubqueryTableSegment subqueryTableSegment = new SubqueryTableSegment(segment.getStartIndex(), segment.getStopIndex(), segment.getSubquery());
         subqueryTableSegment.setAlias(segment.getAliasSegment());
         SubqueryTableSegment boundSubquerySegment =
                 SubqueryTableSegmentBinder.bind(subqueryTableSegment, binderContext, LinkedHashMultimap.create(), binderContext.getExternalTableBinderContexts());
         CommonTableExpressionSegment result = new CommonTableExpressionSegment(
                 segment.getStartIndex(), segment.getStopIndex(), boundSubquerySegment.getAliasSegment().orElse(null), boundSubquerySegment.getSubquery());
-        // TODO bind with columns
         result.getColumns().addAll(segment.getColumns());
+        if (result.getAliasName().isPresent()) {
+            binderContext.getExternalTableBinderContexts().removeAll(new CaseInsensitiveString(result.getAliasName().get()));
+            binderContext.getExternalTableBinderContexts().put(new CaseInsensitiveString(result.getAliasName().get()),
+                    createWithTableBinderContext(result, binderContext));
+        }
+        result.getColumns().clear();

Review Comment:
   Thanks for reply @strongduanmu 
   This segment `result.getColumns().addAll(segment.getColumns());` and `result.getColumns().clear();` are needed for creating ExternalTableBinderContexts.
   And in order to perform column bind for CommonTableExpression we need the updated ExternalTableBinderContexts.



-- 
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: notifications-unsubscribe@shardingsphere.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Column bind update in with segment bind [shardingsphere]

Posted by "strongduanmu (via GitHub)" <gi...@apache.org>.
strongduanmu merged PR #34384:
URL: https://github.com/apache/shardingsphere/pull/34384


-- 
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: notifications-unsubscribe@shardingsphere.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Column bind update in with segment bind [shardingsphere]

Posted by "Yash-cor (via GitHub)" <gi...@apache.org>.
Yash-cor commented on code in PR #34384:
URL: https://github.com/apache/shardingsphere/pull/34384#discussion_r1940509218


##########
test/it/binder/src/test/resources/cases/dml/select.xml:
##########
@@ -478,6 +478,151 @@
         </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">
+                    <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>
+                <column name="col2" start-index="24" stop-index="27">
+                    <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>
+                <column name="col3" start-index="30" stop-index="33">
+                    <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>
+                <column name="col4" start-index="36" stop-index="39">
+                    <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>
+                <column name="col5" start-index="42" stop-index="45">
+                    <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>
+                <column name="col6" start-index="48" stop-index="51">

Review Comment:
   Hello @strongduanmu  could you give any updates on this PR.



-- 
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: notifications-unsubscribe@shardingsphere.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org