diff --git a/cpp/src/arrow/compute/exec/expression.cc b/cpp/src/arrow/compute/exec/expression.cc index 1f819cf3d04..59def380db5 100644 --- a/cpp/src/arrow/compute/exec/expression.cc +++ b/cpp/src/arrow/compute/exec/expression.cc @@ -526,23 +526,6 @@ Result ExecuteScalarExpression(const Expression& expr, const Datum& input "ExecuteScalarExpression cannot Execute non-scalar expression ", expr.ToString()); } - if (input.kind() == Datum::TABLE) { - TableBatchReader reader(*input.table()); - std::shared_ptr batch; - - while (true) { - RETURN_NOT_OK(reader.ReadNext(&batch)); - if (batch != nullptr) { - break; - } - ARROW_ASSIGN_OR_RAISE(Datum res, ExecuteScalarExpression(expr, batch)); - if (res.is_scalar()) { - ARROW_ASSIGN_OR_RAISE(res, MakeArrayFromScalar(*res.scalar(), batch->num_rows(), - exec_context->memory_pool())); - } - } - } - if (auto lit = expr.literal()) return *lit; if (auto ref = expr.field_ref()) { diff --git a/cpp/src/arrow/compute/exec/expression_test.cc b/cpp/src/arrow/compute/exec/expression_test.cc index ab3fbb4d196..e8b8fb31cd8 100644 --- a/cpp/src/arrow/compute/exec/expression_test.cc +++ b/cpp/src/arrow/compute/exec/expression_test.cc @@ -172,6 +172,7 @@ TEST(Expression, ToString) { EXPECT_EQ(literal("a").ToString(), "\"a\""); EXPECT_EQ(literal("a\nb").ToString(), "\"a\\nb\""); EXPECT_EQ(literal(std::make_shared()).ToString(), "null"); + EXPECT_EQ(literal(std::make_shared()).ToString(), "null"); EXPECT_EQ(literal(std::make_shared(Buffer::FromString("az"))).ToString(), "\"617A\""); @@ -540,7 +541,7 @@ void ExpectExecute(Expression expr, Datum in, Datum* actual_out = NULLPTR) { if (in.is_value()) { ASSERT_OK_AND_ASSIGN(expr, expr.Bind(in.descr())); } else { - ASSERT_OK_AND_ASSIGN(expr, expr.Bind(*in.record_batch()->schema())); + ASSERT_OK_AND_ASSIGN(expr, expr.Bind(*in.schema())); } ASSERT_OK_AND_ASSIGN(Datum actual, ExecuteScalarExpression(expr, in)); diff --git a/cpp/src/arrow/dataset/dataset_internal.h b/cpp/src/arrow/dataset/dataset_internal.h index 6527eac07dd..4336f9c157e 100644 --- a/cpp/src/arrow/dataset/dataset_internal.h +++ b/cpp/src/arrow/dataset/dataset_internal.h @@ -54,11 +54,6 @@ inline Result GetFragmentsFromDatasets(const DatasetVector& da return MakeFlattenIterator(std::move(fragments_it)); } -inline RecordBatchIterator IteratorFromReader( - const std::shared_ptr& reader) { - return MakeFunctionIterator([reader] { return reader->Next(); }); -} - inline std::shared_ptr SchemaFromColumnNames( const std::shared_ptr& input, const std::vector& column_names) { std::vector> columns; diff --git a/cpp/src/arrow/dataset/test_util.h b/cpp/src/arrow/dataset/test_util.h index 83ae4bbf1e8..42c544dd93e 100644 --- a/cpp/src/arrow/dataset/test_util.h +++ b/cpp/src/arrow/dataset/test_util.h @@ -1161,7 +1161,7 @@ class WriteFileSystemDatasetMixin : public MakeFileSystemDatasetMixin { std::shared_ptr actual_struct; for (auto maybe_batch : - IteratorFromReader(std::make_shared(*actual_table))) { + MakeIteratorFromReader(std::make_shared(*actual_table))) { ASSERT_OK_AND_ASSIGN(auto batch, maybe_batch); ASSERT_OK_AND_ASSIGN(actual_struct, batch->ToStructArray()); } diff --git a/cpp/src/arrow/record_batch.h b/cpp/src/arrow/record_batch.h index 59c6d5568e9..a75dd043e5d 100644 --- a/cpp/src/arrow/record_batch.h +++ b/cpp/src/arrow/record_batch.h @@ -199,6 +199,8 @@ class ARROW_EXPORT RecordBatch { /// \brief Abstract interface for reading stream of record batches class ARROW_EXPORT RecordBatchReader { public: + using ValueType = std::shared_ptr; + virtual ~RecordBatchReader() = default; /// \return the shared schema of the record batches in the stream diff --git a/cpp/src/arrow/util/iterator.h b/cpp/src/arrow/util/iterator.h index 4d9e7b18290..b82021e4b21 100644 --- a/cpp/src/arrow/util/iterator.h +++ b/cpp/src/arrow/util/iterator.h @@ -560,4 +560,10 @@ Iterator MakeFlattenIterator(Iterator> it) { return Iterator(FlattenIterator(std::move(it))); } +template +Iterator MakeIteratorFromReader( + const std::shared_ptr& reader) { + return MakeFunctionIterator([reader] { return reader->Next(); }); +} + } // namespace arrow