@@ -796,15 +796,18 @@ Y_UNIT_TEST_SUITE(KqpParams) {
796796 --!syntax_v1
797797 CREATE TABLE Table (
798798 Key Int32,
799+ Key1 Decimal(1,0),
800+ Key22 Decimal(22,9),
801+ Key35 Decimal(35,10),
799802 Value1 Decimal(1,0),
800803 Value22 Decimal(22,9),
801804 Value35 Decimal(35,10),
802- PRIMARY KEY (Key)
805+ PRIMARY KEY (Key, Key1, Key22, Key35 )
803806 );
804807 )" ).GetValueSync ();
805808 UNIT_ASSERT_C (schemeResult.IsSuccess (), schemeResult.GetIssues ().ToString ());
806809
807- auto execUpsertQuery = [&] (const TString& query, const NYdb::TParams& params) -> std::tuple<NYdb::EStatus, TString> {
810+ auto execModifyQuery = [&] (const TString& query, const NYdb::TParams& params) -> std::tuple<NYdb::EStatus, TString> {
808811 if (QueryService) {
809812 auto result = queryClient.ExecuteQuery (query, NYdb::NQuery::TTxControl::BeginTx ().CommitTx (), params).ExtractValueSync ();
810813 return {result.GetStatus (), result.GetIssues ().ToString ()};
@@ -830,28 +833,37 @@ Y_UNIT_TEST_SUITE(KqpParams) {
830833 {
831834 auto upsertParams = tableClient.GetParamsBuilder ()
832835 .AddParam (" $key" ).Int32 (1 ).Build ()
836+ .AddParam (" $key1" ).Decimal (TDecimalValue (" 2" , 1 , 0 )).Build ()
837+ .AddParam (" $key22" ).Decimal (TDecimalValue (" 1234.4321" , 22 , 9 )).Build ()
838+ .AddParam (" $key35" ).Decimal (TDecimalValue (" 1555555555555555.1234567890" , 35 , 10 )).Build ()
833839 .AddParam (" $value1" ).Decimal (TDecimalValue (" 9" , 1 , 0 )).Build ()
834840 .AddParam (" $value22" ).Decimal (TDecimalValue (" 123.321" , 22 , 9 )).Build ()
835841 .AddParam (" $value35" ).Decimal (TDecimalValue (" 555555555555555.1234567890" , 35 , 10 )).Build ()
836842 .Build ();
837843
838844 // All upsert parameters are declared
839845 {
840- auto [status, issues] = execUpsertQuery (Q1_ (R"(
846+ auto [status, issues] = execModifyQuery (Q1_ (R"(
841847 DECLARE $key AS Int32;
848+ DECLARE $key1 AS Decimal(1,0);
849+ DECLARE $key22 AS Decimal(22,9);
850+ DECLARE $key35 AS Decimal(35,10);
842851 DECLARE $value1 AS Decimal(1,0);
843852 DECLARE $value22 AS Decimal(22,9);
844853 DECLARE $value35 AS Decimal(35,10);
845854
846- UPSERT INTO Table (Key, Value1, Value22, Value35) VALUES
847- ($key, $value1, $value22, $value35);
855+ UPSERT INTO Table (Key, Key1, Key22, Key35, Value1, Value22, Value35) VALUES
856+ ($key, $key1, $key22, $key35, $ value1, $value22, $value35);
848857 )" ), upsertParams);
849858 UNIT_ASSERT_VALUES_EQUAL_C (status, EStatus::SUCCESS, issues);
850859 }
851860
852- TString expected = R"( [[[1];["9"];["123.321"];["555555555555555.123456789"]]])" ;
861+ TString expected = R"( [[[1];["2"];["1234.4321"];["1555555555555555.123456789"];[" 9"];["123.321"];["555555555555555.123456789"]]])" ;
853862 auto selectParams = tableClient.GetParamsBuilder ()
854863 .AddParam (" $key" ).Int32 (1 ).Build ()
864+ .AddParam (" $key1" ).Decimal (TDecimalValue (" 2" , 1 , 0 )).Build ()
865+ .AddParam (" $key22" ).Decimal (TDecimalValue (" 1234.4321" , 22 , 9 )).Build ()
866+ .AddParam (" $key35" ).Decimal (TDecimalValue (" 1555555555555555.1234567890" , 35 , 10 )).Build ()
855867 .AddParam (" $value1" ).Decimal (TDecimalValue (" 9" , 1 , 0 )).Build ()
856868 .AddParam (" $value22" ).Decimal (TDecimalValue (" 123.321" , 22 , 9 )).Build ()
857869 .AddParam (" $value35" ).Decimal (TDecimalValue (" 555555555555555.1234567890" , 35 , 10 )).Build ()
@@ -861,17 +873,52 @@ Y_UNIT_TEST_SUITE(KqpParams) {
861873 {
862874 auto [status, issues, resultSet] = execSelectQuery (Q1_ (R"(
863875 DECLARE $key AS Int32;
876+ DECLARE $key1 AS Decimal(1,0);
877+ DECLARE $key22 AS Decimal(22,9);
878+ DECLARE $key35 AS Decimal(35,10);
864879 DECLARE $value1 AS Decimal(1,0);
865880 DECLARE $value22 AS Decimal(22,9);
866881 DECLARE $value35 AS Decimal(35,10);
867882
868- SELECT * FROM Table WHERE Key = $key AND Value1 = $value1 AND Value22 = $value22 AND Value35 = $value35;
883+ SELECT * FROM Table WHERE Key = $key AND Key1 = $key1 AND Key22 = $key22 AND Key35 = $key35 AND Value1 = $value1 AND Value22 = $value22 AND Value35 = $value35;
869884 )" ), selectParams);
870885 UNIT_ASSERT_VALUES_EQUAL_C (status, EStatus::SUCCESS, issues);
871886 CompareYson (expected, FormatResultSetYson (resultSet));
872887 }
873888 }
874889
890+ // Delete
891+ {
892+ auto deleteParams = tableClient.GetParamsBuilder ()
893+ .AddParam (" $key" ).Int32 (1 ).Build ()
894+ .AddParam (" $key1" ).Decimal (TDecimalValue (" 2" , 1 , 0 )).Build ()
895+ .AddParam (" $key22" ).Decimal (TDecimalValue (" 1234.4321" , 22 , 9 )).Build ()
896+ .AddParam (" $key35" ).Decimal (TDecimalValue (" 1555555555555555.1234567890" , 35 , 10 )).Build ()
897+ .Build ();
898+
899+ {
900+ auto [status, issues] = execModifyQuery (Q1_ (R"(
901+ DECLARE $key AS Int32;
902+ DECLARE $key1 AS Decimal(1,0);
903+ DECLARE $key22 AS Decimal(22,9);
904+ DECLARE $key35 AS Decimal(35,10);
905+
906+ DELETE FROM Table WHERE Key = $key AND Key1 = $key1 AND Key22 = $key22 AND Key35 = $key35;
907+ )" ), deleteParams);
908+ UNIT_ASSERT_VALUES_EQUAL_C (status, EStatus::SUCCESS, issues);
909+ }
910+
911+ TString expected = R"( [])" ;
912+ auto selectParams = tableClient.GetParamsBuilder ().Build ();
913+ {
914+ auto [status, issues, resultSet] = execSelectQuery (Q1_ (R"(
915+ SELECT * FROM Table;
916+ )" ), selectParams);
917+ UNIT_ASSERT_VALUES_EQUAL_C (status, EStatus::SUCCESS, issues);
918+ CompareYson (expected, FormatResultSetYson (resultSet));
919+ }
920+ }
921+
875922 // Declare wrong decimal params
876923 {
877924 auto params = tableClient.GetParamsBuilder ()
@@ -890,17 +937,23 @@ Y_UNIT_TEST_SUITE(KqpParams) {
890937 {
891938 auto upsertParams = tableClient.GetParamsBuilder ()
892939 .AddParam (" $key" ).Int32 (1 ).Build ()
940+ .AddParam (" $key1" ).Decimal (TDecimalValue (" 2" , 1 , 0 )).Build ()
941+ .AddParam (" $key22" ).Decimal (TDecimalValue (" 1234.4321" , 22 , 9 )).Build ()
942+ .AddParam (" $key35" ).Decimal (TDecimalValue (" 1555555555555555.1234567890" , 35 , 10 )).Build ()
893943 .AddParam (" $value22" ).Decimal (TDecimalValue (" 123.321" , 35 , 10 )).Build ()
894944 .AddParam (" $value35" ).Decimal (TDecimalValue (" 555555555555555.1234567890" , 35 , 10 )).Build ()
895945 .Build ();
896946
897- auto [status, issues] = execUpsertQuery (Q1_ (R"(
947+ auto [status, issues] = execModifyQuery (Q1_ (R"(
898948 DECLARE $key AS Int32;
949+ DECLARE $key1 AS Decimal(1,0);
950+ DECLARE $key22 AS Decimal(22,9);
951+ DECLARE $key35 AS Decimal(35,10);
899952 DECLARE $value22 AS Decimal(22,9);
900953 DECLARE $value35 AS Decimal(35,10);
901954
902- UPSERT INTO Table (Key, Value22, Value35) VALUES
903- ($key, $value22, $value35);
955+ UPSERT INTO Table (Key, Key1, Key22, Key35, Value22, Value35) VALUES
956+ ($key, $key1, $key22, $key35, $ value22, $value35);
904957 )" ), upsertParams);
905958 UNIT_ASSERT_VALUES_EQUAL (status, EStatus::BAD_REQUEST);
906959 UNIT_ASSERT_STRING_CONTAINS (issues, " Parameter $value22 type mismatch" );
@@ -914,7 +967,7 @@ Y_UNIT_TEST_SUITE(KqpParams) {
914967 .AddParam (" $value35" ).Decimal (TDecimalValue (" 555555555555555.1234567890" , 35 , 10 )).Build ()
915968 .Build ();
916969
917- auto [status, issues] = execUpsertQuery (Q1_ (R"(
970+ auto [status, issues] = execModifyQuery (Q1_ (R"(
918971 DECLARE $key AS Int32;
919972 DECLARE $value22 AS Decimal(35,10);
920973 DECLARE $value35 AS Decimal(35,10);
@@ -930,39 +983,51 @@ Y_UNIT_TEST_SUITE(KqpParams) {
930983 {
931984 auto upsertParams = tableClient.GetParamsBuilder ()
932985 .AddParam (" $key" ).Int32 (1001 ).Build ()
986+ .AddParam (" $key1" ).Decimal (TDecimalValue (" 20" , 1 , 0 )).Build ()
987+ .AddParam (" $key22" ).Decimal (TDecimalValue (" 212345678901234567890.1234567891" , 22 , 9 )).Build ()
988+ .AddParam (" $key35" ).Decimal (TDecimalValue (" 21234567890123456789012345678901234567890.1234567891" , 35 , 10 )).Build ()
933989 .AddParam (" $value1" ).Decimal (TDecimalValue (" 10" , 1 , 0 )).Build ()
934990 .AddParam (" $value22" ).Decimal (TDecimalValue (" 12345678901234567890.1234567891" , 22 , 9 )).Build ()
935991 .AddParam (" $value35" ).Decimal (TDecimalValue (" 1234567890123456789012345678901234567890.1234567891" , 35 , 10 )).Build ()
936992 .Build ();
937993
938- auto [status, issues] = execUpsertQuery (Q1_ (R"(
994+ auto [status, issues] = execModifyQuery (Q1_ (R"(
939995 DECLARE $key AS Int32;
996+ DECLARE $key1 AS Decimal(1,0);
997+ DECLARE $key22 AS Decimal(22,9);
998+ DECLARE $key35 AS Decimal(35,10);
940999 DECLARE $value1 AS Decimal(1,0);
9411000 DECLARE $value22 AS Decimal(22,9);
9421001 DECLARE $value35 AS Decimal(35,10);
9431002
944- UPSERT INTO Table (Key, Value1, Value22, Value35) VALUES
945- ($key, $value1, $value22, $value35);
1003+ UPSERT INTO Table (Key, Key1, Key22, Key35, Value1, Value22, Value35) VALUES
1004+ ($key, $key1, $key22, $key35, $ value1, $value22, $value35);
9461005 )" ), upsertParams);
9471006 UNIT_ASSERT_VALUES_EQUAL_C (status, EStatus::SUCCESS, issues);
9481007 }
9491008 // Good case: Upsert inf Decimal
9501009 {
9511010 auto upsertParams = tableClient.GetParamsBuilder ()
9521011 .AddParam (" $key" ).Int32 (1002 ).Build ()
1012+ .AddParam (" $key1" ).Decimal (TDecimalValue (" inf" , 1 , 0 )).Build ()
1013+ .AddParam (" $key22" ).Decimal (TDecimalValue (" inf" , 22 , 9 )).Build ()
1014+ .AddParam (" $key35" ).Decimal (TDecimalValue (" inf" , 35 , 10 )).Build ()
9531015 .AddParam (" $value1" ).Decimal (TDecimalValue (" inf" , 1 , 0 )).Build ()
9541016 .AddParam (" $value22" ).Decimal (TDecimalValue (" inf" , 22 , 9 )).Build ()
9551017 .AddParam (" $value35" ).Decimal (TDecimalValue (" inf" , 35 , 10 )).Build ()
9561018 .Build ();
9571019
958- auto [status, issues] = execUpsertQuery (Q1_ (R"(
1020+ auto [status, issues] = execModifyQuery (Q1_ (R"(
9591021 DECLARE $key AS Int32;
1022+ DECLARE $key1 AS Decimal(1,0);
1023+ DECLARE $key22 AS Decimal(22,9);
1024+ DECLARE $key35 AS Decimal(35,10);
9601025 DECLARE $value1 AS Decimal(1,0);
9611026 DECLARE $value22 AS Decimal(22,9);
9621027 DECLARE $value35 AS Decimal(35,10);
9631028
964- UPSERT INTO Table (Key, Value1, Value22, Value35) VALUES
965- ($key, $value1, $value22, $value35);
1029+ UPSERT INTO Table (Key, Key1, Key22, Key35, Value1, Value22, Value35) VALUES
1030+ ($key, $key1, $key22, $key35, $ value1, $value22, $value35);
9661031 )" ), upsertParams);
9671032 UNIT_ASSERT_VALUES_EQUAL_C (status, EStatus::SUCCESS, issues);
9681033 }
@@ -974,8 +1039,8 @@ Y_UNIT_TEST_SUITE(KqpParams) {
9741039 )" ), emptyParams);
9751040 UNIT_ASSERT_VALUES_EQUAL_C (status, EStatus::SUCCESS, issues);
9761041 TString expected = R"( [
977- [[1001];["inf"];["inf"];["inf"]];
978- [[1002];["inf"];["inf"];["inf"]]
1042+ [[1001];["inf"];["inf"];["inf"];["inf"];["inf"];["inf"] ];
1043+ [[1002];["inf"];["inf"];["inf"];["inf"];["inf"];["inf"] ]
9791044 ])" ;
9801045 TString actual = FormatResultSetYson (resultSet);
9811046 CompareYson (expected, actual);
0 commit comments