OmniSciDB  6686921089
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
StringTransform.h File Reference
#include <boost/config.hpp>
#include <boost/regex.hpp>
#include <optional>
#include <string_view>
#include <algorithm>
#include <iomanip>
#include <sstream>
#include <string>
#include <vector>
+ Include dependency graph for StringTransform.h:
+ This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Namespaces

 anonymous_namespace{StringTransform.h}
 

Functions

void apply_shim (std::string &result, const boost::regex &reg_expr, const std::function< void(std::string &, const boost::smatch &)> &shim_fn)
 
template<typename... Ts>
std::string cat (Ts &&...args)
 
std::vector< std::pair< size_t,
size_t > > 
find_string_literals (const std::string &query)
 
std::string hide_sensitive_data_from_query (std::string const &query_str)
 
std::optional< size_t > inside_string_literal (const size_t start, const size_t length, const std::vector< std::pair< size_t, size_t >> &literal_positions)
 
template<typename T >
std::string join (T const &container, std::string const &delim)
 
template<typename T >
std::string to_string (T &&v)
 
template<>
std::string to_string (char const *&&v)
 
template<>
std::string to_string (std::string &&v)
 
std::string to_upper (const std::string &str)
 
std::string to_lower (const std::string &str)
 
std::string generate_random_string (const size_t len)
 
std::vector< std::string > split (std::string_view str, std::string_view delim={}, std::optional< size_t > maxsplit=std::nullopt)
 split apart a string into a vector of substrings More...
 
std::string strip (std::string_view str)
 trim any whitespace from the left and right ends of a string More...
 
bool remove_unquoted_newlines_linefeeds_and_tabs_from_sql_string (std::string &str) noexcept
 sanitize an SQL string More...
 
std::string simple_sanitize (const std::string &str)
 simple sanitize string (replace control characters with space) More...
 
std::string get_quoted_string (const std::string &filename, char quote= '"', char escape = '\\')
 Quote a string while escaping any existing quotes in the string. More...
 
template<typename T >
decltype(auto) anonymous_namespace{StringTransform.h}::stringlike (T &&parm)
 
template<typename... Types>
std::string concat (Types &&...parms)
 
template<typename... Types>
std::string concat_with (std::string_view with, Types &&...parms)
 

Function Documentation

void apply_shim ( std::string &  result,
const boost::regex &  reg_expr,
const std::function< void(std::string &, const boost::smatch &)> &  shim_fn 
)

Definition at line 32 of file StringTransform.cpp.

References find_string_literals(), and inside_string_literal().

Referenced by anonymous_namespace{CalciteAdapter.cpp}::pg_shim_impl().

34  {
35  boost::smatch what;
36  std::vector<std::pair<size_t, size_t>> lit_pos = find_string_literals(result);
37  auto start_it = result.cbegin();
38  auto end_it = result.cend();
39  while (true) {
40  if (!boost::regex_search(start_it, end_it, what, reg_expr)) {
41  break;
42  }
43  const auto next_start =
44  inside_string_literal(what.position(), what.length(), lit_pos);
45  if (next_start) {
46  start_it = result.cbegin() + *next_start;
47  } else {
48  shim_fn(result, what);
49  lit_pos = find_string_literals(result);
50  start_it = result.cbegin();
51  end_it = result.cend();
52  }
53  }
54 }
std::vector< std::pair< size_t, size_t > > find_string_literals(const std::string &query)
std::optional< size_t > inside_string_literal(const size_t start, const size_t length, const std::vector< std::pair< size_t, size_t >> &literal_positions)

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

template<typename... Ts>
std::string cat ( Ts &&...  args)

Definition at line 52 of file StringTransform.h.

References run_benchmark_import::args.

