MCPcopy Create free account
hub / github.com/apache/arrow / TEST

Function TEST

cpp/src/arrow/compute/expression_test.cc:95–127  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

93const auto no_change = std::nullopt;
94
95TEST(ExpressionUtils, Comparison) {
96 auto cmp_name = [](Datum l, Datum r) {
97 return Comparison::Execute(l, r).Map(Comparison::GetName);
98 };
99
100 Datum zero(0), one(1), two(2), null(std::make_shared<Int32Scalar>());
101 Datum str("hello"), bin(std::make_shared<BinaryScalar>(Buffer::FromString("hello")));
102 Datum dict_str(DictionaryScalar::Make(std::make_shared<Int32Scalar>(0),
103 ArrayFromJSON(utf8(), R"(["a", "b", "c"])")));
104
105 auto RaisesNotImpl =
106 Raises(StatusCode::NotImplemented, HasSubstr("no kernel matching input types"));
107
108 EXPECT_THAT(cmp_name(one, one), ResultWith(Eq("equal")));
109 EXPECT_THAT(cmp_name(one, two), ResultWith(Eq("less")));
110 EXPECT_THAT(cmp_name(one, zero), ResultWith(Eq("greater")));
111
112 EXPECT_THAT(cmp_name(one, null), ResultWith(Eq("na")));
113 EXPECT_THAT(cmp_name(null, one), ResultWith(Eq("na")));
114
115 // strings and ints are not comparable without explicit casts
116 EXPECT_THAT(cmp_name(str, one), RaisesNotImpl);
117 EXPECT_THAT(cmp_name(one, str), RaisesNotImpl);
118 EXPECT_THAT(cmp_name(str, null), RaisesNotImpl); // not even null ints
119
120 // string -> binary implicit cast allowed
121 EXPECT_THAT(cmp_name(str, bin), ResultWith(Eq("equal")));
122 EXPECT_THAT(cmp_name(bin, str), ResultWith(Eq("equal")));
123
124 // dict_str -> string, implicit casts allowed
125 EXPECT_THAT(cmp_name(dict_str, str), ResultWith(Eq("less")));
126 EXPECT_THAT(cmp_name(dict_str, bin), ResultWith(Eq("less")));
127}
128
129TEST(ExpressionUtils, StripOrderPreservingCasts) {
130 auto Expect = [](Expression expr, std::optional<Expression> expected_stripped) {

Callers 1

ASSERT_OK_AND_ASSIGNFunction · 0.70

Calls 15

FromStringFunction · 0.85
ArrayFromJSONFunction · 0.85
RaisesFunction · 0.85
ResultWithFunction · 0.85
field_refFunction · 0.85
to_stringFunction · 0.85
AssertDatumsEqualFunction · 0.85
RecordBatchFromJSONFunction · 0.85
GetFieldFunction · 0.85
MakeExecBatchFunction · 0.85
and_Function · 0.85
or_Function · 0.85

Tested by

no test coverage detected