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 parsing SQL Server SELECT name, sql #29627

Merged
merged 13 commits into from
Jan 5, 2024
Merged

Conversation

yydeng626
Copy link
Collaborator

Fixes #29174.

Changes proposed in this pull request:

SELECT ProductId, Name, value
FROM Product
    CROSS APPLY STRING_SPLIT(Tags, ',')
SELECT value as tag, COUNT(*) AS [number_of_articles]
FROM Product
    CROSS APPLY STRING_SPLIT(Tags, ',')
GROUP BY value
HAVING COUNT(*) > 2
ORDER BY COUNT(*) DESC
SELECT ProductId, Name, Tags
FROM Product
WHERE EXISTS (SELECT *
    FROM STRING_SPLIT(Tags, ',')
    WHERE value IN ('clothing', 'road'))
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'

Before committing this PR, I'm sure that I have checked the following options:

  • My code follows the code of conduct 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.

# Conflicts:
#	parser/sql/dialect/sqlserver/src/main/antlr4/imports/sqlserver/BaseRule.g4
#	parser/sql/dialect/sqlserver/src/main/antlr4/imports/sqlserver/DMLStatement.g4
#	parser/sql/dialect/sqlserver/src/main/java/org/apache/shardingsphere/sql/parser/sqlserver/visitor/statement/SQLServerStatementVisitor.java
#	test/it/parser/src/main/resources/case/dml/select.xml
#	test/it/parser/src/main/resources/sql/supported/dml/select.xml
@strongduanmu
Copy link
Member

Hi @yydeng626, can you solve code conflict?

# Conflicts:
#	parser/sql/dialect/sqlserver/src/main/antlr4/imports/sqlserver/BaseRule.g4
#	test/it/parser/src/main/resources/case/dml/insert.xml
#	test/it/parser/src/main/resources/sql/supported/dml/insert.xml
@yydeng626
Copy link
Collaborator Author

Sure, I will solve the conflicts.

@yydeng626
Copy link
Collaborator Author

@strongduanmu Please check again

@@ -692,3 +692,6 @@ WITHOUT
: W I T H O U T
;

APPLY
: A P P L Y
;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add new line at the end of file.

@@ -295,4 +296,27 @@ public static void setWhereSegment(final InsertStatement insertStatement, final
((OracleInsertStatement) insertStatement).setWhere(whereSegment);
}
}

/**
* get execute segment.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please use Get in javadoc for first word.


/**
* get execute segment.
* @param insertStatement insert statement
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add new line after javadoc and param.

import java.util.LinkedList;

/**
* execute segment.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please use Execute for first word in javadoc.

*/
@RequiredArgsConstructor
@Getter
public class ExecSegment implements SQLSegment {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add final for this class.

import java.util.List;

/**
* MySQL call statement.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please replace MySQL with SQLServer.

import static org.junit.jupiter.api.Assertions.assertTrue;

/**
* insert execute clause assert.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please use Insert for first word.

public class InsertExecClauseAssert {

/**
* Assert actual execute segment is correct with expected execute clause.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add new line after java doc.

assertTrue(actual.getProcedureName().getOwner().isPresent(), assertContext.getText("Actual owner should exist."));
OwnerAssert.assertIs(assertContext, actual.getProcedureName().getOwner().get(), expected.getOwner());
}

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please remove this useless blank line.

@@ -591,4 +591,44 @@
</subquery-table>
</from>
</select>

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please keep one blank line here.

Copy link
Member

@strongduanmu strongduanmu left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@yydeng626 Good job, merged.

@strongduanmu strongduanmu merged commit 55065b7 into apache:master Jan 5, 2024
133 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Support parsing SQL Server SELECT name, sql
2 participants