Referenced by AlterForeignTableCommand::alterOptions(), AlterForeignServerCommand::changeForeignServerOwner(), DBHandler::check_table_load_privileges(), Catalog_Namespace::SessionInfo::checkDBAccessPrivileges(), DBHandler::checkpoint(), DBHandler::clone_session(), anonymous_namespace{InputMetadata.cpp}::collect_table_infos(), QueryCompilationDescriptor::compile(), DBHandler::connect(), Fragmenter_Namespace::copyDataOfShard(), DBHandler::create_dashboard(), DBHandler::create_link(), Catalog_Namespace::SysCatalog::createDatabase(), QueryRunner::QueryRunner::createDDLStatement(), dateTimeParse(), DBHandler::delete_dashboards(), anonymous_namespace{RelAlgExecutor.cpp}::do_table_reordering(), Catalog_Namespace::SysCatalog::dropDatabase(), RefreshForeignTablesCommand::execute(), DBHandler::execute_rel_alg(), DBHandler::execute_rel_alg_df(), anonymous_namespace{GroupByAndAggregate.cpp}::expr_is_rowid(), Executor::fetchChunks(), Executor::fetchUnionChunks(), ColumnFetcher::freeLinearizedBuf(), ColumnFetcher::freeTemporaryCpuLinearizedIdxBuf(), DBHandler::get_dashboard(), DBHandler::get_dashboard_grantees(), DBHandler::get_dashboard_impl(), DBHandler::get_dashboards(), DBHandler::get_db_object_privs(), DBHandler::get_link_view(), DBHandler::get_table_details_impl(), DBHandler::get_table_epoch(), DBHandler::get_table_epoch_by_name(), DBHandler::get_table_epochs(), DBHandler::get_tables_meta_impl(), DBHandler::get_valid_groups(), Catalog_Namespace::SysCatalog::getCatalog(), Calcite::getCompletionHints(), RangeJoinHashTable::getInstance(), QueryRunner::QueryRunner::getLoader(), ColumnFetcher::getOneTableColumnFragment(), QueryRunner::QueryRunner::getParsedQueryHint(), QueryRunner::QueryRunner::getParsedQueryHints(), QueryRunner::QueryRunner::getQueryInfoForDataRecyclerTest(), lockmgr::TableLockMgrImpl< TableDataLockMgr >::getReadLockForTable(), QueryRunner::QueryRunner::getRelAlgTranslator(), InputTableInfoCache::getTableInfo(), lockmgr::TableLockMgrImpl< TableDataLockMgr >::getWriteLockForTable(), DBHandler::has_object_privilege(), DBHandler::hasTableAccessPrivileges(), DBHandler::import_geo_table(), DBHandler::import_table(), import_export::Importer::importDelimited(), import_export::Importer::importGDAL(), QueryRunner::ImportDriver::importGeoTable(), DBHandler::insert_data(), Fragmenter_Namespace::InsertDataLoader::insertData(), DBHandler::internal_connect(), DBHandler::interrupt(), ColumnFetcher::linearizeColumnFragments(), migrations::MigrationMgr::migrateDateInDaysMetadata(), HashJoin::normalizeColumnPair(), HashJoin::normalizeColumnPairs(), QueryPlanDagExtractor::normalizeColumnsPair(), DBHandler::parse_to_ra(), DBHandler::prepare_loader_generic(), Calcite::processImpl(), QueryRunner::QueryRunner::QueryRunner(), AlterForeignTableCommand::renameColumn(), AlterForeignServerCommand::renameForeignServer(), AlterForeignTableCommand::renameTable(), DBHandler::replace_dashboard(), QueryRewriter::rewriteColumnarUpdate(), QueryRunner::anonymous_namespace{QueryRunner.cpp}::run_select_query_with_filter_push_down(), QueryRunner::QueryRunner::runDDLStatement(), QueryRunner::QueryRunner::runSelectQuery(), QueryRunner::QueryRunner::runSQLWithAllowingInterrupt(), DBHandler::set_table_epoch(), DBHandler::set_table_epoch_by_name(), DBHandler::set_table_epochs(), AlterForeignServerCommand::setForeignServerDataWrapper(), AlterForeignServerCommand::setForeignServerOptions(), DBHandler::sql_execute_impl(), DBHandler::switch_database(), Catalog_Namespace::SysCatalog::switchDatabase(), anonymous_namespace{QueryMemoryDescriptor.cpp}::target_expr_proj_indices(), RexAbstractInput::toString(), RexOperator::toString(), RexSubQuery::toString(), RexInput::toString(), RexCase::toString(), RexFunctionOperator::toString(), SortField::toString(), RexWindowFunctionOperator::toString(), RexRef::toString(), RexAgg::toString(), RelScan::toString(), RelProject::toString(), RelAggregate::toString(), RelJoin::toString(), RelTranslatedJoin::toString(), RelFilter::toString(), RelCompound::toString(), RelSort::toString(), RelModify::toString(), RelTableFunction::toString(), RelLogicalUnion::toString(), anonymous_namespace{RelAlgExecutor.cpp}::translate_scalar_sources_for_update(), DateTimeParser::updateDateTimeAndStr(), DBHandler::user_can_access_table(), Parser::anonymous_namespace{ParserNode.cpp}::user_can_access_table(), DBHandler::validateDashboardIdsForSharing(), and QueryRunner::QueryRunner::validateDDLStatement().

52  {
53  std::ostringstream oss;
54  (oss << ... << std::forward<Ts>(args));
55  return oss.str();
56 }
template<typename... Types>
std::string concat ( Types &&...  parms)

Definition at line 184 of file StringTransform.h.

References File_Namespace::append(), and anonymous_namespace{StringTransform.h}::stringlike().

Referenced by HashtableRecycler::getHashtableKeyString(), and SQLTypeInfo::to_string().

184  {
185  struct Joiner {
186  Joiner() {}
187 
188  std::string txt;
189 
190  void append(std::string_view moretxt) { txt += moretxt; }
191  }; // struct Joiner
192  Joiner j{};
193  (j.append(stringlike(std::forward<Types>(parms))), ...);
194  return std::move(j.txt);
195 }
size_t append(FILE *f, const size_t size, const int8_t *buf)
Appends the specified number of bytes to the end of the file f from buf.
Definition: File.cpp:159

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

template<typename... Types>
std::string concat_with ( std::string_view  with,
Types &&...  parms 
)

Definition at line 198 of file StringTransform.h.

References File_Namespace::append(), join(), and anonymous_namespace{StringTransform.h}::stringlike().

198  {
199  struct JoinerWith {
200  JoinerWith(std::string_view join) : join(join), first(true) {}
201 
202  std::string_view join;
203  bool first;
204  std::string txt;
205 
206  void append(std::string_view moretxt) {
207  if (!first) {
208  txt += join;
209  } else {
210  first = false;
211  }
212  txt += moretxt;
213  }
214  }; // struct JoinerWith
215  JoinerWith j{with};
216  (j.append(stringlike(std::forward<Types>(parms))), ...);
217  return std::move(j.txt);
218 }
size_t append(FILE *f, const size_t size, const int8_t *buf)
Appends the specified number of bytes to the end of the file f from buf.
Definition: File.cpp:159
std::string join(T const &container, std::string const &delim)
bool g_enable_smem_group_by true

+ Here is the call graph for this function:

std::vector<std::pair<size_t, size_t> > find_string_literals ( const std::string &  query)

Definition at line 56 of file StringTransform.cpp.

References CHECK_GT, LOG, and logger::WARNING.

Referenced by apply_shim().

