Skip to content

Commit 7e3d0de

Browse files
committed
fix: return raw string for StringType literal
1 parent a89924d commit 7e3d0de

File tree

5 files changed

+10
-11
lines changed

5 files changed

+10
-11
lines changed

src/iceberg/expression/literal.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -488,7 +488,7 @@ std::string Literal::ToString() const {
488488
.value_or("invalid literal of type decimal");
489489
}
490490
case TypeId::kString: {
491-
return "\"" + std::get<std::string>(value_) + "\"";
491+
return std::get<std::string>(value_);
492492
}
493493
case TypeId::kUuid: {
494494
return std::get<Uuid>(value_).ToString();

src/iceberg/test/expression_visitor_test.cc

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -114,14 +114,14 @@ TEST_F(BinderTest, ComparisonPredicates) {
114114
ICEBERG_UNWRAP_OR_FAIL(auto bound_eq, Bind(unbound_eq));
115115
EXPECT_EQ(bound_eq->op(), Expression::Operation::kEq);
116116
EXPECT_TRUE(bound_eq->is_bound_predicate());
117-
EXPECT_EQ(bound_eq->ToString(), "ref(id=2, type=string) == \"Alice\"");
117+
EXPECT_EQ(bound_eq->ToString(), "ref(id=2, type=string) == Alice");
118118

119119
// Test NotEqual
120120
auto unbound_neq = Expressions::NotEqual("name", Literal::String("Bob"));
121121
ICEBERG_UNWRAP_OR_FAIL(auto bound_neq, Bind(unbound_neq));
122122
EXPECT_EQ(bound_neq->op(), Expression::Operation::kNotEq);
123123
EXPECT_TRUE(bound_neq->is_bound_predicate());
124-
EXPECT_EQ(bound_neq->ToString(), "ref(id=2, type=string) != \"Bob\"");
124+
EXPECT_EQ(bound_neq->ToString(), "ref(id=2, type=string) != Bob");
125125
}
126126

127127
TEST_F(BinderTest, StringPredicates) {
@@ -130,15 +130,14 @@ TEST_F(BinderTest, StringPredicates) {
130130
ICEBERG_UNWRAP_OR_FAIL(auto bound_starts, Bind(unbound_starts));
131131
EXPECT_EQ(bound_starts->op(), Expression::Operation::kStartsWith);
132132
EXPECT_TRUE(bound_starts->is_bound_predicate());
133-
EXPECT_EQ(bound_starts->ToString(), "ref(id=2, type=string) startsWith \"\"Al\"\"");
133+
EXPECT_EQ(bound_starts->ToString(), "ref(id=2, type=string) startsWith \"Al\"");
134134

135135
// Test NotStartsWith
136136
auto unbound_not_starts = Expressions::NotStartsWith("name", "Bo");
137137
ICEBERG_UNWRAP_OR_FAIL(auto bound_not_starts, Bind(unbound_not_starts));
138138
EXPECT_EQ(bound_not_starts->op(), Expression::Operation::kNotStartsWith);
139139
EXPECT_TRUE(bound_not_starts->is_bound_predicate());
140-
EXPECT_EQ(bound_not_starts->ToString(),
141-
"ref(id=2, type=string) notStartsWith \"\"Bo\"\"");
140+
EXPECT_EQ(bound_not_starts->ToString(), "ref(id=2, type=string) notStartsWith \"Bo\"");
142141
}
143142

144143
TEST_F(BinderTest, SetPredicates) {
@@ -179,7 +178,7 @@ TEST_F(BinderTest, AndExpression) {
179178
ICEBERG_UNWRAP_OR_FAIL(auto bound_and, Bind(unbound_and));
180179
EXPECT_EQ(bound_and->op(), Expression::Operation::kAnd);
181180
EXPECT_EQ(bound_and->ToString(),
182-
"(ref(id=2, type=string) == \"Alice\" and ref(id=3, type=int) > 25)");
181+
"(ref(id=2, type=string) == Alice and ref(id=3, type=int) > 25)");
183182

184183
// Verify both children are bound
185184
auto result = IsBoundVisitor::IsBound(bound_and);
@@ -447,7 +446,7 @@ TEST_F(RewriteNotTest, NotExpression) {
447446
// Equal should be negated to NotEqual
448447
EXPECT_EQ(rewritten->op(), Expression::Operation::kNotEq);
449448
EXPECT_TRUE(rewritten->is_bound_predicate());
450-
EXPECT_EQ(rewritten->ToString(), "ref(id=2, type=string) != \"Alice\"");
449+
EXPECT_EQ(rewritten->ToString(), "ref(id=2, type=string) != Alice");
451450
}
452451

453452
TEST_F(RewriteNotTest, DoubleNegation) {

src/iceberg/test/inclusive_metrics_evaluator_test.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -841,7 +841,7 @@ TEST_F(InclusiveMetricsEvaluatorMigratedTest, StringStartsWithTest) {
841841
auto above_max = TruncateUtils::TruncateLiteral(Literal::String("イロハニホヘト"), 4)
842842
.value()
843843
.ToString();
844-
RunTest(Expressions::StartsWith("required", above_max), kRowCannotMatch, file4_);
844+
RunTest(Expressions::StartsWith("required", above_max), kRowsMightMatch, file4_);
845845
}
846846

847847
TEST_F(InclusiveMetricsEvaluatorMigratedTest, StringNotStartsWithTest) {

src/iceberg/test/literal_test.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -548,7 +548,7 @@ INSTANTIATE_TEST_SUITE_P(
548548
BasicLiteralTestParam{.test_name = "String",
549549
.literal = Literal::String("hello world"),
550550
.expected_type_id = TypeId::kString,
551-
.expected_string = "\"hello world\""},
551+
.expected_string = "hello world"},
552552
BasicLiteralTestParam{
553553
.test_name = "Uuid",
554554
.literal = Literal::UUID(

src/iceberg/test/predicate_test.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -285,7 +285,7 @@ TEST_F(PredicateTest, UnboundPredicateToString) {
285285
EXPECT_EQ(in_pred->ToString(), "ref(name=\"age\") in [10, 20]");
286286

287287
auto starts_with_pred = Expressions::StartsWith("name", "John");
288-
EXPECT_EQ(starts_with_pred->ToString(), "ref(name=\"name\") startsWith \"John\"");
288+
EXPECT_EQ(starts_with_pred->ToString(), "ref(name=\"name\") startsWith John");
289289
}
290290

291291
TEST_F(PredicateTest, UnboundPredicateNegate) {

0 commit comments

Comments
 (0)