2222#include < array>
2323#include < memory>
2424
25+ #include " core/column/column_file.h"
2526#include " core/column/column_nullable.h"
27+ #include " core/column/column_varbinary.h"
2628#include " core/column/variant_v2/column_variant_v2.h"
29+ #include " core/data_type/data_type_array.h"
30+ #include " core/data_type/data_type_file.h"
31+ #include " core/data_type/data_type_map.h"
2732#include " core/data_type/data_type_nullable.h"
33+ #include " core/data_type/data_type_string.h"
34+ #include " core/data_type/data_type_struct.h"
2835#include " core/data_type/data_type_variant_v2.h"
2936
3037namespace doris {
@@ -35,6 +42,81 @@ long address_of(T* pointer) {
3542 return reinterpret_cast <long >(pointer);
3643}
3744
45+ TEST (JniDataBridgeTest, FileTypePreservesLogicalJniNameInNestedTypes) {
46+ DataTypePtr file_type = std::make_shared<DataTypeFile>();
47+ for (const auto & type : {file_type, make_nullable (file_type)}) {
48+ EXPECT_EQ (JniDataBridge::get_jni_type (type), " file" );
49+ EXPECT_EQ (JniDataBridge::get_jni_type_with_different_string (type), " file" );
50+ EXPECT_EQ (JniDataBridge::get_jni_type_with_encoded_struct_fields (type), " file" );
51+ }
52+ auto array = std::make_shared<DataTypeArray>(make_nullable (file_type));
53+ auto map = std::make_shared<DataTypeMap>(std::make_shared<DataTypeString>(),
54+ make_nullable (file_type));
55+ auto nested = std::make_shared<DataTypeStruct>(DataTypes {make_nullable (file_type)},
56+ Strings {" image" });
57+ EXPECT_EQ (JniDataBridge::get_jni_type (array), " array<file>" );
58+ EXPECT_EQ (JniDataBridge::get_jni_type (map), " map<string,file>" );
59+ EXPECT_EQ (JniDataBridge::get_jni_type (nested), " struct<image:file>" );
60+ EXPECT_EQ (JniDataBridge::get_jni_type_with_encoded_struct_fields (nested),
61+ " struct<$aW1hZ2U=:file>" );
62+ }
63+
64+ TEST (JniDataBridgeTest, FillFileFromCanonicalJavaChildren) {
65+ // Rows: inline payload, descriptor, SQL NULL. All six child columns must
66+ // retain the same row count, including null placeholders.
67+ std::array<bool , 3 > file_nulls {false , false , true };
68+ std::array<bool , 3 > descriptor_nulls {true , false , true };
69+ std::array<bool , 3 > inline_nulls {false , true , true };
70+ std::array<bool , 3 > all_nulls {true , true , true };
71+ std::string uri = " file:/data.blob" ;
72+ std::array<int32_t , 3 > uri_offsets {0 , static_cast <int32_t >(uri.size ()),
73+ static_cast <int32_t >(uri.size ())};
74+ std::array<int64_t , 3 > blob_offsets {0 , 17 , 0 };
75+ std::array<int64_t , 3 > blob_sizes {0 , 11 , 0 };
76+ std::array<int32_t , 3 > empty_offsets {0 , 0 , 0 };
77+ std::string payload = " hello world" ;
78+ // Java -> BE VARBINARY entries carry length and pointer, not C++ StringView.
79+ std::array<int64_t , 6 > inline_values {
80+ static_cast <int64_t >(payload.size ()), address_of (payload.data ()), 0 , 0 , 0 , 0 };
81+ std::array<long , 16 > meta {
82+ address_of (file_nulls.data ()),
83+ address_of (descriptor_nulls.data ()),
84+ address_of (uri_offsets.data ()),
85+ address_of (uri.data ()),
86+ address_of (descriptor_nulls.data ()),
87+ address_of (blob_offsets.data ()),
88+ address_of (descriptor_nulls.data ()),
89+ address_of (blob_sizes.data ()),
90+ address_of (all_nulls.data ()),
91+ address_of (empty_offsets.data ()),
92+ address_of (uri.data ()),
93+ address_of (all_nulls.data ()),
94+ address_of (empty_offsets.data ()),
95+ address_of (uri.data ()),
96+ address_of (inline_nulls.data ()),
97+ address_of (inline_values.data ()),
98+ };
99+ JniDataBridge::TableMetaAddress address (address_of (meta.data ()));
100+ DataTypePtr type = make_nullable (std::make_shared<DataTypeFile>());
101+ ColumnPtr column = type->create_column ();
102+ ASSERT_TRUE (JniDataBridge::fill_column (address, column, type, 3 ).ok ());
103+ const auto & nullable = assert_cast<const ColumnNullable&>(*column);
104+ EXPECT_EQ (nullable.get_null_map_data (), NullMap ({0 , 0 , 1 }));
105+ const auto & file = assert_cast<const ColumnFile&>(nullable.get_nested_column ());
106+ ASSERT_EQ (file.size (), 3 );
107+ for (size_t i = 0 ; i < DataTypeFile::FIELD_COUNT ; ++i) {
108+ EXPECT_EQ (file.get_column (i).size (), 3 );
109+ }
110+ const auto & uri_column =
111+ assert_cast<const ColumnNullable&>(file.get_column (DataTypeFile::URI_FIELD_INDEX ));
112+ EXPECT_EQ (uri_column.get_null_map_data (), NullMap ({1 , 0 , 1 }));
113+ EXPECT_EQ (uri_column.get_nested_column ().get_data_at (1 ).to_string (), uri);
114+ const auto & inline_column =
115+ assert_cast<const ColumnNullable&>(file.get_column (DataTypeFile::INLINE_FIELD_INDEX ));
116+ EXPECT_EQ (inline_column.get_null_map_data (), NullMap ({0 , 1 , 1 }));
117+ EXPECT_EQ (inline_column.get_nested_column ().get_data_at (0 ).to_string (), payload);
118+ }
119+
38120TEST (JniDataBridgeTest, VariantTypeUsesVariantJniName) {
39121 auto variant_type = std::make_shared<DataTypeVariantV2>();
40122 auto nullable_variant_type = make_nullable (variant_type);
0 commit comments