| 38 | Filter::~Filter() {} |
| 39 | |
| 40 | Status Filter::Make(SchemaPtr schema, ConditionPtr condition, |
| 41 | std::shared_ptr<Configuration> configuration, |
| 42 | std::shared_ptr<Filter>* filter) { |
| 43 | ARROW_RETURN_IF(schema == nullptr, Status::Invalid("Schema cannot be null")); |
| 44 | ARROW_RETURN_IF(condition == nullptr, Status::Invalid("Condition cannot be null")); |
| 45 | ARROW_RETURN_IF(configuration == nullptr, |
| 46 | Status::Invalid("Configuration cannot be null")); |
| 47 | |
| 48 | std::shared_ptr<Cache<ExpressionCacheKey, std::shared_ptr<llvm::MemoryBuffer>>> cache = |
| 49 | LLVMGenerator::GetCache(); |
| 50 | |
| 51 | Condition conditionToKey = *(condition.get()); |
| 52 | |
| 53 | ExpressionCacheKey cache_key(schema, configuration, conditionToKey); |
| 54 | |
| 55 | bool is_cached = false; |
| 56 | |
| 57 | std::shared_ptr<llvm::MemoryBuffer> prev_cached_obj; |
| 58 | prev_cached_obj = cache->GetObjectCode(cache_key); |
| 59 | |
| 60 | // Verify if previous filter obj code was cached |
| 61 | if (prev_cached_obj != nullptr) { |
| 62 | is_cached = true; |
| 63 | } |
| 64 | |
| 65 | GandivaObjectCache obj_cache(cache, cache_key); |
| 66 | |
| 67 | // Build LLVM generator, and generate code for the specified expression |
| 68 | ARROW_ASSIGN_OR_RAISE(auto llvm_gen, |
| 69 | LLVMGenerator::Make(configuration, is_cached, obj_cache)); |
| 70 | |
| 71 | if (!is_cached) { |
| 72 | // Run the validation on the expression. |
| 73 | // Return if the expression is invalid since we will not be able to process further. |
| 74 | ExprValidator expr_validator(llvm_gen->types(), schema, |
| 75 | configuration->function_registry()); |
| 76 | ARROW_RETURN_NOT_OK(expr_validator.Validate(condition)); |
| 77 | } |
| 78 | |
| 79 | // Set the object cache for LLVM |
| 80 | ARROW_RETURN_NOT_OK(llvm_gen->SetLLVMObjectCache(obj_cache)); |
| 81 | |
| 82 | ARROW_RETURN_NOT_OK(llvm_gen->Build({condition}, SelectionVector::Mode::MODE_NONE)); |
| 83 | |
| 84 | // Instantiate the filter with the completely built llvm generator |
| 85 | *filter = std::make_shared<Filter>(std::move(llvm_gen), schema, configuration); |
| 86 | filter->get()->SetBuiltFromCache(is_cached); |
| 87 | |
| 88 | return Status::OK(); |
| 89 | } |
| 90 | |
| 91 | Status Filter::Evaluate(const arrow::RecordBatch& batch, |
| 92 | std::shared_ptr<SelectionVector> out_selection) { |
no test coverage detected