This is an automated email from the ASF dual-hosted git repository.
hubgeter pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/doris.git
The following commit(s) were added to refs/heads/master by this push:
new 9ee4b8d0c76 [fix](iceberg) Preserve nullness in partition commit
values (#70214)
9ee4b8d0c76 is described below
commit 9ee4b8d0c765e1a944e4ce5b8e70f7a5797c95dc
Author: daidai <[email protected]>
AuthorDate: Fri Dec 4 14:24:04 2026 +0800
[fix](iceberg) Preserve nullness in partition commit values (#70214)
### What problem does this PR solve?
Issue Number: N/A
Related PR: #68786
Problem Summary:
Writing an Iceberg STRING partition whose value is the literal `'null'`
can commit it as SQL NULL. For example, after inserting `(1, 'null')`
and `(2, NULL)`, partition pruning for `p = 'null'` can omit row 1. The
writer routing fix in #68786 separates the files, but commit fragments
still use the same textual token for both partition values.
Preserve nullable partition values through dynamic, static, and mixed
partition writers, and add an optional NULL bitmap to the commit
protocol. Decode it consistently when constructing data files, delete
files, and identity partition conflict filters. Keep the legacy token
fallback for senders without the bitmap, and preserve typed NULLs in
existing JSON fragments. Reject inconsistent bitmap or partition-field
counts before committing metadata.
The complete correction requires upgraded FE and BE processes. It
applies to new writes and does not rewrite existing incorrect manifests.
Older receivers ignore the optional field and retain their previous
behavior.
### Release note
Fix Iceberg writes incorrectly treating the literal STRING partition
value `'null'` as SQL NULL, which could cause partition-filtered queries
to miss rows.
---
.../writer/iceberg/viceberg_partition_writer.cpp | 14 ++-
.../writer/iceberg/viceberg_partition_writer.h | 21 ++--
.../sink/writer/iceberg/viceberg_table_writer.cpp | 30 ++++-
.../sink/writer/iceberg/viceberg_table_writer.h | 5 +-
.../iceberg/iceberg_partition_writer_test.cpp | 27 ++++-
.../writer/iceberg/viceberg_table_writer_test.cpp | 76 +++++++++++--
.../iceberg/IcebergConnectorTransaction.java | 18 +--
.../connector/iceberg/IcebergWriterHelper.java | 66 +++++++----
.../iceberg/IcebergConnectorTransactionTest.java | 39 +++++++
.../connector/iceberg/IcebergWriterHelperTest.java | 109 ++++++++++++++++++
gensrc/thrift/DataSinks.thrift | 3 +
.../test_iceberg_write_string_null_partition.out | 123 ++++++++++++++++++++
...test_iceberg_write_string_null_partition.groovy | 125 +++++++++++++++++++++
13 files changed, 580 insertions(+), 76 deletions(-)
diff --git a/be/src/exec/sink/writer/iceberg/viceberg_partition_writer.cpp
b/be/src/exec/sink/writer/iceberg/viceberg_partition_writer.cpp
index 09f6bf15597..ff97638ee7b 100644
--- a/be/src/exec/sink/writer/iceberg/viceberg_partition_writer.cpp
+++ b/be/src/exec/sink/writer/iceberg/viceberg_partition_writer.cpp
@@ -60,7 +60,7 @@ bool contains_nanosecond_timestamp(const iceberg::Type& type)
{
} // namespace
VIcebergPartitionWriter::VIcebergPartitionWriter(
- const TDataSink& t_sink, std::vector<std::string> partition_values,
+ const TDataSink& t_sink, std::vector<std::optional<std::string>>
partition_values,
const VExprContextSPtrs& write_output_expr_ctxs, const
iceberg::Schema& schema,
const std::string* iceberg_schema_json, std::vector<std::string>
write_column_names,
WriteInfo write_info, std::string file_name, int file_name_index,
@@ -225,7 +225,17 @@ Status
VIcebergPartitionWriter::_build_iceberg_commit_data(TIcebergCommitData* c
commit_data->__set_affected_rows(_row_count);
commit_data->__set_file_size(_file_format_transformer->written_len());
commit_data->__set_file_content(TFileContent::DATA);
- commit_data->__set_partition_values(_partition_values);
+ std::vector<std::string> partition_values;
+ std::vector<bool> partition_values_is_null;
+ partition_values.reserve(_partition_values.size());
+ partition_values_is_null.reserve(_partition_values.size());
+ for (const auto& value : _partition_values) {
+ // Keep the legacy token for older FEs; the bitmap preserves literal
"null" for new FEs.
+ partition_values.emplace_back(value.value_or("null"));
+ partition_values_is_null.emplace_back(!value.has_value());
+ }
+ commit_data->__set_partition_values(partition_values);
+ commit_data->__set_partition_values_is_null(partition_values_is_null);
// Split offsets describe the physical file, even when the table disables
all column metrics.
if (_file_format_type == TFileFormatType::FORMAT_PARQUET) {
std::vector<int64_t> offsets;
diff --git a/be/src/exec/sink/writer/iceberg/viceberg_partition_writer.h
b/be/src/exec/sink/writer/iceberg/viceberg_partition_writer.h
index b0f5f4eefd2..91318a2d1dd 100644
--- a/be/src/exec/sink/writer/iceberg/viceberg_partition_writer.h
+++ b/be/src/exec/sink/writer/iceberg/viceberg_partition_writer.h
@@ -20,6 +20,7 @@
#include <gen_cpp/DataSinks_types.h>
#include <functional>
+#include <optional>
#include "exec/sink/writer/iceberg/vpartition_writer_base.h"
#include "exprs/vexpr_fwd.h"
@@ -48,16 +49,14 @@ public:
using ClosedFileCallback =
std::function<void(std::shared_ptr<io::FileSystem>, const
std::string&)>;
- VIcebergPartitionWriter(const TDataSink& t_sink, std::vector<std::string>
partition_values,
- const VExprContextSPtrs& write_output_expr_ctxs,
- const doris::iceberg::Schema& schema,
- const std::string* iceberg_schema_json,
- std::vector<std::string> write_column_names,
WriteInfo write_info,
- std::string file_name, int file_name_index,
- TFileFormatType::type file_format_type,
- TFileCompressType::type compress_type,
- const std::map<std::string, std::string>&
hadoop_conf,
- ClosedFileCallback closed_file_callback = nullptr);
+ VIcebergPartitionWriter(
+ const TDataSink& t_sink, std::vector<std::optional<std::string>>
partition_values,
+ const VExprContextSPtrs& write_output_expr_ctxs, const
doris::iceberg::Schema& schema,
+ const std::string* iceberg_schema_json, std::vector<std::string>
write_column_names,
+ WriteInfo write_info, std::string file_name, int file_name_index,
+ TFileFormatType::type file_format_type, TFileCompressType::type
compress_type,
+ const std::map<std::string, std::string>& hadoop_conf,
+ ClosedFileCallback closed_file_callback = nullptr);
Status open(RuntimeState* state, RuntimeProfile* profile,
const RowDescriptor* row_desc) override;
@@ -88,7 +87,7 @@ private:
std::string _path;
- std::vector<std::string> _partition_values;
+ std::vector<std::optional<std::string>> _partition_values;
size_t _row_count = 0;
diff --git a/be/src/exec/sink/writer/iceberg/viceberg_table_writer.cpp
b/be/src/exec/sink/writer/iceberg/viceberg_table_writer.cpp
index d20eb8a005f..8ff72dd9b72 100644
--- a/be/src/exec/sink/writer/iceberg/viceberg_table_writer.cpp
+++ b/be/src/exec/sink/writer/iceberg/viceberg_table_writer.cpp
@@ -355,7 +355,17 @@ void VIcebergTableWriter::_init_static_partition_values() {
// For full static mode, build complete partition value list
if (_is_full_static_partition) {
- _static_partition_value_list = _partition_column_static_values;
+ _static_partition_value_list.clear();
+ _static_partition_value_list.reserve(num_cols);
+ for (size_t i = 0; i < num_cols; ++i) {
+ // The textual placeholder for a static SQL NULL is also a valid
STRING value.
+ if (iceberg_sink.static_partition_null_keys.contains(
+ _iceberg_partition_columns[i].field().name())) {
+ _static_partition_value_list.emplace_back(std::nullopt);
+ } else {
+
_static_partition_value_list.emplace_back(_partition_column_static_values[i]);
+ }
+ }
}
}
@@ -809,17 +819,25 @@ std::string VIcebergTableWriter::_escape(const
std::string& path) {
return IcebergPartitionPath::escape(path);
}
-std::vector<std::string> VIcebergTableWriter::_partition_values(
+std::vector<std::optional<std::string>> VIcebergTableWriter::_partition_values(
const doris::iceberg::StructLike& data) {
- std::vector<std::string> partition_values;
+ std::vector<std::optional<std::string>> partition_values;
partition_values.reserve(_iceberg_partition_columns.size());
for (size_t i = 0; i < _iceberg_partition_columns.size(); i++) {
auto& iceberg_partition_column = _iceberg_partition_columns[i];
// In hybrid mode, check if this column is statically specified
if (_has_static_partition && _partition_column_is_static[i]) {
- // Use static partition value
- partition_values.emplace_back(_partition_column_static_values[i]);
+ // Static fields have empty placeholders in data; their NULL state
comes from the sink.
+ if (_t_sink.iceberg_table_sink.static_partition_null_keys.contains(
+ iceberg_partition_column.field().name())) {
+ partition_values.emplace_back(std::nullopt);
+ } else {
+
partition_values.emplace_back(_partition_column_static_values[i]);
+ }
+ } else if (!data.get(i).has_value()) {
+ // Preserve SQL NULL before human rendering can turn it into the
literal "null".
+ partition_values.emplace_back(std::nullopt);
} else {
// Compute from data (dynamic partition)
partition_values.emplace_back(
@@ -836,7 +854,7 @@ std::shared_ptr<IPartitionWriterBase>
VIcebergTableWriter::_create_partition_wri
Block* transformed_block, int position, const std::string* file_name,
int file_name_index) {
DORIS_CHECK(_output_location.has_value());
auto& iceberg_table_sink = _t_sink.iceberg_table_sink;
- std::vector<std::string> partition_values;
+ std::vector<std::optional<std::string>> partition_values;
// Relative to the data location, e.g. "year=2023/month=12"; empty when
the file goes to the
// data location itself.
std::string partition_path;
diff --git a/be/src/exec/sink/writer/iceberg/viceberg_table_writer.h
b/be/src/exec/sink/writer/iceberg/viceberg_table_writer.h
index 5c9a8dddb9f..5e2db721bb7 100644
--- a/be/src/exec/sink/writer/iceberg/viceberg_table_writer.h
+++ b/be/src/exec/sink/writer/iceberg/viceberg_table_writer.h
@@ -133,7 +133,8 @@ private:
std::string _partition_to_writer_key(const doris::iceberg::StructLike&
data);
std::string _partition_to_path(const doris::iceberg::StructLike& data);
std::string _escape(const std::string& path);
- std::vector<std::string> _partition_values(const
doris::iceberg::StructLike& data);
+ std::vector<std::optional<std::string>> _partition_values(
+ const doris::iceberg::StructLike& data);
// Initialize static partition values from Thrift config
void _init_static_partition_values();
@@ -197,7 +198,7 @@ private:
// Pre-computed static partition path prefix (for full static mode, this
is the complete path)
std::string _static_partition_path;
// Pre-computed static partition value list (for full static mode only)
- std::vector<std::string> _static_partition_value_list;
+ std::vector<std::optional<std::string>> _static_partition_value_list;
std::unordered_map<std::string, std::shared_ptr<IPartitionWriterBase>>
_partitions_to_writers;
// Rolled writers are no longer active, so retain their physical paths
until statement outcome is known.
diff --git a/be/test/exec/sink/writer/iceberg/iceberg_partition_writer_test.cpp
b/be/test/exec/sink/writer/iceberg/iceberg_partition_writer_test.cpp
index 762ddef6ec4..a961997b7a4 100644
--- a/be/test/exec/sink/writer/iceberg/iceberg_partition_writer_test.cpp
+++ b/be/test/exec/sink/writer/iceberg/iceberg_partition_writer_test.cpp
@@ -164,7 +164,7 @@ protected:
.file_type =
TFileType::FILE_LOCAL,
.broker_addresses = {}};
return std::make_unique<VIcebergPartitionWriter>(
- sink, std::vector<std::string> {}, output_exprs, schema,
schema_json,
+ sink, std::vector<std::optional<std::string>> {},
output_exprs, schema, schema_json,
std::vector<std::string> {}, std::move(write_info), "data", 0,
format,
TFileCompressType::ZLIB, hadoop_conf);
}
@@ -379,6 +379,27 @@ TEST_F(VIcebergPartitionWriterTest,
OrcSkipsFooterCollectionWhenMetricsAreDisabl
EXPECT_FALSE(commit_data.__isset.column_stats);
}
+TEST_F(VIcebergPartitionWriterTest, CommitDataPreservesPartitionNullBitmap) {
+ VExprContextSPtrs output_exprs;
+ iceberg::Schema schema(std::vector<iceberg::NestedField> {});
+ std::string schema_json;
+ std::map<std::string, std::string> hadoop_conf;
+ IPartitionWriterBase::WriteInfo write_info {
+ .location = IcebergOutputLocation("/tmp/iceberg_null_test",
"/tmp/iceberg_null_test"),
+ .file_type = TFileType::FILE_LOCAL,
+ .broker_addresses = {}};
+ VIcebergPartitionWriter writer(make_table_sink(false), {"null",
std::nullopt, "ordinary", ""},
+ output_exprs, schema, &schema_json, {},
std::move(write_info),
+ "data", 0, TFileFormatType::FORMAT_ORC,
TFileCompressType::ZLIB,
+ hadoop_conf);
+ install_fake_transformer(&writer, output_exprs);
+ TIcebergCommitData commit;
+ ASSERT_TRUE(build_commit_data(&writer, &commit).ok());
+ EXPECT_EQ(std::vector<std::string>({"null", "null", "ordinary", ""}),
commit.partition_values);
+ ASSERT_TRUE(commit.__isset.partition_values_is_null);
+ EXPECT_EQ(std::vector<bool>({false, true, false, false}),
commit.partition_values_is_null);
+}
+
TEST_F(VIcebergPartitionWriterTest,
CommitDataRecordsTheTableFormOfTheLocation) {
// The file is written through FE's normalized form; the commit must keep
the table's own.
VExprContextSPtrs output_exprs;
@@ -462,8 +483,8 @@ TEST_F(VIcebergPartitionWriterTest,
UnsupportedParquetCodecDoesNotCreateFile) {
.file_type =
TFileType::FILE_LOCAL,
.broker_addresses = {}};
auto writer = std::make_unique<VIcebergPartitionWriter>(
- make_table_sink(std::nullopt), std::vector<std::string> {},
output_exprs, schema,
- &schema_json, std::vector<std::string> {}, std::move(write_info),
+ make_table_sink(std::nullopt),
std::vector<std::optional<std::string>> {}, output_exprs,
+ schema, &schema_json, std::vector<std::string> {},
std::move(write_info),
"unsupported_parquet_codec_" + UniqueId::gen_uid().to_string(), 0,
TFileFormatType::FORMAT_PARQUET, TFileCompressType::ZLIB,
hadoop_conf);
diff --git a/be/test/exec/sink/writer/iceberg/viceberg_table_writer_test.cpp
b/be/test/exec/sink/writer/iceberg/viceberg_table_writer_test.cpp
index 41a126a9cbf..edcb5189c58 100644
--- a/be/test/exec/sink/writer/iceberg/viceberg_table_writer_test.cpp
+++ b/be/test/exec/sink/writer/iceberg/viceberg_table_writer_test.cpp
@@ -28,6 +28,7 @@
#include "core/column/column_vector.h"
#include "core/data_type/data_type_nullable.h"
#include "core/data_type/data_type_number.h"
+#include "core/data_type/data_type_string.h"
#include "core/data_type/data_type_struct.h"
#include "core/data_type/data_type_timestamptz.h"
#include "core/data_type/data_type_varbinary.h"
@@ -44,6 +45,8 @@
namespace doris {
namespace {
+using PartitionValues = std::vector<std::optional<std::string>>;
+
class RecordingPartitionWriter : public IPartitionWriterBase {
public:
Status open(RuntimeState*, RuntimeProfile*, const RowDescriptor*) override
{
@@ -168,9 +171,9 @@ TEST(VIcebergTableWriterTest,
TimestampIdentityPreservesUtcCommitAndNull) {
auto value = writer._get_iceberg_partition_value(TYPE_TIMESTAMPTZ,
partition, row);
IcebergPartitionData data({value});
paths.push_back(writer._partition_to_path(data));
- const std::vector<std::string> expected = {"2021-11-07
05:30:00.123456+00:00",
- "2021-11-07
06:30:00.123456+00:00", "null"};
- EXPECT_EQ(std::vector<std::string>({expected[row]}),
writer._partition_values(data));
+ const PartitionValues expected = {"2021-11-07 05:30:00.123456+00:00",
+ "2021-11-07 06:30:00.123456+00:00",
std::nullopt};
+ EXPECT_EQ(PartitionValues({expected[row]}),
writer._partition_values(data));
}
EXPECT_NE(paths[0], paths[1]);
EXPECT_EQ("event_time=null", paths[2]);
@@ -179,7 +182,7 @@ TEST(VIcebergTableWriterTest,
TimestampIdentityPreservesUtcCommitAndNull) {
{{"event_time", "2021-11-07 01:30:00.123456-05:00"}});
writer._init_static_partition_values();
EXPECT_EQ(paths[1], writer._static_partition_path);
- EXPECT_EQ(std::vector<std::string>({"2021-11-07 06:30:00.123456+00:00"}),
+ EXPECT_EQ(PartitionValues({"2021-11-07 06:30:00.123456+00:00"}),
writer._static_partition_value_list);
}
@@ -238,7 +241,7 @@ TEST(VIcebergTableWriterTest,
StaticNullBinaryPartitionsKeepNullPathsAndCommitVa
ASSERT_NO_THROW(writer._init_static_partition_values());
EXPECT_TRUE(writer._is_full_static_partition);
ASSERT_EQ("key=null", writer._static_partition_path);
- EXPECT_EQ(std::vector<std::string>({"null"}),
writer._static_partition_value_list);
+ EXPECT_EQ(PartitionValues({std::nullopt}),
writer._static_partition_value_list);
auto recording_writer = std::make_shared<RecordingPartitionWriter>();
writer._partitions_to_writers["key=null"] = recording_writer;
auto null_column = type->create_column();
@@ -260,7 +263,7 @@ TEST(VIcebergTableWriterTest,
StaticNullBinaryPartitionsKeepNullPathsAndCommitVa
EXPECT_FALSE(writer._is_full_static_partition);
IcebergPartitionData hybrid({std::any(), Int32(7)});
ASSERT_EQ("key=null/id=7", writer._partition_to_path(hybrid));
- EXPECT_EQ(std::vector<std::string>({"null", "7"}),
writer._partition_values(hybrid));
+ EXPECT_EQ(PartitionValues({std::nullopt, "7"}),
writer._partition_values(hybrid));
writer._partitions_to_writers[writer._partition_to_writer_key(hybrid)]
= recording_writer;
Block hybrid_block({ColumnWithTypeAndName(null_column->get_ptr(),
type, "key"),
ColumnWithTypeAndName(id_column->get_ptr(),
id_type, "id")});
@@ -273,7 +276,7 @@ TEST(VIcebergTableWriterTest,
StaticNullBinaryPartitionsKeepNullPathsAndCommitVa
writer._t_sink.iceberg_table_sink.__set_static_partition_values({{"key",
"0x"}});
ASSERT_NO_THROW(writer._init_static_partition_values());
EXPECT_EQ("key=/id=7", writer._partition_to_path(hybrid));
- EXPECT_EQ(std::vector<std::string>({"0x", "7"}),
writer._partition_values(hybrid));
+ EXPECT_EQ(PartitionValues({"0x", "7"}),
writer._partition_values(hybrid));
writer._t_sink.iceberg_table_sink.__set_static_partition_values({{"key",
"null"}});
EXPECT_THROW(writer._init_static_partition_values(), Exception);
}
@@ -306,7 +309,7 @@ TEST(VIcebergTableWriterTest,
BinaryIdentityStaticAndDynamicRouting) {
EXPECT_EQ(bytes, std::any_cast<std::string>(value));
IcebergPartitionData data({value});
EXPECT_EQ("key=3q0%3D", writer._partition_to_path(data));
- EXPECT_EQ(std::vector<std::string>({"0xdead"}),
writer._partition_values(data));
+ EXPECT_EQ(PartitionValues({"0xdead"}), writer._partition_values(data));
IcebergPartitionData null_value({std::any()});
IcebergPartitionData null_text({std::string("\x9e\xe9\x65", 3)});
EXPECT_EQ(writer._partition_to_path(null_value),
writer._partition_to_path(null_text));
@@ -315,7 +318,7 @@ TEST(VIcebergTableWriterTest,
BinaryIdentityStaticAndDynamicRouting) {
writer._init_static_partition_values();
EXPECT_TRUE(writer._is_full_static_partition);
EXPECT_EQ("key=3q0%3D", writer._static_partition_path);
- EXPECT_EQ(std::vector<std::string>({"0xdead"}),
writer._static_partition_value_list);
+ EXPECT_EQ(PartitionValues({"0xdead"}),
writer._static_partition_value_list);
// Add a dynamic field to exercise hybrid routing with the same static
binary value.
iceberg::PartitionField dynamic_field(2, 1001, "id", "identity");
writer._iceberg_partition_columns.emplace_back(
@@ -325,7 +328,56 @@ TEST(VIcebergTableWriterTest,
BinaryIdentityStaticAndDynamicRouting) {
EXPECT_FALSE(writer._is_full_static_partition);
IcebergPartitionData hybrid({std::any(), Int32(7)});
EXPECT_EQ("key=3q0%3D/id=7", writer._partition_to_path(hybrid));
- EXPECT_EQ(std::vector<std::string>({"0xdead", "7"}),
writer._partition_values(hybrid));
+ EXPECT_EQ(PartitionValues({"0xdead", "7"}),
writer._partition_values(hybrid));
+}
+
+TEST(VIcebergTableWriterTest, StringNullAndSqlNullKeepDistinctPartitionValues)
{
+ std::vector<iceberg::NestedField> columns;
+ columns.emplace_back(true, 1, "p",
std::make_unique<iceberg::StringType>(), std::nullopt);
+ auto schema = std::make_shared<iceberg::Schema>(std::move(columns));
+ auto spec = iceberg::PartitionSpecParser::from_json(
+ schema,
+
R"({"spec-id":0,"fields":[{"name":"p","transform":"identity","source-id":1,"field-id":1000}]})");
+ TIcebergTableSink sink;
+ TDataSink data_sink;
+ data_sink.__set_iceberg_table_sink(sink);
+ VExprContextSPtrs exprs;
+ VIcebergTableWriter writer(data_sink, exprs);
+ writer._schema = schema;
+ writer._iceberg_partition_columns.emplace_back(
+ spec->fields()[0], TYPE_STRING, 0, std::vector<size_t> {},
+
std::make_unique<IdentityPartitionColumnTransform>(std::make_shared<DataTypeString>()));
+
+ IcebergPartitionData literal_null({std::string("null")});
+ IcebergPartitionData sql_null({std::any()});
+ EXPECT_EQ("p=null", writer._partition_to_path(literal_null));
+ EXPECT_EQ(writer._partition_to_path(literal_null),
writer._partition_to_path(sql_null));
+ EXPECT_NE(writer._partition_to_writer_key(literal_null),
+ writer._partition_to_writer_key(sql_null));
+ EXPECT_EQ(PartitionValues({"null"}),
writer._partition_values(literal_null));
+ EXPECT_EQ(PartitionValues({std::nullopt}),
writer._partition_values(sql_null));
+ EXPECT_EQ(PartitionValues({""}),
+ writer._partition_values(IcebergPartitionData({std::string()})));
+ EXPECT_EQ(PartitionValues({"ordinary"}),
+
writer._partition_values(IcebergPartitionData({std::string("ordinary")})));
+
+ writer._t_sink.iceberg_table_sink.__set_static_partition_values({{"p",
"null"}});
+ writer._init_static_partition_values();
+ EXPECT_EQ(PartitionValues({"null"}), writer._static_partition_value_list);
+ writer._t_sink.iceberg_table_sink.__set_static_partition_null_keys({"p"});
+ writer._init_static_partition_values();
+ EXPECT_EQ(PartitionValues({std::nullopt}),
writer._static_partition_value_list);
+
+ iceberg::PartitionField dynamic_field(2, 1001, "id", "identity");
+ writer._iceberg_partition_columns.emplace_back(
+ dynamic_field, TYPE_INT, 1, std::vector<size_t> {},
+
std::make_unique<IdentityPartitionColumnTransform>(std::make_shared<DataTypeInt32>()));
+ writer._init_static_partition_values();
+ IcebergPartitionData hybrid({std::any(), Int32(7)});
+ EXPECT_EQ(PartitionValues({std::nullopt, "7"}),
writer._partition_values(hybrid));
+ writer._t_sink.iceberg_table_sink.__set_static_partition_null_keys({});
+ writer._init_static_partition_values();
+ EXPECT_EQ(PartitionValues({"null", "7"}),
writer._partition_values(hybrid));
}
TEST(VIcebergTableWriterTest,
OpenRejectsASinkWithoutTheTableFormOfTheDataLocation) {
@@ -440,7 +492,7 @@ TEST(VIcebergTableWriterTest,
VoidPartitionFieldNeedsNoSourceColumn) {
IcebergPartitionData partition({std::any(), Int32(7)});
EXPECT_EQ("region=null/category=7", writer._partition_to_path(partition));
- EXPECT_EQ(std::vector<std::string>({"null", "7"}),
writer._partition_values(partition));
+ EXPECT_EQ(PartitionValues({std::nullopt, "7"}),
writer._partition_values(partition));
auto recording_writer = std::make_shared<RecordingPartitionWriter>();
writer._partitions_to_writers[writer._partition_to_writer_key(partition)]
= recording_writer;
auto note = int_type->create_column();
@@ -530,7 +582,7 @@ TEST(VIcebergTableWriterTest,
UuidStaticPartitionAcceptsCanonicalText) {
std::make_shared<DataTypeVarbinary>()));
writer._init_static_partition_values();
EXPECT_EQ("key=" + uuid, writer._static_partition_path);
- EXPECT_EQ(std::vector<std::string>({"0x00112233445566778899aabbccddeeff"}),
+ EXPECT_EQ(PartitionValues({"0x00112233445566778899aabbccddeeff"}),
writer._static_partition_value_list);
writer._t_sink.iceberg_table_sink.static_partition_values["key"] =
"invalid";
EXPECT_THROW(writer._init_static_partition_values(), Exception);
diff --git
a/fe/fe-connector/fe-connector-iceberg/src/main/java/org/apache/doris/connector/iceberg/IcebergConnectorTransaction.java
b/fe/fe-connector/fe-connector-iceberg/src/main/java/org/apache/doris/connector/iceberg/IcebergConnectorTransaction.java
index a5613c4757e..a409ec6dd34 100644
---
a/fe/fe-connector/fe-connector-iceberg/src/main/java/org/apache/doris/connector/iceberg/IcebergConnectorTransaction.java
+++
b/fe/fe-connector/fe-connector-iceberg/src/main/java/org/apache/doris/connector/iceberg/IcebergConnectorTransaction.java
@@ -1389,7 +1389,7 @@ public class IcebergConnectorTransaction implements
ConnectorTransaction, Rewrit
return Optional.empty();
}
- List<String> partitionValues = extractPartitionValues(data);
+ List<String> partitionValues =
IcebergWriterHelper.extractPartitionValues(data);
if (partitionValues.isEmpty() || partitionValues.size() !=
spec.fields().size()) {
return Optional.empty();
}
@@ -1424,9 +1424,6 @@ public class IcebergConnectorTransaction implements
ConnectorTransaction, Rewrit
return null;
}
String valueStr = partitionValues.get(i);
- if ("null".equals(valueStr)) {
- valueStr = null;
- }
Object value =
IcebergPartitionUtils.parsePartitionValueFromString(valueStr,
sourceField.type(), zone);
// Conflict detection may widen, but must never miss files with
retained DATE metrics.
if (value != null &&
unsafeNanosFields.contains(sourceField.fieldId())) {
@@ -1438,19 +1435,6 @@ public class IcebergConnectorTransaction implements
ConnectorTransaction, Rewrit
return expression;
}
- private List<String> extractPartitionValues(TIcebergCommitData commitData)
{
- if (commitData == null) {
- return Collections.emptyList();
- }
- if (commitData.getPartitionValues() != null &&
!commitData.getPartitionValues().isEmpty()) {
- return commitData.getPartitionValues();
- }
- if (commitData.getPartitionDataJson() != null &&
!commitData.getPartitionDataJson().isEmpty()) {
- return
IcebergPartitionUtils.parsePartitionValuesFromJson(commitData.getPartitionDataJson());
- }
- return Collections.emptyList();
- }
-
IsolationLevel resolveIsolationLevel(Table icebergTable, WriteOperation
operation) {
String property;
String defaultLevel;
diff --git
a/fe/fe-connector/fe-connector-iceberg/src/main/java/org/apache/doris/connector/iceberg/IcebergWriterHelper.java
b/fe/fe-connector/fe-connector-iceberg/src/main/java/org/apache/doris/connector/iceberg/IcebergWriterHelper.java
index b55ef063559..172f02e9c7e 100644
---
a/fe/fe-connector/fe-connector-iceberg/src/main/java/org/apache/doris/connector/iceberg/IcebergWriterHelper.java
+++
b/fe/fe-connector/fe-connector-iceberg/src/main/java/org/apache/doris/connector/iceberg/IcebergWriterHelper.java
@@ -56,11 +56,11 @@ import java.io.IOException;
import java.nio.ByteBuffer;
import java.time.ZoneId;
import java.util.ArrayList;
+import java.util.Collections;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
-import java.util.Objects;
import java.util.Optional;
import java.util.stream.Collectors;
@@ -80,6 +80,9 @@ final class IcebergWriterHelper {
private static final Logger LOG =
LogManager.getLogger(IcebergWriterHelper.class);
+ // An older host FE supplies a Thrift class without the bitmap accessors.
+ private static final boolean HOST_SUPPORTS_PARTITION_NULL_BITMAP =
+ TIcebergCommitData._Fields.findByName("partition_values_is_null")
!= null;
private static final String WRITE_FORMAT = "write-format";
private static final String PARQUET_NAME = "parquet";
private static final String ORC_NAME = "orc";
@@ -139,7 +142,7 @@ final class IcebergWriterHelper {
/**
* Converts the BE data-file commit fragments into an iceberg {@link
WriteResult} of {@link DataFile}s
* (the INSERT / OVERWRITE / MERGE-data path). A partitioned table
requires non-empty partition values per
- * file; {@code "null"} partition tokens map to a real {@code null}.
+ * file. The commit's NULL bitmap distinguishes SQL NULL from the literal
string {@code "null"}.
*/
static WriteResult convertToWriterResult(Table table,
List<TIcebergCommitData> commitDataList, ZoneId zone) {
return convertToWriterResult(table, SortOrder.unsorted(),
commitDataList, zone);
@@ -182,12 +185,10 @@ final class IcebergWriterHelper {
Metrics metrics = buildDataFileMetrics(commitData, schema,
metricsConfig, fileFormat);
Optional<PartitionData> partitionData = Optional.empty();
if (spec.isPartitioned()) {
- List<String> partitionValues = commitData.getPartitionValues();
- if (Objects.isNull(partitionValues) ||
partitionValues.isEmpty()) {
+ List<String> partitionValues =
extractPartitionValues(commitData);
+ if (partitionValues.isEmpty()) {
throw new VerifyException("No partition data for
partitioned table");
}
- partitionValues = partitionValues.stream().map(s ->
s.equals("null") ? null : s)
- .collect(Collectors.toList());
partitionData =
Optional.of(convertToPartitionData(partitionValues, spec, zone));
}
DataFile dataFile = genDataFile(fileFormat, location, spec,
partitionData, recordCount, fileSize,
@@ -217,6 +218,34 @@ final class IcebergWriterHelper {
return builder.build();
}
+ /** Decode commit partition values once for file metadata and conflict
detection. */
+ static List<String> extractPartitionValues(TIcebergCommitData commitData) {
+ List<String> values = commitData.getPartitionValues();
+ if (HOST_SUPPORTS_PARTITION_NULL_BITMAP &&
commitData.isSetPartitionValuesIsNull()) {
+ List<Boolean> isNull = commitData.getPartitionValuesIsNull();
+ // A missing value or a shifted bitmap would commit the file under
a different partition.
+ if (values == null || values.size() != isNull.size()) {
+ throw new VerifyException("Partition values and NULL bitmap
size mismatch for "
+ + commitData.getFilePath());
+ }
+ List<String> decoded = new ArrayList<>(values.size());
+ for (int i = 0; i < values.size(); i++) {
+ decoded.add(isNull.get(i) ? null : values.get(i));
+ }
+ return decoded;
+ }
+ if (values != null && !values.isEmpty()) {
+ // Older BEs lose the distinction between SQL NULL and the literal
"null" before reporting.
+ return values.stream().map(value -> "null".equals(value) ? null :
value)
+ .collect(Collectors.toList());
+ }
+ if (commitData.getPartitionDataJson() != null &&
!commitData.getPartitionDataJson().isEmpty()) {
+ // JSON already distinguishes null from "null"; never apply the
legacy token conversion to it.
+ return
IcebergPartitionUtils.parsePartitionValuesFromJson(commitData.getPartitionDataJson());
+ }
+ return Collections.emptyList();
+ }
+
/**
* Convert human-readable partition values (from BE) to {@link
PartitionData}: DATE strings like
* {@code "2025-01-25"} and DATETIME strings like {@code "2025-01-25
10:00:00"} become the iceberg internal
@@ -227,6 +256,11 @@ final class IcebergWriterHelper {
PartitionData partitionData = new PartitionData(spec.partitionType());
Types.StructType partitionType = spec.partitionType();
List<Types.NestedField> partitionTypeFields = partitionType.fields();
+ if (humanReadableValues.size() != partitionTypeFields.size()) {
+ throw new VerifyException("Partition value count " +
humanReadableValues.size()
+ + " does not match partition spec " + spec.specId() + "
field count "
+ + partitionTypeFields.size());
+ }
for (int i = 0; i < humanReadableValues.size(); i++) {
String humanReadableValue = humanReadableValues.get(i);
@@ -423,25 +457,11 @@ final class IcebergWriterHelper {
}
if (spec.isPartitioned()) {
- PartitionData partitionData;
- if (commitData.getPartitionValues() != null &&
!commitData.getPartitionValues().isEmpty()) {
- List<String> partitionValues =
commitData.getPartitionValues().stream()
- .map(s -> s.equals("null") ? null : s)
- .collect(Collectors.toList());
- partitionData = convertToPartitionData(partitionValues,
spec, zone);
- } else if (commitData.getPartitionDataJson() != null
- && !commitData.getPartitionDataJson().isEmpty()) {
- List<String> partitionValues =
IcebergPartitionUtils.parsePartitionValuesFromJson(
- commitData.getPartitionDataJson());
- if (!partitionValues.isEmpty()) {
- partitionData =
convertToPartitionData(partitionValues, spec, zone);
- } else {
- partitionData = new
PartitionData(spec.partitionType());
- }
- } else {
+ List<String> partitionValues =
extractPartitionValues(commitData);
+ if (partitionValues.isEmpty()) {
throw new VerifyException("No partition data for
partitioned table");
}
- deleteBuilder.withPartition(partitionData);
+
deleteBuilder.withPartition(convertToPartitionData(partitionValues, spec,
zone));
}
deleteFiles.add(deleteBuilder.build());
diff --git
a/fe/fe-connector/fe-connector-iceberg/src/test/java/org/apache/doris/connector/iceberg/IcebergConnectorTransactionTest.java
b/fe/fe-connector/fe-connector-iceberg/src/test/java/org/apache/doris/connector/iceberg/IcebergConnectorTransactionTest.java
index 1ff9db75a6d..eb677e3b86a 100644
---
a/fe/fe-connector/fe-connector-iceberg/src/test/java/org/apache/doris/connector/iceberg/IcebergConnectorTransactionTest.java
+++
b/fe/fe-connector/fe-connector-iceberg/src/test/java/org/apache/doris/connector/iceberg/IcebergConnectorTransactionTest.java
@@ -2097,6 +2097,45 @@ public class IcebergConnectorTransactionTest {
"a concurrent append to the SAME partition the delete touches
must be detected as a conflict");
}
+ @Test
+ public void deleteNullStringPartitionDetectsConflictsWithBitmapAndJson() {
+ for (boolean json : new boolean[] {false, true}) {
+ Assertions.assertThrows(DorisConnectorException.class, () ->
runNullStringPartitionDelete(json, "null"),
+ "a concurrent append to the literal null partition must
conflict");
+ Assertions.assertDoesNotThrow(() ->
runNullStringPartitionDelete(json, null),
+ "a concurrent append to the SQL NULL partition must remain
outside the filter");
+ }
+ }
+
+ private static void runNullStringPartitionDelete(boolean json, String
concurrentValue) {
+ PartitionSpec spec =
PartitionSpec.builderFor(PART_SCHEMA).identity("region").build();
+ InMemoryCatalog catalog = freshCatalog();
+ TableIdentifier id = TableIdentifier.of("db1", "t1");
+ Table table = catalog.createTable(id, PART_SCHEMA, spec,
props("format-version", "2"));
+ PartitionData partition = new PartitionData(spec.partitionType());
+ partition.set(0, "null");
+ String seedPath = "s3://b/db1/t1/seed.parquet";
+
table.newAppend().appendFile(DataFiles.builder(spec).withPath(seedPath).withFileSizeInBytes(128L)
+
.withRecordCount(5L).withFormat(FileFormat.PARQUET).withPartition(partition).build()).commit();
+ IcebergConnectorTransaction txn =
txnFor(opsReturning(catalog.loadTable(id)), new RecordingConnectorContext());
+ txn.beginWrite(SESSION, "db1", "t1", deleteCtx());
+
+ partition.set(0, concurrentValue);
+ catalog.loadTable(id).newAppend().appendFile(DataFiles.builder(spec)
+
.withPath("s3://b/db1/t1/concurrent.parquet").withFileSizeInBytes(128L)
+
.withRecordCount(1L).withFormat(FileFormat.PARQUET).withPartition(partition).build()).commit();
+ TIcebergCommitData del =
positionDeleteItem("s3://b/db1/t1/del.parquet", 1L, seedPath);
+ del.setPartitionSpecId(spec.specId());
+ if (json) {
+ del.setPartitionDataJson("[\"null\"]");
+ } else {
+ del.setPartitionValues(Collections.singletonList("null"));
+ del.setPartitionValuesIsNull(Collections.singletonList(false));
+ }
+ txn.addCommitData(commitBytes(del));
+ txn.commit();
+ }
+
@Test
public void deleteNonIdentityPartitionSpecDisablesConflictNarrowing() {
// parity: when not every partition transform is identity
(areAllIdentityPartitions == false), no partition
diff --git
a/fe/fe-connector/fe-connector-iceberg/src/test/java/org/apache/doris/connector/iceberg/IcebergWriterHelperTest.java
b/fe/fe-connector/fe-connector-iceberg/src/test/java/org/apache/doris/connector/iceberg/IcebergWriterHelperTest.java
index 3c46a1c9a33..d7a1666696b 100644
---
a/fe/fe-connector/fe-connector-iceberg/src/test/java/org/apache/doris/connector/iceberg/IcebergWriterHelperTest.java
+++
b/fe/fe-connector/fe-connector-iceberg/src/test/java/org/apache/doris/connector/iceberg/IcebergWriterHelperTest.java
@@ -22,6 +22,7 @@ import org.apache.doris.thrift.TIcebergColumnStats;
import org.apache.doris.thrift.TIcebergCommitData;
import com.google.common.base.VerifyException;
+import org.apache.iceberg.AppendFiles;
import org.apache.iceberg.DataFile;
import org.apache.iceberg.DataFiles;
import org.apache.iceberg.DeleteFile;
@@ -34,6 +35,8 @@ import org.apache.iceberg.SortOrder;
import org.apache.iceberg.Table;
import org.apache.iceberg.catalog.Namespace;
import org.apache.iceberg.catalog.TableIdentifier;
+import org.apache.iceberg.expressions.Expression;
+import org.apache.iceberg.expressions.Expressions;
import org.apache.iceberg.inmemory.InMemoryCatalog;
import org.apache.iceberg.io.CloseableIterable;
import org.apache.iceberg.io.WriteResult;
@@ -317,6 +320,112 @@ public class IcebergWriterHelperTest {
Assertions.assertNull(file.splitOffsets());
}
+ @Test
+ public void convertToWriterResultKeepsNullStringFilterable() throws
Exception {
+ for (String fileFormat : Arrays.asList("parquet", "orc")) {
+ Table table = tableWith("write.format.default", fileFormat);
+ table.updateSpec().addField("name").commit();
+ List<String> values = Arrays.asList("null", "null", "ordinary",
"");
+ List<String> expected = Arrays.asList("null", null, "ordinary",
"");
+ List<TIcebergCommitData> commits = new ArrayList<>();
+ for (int i = 0; i < values.size(); i++) {
+ TIcebergCommitData commit = new TIcebergCommitData();
+ commit.setFilePath("s3://b/db1/t/data-" + i + "." +
fileFormat);
+ commit.setFileSize(128L);
+ commit.setRowCount(1L);
+ commit.setFileContent(TFileContent.DATA);
+
commit.setPartitionValues(Collections.singletonList(values.get(i)));
+ commit.setPartitionValuesIsNull(Collections.singletonList(i ==
1));
+ commits.add(commit);
+ }
+ DataFile[] files =
IcebergWriterHelper.convertToWriterResult(table, commits,
ZoneOffset.UTC).dataFiles();
+ AppendFiles append = table.newAppend();
+ for (int i = 0; i < files.length; i++) {
+ Assertions.assertEquals(expected.get(i),
files[i].partition().get(0, String.class));
+ append.appendFile(files[i]);
+ }
+ append.commit();
+
+ List<Expression> filters = Arrays.asList(Expressions.equal("name",
"null"), Expressions.isNull("name"),
+ Expressions.equal("name", "ordinary"),
Expressions.equal("name", ""));
+ for (int i = 0; i < filters.size(); i++) {
+ List<String> planned = new ArrayList<>();
+ try (CloseableIterable<FileScanTask> tasks =
table.newScan().filter(filters.get(i)).planFiles()) {
+ tasks.forEach(task ->
planned.add(task.file().path().toString()));
+ }
+
Assertions.assertEquals(Collections.singletonList(commits.get(i).getFilePath()),
planned,
+ "partition pruning must retain exactly the matching
file for " + filters.get(i));
+ }
+ }
+ }
+
+ @Test
+ public void convertToDeleteFilesPreservesNullStringWithBitmapAndJson() {
+ PartitionSpec spec =
PartitionSpec.builderFor(schema).identity("name").build();
+ for (boolean json : new boolean[] {false, true}) {
+ for (String value : Arrays.asList("null", null, "ordinary", "")) {
+ TIcebergCommitData commit = new TIcebergCommitData();
+ commit.setFilePath("s3://b/db1/t/delete.parquet");
+ commit.setFileSize(128L);
+ commit.setRowCount(1L);
+ commit.setFileContent(TFileContent.POSITION_DELETES);
+ if (json) {
+ commit.setPartitionDataJson(value == null ? "[null]" :
"[\"" + value + "\"]");
+ } else {
+ commit.setPartitionValues(Collections.singletonList(value
== null ? "null" : value));
+
commit.setPartitionValuesIsNull(Collections.singletonList(value == null));
+ }
+ DeleteFile file = IcebergWriterHelper.convertToDeleteFiles(
+ format, spec, Collections.singletonList(commit),
ZoneOffset.UTC).get(0);
+ Assertions.assertEquals(value, file.partition().get(0,
String.class));
+ }
+ }
+ }
+
+ @Test
+ public void partitionNullBitmapUsesOptionalField16() throws Exception {
+ // An unknown optional field does not interfere with bitmap decoding.
+ String encoded = "{\"5\":{\"lst\":[\"str\",2,\"null\",\"null\"]},"
+ + "\"16\":{\"lst\":[\"tf\",2,0,1]},\"17\":{\"i64\":1}}";
+ TIcebergCommitData commit = new TIcebergCommitData();
+ new TDeserializer(new TJSONProtocol.Factory()).deserialize(commit,
encoded.getBytes(StandardCharsets.UTF_8));
+ Assertions.assertTrue(commit.isSetPartitionValuesIsNull());
+ Assertions.assertEquals(Arrays.asList("null", null),
IcebergWriterHelper.extractPartitionValues(commit));
+ }
+
+ @Test
+ public void partitionValuesKeepLegacyNullTokensForOldBeFragments() {
+ TIcebergCommitData commit = new TIcebergCommitData();
+ commit.setPartitionValues(Arrays.asList("null", "NULL", "ordinary",
""));
+ Assertions.assertEquals(Arrays.asList(null, "NULL", "ordinary", ""),
+ IcebergWriterHelper.extractPartitionValues(commit));
+ Assertions.assertFalse(commit.isSetPartitionValuesIsNull());
+ }
+
+ @Test
+ public void partitionValuesRejectMissingOrMismatchedNullBitmapValues() {
+ TIcebergCommitData commit = new TIcebergCommitData();
+ commit.setPartitionValuesIsNull(Collections.singletonList(false));
+ Assertions.assertThrows(VerifyException.class, () ->
IcebergWriterHelper.extractPartitionValues(commit));
+ commit.setPartitionValues(Arrays.asList("null", "ordinary"));
+ Assertions.assertThrows(VerifyException.class, () ->
IcebergWriterHelper.extractPartitionValues(commit));
+ }
+
+ @Test
+ public void partitionValuesRejectIncompletePartitionSpec() {
+ Table table = tableWith("write.format.default", "parquet");
+ table.updateSpec().addField("name").addField("age").commit();
+ TIcebergCommitData commit = new TIcebergCommitData();
+ commit.setFilePath("s3://b/db1/t/incomplete.parquet");
+ commit.setPartitionValues(Collections.singletonList("null"));
+ commit.setPartitionValuesIsNull(Collections.singletonList(false));
+ Assertions.assertThrows(VerifyException.class, () ->
IcebergWriterHelper.convertToWriterResult(
+ table, Collections.singletonList(commit), ZoneOffset.UTC));
+ commit.setFileContent(TFileContent.POSITION_DELETES);
+ Assertions.assertThrows(VerifyException.class, () ->
IcebergWriterHelper.convertToDeleteFiles(
+ format, table.spec(), Collections.singletonList(commit),
ZoneOffset.UTC));
+ }
+
@Test
public void convertToWriterResultUsesPinnedMetadataAfterTableEvolution() {
// Files are labeled with the spec, sort order, format and metrics
policy the writer was pinned to, even after
diff --git a/gensrc/thrift/DataSinks.thrift b/gensrc/thrift/DataSinks.thrift
index b9085845e0d..79234b8aeec 100644
--- a/gensrc/thrift/DataSinks.thrift
+++ b/gensrc/thrift/DataSinks.thrift
@@ -471,6 +471,9 @@ struct TIcebergCommitData {
14: optional i64 affected_rows
// Parquet data-file row-group starts, independent of column metrics
policy.
15: optional list<i64> split_offsets
+ // In partition_values order. Distinguishes SQL NULL from the literal
string "null".
+ // Unset means the sender uses the legacy "null" token for SQL NULL.
+ 16: optional list<bool> partition_values_is_null
}
struct TSortField {
diff --git
a/regression-test/data/external_table_p0/iceberg/write/test_iceberg_write_string_null_partition.out
b/regression-test/data/external_table_p0/iceberg/write/test_iceberg_write_string_null_partition.out
new file mode 100644
index 00000000000..c03969114bd
--- /dev/null
+++
b/regression-test/data/external_table_p0/iceberg/write/test_iceberg_write_string_null_partition.out
@@ -0,0 +1,123 @@
+-- This file is automatically generated. You should know what you did if you
want to edit this
+-- !parquet_rows --
+1 null false
+2 \N true
+3 ordinary false
+4 false
+5 NULL false
+6 __HIVE_DEFAULT_PARTITION__ false
+
+-- !parquet_literal_null --
+1
+
+-- !parquet_sql_null --
+2
+
+-- !parquet_empty --
+4
+
+-- !parquet_partitions --
+{"p":""} 1
+{"p":"NULL"} 1
+{"p":"__HIVE_DEFAULT_PARTITION__"} 1
+{"p":"null"} 1
+{"p":"ordinary"} 1
+{"p":null} 1
+
+-- !parquet_static_rows --
+10 null false
+20 \N true
+3 ordinary false
+4 false
+5 NULL false
+6 __HIVE_DEFAULT_PARTITION__ false
+
+-- !parquet_static_literal_null --
+10
+
+-- !parquet_static_sql_null --
+20
+
+-- !parquet_hybrid_rows --
+10 null b false
+20 \N b true
+3 ordinary a false
+
+-- !parquet_hybrid_literal_null --
+10
+
+-- !parquet_hybrid_sql_null --
+20
+
+-- !parquet_truncate_rows --
+1 null-value
+2 \N
+3 ordinary
+
+-- !parquet_truncate_literal_null --
+1
+
+-- !parquet_truncate_sql_null --
+2
+
+-- !orc_rows --
+1 null false
+2 \N true
+3 ordinary false
+4 false
+5 NULL false
+6 __HIVE_DEFAULT_PARTITION__ false
+
+-- !orc_literal_null --
+1
+
+-- !orc_sql_null --
+2
+
+-- !orc_empty --
+4
+
+-- !orc_partitions --
+{"p":""} 1
+{"p":"NULL"} 1
+{"p":"__HIVE_DEFAULT_PARTITION__"} 1
+{"p":"null"} 1
+{"p":"ordinary"} 1
+{"p":null} 1
+
+-- !orc_static_rows --
+10 null false
+20 \N true
+3 ordinary false
+4 false
+5 NULL false
+6 __HIVE_DEFAULT_PARTITION__ false
+
+-- !orc_static_literal_null --
+10
+
+-- !orc_static_sql_null --
+20
+
+-- !orc_hybrid_rows --
+10 null b false
+20 \N b true
+3 ordinary a false
+
+-- !orc_hybrid_literal_null --
+10
+
+-- !orc_hybrid_sql_null --
+20
+
+-- !orc_truncate_rows --
+1 null-value
+2 \N
+3 ordinary
+
+-- !orc_truncate_literal_null --
+1
+
+-- !orc_truncate_sql_null --
+2
+
diff --git
a/regression-test/suites/external_table_p0/iceberg/write/test_iceberg_write_string_null_partition.groovy
b/regression-test/suites/external_table_p0/iceberg/write/test_iceberg_write_string_null_partition.groovy
new file mode 100644
index 00000000000..919af0ed0e5
--- /dev/null
+++
b/regression-test/suites/external_table_p0/iceberg/write/test_iceberg_write_string_null_partition.groovy
@@ -0,0 +1,125 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements. See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership. The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License. You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied. See the License for the
+// specific language governing permissions and limitations
+// under the License.
+
+suite("test_iceberg_write_string_null_partition",
+ "p0,external,iceberg,external_docker,external_docker_iceberg") {
+ String enabled = context.config.otherConfigs.get("enableIcebergTest")
+ if (enabled == null || !enabled.equalsIgnoreCase("true")) {
+ logger.info("disable iceberg test")
+ return
+ }
+
+ String restPort = context.config.otherConfigs.get("iceberg_rest_uri_port")
+ String minioPort = context.config.otherConfigs.get("iceberg_minio_port")
+ String externalEnvIp = context.config.otherConfigs.get("externalEnvIp")
+ sql """drop catalog if exists iceberg_string_null_partition_catalog"""
+ sql """
+ create catalog iceberg_string_null_partition_catalog properties (
+ "type" = "iceberg",
+ "iceberg.catalog.type" = "rest",
+ "uri" = "http://${externalEnvIp}:${restPort}",
+ "s3.access_key" = "admin",
+ "s3.secret_key" = "password",
+ "s3.endpoint" = "http://${externalEnvIp}:${minioPort}",
+ "s3.region" = "us-east-1"
+ )
+ """
+ sql """switch iceberg_string_null_partition_catalog"""
+ sql """create database if not exists iceberg_string_null_partition_db"""
+ sql """use iceberg_string_null_partition_db"""
+
+ for (String fileFormat : ["parquet", "orc"]) {
+ sql """drop table if exists iceberg_string_null_partition"""
+ sql """
+ create table iceberg_string_null_partition (id int, p string)
+ partition by list (p) ()
+ properties ("format-version" = "2", "write.format.default" =
"${fileFormat}")
+ """
+ sql """
+ insert into iceberg_string_null_partition values
+ (1, 'null'), (2, NULL), (3, 'ordinary'), (4, ''), (5, 'NULL'),
+ (6, '__HIVE_DEFAULT_PARTITION__')
+ """
+ "order_qt_${fileFormat}_rows" """
+ select id, p, p is null from iceberg_string_null_partition order
by id
+ """
+ "order_qt_${fileFormat}_literal_null" """
+ select id from iceberg_string_null_partition where p = 'null'
order by id
+ """
+ "order_qt_${fileFormat}_sql_null" """
+ select id from iceberg_string_null_partition where p is null order
by id
+ """
+ "order_qt_${fileFormat}_empty" """
+ select id from iceberg_string_null_partition where p = '' order by
id
+ """
+ "order_qt_${fileFormat}_partitions" """
+ select cast(`partition` as string), sum(record_count)
+ from iceberg_string_null_partition\$files
+ group by cast(`partition` as string) order by cast(`partition` as
string)
+ """
+
+ sql """insert overwrite table iceberg_string_null_partition
partition(p='null') select 10"""
+ sql """insert overwrite table iceberg_string_null_partition
partition(p=NULL) select 20"""
+ "order_qt_${fileFormat}_static_rows" """
+ select id, p, p is null from iceberg_string_null_partition order
by id
+ """
+ "order_qt_${fileFormat}_static_literal_null" """
+ select id from iceberg_string_null_partition where p = 'null'
order by id
+ """
+ "order_qt_${fileFormat}_static_sql_null" """
+ select id from iceberg_string_null_partition where p is null order
by id
+ """
+
+ sql """drop table if exists iceberg_string_null_hybrid"""
+ sql """
+ create table iceberg_string_null_hybrid (id int, p string, q
string)
+ partition by list (p, q) ()
+ properties ("format-version" = "2", "write.format.default" =
"${fileFormat}")
+ """
+ sql """insert into iceberg_string_null_hybrid values
+ (1, 'null', 'a'), (2, NULL, 'a'), (3, 'ordinary', 'a')"""
+ sql """insert overwrite table iceberg_string_null_hybrid
partition(p='null') select 10, 'b'"""
+ sql """insert overwrite table iceberg_string_null_hybrid
partition(p=NULL) select 20, 'b'"""
+ "order_qt_${fileFormat}_hybrid_rows" """
+ select id, p, q, p is null from iceberg_string_null_hybrid order
by id
+ """
+ "order_qt_${fileFormat}_hybrid_literal_null" """
+ select id from iceberg_string_null_hybrid where p = 'null' order
by id
+ """
+ "order_qt_${fileFormat}_hybrid_sql_null" """
+ select id from iceberg_string_null_hybrid where p is null order by
id
+ """
+
+ sql """drop table if exists iceberg_string_null_truncate"""
+ sql """
+ create table iceberg_string_null_truncate (id int, p string)
+ partition by list (truncate(4, p)) ()
+ properties ("format-version" = "2", "write.format.default" =
"${fileFormat}")
+ """
+ sql """insert into iceberg_string_null_truncate values
+ (1, 'null-value'), (2, NULL), (3, 'ordinary')"""
+ "order_qt_${fileFormat}_truncate_rows" """
+ select id, p from iceberg_string_null_truncate order by id
+ """
+ "order_qt_${fileFormat}_truncate_literal_null" """
+ select id from iceberg_string_null_truncate where p = 'null-value'
order by id
+ """
+ "order_qt_${fileFormat}_truncate_sql_null" """
+ select id from iceberg_string_null_truncate where p is null order
by id
+ """
+ }
+}
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]