OmniSciDB  4201147b46
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
StringOps_Namespace Namespace Reference

Classes

struct  StringOpInfo
 

Typedefs

using LiteralArgMap = std::map< size_t, std::pair< SQLTypes, Datum >>
 

Functions

std::ostream & operator<< (std::ostream &stream, const StringOpInfo &string_op_info)
 
std::ostream & operator<< (std::ostream &stream, const std::vector< StringOpInfo > &string_op_infos)
 
std::string toString (const std::vector< StringOpInfo > &string_op_infos)
 
std::unique_ptr< const StringOp > gen_string_op (const StringOpInfo &string_op_info)
 
std::pair< std::string, bool > apply_string_op_to_literals (const StringOpInfo &string_op_info)
 

Typedef Documentation

using StringOps_Namespace::LiteralArgMap = typedef std::map<size_t, std::pair<SQLTypes, Datum>>

Definition at line 30 of file StringOpInfo.h.

Function Documentation

std::pair<std::string, bool > StringOps_Namespace::apply_string_op_to_literals ( const StringOpInfo &  string_op_info)

Definition at line 617 of file StringOps.cpp.

References CHECK, gen_string_op(), StringOps_Namespace::StringOpInfo::hasNullLiteralArg(), and StringOps_Namespace::StringOpInfo::hasVarStringLiteral().

Referenced by TransientStringLiteralsVisitor::visitStringOper(), and anonymous_namespace{ExpressionRewrite.cpp}::ConstantFoldingVisitor::visitStringOper().

618  {
619  CHECK(string_op_info.hasVarStringLiteral());
620  if (string_op_info.hasNullLiteralArg()) {
621  const std::string null_str{""};
622  return std::make_pair(null_str, true);
623  }
624  const auto string_op = gen_string_op(string_op_info);
625  return string_op->operator()().toPair();
626 }
#define CHECK(condition)
Definition: Logger.h:222
std::unique_ptr< const StringOp > gen_string_op(const StringOpInfo &string_op_info)
Definition: StringOps.cpp:467

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

std::unique_ptr<const StringOp> StringOps_Namespace::gen_string_op ( const StringOpInfo &  string_op_info)

Definition at line 467 of file StringOps.cpp.

References CHECK_EQ, CHECK_GE, CHECK_LE, CONCAT, StringOps_Namespace::StringOpInfo::getIntLiteral(), StringOps_Namespace::StringOpInfo::getOpKind(), StringOps_Namespace::StringOpInfo::getStringLiteral(), StringOps_Namespace::StringOpInfo::hasNullLiteralArg(), StringOps_Namespace::StringOpInfo::hasVarStringLiteral(), INITCAP, StringOps_Namespace::StringOpInfo::intLiteralArgAtIdxExists(), LOWER, LPAD, LTRIM, StringOps_Namespace::StringOpInfo::numLiterals(), StringOps_Namespace::StringOpInfo::numNonVariableLiterals(), OVERLAY, RCONCAT, REGEXP_REPLACE, REGEXP_SUBSTR, REPEAT, REPLACE, REVERSE, RPAD, RTRIM, SPLIT_PART, SUBSTRING, TRIM, UNREACHABLE, and UPPER.

Referenced by apply_string_op_to_literals().