56  {
57  boost::regex literal_string_regex{R"(([^']+)('(?:[^']+|'')+'))", boost::regex::perl};
58  boost::smatch what;
59  auto it = query.begin();
60  auto prev_it = it;
61  std::vector<std::pair<size_t, size_t>> positions;
62  while (true) {
63  try {
64  if (!boost::regex_search(it, query.end(), what, literal_string_regex)) {
65  break;
66  }
67  } catch (const std::exception& e) {
68  LOG(WARNING) << "Error processing literals: " << e.what()
69  << "\nContinuing query parse...";
70  // boost::regex throws an exception about the complexity of matching when
71  // the wrong type of quotes are used or they're mismatched. Let the query
72  // through unmodified, the parser will throw a much more informative error.
73  // This can also throw on very long queries
74  break;
75  }
76  CHECK_GT(what[1].length(), 0);
77  prev_it = it;
78  it += what.length();
79  positions.emplace_back(prev_it + what[1].length() - query.begin(),
80  it - query.begin());
81  }
82  return positions;
83 }
#define LOG(tag)
Definition: Logger.h:203
#define CHECK_GT(x, y)
Definition: Logger.h:221

+ Here is the caller graph for this function:

std::string generate_random_string ( const size_t  len)

Definition at line 110 of file StringTransform.cpp.

References i.

Referenced by DBHandler::create_new_session(), DBHandler::createInMemoryCalciteSession(), Catalog_Namespace::SysCatalog::syncUserWithRemoteProvider(), and Catalog_Namespace::SysCatalog::updateBlankPasswordsToRandom().

110  {
111  static char charset[] =
112  "0123456789"
113  "abcdefghijklmnopqrstuvwxyz"
114  "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
115 
116  static std::mt19937 prng{std::random_device{}()};
117  static std::uniform_int_distribution<size_t> dist(0, strlen(charset) - 1);
118 
119  std::string str;
120  str.reserve(len);
121  for (size_t i = 0; i < len; i++) {
122  str += charset[dist(prng)];
123  }
124  return str;
125 }

+ Here is the caller graph for this function:

std::string get_quoted_string ( const std::string &  filename,
char  quote = '"',
char  escape = '\\' 
)

Quote a string while escaping any existing quotes in the string.

Definition at line 244 of file StringTransform.cpp.

Referenced by TableArchiver::dumpTable(), Catalog_Namespace::Catalog::quoteIfRequired(), TableArchiver::restoreTable(), and anonymous_namespace{TableArchiver.cpp}::simple_file_cat().

244  {
245  std::stringstream ss;
246  ss << std::quoted(filename, quote, escape); // TODO: prevents string_view Jun 2020
247  return ss.str();
248 }

+ Here is the caller graph for this function:

std::string hide_sensitive_data_from_query ( std::string const query_str)

Definition at line 85 of file StringTransform.cpp.

References gpu_enabled::accumulate().

Referenced by query_state::StdLog::log().

85  {
86  constexpr std::regex::flag_type flags =
87  std::regex::ECMAScript | std::regex::icase | std::regex::optimize;
88  static const std::initializer_list<std::pair<std::regex, std::string>> rules{
89  {std::regex(
90  R"(\b((?:password|s3_access_key|s3_secret_key|s3_session_token|username|credential_string)\s*=\s*)'.+?')",
91  flags),
92  "$1'XXXXXXXX'"},
93  {std::regex(R"((\\set_license\s+)\S+)", flags), "$1XXXXXXXX"}};
94  return std::accumulate(
95  rules.begin(), rules.end(), query_str, [](auto& str, auto& rule) {
96  return std::regex_replace(str, rule.first, rule.second);
97  });
98 }
DEVICE auto accumulate(ARGS &&...args)
Definition: gpu_enabled.h:42

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

std::optional<size_t> inside_string_literal ( const size_t  start,
const size_t  length,
const std::vector< std::pair< size_t, size_t >> &  literal_positions 
)

Definition at line 189 of file StringTransform.cpp.

Referenced by apply_shim().

192  {
193  const auto end = start + length;
194  for (const auto& literal_position : literal_positions) {
195  if (literal_position.first <= start && end <= literal_position.second) {
196  return literal_position.second;
197  }
198  }
199  return std::nullopt;
200 }

+ Here is the caller graph for this function:

template<typename T >
std::string join ( T const container,
std::string const delim 
)

Definition at line 72 of file StringTransform.h.

