westonpace commented on issue #34515: URL: https://github.com/apache/arrow/issues/34515#issuecomment-1478187823
If I use literal(std::make_shared<TimestampScalar>(timestamp(), 17)), is the problem likely to be solved? Yes. Full example: ``` // 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. #include <arrow/io/api.h> #include <arrow/array/builder_primitive.h> #include <arrow/array/builder_binary.h> #include <arrow/compute/api.h> #include <arrow/compute/exec/exec_plan.h> #include <arrow/compute/exec/options.h> #include <arrow/result.h> #include <arrow/status.h> #include <arrow/table.h> #include <parquet/arrow/writer.h> #include <iostream> using arrow::Result; using arrow::Status; namespace { static constexpr int32_t kNumVals = 1000000; Result<std::shared_ptr<arrow::Array>> ValuesArray() { arrow::Int64Builder builder; ARROW_RETURN_NOT_OK(builder.Reserve(kNumVals)); for (int32_t i = 0; i < kNumVals; i++) { ARROW_RETURN_NOT_OK(builder.Append(i)); } return builder.Finish(); } Status DoTheThing() { std::shared_ptr<arrow::DataType> ns_timestamp = arrow::timestamp(arrow::TimeUnit::NANO); ARROW_ASSIGN_OR_RAISE(std::shared_ptr<arrow::Array> array, ValuesArray()); ARROW_ASSIGN_OR_RAISE(arrow::Datum timestamps, arrow::compute::Cast(array, ns_timestamp)); std::shared_ptr<arrow::RecordBatch> batch = arrow::RecordBatch::Make( arrow::schema({arrow::field("times", ns_timestamp)}), kNumVals, {timestamps.array()}); arrow::compute::Expression timestamp_17 = arrow::compute::literal(std::make_shared<arrow::TimestampScalar>(17, ns_timestamp)); arrow::compute::Expression gt_17 = arrow::compute::call("greater", {arrow::compute::field_ref(0), timestamp_17}); ARROW_ASSIGN_OR_RAISE(gt_17, gt_17.Bind(*batch->schema())); ARROW_ASSIGN_OR_RAISE(arrow::Datum mask, arrow::compute::ExecuteScalarExpression(gt_17, *batch->schema(), arrow::Datum(batch))); ARROW_ASSIGN_OR_RAISE(arrow::Datum filtered, arrow::compute::Filter(array, mask)); std::cout << "There were " << timestamps.length() << " values and the filtered reduced it to " << filtered.length() << std::endl; return Status::OK(); } } // namespace int main() { Status st = DoTheThing(); if (!st.ok()) { std::cerr << st << std::endl; return 1; } return 0; } ``` > What about the other types? Every data type has a corresponding scalar type. Literals are typed. You should create a literal of the appropriate type. Some type mismatches we can handle with implicit casting but int64->timestamp is not one of those. -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