467  {
468  std::optional<std::string> var_string_optional_literal;
469  const auto op_kind = string_op_info.getOpKind();
470 
471  if (string_op_info.hasNullLiteralArg()) {
472  return std::make_unique<const NullOp>(var_string_optional_literal, op_kind);
473  }
474 
475  const auto num_non_variable_literals = string_op_info.numNonVariableLiterals();
476  if (string_op_info.hasVarStringLiteral()) {
477  CHECK_EQ(num_non_variable_literals + 1UL, string_op_info.numLiterals());
478  var_string_optional_literal = string_op_info.getStringLiteral(0);
479  }
480 
481  switch (op_kind) {
482  case SqlStringOpKind::LOWER: {
483  CHECK_EQ(num_non_variable_literals, 0UL);
484  return std::make_unique<const Lower>(var_string_optional_literal);
485  }
486  case SqlStringOpKind::UPPER: {
487  CHECK_EQ(num_non_variable_literals, 0UL);
488  return std::make_unique<const Upper>(var_string_optional_literal);
489  }
491  CHECK_EQ(num_non_variable_literals, 0UL);
492  return std::make_unique<const InitCap>(var_string_optional_literal);
493  }
495  CHECK_EQ(num_non_variable_literals, 0UL);
496  return std::make_unique<const Reverse>(var_string_optional_literal);
497  }
499  CHECK_EQ(num_non_variable_literals, 1UL);
500  const auto num_repeats_literal = string_op_info.getIntLiteral(1);
501  return std::make_unique<const Repeat>(var_string_optional_literal,
502  num_repeats_literal);
503  }
506  CHECK_EQ(num_non_variable_literals, 1UL);
507  const auto str_literal = string_op_info.getStringLiteral(1);
508  // Handle lhs literals by having RCONCAT operator set a flag
509  return std::make_unique<const Concat>(
510  var_string_optional_literal, str_literal, op_kind == SqlStringOpKind::RCONCAT);
511  }
513  case SqlStringOpKind::RPAD: {
514  CHECK_EQ(num_non_variable_literals, 2UL);
515  const auto padded_length_literal = string_op_info.getIntLiteral(1);
516  const auto padding_string_literal = string_op_info.getStringLiteral(2);
517  return std::make_unique<Pad>(var_string_optional_literal,
518  op_kind,
519  padded_length_literal,
520  padding_string_literal);
521  }
524  case SqlStringOpKind::RTRIM: {
525  CHECK_EQ(num_non_variable_literals, 1UL);
526  const auto trim_chars_literal = string_op_info.getStringLiteral(1);
527  return std::make_unique<Trim>(
528  var_string_optional_literal, op_kind, trim_chars_literal);
529  }
531  CHECK_GE(num_non_variable_literals, 1UL);
532  CHECK_LE(num_non_variable_literals, 2UL);
533  const auto start_pos_literal = string_op_info.getIntLiteral(1);
534  const bool has_length_literal = string_op_info.intLiteralArgAtIdxExists(2);
535  if (has_length_literal) {
536  const auto length_literal = string_op_info.getIntLiteral(2);
537  return std::make_unique<const Substring>(
538  var_string_optional_literal, start_pos_literal, length_literal);
539  } else {
540  return std::make_unique<const Substring>(var_string_optional_literal,
541  start_pos_literal);
542  }
543  }
545  CHECK_GE(num_non_variable_literals, 2UL);
546  CHECK_LE(num_non_variable_literals, 3UL);
547  const auto replace_string_literal = string_op_info.getStringLiteral(1);
548  const auto start_pos_literal = string_op_info.getIntLiteral(2);
549  const bool has_length_literal = string_op_info.intLiteralArgAtIdxExists(3);
550  if (has_length_literal) {
551  const auto length_literal = string_op_info.getIntLiteral(3);
552  return std::make_unique<const Overlay>(var_string_optional_literal,
553  replace_string_literal,
554  start_pos_literal,
555  length_literal);
556  } else {
557  return std::make_unique<const Overlay>(
558  var_string_optional_literal, replace_string_literal, start_pos_literal);
559  }
560  }
562  CHECK_GE(num_non_variable_literals, 2UL);
563  CHECK_LE(num_non_variable_literals, 2UL);
564  const auto pattern_string_literal = string_op_info.getStringLiteral(1);
565  const auto replacement_string_literal = string_op_info.getStringLiteral(2);
566  return std::make_unique<const Replace>(var_string_optional_literal,
567  pattern_string_literal,
568  replacement_string_literal);
569  }
571  CHECK_GE(num_non_variable_literals, 2UL);
572  CHECK_LE(num_non_variable_literals, 2UL);
573  const auto delimiter_literal = string_op_info.getStringLiteral(1);
574  const auto split_part_literal = string_op_info.getIntLiteral(2);
575  return std::make_unique<const SplitPart>(
576  var_string_optional_literal, delimiter_literal, split_part_literal);
577  }
579  CHECK_GE(num_non_variable_literals, 5UL);
580  CHECK_LE(num_non_variable_literals, 5UL);
581  const auto pattern_literal = string_op_info.getStringLiteral(1);
582  const auto replacement_literal = string_op_info.getStringLiteral(2);
583  const auto start_pos_literal = string_op_info.getIntLiteral(3);
584  const auto occurrence_literal = string_op_info.getIntLiteral(4);
585  const auto regex_params_literal = string_op_info.getStringLiteral(5);
586  return std::make_unique<const RegexpReplace>(var_string_optional_literal,
587  pattern_literal,
588  replacement_literal,
589  start_pos_literal,
590  occurrence_literal,
591  regex_params_literal);
592  }
594  CHECK_GE(num_non_variable_literals, 5UL);
595  CHECK_LE(num_non_variable_literals, 5UL);
596  const auto pattern_literal = string_op_info.getStringLiteral(1);
597  const auto start_pos_literal = string_op_info.getIntLiteral(2);
598  const auto occurrence_literal = string_op_info.getIntLiteral(3);
599  const auto regex_params_literal = string_op_info.getStringLiteral(4);
600  const auto sub_match_idx_literal = string_op_info.getIntLiteral(5);
601  return std::make_unique<const RegexpSubstr>(var_string_optional_literal,
602  pattern_literal,
603  start_pos_literal,
604  occurrence_literal,
605  regex_params_literal,
606  sub_match_idx_literal);
607  }
608  default: {
609  UNREACHABLE();
610  return std::make_unique<NullOp>(var_string_optional_literal, op_kind);
611  }
612  }
613  // Make compiler happy
614  return std::make_unique<NullOp>(var_string_optional_literal, op_kind);
615 }
#define CHECK_EQ(x, y)
Definition: Logger.h:230
#define UNREACHABLE()
Definition: Logger.h:266
#define CHECK_GE(x, y)
Definition: Logger.h:235
#define CHECK_LE(x, y)
Definition: Logger.h:233

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