Referenced by omnisci.thrift.ttypes.TOmniSciException::__repr__(), generate_TableFunctionsFactory_init.Declaration::__str__(), generate_TableFunctionsFactory_init.Bracket::__str__(), generate_TableFunctionsFactory_init.ArgNode::__str__(), generate_TableFunctionsFactory_init.ComposedNode::__str__(), generate_TableFunctionsFactory_init::build_require_check_function(), generate_TableFunctionsFactory_init::build_template_function_call(), ResultSetReductionJIT::cacheKey(), anonymous_namespace{Execute.cpp}::checkWorkUnitWatchdog(), concat_with(), DBHandler::connect_impl(), org.apache.calcite.sql2rel.SqlToRelConverter::convertFrom(), org.apache.calcite.sql2rel.SqlToRelConverter::convertMerge(), anonymous_namespace{RelLeftDeepInnerJoin.cpp}::create_left_deep_join(), DBHandler::create_table(), Catalog_Namespace::Catalog::deleteCustomExpressions(), Catalog_Namespace::Catalog::dumpCreateTable(), Catalog_Namespace::Catalog::dumpSchema(), TableArchiver::dumpTable(), RelAlgExecutor::executeRelAlgQueryNoRetry(), ProxyTHttpClient::flush(), generate_TableFunctionsFactory_init::format_annotations(), anonymous_namespace{SerializeToSql.cpp}::from_to_string(), tests.conftest::gen_string(), generate_loop_ref::generate(), create_table.SyntheticTable::generateData(), anonymous_namespace{RelAlgExecutor.cpp}::get_data_sink(), anonymous_namespace{RelAlgOptimizer.cpp}::get_field_name(), anonymous_namespace{RelAlgExecutor.cpp}::get_join_source_used_inputs(), anonymous_namespace{RelAlgExecutor.cpp}::get_join_type(), get_left_deep_join_root(), anonymous_namespace{RelAlgOptimizer.cpp}::get_live_ins(), run_benchmark::get_machine_info(), get_qualified_column_hints(), anonymous_namespace{RelAlgOptimizer.cpp}::get_visible_projects(), ExtensionFunctionsWhitelist::getLLVMDeclarations(), anonymous_namespace{SerializeToSql.cpp}::group_by_to_string(), hoist_filter_cond_to_cross_join(), QueryRunner::ImportDriver::importGeoTable(), anonymous_namespace{RelAlgDagBuilder.cpp}::isRenamedInput(), anonymous_namespace{SerializeToSql.cpp}::join_condition_to_string(), make-m2-proxy::make_settings(), generate_TableFunctionsFactory_init.Bracket::normalize(), org.apache.calcite.rel.rules.DynamicFilterJoinRule::onMatch(), org.apache.calcite.rel.rules.OuterJoinOptViaNullRejectionRule::onMatch(), operator<<(), generate_TableFunctionsFactory_init::parse_annotations(), org.apache.calcite.rel.rules.DynamicFilterJoinRule::performSelectivePushDown(), anonymous_namespace{RelAlgOptimizer.cpp}::pick_always_live_col_idx(), anonymous_namespace{RelAlgOptimizer.cpp}::propagate_input_renumbering(), anonymous_namespace{RelAlgOptimizer.cpp}::redirect_inputs_of(), QueryMemoryDescriptor::reductionKey(), org.apache.calcite.sql2rel.SqlToRelConverter.Blackboard::register(), TableArchiver::restoreTable(), com.mapd.calcite.parser.MapDParser::rewriteSimpleUpdateAsSelect(), make-m2-proxy::simple_xml(), sink_projected_boolean_expr_to_join(), start_calcite_server_as_daemon(), org.apache.calcite.sql2rel.SqlToRelConverter::substituteSubQuery(), Catalog_Namespace::SysCatalog::syncUserWithRemoteProvider(), import_export::anonymous_namespace{QueryExporterCSV.cpp}::target_value_to_string(), anonymous_namespace{SerializeToSql.cpp}::targets_to_string(), generate_TableFunctionsFactory_init.Bracket::tostring(), org.apache.calcite.sql2rel.SqlToRelConverter::translateIn(), shared::validate_sort_options(), DBHandler::validateDashboardIdsForSharing(), foreign_storage::ForeignDataWrapperFactory::validateDataWrapperType(), foreign_storage::AbstractFileStorageDataWrapper::validateServerOptions(), RelAlgVisitor< std::vector< unsigned > >::visit(), generate_TableFunctionsFactory_init.AstPrinter::visit_annotation_node(), generate_TableFunctionsFactory_init.AstPrinter::visit_arg_node(), generate_TableFunctionsFactory_init.AstPrinter::visit_composed_node(), generate_TableFunctionsFactory_init.AstPrinter::visit_template_node(), generate_TableFunctionsFactory_init.AstPrinter::visit_udtf_node(), ScalarExprToSql::visitFunctionOper(), anonymous_namespace{RelAlgOptimizer.cpp}::RexProjectInputRedirector::visitInput(), anonymous_namespace{RelAlgOptimizer.cpp}::RexInputCollector::visitInput(), anonymous_namespace{RelAlgOptimizer.cpp}::RexInputRedirector::visitInput(), ScalarExprToSql::visitInValues(), anonymous_namespace{RelAlgOptimizer.cpp}::RexRebindInputsVisitor::visitNode(), ScalarExprToSql::visitWindowFunction(), anonymous_namespace{ExternalExecutor.cpp}::vt_create(), and anonymous_namespace{SerializeToSql.cpp}::where_to_string().

72  {
73  std::stringstream ss;
74  if (!container.empty()) {
75  ss << *container.cbegin();
76  for (auto itr = std::next(container.cbegin()); itr != container.cend(); ++itr) {
77  ss << delim << *itr;
78  }
79  }
80  return ss.str();
81 }
bool remove_unquoted_newlines_linefeeds_and_tabs_from_sql_string ( std::string &  str)
noexcept

sanitize an SQL string

Definition at line 204 of file StringTransform.cpp.

205  {
206  char inside_quote = 0;
207  bool previous_c_was_backslash = false;
208  for (auto& c : str) {
209  // if this character is a quote of either type
210  if (c == '\'' || c == '\"') {
211  // ignore if previous character was a backslash
212  if (!previous_c_was_backslash) {
213  // start or end of a quoted region
214  if (inside_quote == c) {
215  // end region
216  inside_quote = 0;
217  } else if (inside_quote == 0) {
218  // start region
219  inside_quote = c;
220  }
221  }
222  } else if (inside_quote == 0) {
223  // outside quoted region
224  if (c == '\n' || c == '\t' || c == '\r') {
225  // replace these with space
226  c = ' ';
227  }
228  // otherwise leave alone, including quotes of a different type
229  }
230  // handle backslashes, except for double backslashes
231  if (c == '\\') {
232  previous_c_was_backslash = !previous_c_was_backslash;
233  } else {
234  previous_c_was_backslash = false;
235  }
236  }
237  // if we didn't end a region, there were unclosed or mixed-nested quotes
238  // accounting for backslashes should mean that this should only be the
239  // case with truly malformed strings which Calcite will barf on anyway
240  return (inside_quote == 0);
241 }
std::string simple_sanitize ( const std::string &  str)

simple sanitize string (replace control characters with space)

Definition at line 252 of file StringTransform.cpp.

