MCPcopy Create free account
hub / github.com/apache/impala / TestBinary

Method TestBinary

be/src/exprs/iceberg-functions-test.cc:227–260  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

225}
226
227void IcebergTruncatePartitionTransformTests::TestBinary() {
228 MemTracker m;
229 MemPool pool(&m);
230
231 // UTF-8 compatible bytes: "Hello " + UTF-8 encoded "世界" (world in Chinese) + "!"
232 uint8_t binary_data[] = {0x48, 0x65, 0x6C, 0x6C, 0x6F, 0x20, 0xE4, 0xB8,
233 0x96, 0xE7, 0x95, 0x8C, 0x21};
234 StringVal input(binary_data, sizeof(binary_data));
235 FunctionContext* ctx = CreateFunctionContext(&pool);
236
237 for (size_t width = 1; width <= sizeof(binary_data); ++width) {
238 StringVal ret_val = IcebergFunctions::TruncatePartitionTransform<true>(
239 ctx, input, IntVal(width));
240 EXPECT_EQ(ret_val.len, width);
241 EXPECT_EQ(memcmp((char*)input.ptr, (char*)ret_val.ptr, width), 0);
242 }
243
244 // Truncate width is longer than the input binary.
245 StringVal ret_val = IcebergFunctions::TruncatePartitionTransform<true>(ctx, input, 100);
246 EXPECT_EQ(ret_val.len, input.len);
247 EXPECT_EQ(memcmp((char*)input.ptr, (char*)ret_val.ptr, input.len), 0);
248
249 // Test NULL input.
250 ret_val = IcebergFunctions::TruncatePartitionTransform<true>(
251 nullptr, StringVal::null(), IntVal(10));
252 EXPECT_TRUE(ret_val.is_null);
253
254 // Test empty string input.
255 ctx = CreateFunctionContext(&pool);
256 ret_val = IcebergFunctions::TruncatePartitionTransform<true>(ctx, "", 10);
257 EXPECT_EQ(ret_val.len, 0);
258
259 pool.FreeAll();
260}
261
262void IcebergTruncatePartitionTransformTests::TestDecimal() {
263 // Testing decimal in unit tests by invoking TruncatePartitionTransform seems

Callers

nothing calls this directly

Calls 3

CreateFunctionContextFunction · 0.85
IntValClass · 0.85
FreeAllMethod · 0.45

Tested by

no test coverage detected