std::ostream& StringOps_Namespace::operator<< ( std::ostream &  stream,
const StringOpInfo &  string_op_info 
)

Definition at line 24 of file StringOpInfo.cpp.

References CHECK, extract_int_type_from_datum(), StringOps_Namespace::StringOpInfo::getOpKind(), IS_INTEGER, IS_STRING, StringOps_Namespace::StringOpInfo::isLiteralArgNull(), StringOps_Namespace::StringOpInfo::literal_arg_map_, and toString().

24  {
25  stream << "StringOp("
26  << "operator: " << ::toString(string_op_info.getOpKind()) << ", literals: [";
27  bool first_elem = true;
28  for (const auto& literal_arg : string_op_info.literal_arg_map_) {
29  if (!first_elem) {
30  stream << ", ";
31  }
32  first_elem = false;
33  const auto datum_type = literal_arg.second.first;
34  const auto& datum = literal_arg.second.second;
35  stream << "{slot: " << literal_arg.first /* slot/idx */ << ", type: "
36  << ::toString(datum_type) << ", value: ";
37  if (string_op_info.isLiteralArgNull(datum_type, literal_arg.second.second)) {
38  stream << "NULL";
39  } else if (IS_STRING(datum_type)) {
40  stream << *datum.stringval;
41  } else {
42  CHECK(IS_INTEGER(datum_type));
43  const SQLTypeInfo ti(datum_type, false);
44  stream << extract_int_type_from_datum(datum, ti);
45  }
46  stream << "}";
47  }
48  stream << "]";
49  return stream;
50 }
int64_t extract_int_type_from_datum(const Datum datum, const SQLTypeInfo &ti)
Definition: Datum.cpp:455
std::string toString(const Executor::ExtModuleKinds &kind)
Definition: Execute.h:1457
#define IS_INTEGER(T)
Definition: sqltypes.h:245
#define IS_STRING(T)
Definition: sqltypes.h:250
#define CHECK(condition)
Definition: Logger.h:222

+ Here is the call graph for this function:

std::ostream & StringOps_Namespace::operator<< ( std::ostream &  stream,
const std::vector< StringOpInfo > &  string_op_infos 
)

Definition at line 52 of file StringOpInfo.cpp.

53  {
54  stream << "[";
55  bool first_elem = true;
56  for (const auto& string_op_info : string_op_infos) {
57  if (!first_elem) {
58  stream << ", ";
59  }
60  first_elem = false;
61  stream << string_op_info;
62  }
63  stream << "]";
64  return stream;
65 }
std::string StringOps_Namespace::toString ( const std::vector< StringOpInfo > &  string_op_infos)

Definition at line 67 of file StringOpInfo.cpp.

Referenced by operator<<().

67  {
68  std::ostringstream oss;
69  oss << string_op_infos;
70  return oss.str();
71 }

+ Here is the caller graph for this function: