You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@shardingsphere.apache.org by "yydeng626 (via GitHub)" <gi...@apache.org> on 2024/01/26 11:00:41 UTC
[PR] Support parsing SQL Server SELECT ProductId, sql #29159 [shardingsphere]
yydeng626 opened a new pull request, #29868:
URL: https://github.com/apache/shardingsphere/pull/29868
Fixes #29159.
Changes proposed in this pull request:
- support window function feature
- support sql :
```
1. SELECT ProductId, Name, Tags
FROM Product
WHERE EXISTS (SELECT *
FROM STRING_SPLIT(Tags, ',')
WHERE value IN ('clothing', 'road'))
2. SELECT BusinessEntityID
, DATEPART(QUARTER, QuotaDate) AS Quarter
, YEAR(QuotaDate) AS SalesYear
, SalesQuota AS QuotaThisQuarter
, SalesQuota - FIRST_VALUE(SalesQuota)
OVER (PARTITION BY BusinessEntityID, YEAR(QuotaDate)
ORDER BY DATEPART(QUARTER, QuotaDate)) AS DifferenceFromFirstQuarter
, SalesQuota - LAST_VALUE(SalesQuota)
OVER (PARTITION BY BusinessEntityID, YEAR(QuotaDate)
ORDER BY DATEPART(QUARTER, QuotaDate)
RANGE BETWEEN CURRENT ROW AND UNBOUNDED FOLLOWING) AS DifferenceFromLastQuarter
FROM Sales.SalesPersonQuotaHistory
WHERE YEAR(QuotaDate) > 2005 AND BusinessEntityID BETWEEN 274 AND 275
ORDER BY BusinessEntityID, SalesYear, Quarter
3. INSERT INTO iris_rx_data ("Sepal.Length", "Sepal.Width", "Petal.Length", "Petal.Width" , "Species")
EXECUTE sp_execute_external_script
@language = N'R'
, @script = N'iris_data <- iris'
4. INSERT INTO prediction_results (
tipped_Pred
,payment_type
,tipped
,passenger_count
,trip_distance
,trip_time_in_secs
,direct_distance
)
EXECUTE [predict_per_partition]
5. INSERT INTO TestBatch VALUSE (3, 'ccc') // error syntax do not explain
```
---
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.
--
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] Support parsing SQL Server SELECT ProductId, sql #29159 [shardingsphere]
Posted by "yydeng626 (via GitHub)" <gi...@apache.org>.
yydeng626 commented on PR #29868:
URL: https://github.com/apache/shardingsphere/pull/29868#issuecomment-1914417787
@strongduanmu I have already fix the code style, please check again
--
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] Support parsing SQL Server SELECT ProductId, sql #29159 [shardingsphere]
Posted by "strongduanmu (via GitHub)" <gi...@apache.org>.
strongduanmu commented on code in PR #29868:
URL: https://github.com/apache/shardingsphere/pull/29868#discussion_r1469072600
##########
parser/sql/dialect/sqlserver/src/main/java/org/apache/shardingsphere/sql/parser/sqlserver/visitor/statement/SQLServerStatementVisitor.java:
##########
@@ -977,8 +985,19 @@ private SQLServerSelectStatement visitOrderBy(final SQLServerSelectStatement sel
if (null != offset) {
limitSegment = new LimitSegment(ctx.OFFSET().getSymbol().getStartIndex(), ctx.stop.getStopIndex(), offset, rowcount);
}
- selectStatement.setLimit(limitSegment);
- return selectStatement;
+ return limitSegment;
+ }
+
+ private OrderBySegment getOrderBySegment(final OrderByClauseContext ctx) {
+ Collection<OrderByItemSegment> items = new LinkedList<>();
+ int orderByStartIndex = ctx.start.getStartIndex();
+ int orderByStopIndex = ctx.start.getStartIndex();
+ for (OrderByItemContext each : ctx.orderByItem()) {
+ items.add((OrderByItemSegment) visit(each));
+ orderByStopIndex = each.stop.getStopIndex();
+ }
+ OrderBySegment orderBySegment = new OrderBySegment(orderByStartIndex, orderByStopIndex, items);
Review Comment:
Please return `new OrderBySegment(orderByStartIndex, orderByStopIndex, items);` directly.
##########
parser/sql/dialect/sqlserver/src/main/java/org/apache/shardingsphere/sql/parser/sqlserver/visitor/statement/SQLServerStatementVisitor.java:
##########
@@ -944,15 +955,12 @@ public ASTNode visitHavingClause(final HavingClauseContext ctx) {
}
private SQLServerSelectStatement visitOrderBy(final SQLServerSelectStatement selectStatement, final OrderByClauseContext ctx) {
- Collection<OrderByItemSegment> items = new LinkedList<>();
- int orderByStartIndex = ctx.start.getStartIndex();
- int orderByStopIndex = ctx.start.getStartIndex();
- for (OrderByItemContext each : ctx.orderByItem()) {
- items.add((OrderByItemSegment) visit(each));
- orderByStopIndex = each.stop.getStopIndex();
- }
- OrderBySegment orderBySegment = new OrderBySegment(orderByStartIndex, orderByStopIndex, items);
- selectStatement.setOrderBy(orderBySegment);
+ selectStatement.setOrderBy(getOrderBySegment(ctx));
+ selectStatement.setLimit(getLimitSegment(ctx));
+ return selectStatement;
Review Comment:
Please rename this param to result.
##########
parser/sql/dialect/sqlserver/src/main/java/org/apache/shardingsphere/sql/parser/sqlserver/visitor/statement/SQLServerStatementVisitor.java:
##########
@@ -977,8 +985,19 @@ private SQLServerSelectStatement visitOrderBy(final SQLServerSelectStatement sel
if (null != offset) {
limitSegment = new LimitSegment(ctx.OFFSET().getSymbol().getStartIndex(), ctx.stop.getStopIndex(), offset, rowcount);
}
- selectStatement.setLimit(limitSegment);
- return selectStatement;
+ return limitSegment;
Review Comment:
Please rename this param to result.
--
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] Support parsing SQL Server SELECT ProductId, sql #29159 [shardingsphere]
Posted by "strongduanmu (via GitHub)" <gi...@apache.org>.
strongduanmu merged PR #29868:
URL: https://github.com/apache/shardingsphere/pull/29868
--
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