252  {
253  auto sanitized_str{str};
254  for (auto& c : sanitized_str) {
255  c = (c < 32) ? ' ' : c;
256  }
257  return sanitized_str;
258 }
std::vector<std::string> split ( std::string_view  str,
std::string_view  delim = {},
std::optional< size_t >  maxsplit = std::nullopt 
)

split apart a string into a vector of substrings

Definition at line 131 of file StringTransform.cpp.

References i, and run_benchmark_import::result.

Referenced by anonymous_namespace{TableArchiver.cpp}::adjust_altered_table_files(), create_table.SyntheticTable::createDataAndImportTable(), Parser::AlterTableStmt::delegate(), com.omnisci.jdbc.OmniSciStatement::executeQuery(), anonymous_namespace{DBHandler.cpp}::extract_projection_tokens_for_completion(), generate_TableFunctionsFactory_init::find_signatures(), get_qualified_column_hints(), ColumnDescriptor::getDefaultValueLiteral(), QueryPlanDagExtractor::handleTranslatedJoin(), AutomaticIRMetadataGuard::makeBaseFilename(), AutomaticIRMetadataGuard::makeQueryEngineFilename(), TrackingProcessor::process(), Data_Namespace::ProcMeminfoParser::ProcMeminfoParser(), run_benchmark::read_query_files(), TableArchiver::restoreTable(), QueryRunner::QueryRunner::runMultipleStatements(), Parser::splitObjectHierName(), com.mapd.parser.server.ExtensionFunctionSignatureParser::toSignature(), and ddl_utils::anonymous_namespace{DdlUtils.cpp}::validate_literal().

133  {
134  std::vector<std::string> result;
135 
136  // Use an explicit delimiter.
137  if (!delim.empty()) {
138  std::string::size_type i = 0, j = 0;
139  while ((i = str.find(delim, i)) != std::string::npos &&
140  (!maxsplit || result.size() < maxsplit.value())) {
141  result.emplace_back(str, j, i - j);
142  i += delim.size();
143  j = i;
144  }
145  result.emplace_back(str, j, std::string::npos);
146  return result;
147 
148  // Treat any number of consecutive whitespace characters as a delimiter.
149  } else {
150  bool prev_ws = true;
151  std::string::size_type i = 0, j = 0;
152  for (; i < str.size(); ++i) {
153  if (prev_ws) {
154  if (!isspace(str[i])) {
155  // start of word
156  prev_ws = false;
157  j = i;
158  }
159  } else {
160  if (isspace(str[i])) {
161  // start of space
162  result.emplace_back(str, j, i - j);
163  prev_ws = true;
164  j = i;
165  if ((maxsplit && result.size() == maxsplit.value())) {
166  // stop early if maxsplit was reached
167  result.emplace_back(str, j, std::string::npos);
168  return result;
169  }
170  }
171  }
172  }
173  if (!prev_ws) {
174  result.emplace_back(str, j, std::string::npos);
175  }
176  return result;
177  }
178 }

+ Here is the caller graph for this function:

std::string strip ( std::string_view  str)

trim any whitespace from the left and right ends of a string

Definition at line 180 of file StringTransform.cpp.

References i.

Referenced by generate_TableFunctionsFactory_init.Bracket::parse(), Data_Namespace::ProcMeminfoParser::ProcMeminfoParser(), QueryRunner::QueryRunner::runMultipleStatements(), and DBHandler::sql_execute_impl().

180  {
181  std::string::size_type i, j;
182  for (i = 0; i < str.size() && std::isspace(str[i]); ++i) {
183  }
184  for (j = str.size(); j > i && std::isspace(str[j - 1]); --j) {
185  }
186  return std::string(str.substr(i, j - i));
187 }

+ Here is the caller graph for this function:

std::string to_lower ( const std::string &  str)
inline
template<typename T >
std::string to_string ( T &&  v)

Definition at line 84 of file StringTransform.h.

84  {
85  std::ostringstream oss;
86  oss << v;
87  return oss.str();
88 }
template<>
std::string to_string ( char const *&&  v)

Definition at line 101 of file StringTransform.cpp.

Referenced by lockmgr::TableSchemaLockContainer< ReadLock >::acquireTableDescriptor(), lockmgr::TableSchemaLockContainer< WriteLock >::acquireTableDescriptor(), import_export::TypedImportBuffer::add_value(), Catalog_Namespace::Catalog::addColumn(), import_export::TypedImportBuffer::addDefaultValues(), Catalog_Namespace::Catalog::addFrontendViewToMapNoLock(), Catalog_Namespace::Catalog::addLinkToMap(), Catalog_Namespace::Catalog::addReferenceToForeignDict(), CgenState::addStringConstant(), anonymous_namespace{TableArchiver.cpp}::adjust_altered_table_files(), anonymous_namespace{TargetExprBuilder.cpp}::agg_fn_base_names(), Catalog_Namespace::Catalog::alterPhysicalTableMetadata(), Catalog_Namespace::SysCatalog::alterUser(), query_state::StdLog::appendNameValuePairs(), foreign_storage::LazyParquetChunkLoader::appendRowGroups(), Archive::archive_error(), import_export::QueryExporterGDAL::beginExport(), Catalog_Namespace::Catalog::buildMaps(), Catalog_Namespace::SysCatalog::buildObjectDescriptorMap(), ResultSetReductionJIT::cacheKey(), Catalog_Namespace::SysCatalog::changeDBObjectOwnership(), Catalog_Namespace::Catalog::changeForeignServerOwner(), anonymous_namespace{DBETypes.cpp}::checkColumnRange(), foreign_storage::SingleTextFileReader::checkForMoreRows(), anonymous_namespace{Execute.cpp}::checkWorkUnitWatchdog(), anonymous_namespace{GpuSharedMemoryUtils.cpp}::codegen_smem_dest_slot_ptr(), GroupByAndAggregate::codegenAggColumnPtr(), TargetExprCodegen::codegenAggregate(), CodeGenerator::codegenArrayAt(), CodeGenerator::codegenHoistedConstantsLoads(), CodeGenerator::codegenHoistedConstantsPlaceholders(), BaselineJoinHashTable::codegenMatchingSet(), OverlapsJoinHashTable::codegenMatchingSet(), RangeJoinHashTable::codegenMatchingSetWithOffset(), GroupByAndAggregate::codegenOutputSlot(), BaselineJoinHashTable::codegenSlot(), CodeGenerator::codgenAdjustFixedEncNull(), CodeGenerator::colByteStream(), UdfCompiler::compileToLLVMIR(), BloscCompressor::compress(), Geospatial::compress_coords(), anonymous_namespace{OverlapsJoinHashTable.cpp}::compute_bucket_sizes(), DBHandler::convertRows(), File_Namespace::FileMgr::coreInit(), DBHandler::create_dashboard(), create_dev_group_by_buffers(), DBHandler::create_table(), Catalog_Namespace::Catalog::createCustomExpression(), Catalog_Namespace::Catalog::createDashboard(), Catalog_Namespace::Catalog::createDashboardSystemRoles(), Catalog_Namespace::SysCatalog::createDatabase(), Catalog_Namespace::Catalog::createForeignServerNoLocks(), Catalog_Namespace::Catalog::createLink(), Catalog_Namespace::Catalog::createTable(), RelAlgExecutor::createTableFunctionWorkUnit(), Catalog_Namespace::SysCatalog::createUser(), anonymous_namespace{ArrowImporter.h}::data_conversion_error(), DatumToString(), ArrowResultSet::deallocateArrowResultBuffer(), BloscCompressor::decompress(), Catalog_Namespace::Catalog::delDictionary(), Catalog_Namespace::Catalog::deleteCustomExpressions(), Catalog_Namespace::Catalog::deleteMetadataForDashboards(), Catalog_Namespace::SysCatalog::deleteObjectDescriptorMap(), Catalog_Namespace::anonymous_namespace{SysCatalog.cpp}::deleteObjectPrivileges(), DecimalOverflowValidator::do_validate(), Catalog_Namespace::Catalog::dropColumn(), Catalog_Namespace::SysCatalog::dropDatabase(), Catalog_Namespace::Catalog::dropForeignServer(), Catalog_Namespace::Catalog::dropTable(), Catalog_Namespace::SysCatalog::dropUser(), ChunkMetadata::dump(), Catalog_Namespace::Catalog::dumpCreateTable(), Catalog_Namespace::Catalog::dumpSchema(), TableArchiver::dumpTable(), anonymous_namespace{ResultSetReductionJIT.cpp}::emit_write_projection(), FixedLengthEncoder< T, V >::encodeDataAndUpdateStats(), anonymous_namespace{ArrowImporter.h}::error_context(), CudaMgr_Namespace::errorMessage(), ShowUserDetailsCommand::execute(), Parser::CopyTableStmt::execute(), Catalog_Namespace::Catalog::executeDropTableSqliteQueries(), RelAlgExecutor::executeRelAlgQueryNoRetry(), RelAlgExecutor::executeSimpleInsert(), File_Namespace::FileMgr::FileMgr(), import_export::delimited_parser::find_end(), foreign_storage::anonymous_namespace{RegexFileBufferParser.cpp}::find_last_end_of_line(), ProxyTHttpClient::flush(), Geospatial::anonymous_namespace{GDAL.cpp}::gdal_error_handler(), anonymous_namespace{JoinLoopTest.cpp}::generate_descriptors(), UdfCompiler::generateAST(), TableFunctionCompilationContext::generateEntryPoint(), Catalog_Namespace::Catalog::generatePhysicalTableName(), CodeGenerator::generatePTX(), Parser::anonymous_namespace{ParserNode.cpp}::generateUniqueTableName(), Geospatial::GeoPoint::GeoPoint(), anonymous_namespace{ArrowResultSetConverter.cpp}::get_arrow_type(), DBHandler::get_dashboard(), DBHandler::get_dashboard_grantees(), File_Namespace::get_data_file_path(), DateTimeUtils::get_dateadd_high_precision_adjusted_scale(), DateTimeUtils::get_dateadd_timestamp_precision_scale(), DBHandler::get_db_object_privs(), DateTimeUtils::get_extract_timestamp_precision_scale(), import_export::Detector::get_headers(), DBHandler::get_link_view(), get_nvidia_compute_capability(), ThriftClientConnection::get_protocol(), HitTestTypes::get_rowid_regex(), anonymous_namespace{Execute.cpp}::get_table_name(), DateTimeUtils::get_timestamp_precision_scale(), SQLTypeInfo::get_type_name(), DBHandler::get_valid_groups(), getArrowImportType(), Fragmenter_Namespace::InsertOrderFragmenter::getChunkMetadata(), Parser::LocalConnector::getColumnDescriptors(), getCurrentStackTrace(), Catalog_Namespace::Catalog::getCustomExpressionFromStorage(), DataRecyclerUtil::getDeviceIdentifierString(), CudaMgr_Namespace::CudaMgr::getDeviceProperties(), RelAlgExecutor::getErrorMessageFromCode(), Catalog_Namespace::Catalog::getForeignServersForUser(), Catalog_Namespace::Catalog::getForeignTableFromStorage(), Catalog_Namespace::SysCatalog::getGranteesOfSharedDashboards(), Catalog_Namespace::Catalog::getMetadataForDashboard(), Catalog_Namespace::SysCatalog::getMetadataForDBById(), Catalog_Namespace::SysCatalog::getMetadataForObject(), Catalog_Namespace::SysCatalog::getMetadataForUserById(), Catalog_Namespace::SysCatalog::getMetadataWithDefaultDB(), foreign_storage::IntegralFixedLengthBoundsValidator< T >::getMinMaxBoundsAsStrings(), foreign_storage::FloatPointValidator< T >::getMinMaxBoundsAsStrings(), Catalog_Namespace::SysCatalog::getRoles(), DBHandler::has_object_privilege(), DBHandler::import_geo_table(), import_export::import_thread_delimited(), import_export::import_thread_shapefile(), RangeJoinHashTable::initHashTableOnCpu(), OverlapsJoinHashTable::initHashTableOnCpu(), anonymous_namespace{HashTable.cpp}::inner_to_string(), Catalog_Namespace::anonymous_namespace{SysCatalog.cpp}::insertOrUpdateObjectPrivileges(), Executor::interrupt(), ResultSet::isGeoColOnGpu(), TableFunctionExecutionContext::launchCpuCode(), TableFunctionExecutionContext::launchGpuCode(), QueryExecutionContext::launchGpuCode(), DBObject::loadKey(), main(), anonymous_namespace{ExtensionFunctionsBinding.cpp}::match_arguments(), migrations::MigrationMgr::migrateDateInDaysMetadata(), Catalog_Namespace::SysCatalog::migrateDBAccessPrivileges(), numeric_type_name(), import_export::ogr_to_type(), Geospatial::GeoTypesError::OGRErrorToStr(), File_Namespace::open(), anonymous_namespace{ArrowImporter.h}::ArrowValue< float >::operator DATA_TYPE(), anonymous_namespace{ArrowImporter.h}::ArrowValue< double >::operator DATA_TYPE(), anonymous_namespace{ArrowImporter.h}::ArrowValue< int64_t >::operator DATA_TYPE(), logger::JsonEncoder::operator()(), operator<<(), omnisci::JSON::operator[](), ColumnList< T >::operator[](), OutOfMemory::parse_error_str(), import_export::delimited_parser::parse_string_array(), DBHandler::prepare_loader_generic(), anonymous_namespace{Types.cpp}::process_poly_ring(), DictionaryValueConverter< TARGET_TYPE >::processBuffer(), foreign_storage::TextFileBufferParser::processGeoColumn(), query_template_impl(), ra_exec_unit_desc_for_caching(), foreign_storage::SingleTextFileReader::readRegion(), Catalog_Namespace::SysCatalog::reassignObjectOwners(), Catalog_Namespace::Catalog::reassignOwners(), Catalog_Namespace::SysCatalog::recordExecutedMigration(), Catalog_Namespace::Catalog::recordOwnershipOfObjectsInObjectPermissions(), Executor::redeclareFilterFunction(), ResultSetReductionJIT::reduceOneEntryBaseline(), ResultSetReductionJIT::reduceOneEntryTargetsNoCollisions(), QueryMemoryDescriptor::reductionKey(), Executor::registerActiveModule(), PerfectJoinHashTable::reifyForDevice(), BaselineJoinHashTable::reifyForDevice(), AutomaticIRMetadataGuard::rememberOurInstructions(), Catalog_Namespace::Catalog::renameColumn(), Catalog_Namespace::SysCatalog::renameDatabase(), File_Namespace::renameForDelete(), Catalog_Namespace::SysCatalog::renameObjectsInDescriptorMap(), Catalog_Namespace::Catalog::renamePhysicalTable(), Catalog_Namespace::Catalog::replaceDashboard(), Catalog_Namespace::Catalog::restoreOldOwners(), Catalog_Namespace::Catalog::restoreOldOwnersInMemory(), TableArchiver::restoreTable(), ArrowResultSet::resultSetArrowLoopback(), Catalog_Namespace::SysCatalog::revokeAllOnDatabase_unsafe(), QueryRewriter::rewriteColumnarUpdate(), anonymous_namespace{TableArchiver.cpp}::run(), ExecutionKernel::runImpl(), import_export::QueryExporter::safeColumnName(), import_export::RenderGroupAnalyzer::seedFromExistingTableContents(), serialize_column_ref(), serialize_table_ref(), anonymous_namespace{DdlCommandExecutor.cpp}::set_headers_with_type(), Catalog_Namespace::Catalog::setColumnDictionary(), Catalog_Namespace::Catalog::setColumnSharedDictionary(), Catalog_Namespace::Catalog::setForeignServerProperty(), Catalog_Namespace::Catalog::setForeignTableProperty(), Executor::skipFragment(), start_calcite_server_as_daemon(), query_state::StdLogData::StdLogData(), anonymous_namespace{StringTransform.h}::stringlike(), switch(), Catalog_Namespace::anonymous_namespace{Catalog.cpp}::table_epochs_to_string(), anonymous_namespace{ResultSetReductionJIT.cpp}::target_info_key(), ThriftSerializers::target_meta_info_to_thrift(), import_export::anonymous_namespace{QueryExporterCSV.cpp}::target_value_to_string(), DBHandler::thrift_to_copyparams(), foreign_storage::anonymous_namespace{LazyParquetChunkLoader.cpp}::throw_missing_metadata_error(), foreign_storage::throw_number_of_columns_mismatch_error(), foreign_storage::anonymous_namespace{LazyParquetChunkLoader.cpp}::throw_row_group_larger_than_fragment_size_error(), foreign_storage::ParquetFixedLengthArrayEncoder::throwEmptyArrayException(), foreign_storage::ParquetFixedLengthArrayEncoder::throwWrongSizeArray(), logger::JsonEncoder::timer(), Parser::InSubquery::to_string(), Parser::InValues::to_string(), InputDescriptor::toString(), HashTable::toString(), RexAbstractInput::toString(), InputColDescriptor::toString(), table_functions::TableFunctionOutputRowSizer::toString(), ColSlotContext::toString(), ExpressionRange::toString(), toString(), anonymous_namespace{Datum.cpp}::toString(), Analyzer::ColumnVar::toString(), DBObject::toString(), RexOperator::toString(), Analyzer::Var::toString(), QueryMemoryDescriptor::toString(), RexInput::toString(), Analyzer::UOper::toString(), SortField::toString(), RexRef::toString(), Analyzer::InValues::toString(), RexAgg::toString(), Analyzer::InIntegerSet::toString(), RelAggregate::toString(), Analyzer::LikelihoodExpr::toString(), Analyzer::ExtractExpr::toString(), Analyzer::DateaddExpr::toString(), Analyzer::DatediffExpr::toString(), Analyzer::DatetruncExpr::toString(), Analyzer::OrderEntry::toString(), RelCompound::toString(), RelSort::toString(), RelModify::toString(), Analyzer::GeoTransformOperator::toString(), anonymous_namespace{HashJoin.cpp}::toStringFlat(), RelAlgTranslator::translateArrayFunction(), RelAlgTranslator::translateGeoFunctionArg(), RelAlgTranslator::translateHPTLiteral(), Executor::unregisterActiveModule(), Catalog_Namespace::SysCatalog::updateBlankPasswordsToRandom(), Fragmenter_Namespace::InsertOrderFragmenter::updateColumn(), Catalog_Namespace::Catalog::updateCustomExpression(), Catalog_Namespace::Catalog::updateDeletedColumnIndicator(), Catalog_Namespace::Catalog::updateDictionaryNames(), Catalog_Namespace::Catalog::updateFixlenArrayColumns(), Catalog_Namespace::Catalog::updateForeignTableRefreshTimes(), Catalog_Namespace::Catalog::updateGeoColumns(), Catalog_Namespace::Catalog::updateLogicalToPhysicalTableMap(), Catalog_Namespace::SysCatalog::updateObjectDescriptorMap(), Catalog_Namespace::Catalog::updatePageSize(), Catalog_Namespace::SysCatalog::updateSupportUserDeactivation(), Catalog_Namespace::Catalog::updateTableDescriptorSchema(), Catalog_Namespace::UserMetadata::userLoggable(), DateDaysOverflowValidator::validate(), CommandLineOptions::validate(), foreign_storage::Csv::anonymous_namespace{CsvShared.cpp}::validate_and_get_string_with_length(), foreign_storage::anonymous_namespace{CsvFileBufferParser.cpp}::validate_and_get_string_with_length(), foreign_storage::anonymous_namespace{LazyParquetChunkLoader.cpp}::validate_equal_schema(), ddl_utils::anonymous_namespace{DdlUtils.cpp}::validate_literal(), foreign_storage::anonymous_namespace{LazyParquetChunkLoader.cpp}::validate_max_repetition_and_definition_level(), system_validator::validate_table_epochs(), foreign_storage::IntegralFixedLengthBoundsValidator< T >::validateValue(), foreign_storage::FloatPointValidator< T >::validateValue(), ColSlotContext::varlenOutputElementSize(), and ScalarExprToSql::visitUOper().

101  {
102  return std::string(v);
103 }
template<>
std::string to_string ( std::string &&  v)

Definition at line 106 of file StringTransform.cpp.

106  {
107  return std::move(v);
108 }
std::string to_upper ( const std::string &  str)
inline

Definition at line 102 of file StringTransform.h.

Referenced by Catalog_Namespace::Catalog::addColumn(), ExtensionFunctionsWhitelist::addCommon(), Catalog_Namespace::Catalog::addTableToMap(), Catalog_Namespace::Catalog::buildMaps(), Catalog_Namespace::SysCatalog::buildRoleMap(), Catalog_Namespace::SysCatalog::createDatabase(), Catalog_Namespace::SysCatalog::createRole_unsafe(), system_validator::DistributedValidate::DistributedValidate(), Catalog_Namespace::Catalog::dropColumn(), Catalog_Namespace::SysCatalog::dropRole_unsafe(), CreateForeignServerCommand::execute(), anonymous_namespace{DBHandler.cpp}::extract_projection_tokens_for_completion(), ExtensionFunctionsWhitelist::get(), DBHandler::get_completion_hints(), ExtensionFunctionsWhitelist::get_ext_funcs(), DBHandler::get_uc_compatible_table_names_by_column(), ExtensionFunctionsWhitelist::get_udf(), Catalog_Namespace::Catalog::getDictionary(), ShowTableDetailsCommand::getFilteredTableNames(), Catalog_Namespace::Catalog::getForeignTableUnlocked(), Catalog_Namespace::SysCatalog::getGrantee(), shared::FileOrderBase< LocalFileComparator >::getSortBy(), Catalog_Namespace::is_reserved_sql_keyword(), just_whitelisted_keyword_hints(), parseStorageType(), foreign_storage::OptionsContainer::populateOptionsMap(), Catalog_Namespace::Catalog::removeTableFromMap(), Catalog_Namespace::Catalog::renameColumn(), Catalog_Namespace::SysCatalog::renameDatabase(), Catalog_Namespace::Catalog::renamePhysicalTable(), Catalog_Namespace::Catalog::roll(), Catalog_Namespace::Catalog::setForeignServerDataWrapper(), Catalog_Namespace::Catalog::setUncappedTableEpoch(), should_suggest_column_hints(), StringToDatum(), Catalog_Namespace::SysCatalog::syncUserWithRemoteProvider(), Catalog_Namespace::SysCatalog::updateUserRoleName(), ddl_utils::validate_and_set_default_value(), ddl_utils::anonymous_namespace{DdlUtils.cpp}::validate_literal(), and shared::validate_sort_options().

102  {
103  auto str_uc = str;
104  std::transform(str_uc.begin(), str_uc.end(), str_uc.begin(), ::toupper);
105  return str_uc;
106 }

+ Here is the caller graph for this function: