From 55da6d1f19c75f4a1adccb7b6f445e2263c29b40 Mon Sep 17 00:00:00 2001 From: Dylan Chen Date: Wed, 10 Apr 2024 15:54:47 +0800 Subject: [PATCH 1/3] fix decimal jdbc sink --- src/jni_core/src/lib.rs | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/src/jni_core/src/lib.rs b/src/jni_core/src/lib.rs index 032d2f3deb54..1b7eed14d891 100644 --- a/src/jni_core/src/lib.rs +++ b/src/jni_core/src/lib.rs @@ -47,7 +47,7 @@ use risingwave_common::array::{ArrayError, StreamChunk}; use risingwave_common::hash::VirtualNode; use risingwave_common::row::{OwnedRow, Row}; use risingwave_common::test_prelude::StreamChunkTestExt; -use risingwave_common::types::ScalarRefImpl; +use risingwave_common::types::{Decimal, ScalarRefImpl}; use risingwave_common::util::panic::rw_catch_unwind; use risingwave_pb::connector_service::{ GetEventStreamResponse, SinkCoordinatorStreamRequest, SinkCoordinatorStreamResponse, @@ -767,11 +767,20 @@ extern "system" fn Java_com_risingwave_java_binding_Binding_iteratorGetDecimalVa idx: jint, ) -> JObject<'a> { execute_and_catch(env, move |env: &mut EnvParam<'_>| { - let value = pointer + let decimal_value = pointer .as_ref() .datum_at(idx as usize) .unwrap() - .into_decimal() + .into_decimal(); + + match decimal_value { + Decimal::NaN | Decimal::NegativeInf | Decimal::PositiveInf => { + return Ok(JObject::null()); + } + Decimal::Normalized(_) => {} + }; + + let value = decimal_value .to_string(); let string_value = env.new_string(value)?; let (decimal_class_ref, constructor) = pointer From a9e6479c472771953b60f0ddb624f9989a823d08 Mon Sep 17 00:00:00 2001 From: Dylan Chen Date: Wed, 10 Apr 2024 18:05:56 +0800 Subject: [PATCH 2/3] add tests --- e2e_test/sink/remote/jdbc.check.pg.slt | 4 ++-- e2e_test/sink/remote/jdbc.load.slt | 4 ++-- e2e_test/sink/remote/mysql_expected_result_2.tsv | 4 ++-- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/e2e_test/sink/remote/jdbc.check.pg.slt b/e2e_test/sink/remote/jdbc.check.pg.slt index d52481bed4e6..0c29969445d2 100644 --- a/e2e_test/sink/remote/jdbc.check.pg.slt +++ b/e2e_test/sink/remote/jdbc.check.pg.slt @@ -23,8 +23,8 @@ query III select * from biz.t_types order by id; ---- 1 Varcharvalue1 Textvalue1 123 456 789 12.34 56.78 90.12 t 2023-05-22 12:34:56 2023-05-22 12:34:56 1 day {"key": "value"} {"Value 1","Value 2"} {12.345,56.789} {1,2,3} {1,2,3} {1,2,3} {12.3,56.7} -2 Varcharvalue2 Textvalue2 234 567 890 23.45 67.89 1.23 f 2023-05-23 23:45:01 2023-05-23 23:45:01 2 days {"key": "value2"} {"Value 3","Value 4"} {43.21,65.432} {4,5,6} {4,5,6} {4,5,6} {43.2,65.4} -3 Varcharvalue1 Textvalue1 123 456 789 12.34 56.78 90.12 t 2023-05-22 12:34:56 2023-05-22 12:34:56 1 day {"key": "value"} {"How're you?","\"hello\\ \\world\""} {12.345,56.789} {1,2,3} {1,2,3} {1,2,3} {43.2,65.4} +2 Varcharvalue2 Textvalue2 234 567 890 NULL 67.89 1.23 f 2023-05-23 23:45:01 2023-05-23 23:45:01 2 days {"key": "value2"} {"Value 3","Value 4"} {43.21,65.432} {4,5,6} {4,5,6} {4,5,6} {43.2,65.4} +3 Varcharvalue1 Textvalue1 123 456 789 NULL 56.78 90.12 t 2023-05-22 12:34:56 2023-05-22 12:34:56 1 day {"key": "value"} {"How're you?","\"hello\\ \\world\""} {12.345,56.789} {1,2,3} {1,2,3} {1,2,3} {43.2,65.4} query IT diff --git a/e2e_test/sink/remote/jdbc.load.slt b/e2e_test/sink/remote/jdbc.load.slt index 80f319443ce0..a453c76feeb7 100644 --- a/e2e_test/sink/remote/jdbc.load.slt +++ b/e2e_test/sink/remote/jdbc.load.slt @@ -202,8 +202,8 @@ INSERT INTO t_remote_1 VALUES statement ok INSERT INTO rw_typed_data (id, varchar_column, text_column, integer_column, smallint_column, bigint_column, decimal_column, real_column, double_column, boolean_column, date_column, time_column, timestamp_column, interval_column, jsonb_column, array_column, array_column2, array_column3, array_column4, array_column5, array_column6) VALUES (1, 'Varcharvalue1', 'Textvalue1', 123, 456, 789, 12.34, 56.78, 90.12, TRUE, '2023-05-22', '12:34:56', '2023-05-22 12:34:56', '1 day', '{"key": "value"}', ARRAY['Value 1', 'Value 2'], '{12.345,56.789}', '{1, 2, 3}', '{1, 2, 3}', '{1, 2, 3}', '{12.3,56.7}'), - (2, 'Varcharvalue2', 'Textvalue2', 234, 567, 890, 23.45, 67.89, 01.23, FALSE, '2023-05-23', '23:45:01', '2023-05-23 23:45:01', '2 days', '{"key": "value2"}', ARRAY['Value 3', 'Value 4'], '{43.21,65.432}', '{4, 5, 6}', '{4, 5, 6}', '{4, 5, 6}', '{43.2,65.4}'), - (3, 'Varcharvalue1', 'Textvalue1', 123, 456, 789, 12.34, 56.78, 90.12, TRUE, '2023-05-22', '12:34:56', '2023-05-22 12:34:56', '1 day', '{"key": "value"}', ARRAY['How''re you?', '"hello\ \world"'], ARRAY[12.345,56.789], ARRAY[1, 2, 3], ARRAY[1, 2, 3], ARRAY[1, 2, 3], ARRAY[43.2,65.4]); + (2, 'Varcharvalue2', 'Textvalue2', 234, 567, 890, 'NAN'::decimal, 67.89, 01.23, FALSE, '2023-05-23', '23:45:01', '2023-05-23 23:45:01', '2 days', '{"key": "value2"}', ARRAY['Value 3', 'Value 4'], '{43.21,65.432}', '{4, 5, 6}', '{4, 5, 6}', '{4, 5, 6}', '{43.2,65.4}'), + (3, 'Varcharvalue1', 'Textvalue1', 123, 456, 789, '+INF'::decimal, 56.78, 90.12, TRUE, '2023-05-22', '12:34:56', '2023-05-22 12:34:56', '1 day', '{"key": "value"}', ARRAY['How''re you?', '"hello\ \world"'], ARRAY[12.345,56.789], ARRAY[1, 2, 3], ARRAY[1, 2, 3], ARRAY[1, 2, 3], ARRAY[43.2,65.4]); statement ok FLUSH; diff --git a/e2e_test/sink/remote/mysql_expected_result_2.tsv b/e2e_test/sink/remote/mysql_expected_result_2.tsv index 061ee02d39d1..5b79b0838a87 100644 --- a/e2e_test/sink/remote/mysql_expected_result_2.tsv +++ b/e2e_test/sink/remote/mysql_expected_result_2.tsv @@ -1,3 +1,3 @@ 1 Varcharvalue1 Textvalue1 123 456 789 12.34 56.78 90.12 1 2023-05-22 12:34:56 2023-05-22 12:34:56 P0Y0M1DT0H0M0S {"key": "value"} Value 1,Value 2 12.345,56.789 1,2,3 1,2,3 1,2,3 12.3,56.7 -2 Varcharvalue2 Textvalue2 234 567 890 23.45 67.89 1.23 0 2023-05-23 23:45:01 2023-05-23 23:45:01 P0Y0M2DT0H0M0S {"key": "value2"} Value 3,Value 4 43.21,65.432 4,5,6 4,5,6 4,5,6 43.2,65.4 -3 Varcharvalue1 Textvalue1 123 456 789 12.34 56.78 90.12 1 2023-05-22 12:34:56 2023-05-22 12:34:56 P0Y0M1DT0H0M0S {"key": "value"} How're you?,"hello\ \world" 12.345,56.789 1,2,3 1,2,3 1,2,3 43.2,65.4 +2 Varcharvalue2 Textvalue2 234 567 890 NULL 67.89 1.23 0 2023-05-23 23:45:01 2023-05-23 23:45:01 P0Y0M2DT0H0M0S {"key": "value2"} Value 3,Value 4 43.21,65.432 4,5,6 4,5,6 4,5,6 43.2,65.4 +3 Varcharvalue1 Textvalue1 123 456 789 NULL 56.78 90.12 1 2023-05-22 12:34:56 2023-05-22 12:34:56 P0Y0M1DT0H0M0S {"key": "value"} How're you?,"hello\ \world" 12.345,56.789 1,2,3 1,2,3 1,2,3 43.2,65.4 From 8a8405a68cf8cf53615e8a40f1ad22e9addd7066 Mon Sep 17 00:00:00 2001 From: Dylan Chen Date: Wed, 10 Apr 2024 18:06:38 +0800 Subject: [PATCH 3/3] fmt --- src/jni_core/src/lib.rs | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/jni_core/src/lib.rs b/src/jni_core/src/lib.rs index 1b7eed14d891..7ff8e5aa930e 100644 --- a/src/jni_core/src/lib.rs +++ b/src/jni_core/src/lib.rs @@ -780,8 +780,7 @@ extern "system" fn Java_com_risingwave_java_binding_Binding_iteratorGetDecimalVa Decimal::Normalized(_) => {} }; - let value = decimal_value - .to_string(); + let value = decimal_value.to_string(); let string_value = env.new_string(value)?; let (decimal_class_ref, constructor) = pointer .as_ref()