Skip to content

Commit

Permalink
Support parsing SQL Server SELECT state_desc sql (apache#29188)
Browse files Browse the repository at this point in the history
  • Loading branch information
KonarzewskiP committed Mar 16, 2024
1 parent dbc7c28 commit 56bf22e
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 0 deletions.
44 changes: 44 additions & 0 deletions test/it/parser/src/main/resources/case/dml/select-expression.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3178,4 +3178,48 @@
</expression-projection>
</projections>
</select>

<select sql-case-id="select_with_case_when_group_by_order_by">
<projections start-index="7" stop-index="177">
<column-projection name="state_desc" start-index="7" stop-index="16"/>
<column-projection name="file_type_desc" start-index="19" stop-index="32"/>
<aggregation-projection type="COUNT" expression="COUNT(*)" start-index="35" stop-index="42" alias="count"/>
<expression-projection alias="on-disk size MB"
text="SUM(CASE WHEN state = 5 AND file_type=0 THEN 128*1024*1024 ELSE file_size_in_bytes END) / 1024 / 1024"
start-index="56" stop-index="177">
<expr>
<binary-operation-expression start-index="56" stop-index="156">
<left>
<binary-operation-expression start-index="56" stop-index="149">
<left>
<aggregation-projection start-index="56" stop-index="142" type="SUM"
expression="SUM(CASE WHEN state = 5 AND file_type=0 THEN 128*1024*1024 ELSE file_size_in_bytes END)"
parameters="CASEWHENstate=5ANDfile_type=0THEN128*1024*1024ELSEfile_size_in_bytesEND">
<expression-projection start-index="40" stop-index="142" text="CASEWHENstate=5ANDfile_type=0THEN128*1024*1024ELSEfile_size_in_bytesEND">
<expr>
<common-expression literal-text="CASEWHENstate=5ANDfile_type=0THEN128*1024*1024ELSEfile_size_in_bytesEND" start-index="40" stop-index="142"/>
</expr>
</expression-projection>
</aggregation-projection>
</left>
<operator>/</operator>
<right>
<literal-expression value="1024" start-index="146" stop-index="149"/>
</right>
</binary-operation-expression>
</left>
<operator>/</operator>
<right>
<literal-expression value="1024" start-index="153" stop-index="156"/>
</right>
</binary-operation-expression>
</expr>
</expression-projection>
</projections>
<from start-index="188" stop-index="213">
<simple-table name="dm_db_xtp_checkpoint_files" start-index="184" stop-index="213">
<owner name="sys" start-index="184" stop-index="186"/>
</simple-table>
</from>
</select>
</sql-parser-test-cases>
Original file line number Diff line number Diff line change
Expand Up @@ -137,4 +137,5 @@
<sql-case id="select_text_inet_function" value="SELECT text(inet '192.168.1.5') AS RESULT;" db-types="openGauss" />
<sql-case id="select_trunc_function" value="SELECT trunc(macaddr '12:34:56:78:90:ab') AS RESULT;" db-types="openGauss" />
<sql-case id="select_with_case_when_from_sys" value="SELECT FileName = df.name, current_file_size_MB = df.size*1.0/128, max_size = CASE df.max_size WHEN 0 THEN 'Autogrowth is off.' WHEN -1 THEN 'Autogrowth is on.' ELSE 'Log file grows to a maximum size of 2 TB.' END, growth_value = CASE WHEN df.growth = 0 THEN df.growth WHEN df.growth > 0 AND df.is_percent_growth = 0 THEN df.growth*1.0/128.0 WHEN df.growth > 0 AND df.is_percent_growth = 1 THEN df.growth END, growth_increment_unit = CASE WHEN df.growth = 0 THEN 'Size is fixed.' WHEN df.growth > 0 AND df.is_percent_growth = 0 THEN 'Growth value is MB.' WHEN df.growth > 0 AND df.is_percent_growth = 1 THEN 'Growth value is a percentage.' END FROM tempdb.sys.database_files AS df" db-types="SQLServer"/>
<sql-case id="select_with_case_when_group_by_order_by" value="SELECT state_desc, file_type_desc, COUNT(*) AS [count], SUM(CASE WHEN state = 5 AND file_type=0 THEN 128*1024*1024 ELSE file_size_in_bytes END) / 1024 / 1024 AS [on-disk size MB] FROM sys.dm_db_xtp_checkpoint_files" db-types="SQLServer"/>
</sql-cases>

0 comments on commit 56bf22e

Please sign in to comment.