@@ -28,9 +28,160 @@ class SubString : public DB::tests::FunctionTest
2828{
2929};
3030
31+ template <typename T1, typename T2>
32+ class TestNullableSigned
33+ {
34+ public:
35+ static void run (SubString & sub_string)
36+ {
37+ ASSERT_COLUMN_EQ (
38+ createColumn<Nullable<String>>({" p.co" , " ww.p" , " pingcap" , " com" , " .com" , " " , " " , " " , {}, {}, {}}),
39+ sub_string.executeFunction (
40+ " substringUTF8" ,
41+ createColumn<Nullable<String>>(
42+ {" www.pingcap.com" ,
43+ " ww.pingcap.com" ,
44+ " w.pingcap.com" ,
45+ " .pingcap.com" ,
46+ " pingcap.com" ,
47+ " pingcap.com" ,
48+ " pingcap.com" ,
49+ " pingcap.com" ,
50+ {},
51+ " pingcap" ,
52+ " pingcap" }),
53+ createColumn<T1>({-5 , 1 , 3 , -3 , 8 , 2 , -100 , 0 , 2 , {}, -3 }),
54+ createColumn<T2>({4 , 4 , 7 , 4 , 5 , -5 , 2 , 3 , 6 , 4 , {}})));
55+ }
56+ };
57+
58+ template <typename T1, typename T2>
59+ class TestSigned
60+ {
61+ public:
62+ static void run (SubString & sub_string)
63+ {
64+ ASSERT_COLUMN_EQ (
65+ createColumn<Nullable<String>>({" p.co" , " ww.p" , " pingcap" , " com" , " .com" , " " , " " , " " , {}}),
66+ sub_string.executeFunction (
67+ " substringUTF8" ,
68+ createColumn<Nullable<String>>(
69+ {" www.pingcap.com" ,
70+ " ww.pingcap.com" ,
71+ " w.pingcap.com" ,
72+ " .pingcap.com" ,
73+ " pingcap.com" ,
74+ " pingcap.com" ,
75+ " pingcap.com" ,
76+ " pingcap.com" ,
77+ {}}),
78+ createColumn<T1>({-5 , 1 , 3 , -3 , 8 , 2 , -100 , 0 , 2 }),
79+ createColumn<T2>({4 , 4 , 7 , 4 , 5 , -5 , 2 , 3 , 6 })));
80+ }
81+ };
82+
83+ template <typename T1, typename T2>
84+ class TestNullableUnsigned
85+ {
86+ public:
87+ static void run (SubString & sub_string)
88+ {
89+ ASSERT_COLUMN_EQ (
90+ createColumn<Nullable<String>>({" p.co" , " ww.p" , " pingcap" , " com" , " .com" , " " , " " , {}, {}, {}}),
91+ sub_string.executeFunction (
92+ " substringUTF8" ,
93+ createColumn<Nullable<String>>(
94+ {" www.pingcap.com" ,
95+ " ww.pingcap.com" ,
96+ " w.pingcap.com" ,
97+ " .pingcap.com" ,
98+ " pingcap.com" ,
99+ " pingcap.com" ,
100+ " pingcap.com" ,
101+ {},
102+ " pingcap" ,
103+ " pingcap" }),
104+ createColumn<T1>({11 , 1 , 3 , 10 , 8 , 2 , 0 , 9 , {}, 7 }),
105+ createColumn<T2>({4 , 4 , 7 , 4 , 5 , 0 , 3 , 6 , 1 , {}})));
106+ }
107+ };
108+
109+ template <typename T1, typename T2>
110+ class TestUnsigned
111+ {
112+ public:
113+ static void run (SubString & sub_string)
114+ {
115+ ASSERT_COLUMN_EQ (
116+ createColumn<Nullable<String>>({" p.co" , " ww.p" , " pingcap" , " com" , " .com" , " " , " " , {}}),
117+ sub_string.executeFunction (
118+ " substringUTF8" ,
119+ createColumn<Nullable<String>>(
120+ {" www.pingcap.com" ,
121+ " ww.pingcap.com" ,
122+ " w.pingcap.com" ,
123+ " .pingcap.com" ,
124+ " pingcap.com" ,
125+ " pingcap.com" ,
126+ " pingcap.com" ,
127+ {}}),
128+ createColumn<T1>({11 , 1 , 3 , 10 , 8 , 2 , 0 , 2 }),
129+ createColumn<T2>({4 , 4 , 7 , 4 , 5 , 0 , 3 , 1 })));
130+ }
131+ };
132+
133+ template <typename T1, typename T2>
134+ class TestConstPos
135+ {
136+ public:
137+ static void run (SubString & sub_string)
138+ {
139+ ASSERT_COLUMN_EQ (
140+ createColumn<Nullable<String>>({" w" , " ww" , " w.p" , " .pin" }),
141+ sub_string.executeFunction (
142+ " substringUTF8" ,
143+ createColumn<Nullable<String>>({" www.pingcap.com" , " ww.pingcap.com" , " w.pingcap.com" , " .pingcap.com" }),
144+ createConstColumn<T1>(4 , 1 ),
145+ createColumn<T2>({1 , 2 , 3 , 4 })));
146+ }
147+ };
148+
149+ template <typename T1, typename T2>
150+ class TestConstLength
151+ {
152+ public:
153+ static void run (SubString & sub_string)
154+ {
155+ ASSERT_COLUMN_EQ (
156+ createColumn<Nullable<String>>({" www." , " w.pi" , " ping" , " ngca" }),
157+ sub_string.executeFunction (
158+ " substringUTF8" ,
159+ createColumn<Nullable<String>>({" www.pingcap.com" , " ww.pingcap.com" , " w.pingcap.com" , " .pingcap.com" }),
160+ createColumn<T1>({1 , 2 , 3 , 4 }),
161+ createConstColumn<T1>(4 , 4 )));
162+ }
163+ };
164+
31165TEST_F (SubString, subStringUTF8Test)
32166try
33167{
168+ TestTypePair<TestNullableIntTypes, TestNullableIntTypes, TestNullableSigned, SubString>::run (*this );
169+ TestTypePair<TestAllIntTypes, TestAllIntTypes, TestSigned, SubString>::run (*this );
170+
171+ TestTypePair<TestNullableIntTypes, TestNullableUIntTypes, TestNullableUnsigned, SubString>::run (*this );
172+ TestTypePair<TestNullableUIntTypes, TestNullableIntTypes, TestNullableUnsigned, SubString>::run (*this );
173+ TestTypePair<TestNullableUIntTypes, TestNullableUIntTypes, TestNullableUnsigned, SubString>::run (*this );
174+
175+ TestTypePair<TestAllIntTypes, TestAllUIntTypes, TestUnsigned, SubString>::run (*this );
176+ TestTypePair<TestAllUIntTypes, TestAllIntTypes, TestUnsigned, SubString>::run (*this );
177+ TestTypePair<TestAllUIntTypes, TestAllUIntTypes, TestUnsigned, SubString>::run (*this );
178+
179+ TestTypePair<TestAllIntTypes, TestAllIntTypes, TestConstPos, SubString>::run (*this );
180+ TestTypePair<TestAllUIntTypes, TestAllUIntTypes, TestConstPos, SubString>::run (*this );
181+
182+ TestTypePair<TestAllIntTypes, TestAllIntTypes, TestConstLength, SubString>::run (*this );
183+ TestTypePair<TestAllUIntTypes, TestAllUIntTypes, TestConstLength, SubString>::run (*this );
184+
34185 // column, const, const
35186 ASSERT_COLUMN_EQ (
36187 createColumn<Nullable<String>>({" www." , " ww.p" , " w.pi" , " .pin" }),
39190 createColumn<Nullable<String>>({" www.pingcap.com" , " ww.pingcap.com" , " w.pingcap.com" , " .pingcap.com" }),
40191 createConstColumn<Nullable<Int64>>(4 , 1 ),
41192 createConstColumn<Nullable<Int64>>(4 , 4 )));
193+
42194 // const, const, const
43195 ASSERT_COLUMN_EQ (
44196 createConstColumn<String>(1 , " www." ),
47199 createConstColumn<Nullable<String>>(1 , " www.pingcap.com" ),
48200 createConstColumn<Nullable<Int64>>(1 , 1 ),
49201 createConstColumn<Nullable<Int64>>(1 , 4 )));
50- // Test Null
51- ASSERT_COLUMN_EQ (
52- createColumn<Nullable<String>>({{}, " www." }),
53- executeFunction (
54- " substringUTF8" ,
55- createColumn<Nullable<String>>(
56- {{}, " www.pingcap.com" }),
57- createConstColumn<Nullable<Int64>>(2 , 1 ),
58- createConstColumn<Nullable<Int64>>(2 , 4 )));
59202}
60203CATCH
61204
62205} // namespace tests
63- } // namespace DB
206+ } // namespace DB
0 commit comments