OmniSciDB  91042dcc5b
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
TableFunctionsCommon.h File Reference
#include <filesystem>
#include <mutex>
#include <shared_mutex>
#include <string>
#include <unordered_map>
#include <vector>
#include "QueryEngine/OmniSciTypes.h"
#include "TableFunctionsCommon.cpp"
+ Include dependency graph for TableFunctionsCommon.h:
+ This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

struct  CacheDataTf
 
class  DataBufferCache
 
class  DataCache< T >
 

Namespaces

 FileUtilities
 

Enumerations

enum  BoundsType { Min, Max }
 
enum  IntervalType { Inclusive, Exclusive }
 

Functions

template<typename T >
TEMPLATE_NOINLINE std::pair< T, T > get_column_min_max (const Column< T > &col)
 
TEMPLATE_NOINLINE std::pair
< int32_t, int32_t > 
get_column_min_max (const Column< TextEncodingDict > &col)
 
template<typename T1 , typename T2 >
TEMPLATE_NOINLINE T1 distance_in_meters (const T1 fromlon, const T1 fromlat, const T2 tolon, const T2 tolat)
 
int64_t x_y_bin_to_bin_index (const int64_t x_bin, const int64_t y_bin, const int64_t num_x_bins)
 
std::pair< int64_t, int64_t > bin_to_x_y_bin_indexes (const int64_t bin, const int64_t num_x_bins)
 
std::vector
< std::filesystem::path > 
FileUtilities::get_fs_paths (const std::string &file_or_directory)
 
template<typename T >
bool is_valid_tf_input (const T input, const T bounds_val, const BoundsType bounds_type, const IntervalType interval_type)
 

Enumeration Type Documentation

enum BoundsType
Enumerator
Min 
Max 

Definition at line 110 of file TableFunctionsCommon.h.

Enumerator
Inclusive 
Exclusive 

Definition at line 112 of file TableFunctionsCommon.h.

Function Documentation

std::pair<int64_t, int64_t> bin_to_x_y_bin_indexes ( const int64_t  bin,
const int64_t  num_x_bins 
)
inline

Definition at line 46 of file TableFunctionsCommon.h.

47  {
48  return std::make_pair(bin % num_x_bins, bin / num_x_bins);
49 }
template<typename T1 , typename T2 >
TEMPLATE_NOINLINE T1 distance_in_meters ( const T1  fromlon,
const T1  fromlat,
const T2  tolon,
const T2  tolat 
)

Definition at line 104 of file TableFunctionsCommon.cpp.

104  {
105  T1 latitudeArc = (fromlat - tolat) * 0.017453292519943295769236907684886;
106  T1 longitudeArc = (fromlon - tolon) * 0.017453292519943295769236907684886;
107  T1 latitudeH = sin(latitudeArc * 0.5);
108  latitudeH *= latitudeH;
109  T1 lontitudeH = sin(longitudeArc * 0.5);
110  lontitudeH *= lontitudeH;
111  T1 tmp = cos(fromlat * 0.017453292519943295769236907684886) *
112  cos(tolat * 0.017453292519943295769236907684886);
113  return 6372797.560856 * (2.0 * asin(sqrt(latitudeH + tmp * lontitudeH)));
114 }
template<typename T >
TEMPLATE_NOINLINE std::pair<T, T> get_column_min_max ( const Column< T > &  col)

Definition at line 37 of file TableFunctionsCommon.cpp.

References Column< T >::isNull(), max_inputs_per_thread, threading_serial::parallel_for(), Column< T >::size(), and omnisci.dtypes::T.

Referenced by ct_union_pushdown_stats__cpu_template(), GeoRaster< T, Z >::GeoRaster(), get_column_min_max(), get_min_or_max(), and get_min_or_max_union().

