github.com/rohankumardubey/aresdb@v0.0.2-0.20190517170215-e54e3ca06b9c/query/dimension_transform.cu (about) 1 // Copyright (c) 2017-2018 Uber Technologies, Inc. 2 // 3 // Licensed under the Apache License, Version 2.0 (the "License"); 4 // you may not use this file except in compliance with the License. 5 // You may obtain a copy of the License at 6 // 7 // http://www.apache.org/licenses/LICENSE-2.0 8 // 9 // Unless required by applicable law or agreed to in writing, software 10 // distributed under the License is distributed on an "AS IS" BASIS, 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 // See the License for the specific language governing permissions and 13 // limitations under the License. 14 15 #include <algorithm> 16 #include "query/transform.hpp" 17 18 namespace ares { 19 20 #define BIND_DIMENSION_OUTPUT(dataType) \ 21 return binder.transform( \ 22 ares::make_dimension_output_iterator<dataType>( \ 23 output.DimValues, output.DimNulls)); 24 25 template <int NInput> 26 class OutputVectorBinderHelper { 27 public: 28 template<typename OutputVectorBinder> 29 int bind(OutputVectorBinder &binder, DimensionOutputVector output) { 30 switch (output.DataType) { 31 case Bool: 32 BIND_DIMENSION_OUTPUT(bool) 33 case Int8: 34 BIND_DIMENSION_OUTPUT(int8_t) 35 case Int16: 36 BIND_DIMENSION_OUTPUT(int16_t) 37 case Int32: 38 BIND_DIMENSION_OUTPUT(int32_t) 39 case Uint8: 40 BIND_DIMENSION_OUTPUT(uint8_t) 41 case Uint16: 42 BIND_DIMENSION_OUTPUT(uint16_t) 43 case Uint32: 44 BIND_DIMENSION_OUTPUT(uint32_t) 45 case Int64: 46 BIND_DIMENSION_OUTPUT(int64_t) 47 case Float32: 48 BIND_DIMENSION_OUTPUT(float_t) 49 default: 50 throw std::invalid_argument( 51 "Unsupported data type for DimensionOutput"); 52 } 53 } 54 }; 55 56 template<> 57 class OutputVectorBinderHelper<1>: OutputVectorBinderHelper<2> { 58 59 typedef OutputVectorBinderHelper<2> super_t; 60 61 public: 62 template<typename OutputVectorBinder> 63 int bind(OutputVectorBinder binder, DimensionOutputVector output) { 64 switch (output.DataType) { 65 case UUID: 66 BIND_DIMENSION_OUTPUT(UUIDT) 67 case GeoPoint: 68 BIND_DIMENSION_OUTPUT(GeoPointT) 69 default: 70 return super_t::bind(binder, output); 71 } 72 } 73 }; 74 75 76 77 template<int NInput, typename FunctorType> 78 int OutputVectorBinder<NInput, FunctorType>::transformDimensionOutput( 79 DimensionOutputVector output) { 80 OutputVectorBinderHelper<NInput> helper; 81 return helper.bind(*this, output); 82 } 83 84 // explicit instantiations. 85 template int OutputVectorBinder<1, 86 UnaryFunctorType>::transformDimensionOutput( 87 DimensionOutputVector output); 88 89 template int OutputVectorBinder<2, 90 BinaryFunctorType>::transformDimensionOutput( 91 DimensionOutputVector output); 92 93 } // namespace ares