shardingsphere
shardingsphere copied to clipboard
Support parsing SQL Server SELECT state_desc sql
Background
Hi community. This issue is for #29149.
The ShardingSphere SQL parser engine helps users to parse SQL to create the AST (Abstract Syntax Tree) and visit the AST to get SQLStatement (Java Object). Currently, we are planning to enhance the support for SQL Server
SQL parsing in ShardingSphere.
More details: https://shardingsphere.apache.org/document/current/en/reference/sharding/parse/
Task
This issue is to support more SQL Server
sql parsing, as follows:
SELECT state_desc
, file_type_desc
, COUNT(*) AS [count]
, SUM(CASE
WHEN state = 5 AND file_type=0 THEN 128*1024*1024
WHEN state = 5 AND file_type=1 THEN 8*1024*1024
WHEN state IN (6,7) THEN 68*1024*1024
ELSE file_size_in_bytes
END) / 1024 / 1024 AS [on-disk size MB]
FROM sys.dm_db_xtp_checkpoint_files
GROUP BY state, state_desc, file_type, file_type_desc
ORDER BY state, file_type
SELECT state_desc
, file_type_desc
, COUNT(*) AS [count]
, SUM(CASE
WHEN state = 5 AND file_type=0 THEN 128*1024*1024
WHEN state = 5 AND file_type=1 THEN 8*1024*1024
WHEN state IN (6,7) THEN 68*1024*1024
ELSE file_size_in_bytes
END) / 1024 / 1024 AS [on-disk size MB]
FROM sys.dm_db_xtp_checkpoint_files
GROUP BY state, state_desc, file_type, file_type_desc
ORDER BY state, file_type
SELECT state_desc
, file_type_desc
, COUNT(*) AS [count]
, SUM(CASE
WHEN state = 5 AND file_type=0 THEN 128*1024*1024
WHEN state = 5 AND file_type=1 THEN 8*1024*1024
WHEN state IN (6,7) THEN 68*1024*1024
ELSE file_size_in_bytes
END) / 1024 / 1024 AS [on-disk size MB]
FROM sys.dm_db_xtp_checkpoint_files
GROUP BY state, state_desc, file_type, file_type_desc
ORDER BY state, file_type
SELECT state_desc
, file_type_desc
, COUNT(*) AS [count]
, SUM(CASE
WHEN state = 5 AND file_type=0 THEN 128*1024*1024
WHEN state = 5 AND file_type=1 THEN 8*1024*1024
WHEN state IN (6,7) THEN 68*1024*1024
ELSE file_size_in_bytes
END) / 1024 / 1024 AS [on-disk size MB]
FROM sys.dm_db_xtp_checkpoint_files
GROUP BY state, state_desc, file_type, file_type_desc
ORDER BY state, file_type
SELECT PersonName, Friends
FROM (
SELECT
Person1.name AS PersonName,
STRING_AGG(Person2.name, '->') WITHIN GROUP (GRAPH PATH) AS Friends,
LAST_VALUE(Person2.name) WITHIN GROUP (GRAPH PATH) AS LastNode
FROM
Person AS Person1,
friendOf FOR PATH AS fo,
Person FOR PATH AS Person2
WHERE MATCH(SHORTEST_PATH(Person1(-(fo)->Person2)+))
AND Person1.name = 'Jacob'
) AS Q
WHERE Q.LastNode = 'Alice'
Process
- First confirm that this is a correct
SQL Server
sql syntax, if not please leave a message under the issue and ignore it; - Compare SQL definitions in Official SQL Doc and ShardingSphere SQL Doc;
- If there is any difference in ShardingSphere SQL Doc, please correct them by referring to the Official SQL Doc;
- Run mvn install the current_file_module;
- Check whether there are any exceptions. If indeed, please fix them. (Especially xxxVisitor.class);
- Add new corresponding SQL case in SQL Cases and expected parsed result in Expected Statement XML;
- Run SQLParserParameterizedTest to make sure no exceptions.
Relevant Skills
- Master JAVA language
- Have a basic understanding of Antlr
g4
file - Be familiar with
SQL Server
SQLs
There hasn't been any activity on this issue recently, and in order to prioritize active issues, it will be marked as stale.
Hi @strongduanmu
I would like to do this issue, could you please assign it to me?
@KonarzewskiP Of course, I just assign it to you.
@strongduanmu
Thanks! I have one question, is there any helpful information/table/source for translating SQL to XML test cases or we need to figure out everything by ourselves? I am happy to do it by myself, but if there is some kind of table or documentation it would save a lot of time.
Hi @KonarzewskiP, You can refer to other similar cases, then copy the XML file into the newly added Case, and then modify the expected value. This is probably the fastest way I know of.
OK, thank you.
Hi @strongduanmu
Is there a possibility to run just 1-2 test case instead of +500 each time?
Hi @strongduanmu
Is there a possibility to run just 1-2 test case instead of +500 each time?
You can control case by modifying InternalSQLParserIT.
public abstract class InternalSQLParserIT {
private static final SQLCases SQL_CASES = SQLCasesRegistry.getInstance().getCases();
private static final SQLParserTestCases SQL_PARSER_TEST_CASES = SQLParserTestCasesRegistry.getInstance().getCases();
@ParameterizedTest(name = "{0} ({1}) -> {2}")
@ArgumentsSource(TestCaseArgumentsProvider.class)
void assertSupportedSQL(final String sqlCaseId, final SQLCaseType sqlCaseType, final String databaseType) {
if (!sqlCaseId.equals("xxx")) {
return;
}
String sql = SQL_CASES.getSQL(sqlCaseId, sqlCaseType, SQL_PARSER_TEST_CASES.get(sqlCaseId).getParameters());
SQLStatement actual = parseSQLStatement("H2".equals(databaseType) ? "MySQL" : databaseType, sql);
SQLParserTestCase expected = SQL_PARSER_TEST_CASES.get(sqlCaseId);
SQLStatementAssert.assertIs(new SQLCaseAssertContext(sqlCaseId, sql, expected.getParameters(), sqlCaseType), actual, expected);
}
@strongduanmu
Amazing, thank you very much!
There hasn't been any activity on this issue recently, and in order to prioritize active issues, it will be marked as stale.
All sql case has been supported, so I will close this issue.