37  {
38  T col_min = std::numeric_limits<T>::max();
39  T col_max = std::numeric_limits<T>::lowest();
40  const int64_t num_rows = col.size();
41  const size_t max_thread_count = std::thread::hardware_concurrency();
42  const size_t max_inputs_per_thread = 200000;
43  const size_t num_threads = std::min(
44  max_thread_count, ((num_rows + max_inputs_per_thread - 1) / max_inputs_per_thread));
45 
46  std::vector<T> local_col_mins(num_threads, std::numeric_limits<T>::max());
47  std::vector<T> local_col_maxes(num_threads, std::numeric_limits<T>::lowest());
48  tbb::task_arena limited_arena(num_threads);
49  tbb::task_group tg;
50 
51  limited_arena.execute([&] {
52  tg.run([&] {
53  tbb::parallel_for(tbb::blocked_range<int64_t>(0, num_rows),
54  [&](const tbb::blocked_range<int64_t>& r) {
55  const int64_t start_idx = r.begin();
56  const int64_t end_idx = r.end();
57  T local_col_min = std::numeric_limits<T>::max();
58  T local_col_max = std::numeric_limits<T>::lowest();
59  for (int64_t r = start_idx; r < end_idx; ++r) {
60  if (col.isNull(r)) {
61  continue;
62  }
63  if (col[r] < local_col_min) {
64  local_col_min = col[r];
65  }
66  if (col[r] > local_col_max) {
67  local_col_max = col[r];
68  }
69  }
70  size_t thread_idx =
71  tbb::this_task_arena::current_thread_index();
72  if (local_col_min < local_col_mins[thread_idx]) {
73  local_col_mins[thread_idx] = local_col_min;
74  }
75  if (local_col_max > local_col_maxes[thread_idx]) {
76  local_col_maxes[thread_idx] = local_col_max;
77  }
78  });
79  });
80  });
81 
82  limited_arena.execute([&] { tg.wait(); });
83 
84  for (size_t thread_idx = 0; thread_idx < num_threads; ++thread_idx) {
85  if (local_col_mins[thread_idx] < col_min) {
86  col_min = local_col_mins[thread_idx];
87  }
88  if (local_col_maxes[thread_idx] > col_max) {
89  col_max = local_col_maxes[thread_idx];
90  }
91  }
92  return std::make_pair(col_min, col_max);
93 }
DEVICE int64_t size() const
Definition: OmniSciTypes.h:248
const size_t max_inputs_per_thread
DEVICE bool isNull(int64_t index) const
Definition: OmniSciTypes.h:250
void parallel_for(const blocked_range< Int > &range, const Body &body, const Partitioner &p=Partitioner())

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

TEMPLATE_NOINLINE std::pair<int32_t, int32_t> get_column_min_max ( const Column< TextEncodingDict > &  col)

Definition at line 95 of file TableFunctionsCommon.cpp.

References get_column_min_max(), Column< T >::ptr_, and Column< T >::size_.

95  {
96  Column<int32_t> int_alias_col;
97  int_alias_col.ptr_ = reinterpret_cast<int32_t*>(col.ptr_);
98  int_alias_col.size_ = col.size_;
99  return get_column_min_max(int_alias_col);
100 }
T * ptr_
Definition: OmniSciTypes.h:229
TEMPLATE_NOINLINE std::pair< T, T > get_column_min_max(const Column< T > &col)
int64_t size_
Definition: OmniSciTypes.h:230

+ Here is the call graph for this function:

template<typename T >
bool is_valid_tf_input ( const input,
const bounds_val,
const BoundsType  bounds_type,
const IntervalType  interval_type 
)

Definition at line 315 of file TableFunctionsCommon.cpp.

References Exclusive, Inclusive, Max, Min, and UNREACHABLE.

318  {
319  switch (bounds_type) {
320  case BoundsType::Min:
321  switch (interval_type) {
323  return input >= bounds_val;
325  return input > bounds_val;
326  default:
327  UNREACHABLE();
328  }
329  case BoundsType::Max:
330  switch (interval_type) {
332  return input <= bounds_val;
334  return input < bounds_val;
335  default:
336  UNREACHABLE();
337  }
338  break;
339  default:
340  UNREACHABLE();
341  }
342  UNREACHABLE();
343  return false; // To address compiler warning
344 }
#define UNREACHABLE()
Definition: Logger.h:255
int64_t x_y_bin_to_bin_index ( const int64_t  x_bin,
const int64_t  y_bin,
const int64_t  num_x_bins 
)
inline

Definition at line 40 of file TableFunctionsCommon.h.

Referenced by GeoRaster< T, Z >::calculate_slope_and_aspect(), GeoRaster< T, Z >::compute(), GeoRaster< T, Z >::computeParallel(), GeoRaster< T, Z >::fill_bin_from_avg_neighbors(), GeoRaster< T, Z >::fill_bins_from_neighbors(), GeoRaster< T, Z >::get_nxn_neighbors_if_not_null(), GeoRaster< T, Z >::offset_source_z_from_raster_z(), and GeoRaster< T, Z >::outputDenseColumns().

42  {
43  return y_bin * num_x_bins + x_bin;
44 }

+ Here is the caller graph for this function: