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

Added Support for SQL Server INSERT INTO Parsing #29230

Closed
wants to merge 5 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
128 changes: 3 additions & 125 deletions test/it/parser/src/main/resources/case/dml/insert.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2952,42 +2952,6 @@
</values>
</insert>

<insert sql-case-id="insert_with_nchar_4">
<table name="@table1" start-index="7" stop-index="13"/>
<columns start-index="15" stop-index="32">
<column name="c2" start-index="16" stop-index="17"/>
<column name="is_transient" start-index="20" stop-index="31"/>
</columns>
<values>
<value>
<assignment-value>
<literal-expression value="sample durable" start-index="42" stop-index="58"/>
</assignment-value>
<assignment-value>
<literal-expression value="0" start-index="61" stop-index="61"/>
</assignment-value>
</value>
</values>
</insert>

<insert sql-case-id="insert_with_nchar_5">
<table name="@table1" start-index="7" stop-index="13"/>
<columns start-index="15" stop-index="32">
<column name="c2" start-index="16" stop-index="17"/>
<column name="is_transient" start-index="20" stop-index="31"/>
</columns>
<values>
<value>
<assignment-value>
<literal-expression value="sample non-durable" start-index="42" stop-index="62"/>
</assignment-value>
<assignment-value>
<literal-expression value="1" start-index="65" stop-index="65"/>
</assignment-value>
</value>
</values>
</insert>

<insert sql-case-id="insert_with_data_base_name">
<table name="VariableTest" start-index="12" stop-index="46">
<owner name="dbo" start-index="31" stop-index="33">
Expand Down Expand Up @@ -3042,99 +3006,13 @@
</values>
</insert>

<insert sql-case-id="insert_with_db_schema_name">
<table name="Affiliation" start-index="12" stop-index="43">
<owner name="dbo" start-index="29" stop-index="31">
<owner name="ContosoWarehouse" start-index="12" stop-index="27"/>
</owner>
</table>
<columns start-index="44" stop-index="44"/>
<select>
<projections start-index="52" stop-index="52">
<shorthand-projection start-index="52" stop-index="52"/>
</projections>
<from>
<simple-table name="Affiliation" start-index="59" stop-index="86">
<owner name="dbo" start-index="72" stop-index="74">
<owner name="My_Lakehouse" start-index="59" stop-index="70"/>
</owner>
</simple-table>
</from>
</select>
</insert>

<insert sql-case-id="insert_with_exec">
<table name="iris_rx_data" start-index="12" stop-index="23" />
<columns start-index="25" stop-index="98">
<column name="Sepal.Length" start-delimiter="&quot;" end-delimiter="&quot;" start-index="26" stop-index="39"/>
<column name="Sepal.Width" start-delimiter="&quot;" end-delimiter="&quot;" start-index="42" stop-index="54"/>
<column name="Petal.Length" start-delimiter="&quot;" end-delimiter="&quot;" start-index="57" stop-index="70"/>
<column name="Petal.Width" start-delimiter="&quot;" end-delimiter="&quot;" start-index="73" stop-index="85"/>
<column name="Species" start-delimiter="&quot;" end-delimiter="&quot;" start-index="89" stop-index="97"/>
</columns>
<exec name="sp_execute_external_script" start-index="100" stop-index="183">
<parameter>
<binary-operation-expression start-index="135" stop-index="150">
<left>
<column start-index="135" stop-index="143" name="@language" />
</left>
<operator>=</operator>
<right>
<literal-expression value="R" start-index="147" stop-index="150" />
</right>
</binary-operation-expression>
</parameter>
<parameter>
<binary-operation-expression start-index="154" stop-index="183">
<left>
<column start-index="154" stop-index="160" name="@script" />
</left>
<operator>=</operator>
<right>
<literal-expression value="iris_data &lt;- iris" start-index="164" stop-index="183" />
</right>
</binary-operation-expression>
</parameter>
</exec>
</insert>

<insert sql-case-id="insert_into_temp_table">
<table name="#NonExistentTable" start-index="12" stop-index="28"/>
<columns start-index="29" stop-index="29"/>
<values>
<value>
<assignment-value>
<literal-expression value="10" start-index="38" stop-index="39"/>
</assignment-value>
</value>
</values>
</insert>

<insert sql-case-id="insert_into_temp_table_with_null_value">
<columns start-index="28" stop-index="28"/>
<table name="#SampleTempTable" start-index="12" stop-index="27"/>
<values>
<value>
<assignment-value>
<literal-expression value="10" start-index="37" stop-index="38"/>
</assignment-value>
<assignment-value>
<literal-expression value="null" start-index="41" stop-index="44"/>
</assignment-value>
</value>
</values>
</insert>

<insert sql-case-id="insert_into_temp_table_with_all_null_value">
<columns start-index="28" stop-index="28"/>
<table name="#SampleTempTable" start-index="12" stop-index="27"/>
<table name="#MyTempTable" start-index="12" stop-index="23"/>
<columns start-index="24" stop-index="24"/>
<values>
<value>
<assignment-value>
<literal-expression value="null" start-index="37" stop-index="40"/>
</assignment-value>
<assignment-value>
<literal-expression value="null" start-index="43" stop-index="46"/>
<literal-expression value="1" start-index="33" stop-index="33"/>
</assignment-value>
</value>
</values>
Expand Down
18 changes: 18 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 @@ -3126,6 +3126,24 @@
</projections>
</select>

<select sql-case-id="select_test1col_from_temp_table">
<projections start-index="7" stop-index="18">
<column-projection start-index="7" stop-index="18" name="x" alias="Test1Col" />
</projections>
<from>
<simple-table name="#t" start-index="25" stop-index="26" />
</from>
</select>

<select sql-case-id="select_test2col_from_temp_table">
<projections start-index="7" stop-index="18">
<column-projection start-index="7" stop-index="18" name="x" alias="Test2Col" />
</projections>
<from>
<simple-table name="#t" start-index="25" stop-index="26" />
</from>
</select>

<select sql-case-id="select_with_case_when_from_sys">
<from start-index="651" stop-index="681">
<simple-table name="database_files" start-index="651" stop-index="681" alias="df">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,10 +106,9 @@
<sql-case id="insert_with_nchar_1" value="INSERT INTO dbo.T1 VALUES (1, N'Natalia')" db-types="SQLServer"/>
<sql-case id="insert_with_nchar_2" value="INSERT INTO dbo.T1 VALUES (2, N'Mark')" db-types="SQLServer"/>
<sql-case id="insert_with_nchar_3" value="INSERT INTO dbo.T1 VALUES (3, N'Randolph')" db-types="SQLServer"/>
<sql-case id="insert_with_nchar_4" value="INSERT @table1 (c2, is_transient) VALUES (N'sample durable', 0)" db-types="SQLServer"/>
<sql-case id="insert_with_nchar_5" value="INSERT @table1 (c2, is_transient) VALUES (N'sample non-durable', 1)" db-types="SQLServer"/>
<sql-case id="insert_with_batch_nchar" value="INSERT INTO TestSchema.Employees (Name, Location) VALUES (N'Jared', N'Australia'), (N'Nikita', N'India'), (N'Tom', N'Germany')" db-types="SQLServer"/>
<sql-case id="insert_with_data_base_name" value="INSERT INTO AdventureWorks2022.dbo.VariableTest(Col1) VALUES('$(tablename)')" db-types="SQLServer"/>
<sql-case id="insert_into_temp_table" value="INSERT INTO #MyTempTable VALUES (1)" db-types="SQLServer"/>
<sql-case id="insert_with_exec" value="INSERT INTO iris_rx_data (&quot;Sepal.Length&quot;, &quot;Sepal.Width&quot;, &quot;Petal.Length&quot;, &quot;Petal.Width&quot; , &quot;Species&quot;) EXECUTE sp_execute_external_script @language = N'R' , @script = N'iris_data &lt;- iris'" db-types="SQLServer"/>
<sql-case id="insert_with_db_schema_name" value="INSERT INTO ContosoWarehouse.dbo.Affiliation SELECT * FROM My_Lakehouse.dbo.Affiliation" db-types="SQLServer"/>
<sql-case id="insert_into_temp_table" value="INSERT INTO #NonExistentTable values (10)" db-types="SQLServer"/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -136,5 +136,7 @@
<sql-case id="select_set_masklen_function" value="SELECT set_masklen('192.168.1.0/24'::cidr, 16) AS RESULT;" db-types="openGauss" />
<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_test1col_from_temp_table" value="SELECT Test1Col = x FROM #t" db-types="SQLServer"/>
<sql-case id="select_test2col_from_temp_table" value="SELECT Test2Col = x FROM #t" db-types="SQLServer"/>
<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-cases>
Loading