1 // Licensed to the Apache Software Foundation (ASF) under one 2 // or more contributor license agreements. See the NOTICE file 3 // distributed with this work for additional information 4 // regarding copyright ownership. The ASF licenses this file 5 // to you under the Apache License, Version 2.0 (the 6 // "License"); you may not use this file except in compliance 7 // with the License. You may obtain a copy of the License at 8 // 9 // http://www.apache.org/licenses/LICENSE-2.0 10 // 11 // Unless required by applicable law or agreed to in writing, 12 // software distributed under the License is distributed on an 13 // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 14 // KIND, either express or implied. See the License for the 15 // specific language governing permissions and limitations 16 // under the License. 17 18 #pragma once 19 20 #include <memory> 21 #include <string> 22 23 #include "arrow/status.h" 24 25 #include "gandiva/visibility.h" 26 27 namespace gandiva { 28 29 class ConfigurationBuilder; 30 /// \brief runtime config for gandiva 31 /// 32 /// It contains elements to customize gandiva execution 33 /// at run time. 34 class GANDIVA_EXPORT Configuration { 35 public: 36 friend class ConfigurationBuilder; 37 Configuration()38 Configuration() : optimize_(true) {} Configuration(bool optimize)39 explicit Configuration(bool optimize) : optimize_(optimize) {} 40 41 std::size_t Hash() const; 42 bool operator==(const Configuration& other) const; 43 bool operator!=(const Configuration& other) const; 44 optimize()45 bool optimize() const { return optimize_; } set_optimize(bool optimize)46 void set_optimize(bool optimize) { optimize_ = optimize; } 47 48 private: 49 bool optimize_; 50 }; 51 52 /// \brief configuration builder for gandiva 53 /// 54 /// Provides a default configuration and convenience methods 55 /// to override specific values and build a custom instance 56 class GANDIVA_EXPORT ConfigurationBuilder { 57 public: build()58 std::shared_ptr<Configuration> build() { 59 std::shared_ptr<Configuration> configuration(new Configuration()); 60 return configuration; 61 } 62 build(bool optimize)63 std::shared_ptr<Configuration> build(bool optimize) { 64 std::shared_ptr<Configuration> configuration(new Configuration(optimize)); 65 return configuration; 66 } 67 DefaultConfiguration()68 static std::shared_ptr<Configuration> DefaultConfiguration() { 69 return default_configuration_; 70 } 71 72 private: InitDefaultConfig()73 static std::shared_ptr<Configuration> InitDefaultConfig() { 74 std::shared_ptr<Configuration> configuration(new Configuration()); 75 return configuration; 76 } 77 78 static const std::shared_ptr<Configuration> default_configuration_; 79 }; 80 81 } // namespace gandiva 82