This is an automated email from the ASF dual-hosted git repository.
panjuan pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/shardingsphere.git
The following commit(s) were added to refs/heads/master by this push:
new f5cc64daf0c Add DML cases for PostgreSQL/openGauss money type (#23523)
f5cc64daf0c is described below
commit f5cc64daf0c6f0c23d44770cd0ed2966f1da8df6
Author: 吴伟杰 <[email protected]>
AuthorDate: Thu Jan 12 16:01:33 2023 +0800
Add DML cases for PostgreSQL/openGauss money type (#23523)
* Add DML insert cases for PostgreSQL/openGauss money type
* Add DML update cases for PostgreSQL/openGauss money type
* Complete BatchDMLE2EIT
---
.../shardingsphere/test/e2e/engine/BatchE2EIT.java | 8 ++++++-
.../test/e2e/engine/dml/BaseDMLE2EIT.java | 6 +++++
.../passthrough/insert_max_money_values.xml | 28 ++++++++++++++++++++++
.../passthrough/insert_min_money_values.xml | 28 ++++++++++++++++++++++
.../passthrough/insert_rounding_money_values.xml | 28 ++++++++++++++++++++++
.../dataset/passthrough/update_money_add_value.xml | 25 +++++++++++++++++++
.../passthrough/update_money_subtract_value.xml | 25 +++++++++++++++++++
.../cases/dml/dml-integration-test-cases.xml | 14 +++++++++++
.../scenario/passthrough/data/actual/dataset.xml | 1 +
.../scenario/passthrough/data/expected/dataset.xml | 1 +
10 files changed, 163 insertions(+), 1 deletion(-)
diff --git
a/test/e2e/suite/src/test/java/org/apache/shardingsphere/test/e2e/engine/BatchE2EIT.java
b/test/e2e/suite/src/test/java/org/apache/shardingsphere/test/e2e/engine/BatchE2EIT.java
index 99f7751c596..81c5f75d989 100644
---
a/test/e2e/suite/src/test/java/org/apache/shardingsphere/test/e2e/engine/BatchE2EIT.java
+++
b/test/e2e/suite/src/test/java/org/apache/shardingsphere/test/e2e/engine/BatchE2EIT.java
@@ -152,13 +152,15 @@ public abstract class BatchE2EIT extends BaseE2EIT {
int count = 0;
while (actualResultSet.next()) {
int index = 1;
- for (String each : expectedDatSetRows.get(count).splitValues(","))
{
+ for (String each : expectedDatSetRows.get(count).splitValues(",
")) {
if (Types.DATE ==
actualResultSet.getMetaData().getColumnType(index)) {
if (!NOT_VERIFY_FLAG.equals(each)) {
assertThat(new
SimpleDateFormat("yyyy-MM-dd").format(actualResultSet.getDate(index)),
is(each));
}
} else if (Types.CHAR ==
actualResultSet.getMetaData().getColumnType(index) &&
("PostgreSQL".equals(getDatabaseType().getType()) ||
"openGauss".equals(getDatabaseType().getType()))) {
assertThat(String.valueOf(actualResultSet.getObject(index)).trim(), is(each));
+ } else if
(isPostgreSQLOrOpenGaussMoney(actualResultSet.getMetaData().getColumnTypeName(index)))
{
+ assertThat(actualResultSet.getString(index), is(each));
} else {
assertThat(String.valueOf(actualResultSet.getObject(index)), is(each));
}
@@ -168,4 +170,8 @@ public abstract class BatchE2EIT extends BaseE2EIT {
}
assertThat("Size of actual result set is different with size of
expected dat set rows.", count, is(expectedDatSetRows.size()));
}
+
+ private boolean isPostgreSQLOrOpenGaussMoney(final String columnTypeName) {
+ return "money".equalsIgnoreCase(columnTypeName) &&
("PostgreSQL".equals(getDatabaseType().getType()) ||
"openGauss".equals(getDatabaseType().getType()));
+ }
}
diff --git
a/test/e2e/suite/src/test/java/org/apache/shardingsphere/test/e2e/engine/dml/BaseDMLE2EIT.java
b/test/e2e/suite/src/test/java/org/apache/shardingsphere/test/e2e/engine/dml/BaseDMLE2EIT.java
index 7f567ed7962..a9d0bf99c15 100644
---
a/test/e2e/suite/src/test/java/org/apache/shardingsphere/test/e2e/engine/dml/BaseDMLE2EIT.java
+++
b/test/e2e/suite/src/test/java/org/apache/shardingsphere/test/e2e/engine/dml/BaseDMLE2EIT.java
@@ -127,8 +127,14 @@ public abstract class BaseDMLE2EIT extends SingleE2EIT {
}
} else if (Types.CHAR ==
actual.getMetaData().getColumnType(columnIndex) &&
("PostgreSQL".equals(getDatabaseType().getType()) ||
"openGauss".equals(getDatabaseType().getType()))) {
assertThat(String.valueOf(actual.getObject(columnIndex)).trim(),
is(expected));
+ } else if
(isPostgreSQLOrOpenGaussMoney(actual.getMetaData().getColumnTypeName(columnIndex)))
{
+ assertThat(actual.getString(columnIndex), is(expected));
} else {
assertThat(String.valueOf(actual.getObject(columnIndex)),
is(expected));
}
}
+
+ private boolean isPostgreSQLOrOpenGaussMoney(final String columnTypeName) {
+ return "money".equalsIgnoreCase(columnTypeName) &&
("PostgreSQL".equals(getDatabaseType().getType()) ||
"openGauss".equals(getDatabaseType().getType()));
+ }
}
diff --git
a/test/e2e/suite/src/test/resources/cases/dml/dataset/passthrough/insert_max_money_values.xml
b/test/e2e/suite/src/test/resources/cases/dml/dataset/passthrough/insert_max_money_values.xml
new file mode 100644
index 00000000000..619aabc1f93
--- /dev/null
+++
b/test/e2e/suite/src/test/resources/cases/dml/dataset/passthrough/insert_max_money_values.xml
@@ -0,0 +1,28 @@
+<!--
+ ~ Licensed to the Apache Software Foundation (ASF) under one or more
+ ~ contributor license agreements. See the NOTICE file distributed with
+ ~ this work for additional information regarding copyright ownership.
+ ~ The ASF licenses this file to You under the Apache License, Version 2.0
+ ~ (the "License"); you may not use this file except in compliance with
+ ~ the License. You may obtain a copy of the License at
+ ~
+ ~ http://www.apache.org/licenses/LICENSE-2.0
+ ~
+ ~ Unless required by applicable law or agreed to in writing, software
+ ~ distributed under the License is distributed on an "AS IS" BASIS,
+ ~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ ~ See the License for the specific language governing permissions and
+ ~ limitations under the License.
+ -->
+
+<dataset update-count="3">
+ <metadata data-nodes="passthrough.t_data_type_money">
+ <column name="id" type="numeric" />
+ <column name="val" type="varchar" />
+ </metadata>
+ <row data-node="passthrough.t_data_type_money" values="4,
$92,233,720,368,547,758.07" />
+ <row data-node="passthrough.t_data_type_money" values="5,
$92,233,720,368,547,758.07" />
+ <row data-node="passthrough.t_data_type_money" values="6,
$92,233,720,368,547,758.07" />
+ <row data-node="passthrough.t_data_type_money" values="1001, $123.00" />
+ <row data-node="passthrough.t_data_type_money" values="1002, $456.00" />
+</dataset>
diff --git
a/test/e2e/suite/src/test/resources/cases/dml/dataset/passthrough/insert_min_money_values.xml
b/test/e2e/suite/src/test/resources/cases/dml/dataset/passthrough/insert_min_money_values.xml
new file mode 100644
index 00000000000..962e5eae9ad
--- /dev/null
+++
b/test/e2e/suite/src/test/resources/cases/dml/dataset/passthrough/insert_min_money_values.xml
@@ -0,0 +1,28 @@
+<!--
+ ~ Licensed to the Apache Software Foundation (ASF) under one or more
+ ~ contributor license agreements. See the NOTICE file distributed with
+ ~ this work for additional information regarding copyright ownership.
+ ~ The ASF licenses this file to You under the Apache License, Version 2.0
+ ~ (the "License"); you may not use this file except in compliance with
+ ~ the License. You may obtain a copy of the License at
+ ~
+ ~ http://www.apache.org/licenses/LICENSE-2.0
+ ~
+ ~ Unless required by applicable law or agreed to in writing, software
+ ~ distributed under the License is distributed on an "AS IS" BASIS,
+ ~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ ~ See the License for the specific language governing permissions and
+ ~ limitations under the License.
+ -->
+
+<dataset update-count="3">
+ <metadata data-nodes="passthrough.t_data_type_money">
+ <column name="id" type="numeric" />
+ <column name="val" type="varchar" />
+ </metadata>
+ <row data-node="passthrough.t_data_type_money" values="1,
-$92,233,720,368,547,758.08" />
+ <row data-node="passthrough.t_data_type_money" values="2,
-$92,233,720,368,547,758.08" />
+ <row data-node="passthrough.t_data_type_money" values="3,
-$92,233,720,368,547,758.08" />
+ <row data-node="passthrough.t_data_type_money" values="1001, $123.00" />
+ <row data-node="passthrough.t_data_type_money" values="1002, $456.00" />
+</dataset>
diff --git
a/test/e2e/suite/src/test/resources/cases/dml/dataset/passthrough/insert_rounding_money_values.xml
b/test/e2e/suite/src/test/resources/cases/dml/dataset/passthrough/insert_rounding_money_values.xml
new file mode 100644
index 00000000000..078ff6cef7a
--- /dev/null
+++
b/test/e2e/suite/src/test/resources/cases/dml/dataset/passthrough/insert_rounding_money_values.xml
@@ -0,0 +1,28 @@
+<!--
+ ~ Licensed to the Apache Software Foundation (ASF) under one or more
+ ~ contributor license agreements. See the NOTICE file distributed with
+ ~ this work for additional information regarding copyright ownership.
+ ~ The ASF licenses this file to You under the Apache License, Version 2.0
+ ~ (the "License"); you may not use this file except in compliance with
+ ~ the License. You may obtain a copy of the License at
+ ~
+ ~ http://www.apache.org/licenses/LICENSE-2.0
+ ~
+ ~ Unless required by applicable law or agreed to in writing, software
+ ~ distributed under the License is distributed on an "AS IS" BASIS,
+ ~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ ~ See the License for the specific language governing permissions and
+ ~ limitations under the License.
+ -->
+
+<dataset update-count="3">
+ <metadata data-nodes="passthrough.t_data_type_money">
+ <column name="id" type="numeric" />
+ <column name="val" type="varchar" />
+ </metadata>
+ <row data-node="passthrough.t_data_type_money" values="7,
$9,223,372,036,854,775.81" />
+ <row data-node="passthrough.t_data_type_money" values="8,
$9,223,372,036,854,775.80" />
+ <row data-node="passthrough.t_data_type_money" values="9,
-$9,223,372,036,854,775.81" />
+ <row data-node="passthrough.t_data_type_money" values="1001, $123.00" />
+ <row data-node="passthrough.t_data_type_money" values="1002, $456.00" />
+</dataset>
diff --git
a/test/e2e/suite/src/test/resources/cases/dml/dataset/passthrough/update_money_add_value.xml
b/test/e2e/suite/src/test/resources/cases/dml/dataset/passthrough/update_money_add_value.xml
new file mode 100644
index 00000000000..17866c44cce
--- /dev/null
+++
b/test/e2e/suite/src/test/resources/cases/dml/dataset/passthrough/update_money_add_value.xml
@@ -0,0 +1,25 @@
+<!--
+ ~ Licensed to the Apache Software Foundation (ASF) under one or more
+ ~ contributor license agreements. See the NOTICE file distributed with
+ ~ this work for additional information regarding copyright ownership.
+ ~ The ASF licenses this file to You under the Apache License, Version 2.0
+ ~ (the "License"); you may not use this file except in compliance with
+ ~ the License. You may obtain a copy of the License at
+ ~
+ ~ http://www.apache.org/licenses/LICENSE-2.0
+ ~
+ ~ Unless required by applicable law or agreed to in writing, software
+ ~ distributed under the License is distributed on an "AS IS" BASIS,
+ ~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ ~ See the License for the specific language governing permissions and
+ ~ limitations under the License.
+ -->
+
+<dataset update-count="1">
+ <metadata data-nodes="passthrough.t_data_type_money">
+ <column name="id" type="numeric" />
+ <column name="val" type="varchar" />
+ </metadata>
+ <row data-node="passthrough.t_data_type_money" values="1001, $12,468.68" />
+ <row data-node="passthrough.t_data_type_money" values="1002, $456.00" />
+</dataset>
diff --git
a/test/e2e/suite/src/test/resources/cases/dml/dataset/passthrough/update_money_subtract_value.xml
b/test/e2e/suite/src/test/resources/cases/dml/dataset/passthrough/update_money_subtract_value.xml
new file mode 100644
index 00000000000..9f3d287d925
--- /dev/null
+++
b/test/e2e/suite/src/test/resources/cases/dml/dataset/passthrough/update_money_subtract_value.xml
@@ -0,0 +1,25 @@
+<!--
+ ~ Licensed to the Apache Software Foundation (ASF) under one or more
+ ~ contributor license agreements. See the NOTICE file distributed with
+ ~ this work for additional information regarding copyright ownership.
+ ~ The ASF licenses this file to You under the Apache License, Version 2.0
+ ~ (the "License"); you may not use this file except in compliance with
+ ~ the License. You may obtain a copy of the License at
+ ~
+ ~ http://www.apache.org/licenses/LICENSE-2.0
+ ~
+ ~ Unless required by applicable law or agreed to in writing, software
+ ~ distributed under the License is distributed on an "AS IS" BASIS,
+ ~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ ~ See the License for the specific language governing permissions and
+ ~ limitations under the License.
+ -->
+
+<dataset update-count="1">
+ <metadata data-nodes="passthrough.t_data_type_money">
+ <column name="id" type="numeric" />
+ <column name="val" type="varchar" />
+ </metadata>
+ <row data-node="passthrough.t_data_type_money" values="1001, $123.00" />
+ <row data-node="passthrough.t_data_type_money" values="1002, -$11,889.68"
/>
+</dataset>
diff --git
a/test/e2e/suite/src/test/resources/cases/dml/dml-integration-test-cases.xml
b/test/e2e/suite/src/test/resources/cases/dml/dml-integration-test-cases.xml
index b11f566ab4b..8a53abcf353 100644
--- a/test/e2e/suite/src/test/resources/cases/dml/dml-integration-test-cases.xml
+++ b/test/e2e/suite/src/test/resources/cases/dml/dml-integration-test-cases.xml
@@ -312,4 +312,18 @@
<test-case sql="/* SHARDINGSPHERE_HINT: t_product.SHARDING_TABLE_VALUE=1
*/INSERT INTO t_product values (21, 'macbook2022', 4, 13999, 'on sale',
'2022-08-08')" db-types="MySQL" scenario-types="tbl">
<assertion expected-data-file="insert_into_t_product_with_hint.xml" />
</test-case>
+
+ <test-case sql="INSERT INTO t_data_type_money (id, val) VALUES (?,
?::money), (?, ?::money), (?, ?::money)" db-types="PostgreSQL,openGauss"
scenario-types="passthrough">
+ <assertion parameters="1:int, -92233720368547758.08:String, 2:int,
-$92233720368547758.08:String, 3:int, (92233720368547758.08):String"
expected-data-file="insert_min_money_values.xml"/>
+ <assertion parameters="4:int, 92233720368547758.07:String, 5:int,
$92233720368547758.07:String, 6:int, 92233720368547758.07:String"
expected-data-file="insert_max_money_values.xml"/>
+ <assertion parameters="7:int, 9223372036854775.807:String, 8:int,
9223372036854775.804:String, 9:int, -9223372036854775.807:String"
expected-data-file="insert_rounding_money_values.xml"/>
+ </test-case>
+
+ <test-case sql="UPDATE t_data_type_money SET val = val + ?::money WHERE id
= ?" db-types="PostgreSQL,openGauss" scenario-types="passthrough">
+ <assertion parameters="12345.6789:String, 1001:int"
expected-data-file="update_money_add_value.xml"/>
+ </test-case>
+
+ <test-case sql="UPDATE t_data_type_money SET val = val + ?::money WHERE id
= ?" db-types="PostgreSQL,openGauss" scenario-types="passthrough">
+ <assertion parameters="-12345.6789:String, 1002:int"
expected-data-file="update_money_subtract_value.xml"/>
+ </test-case>
</integration-test-cases>
diff --git
a/test/e2e/suite/src/test/resources/env/scenario/passthrough/data/actual/dataset.xml
b/test/e2e/suite/src/test/resources/env/scenario/passthrough/data/actual/dataset.xml
index bb86f1aaecd..452f4a4a7bc 100644
---
a/test/e2e/suite/src/test/resources/env/scenario/passthrough/data/actual/dataset.xml
+++
b/test/e2e/suite/src/test/resources/env/scenario/passthrough/data/actual/dataset.xml
@@ -48,4 +48,5 @@
<row data-node="passthrough.t_data_type_integer_unsigned" values="1001,
18446744073709551615, 4294967295, 16777215, 65535, 255" />
<row data-node="passthrough.t_data_type_integer_unsigned" values="1002, 0,
0, 0, 0, 0" />
<row data-node="passthrough.t_data_type_money" values="1001, 123" />
+ <row data-node="passthrough.t_data_type_money" values="1002, 456" />
</dataset>
diff --git
a/test/e2e/suite/src/test/resources/env/scenario/passthrough/data/expected/dataset.xml
b/test/e2e/suite/src/test/resources/env/scenario/passthrough/data/expected/dataset.xml
index 8fab50338d8..a47c11cc5a1 100644
---
a/test/e2e/suite/src/test/resources/env/scenario/passthrough/data/expected/dataset.xml
+++
b/test/e2e/suite/src/test/resources/env/scenario/passthrough/data/expected/dataset.xml
@@ -48,4 +48,5 @@
<row data-node="expected_dataset.t_data_type_integer_unsigned"
values="1001, 18446744073709551615, 4294967295, 16777215, 65535, 255" />
<row data-node="expected_dataset.t_data_type_integer_unsigned"
values="1002, 0, 0, 0, 0, 0" />
<row data-node="expected_dataset.t_data_type_money" values="1001, 123" />
+ <row data-node="expected_dataset.t_data_type_money" values="1002, 456" />
</dataset>