OmniSciDB  a987f07e93
 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)
 
Datum apply_numeric_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

Datum StringOps_Namespace::apply_numeric_op_to_literals ( const StringOpInfo &  string_op_info)

Definition at line 916 of file StringOps.cpp.

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

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

916  {
917  CHECK(string_op_info.hasVarStringLiteral());
918  const auto string_op = gen_string_op(string_op_info);
919  return string_op->numericEval();
920 }
#define CHECK(condition)
Definition: Logger.h:289
std::unique_ptr< const StringOp > gen_string_op(const StringOpInfo &string_op_info)
Definition: StringOps.cpp:715

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

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

Definition at line 905 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().

906  {
907  CHECK(string_op_info.hasVarStringLiteral());
908  if (string_op_info.hasNullLiteralArg()) {
909  const std::string null_str{""};
910  return std::make_pair(null_str, true);
911  }
912  const auto string_op = gen_string_op(string_op_info);
913  return string_op->operator()().toPair();
914 }
#define CHECK(condition)
Definition: Logger.h:289
std::unique_ptr< const StringOp > gen_string_op(const StringOpInfo &string_op_info)
Definition: StringOps.cpp:715

+ 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 715 of file StringOps.cpp.

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

Referenced by apply_numeric_op_to_literals(), and apply_string_op_to_literals().

715  {
716  std::optional<std::string> var_string_optional_literal;
717  const auto op_kind = string_op_info.getOpKind();
718  const auto& return_ti = string_op_info.getReturnType();
719 
720  if (string_op_info.hasNullLiteralArg()) {
721  return std::make_unique<const NullOp>(var_string_optional_literal, op_kind);
722  }
723 
724  const auto num_non_variable_literals = string_op_info.numNonVariableLiterals();
725  if (string_op_info.hasVarStringLiteral()) {
726  CHECK_EQ(num_non_variable_literals + 1UL, string_op_info.numLiterals());
727  var_string_optional_literal = string_op_info.getStringLiteral(0);
728  }
729 
730  switch (op_kind) {
731  case SqlStringOpKind::LOWER: {
732  CHECK_EQ(num_non_variable_literals, 0UL);
733  return std::make_unique<const Lower>(var_string_optional_literal);
734  }
735  case SqlStringOpKind::UPPER: {
736  CHECK_EQ(num_non_variable_literals, 0UL);
737  return std::make_unique<const Upper>(var_string_optional_literal);
738  }
740  CHECK_EQ(num_non_variable_literals, 0UL);
741  return std::make_unique<const InitCap>(var_string_optional_literal);
742  }
744  CHECK_EQ(num_non_variable_literals, 0UL);
745  return std::make_unique<const Reverse>(var_string_optional_literal);
746  }
748  CHECK_EQ(num_non_variable_literals, 1UL);
749  const auto num_repeats_literal = string_op_info.getIntLiteral(1);
750  return std::make_unique<const Repeat>(var_string_optional_literal,
751  num_repeats_literal);
752  }
755  CHECK_GE(num_non_variable_literals, 0UL);
756  CHECK_LE(num_non_variable_literals, 1UL);
757  if (num_non_variable_literals == 1UL) {
758  const auto str_literal = string_op_info.getStringLiteral(1);
759  // Handle lhs literals by having RCONCAT operator set a flag
760  return std::make_unique<const Concat>(var_string_optional_literal,
761  str_literal,
762  op_kind == SqlStringOpKind::RCONCAT);
763  } else {
764  return std::make_unique<const Concat>(var_string_optional_literal);
765  }
766  }
768  case SqlStringOpKind::RPAD: {
769  CHECK_EQ(num_non_variable_literals, 2UL);
770  const auto padded_length_literal = string_op_info.getIntLiteral(1);
771  const auto padding_string_literal = string_op_info.getStringLiteral(2);
772  return std::make_unique<Pad>(var_string_optional_literal,
773  op_kind,
774  padded_length_literal,
775  padding_string_literal);
776  }
779  case SqlStringOpKind::RTRIM: {
780  CHECK_EQ(num_non_variable_literals, 1UL);
781  const auto trim_chars_literal = string_op_info.getStringLiteral(1);
782  return std::make_unique<Trim>(
783  var_string_optional_literal, op_kind, trim_chars_literal);
784  }
786  CHECK_GE(num_non_variable_literals, 1UL);
787  CHECK_LE(num_non_variable_literals, 2UL);
788  const auto start_pos_literal = string_op_info.getIntLiteral(1);
789  const bool has_length_literal = string_op_info.intLiteralArgAtIdxExists(2);
790  if (has_length_literal) {
791  const auto length_literal = string_op_info.getIntLiteral(2);
792  return std::make_unique<const Substring>(
793  var_string_optional_literal, start_pos_literal, length_literal);
794  } else {
795  return std::make_unique<const Substring>(var_string_optional_literal,
796  start_pos_literal);
797  }
798  }
800  CHECK_GE(num_non_variable_literals, 2UL);
801  CHECK_LE(num_non_variable_literals, 3UL);
802  const auto replace_string_literal = string_op_info.getStringLiteral(1);
803  const auto start_pos_literal = string_op_info.getIntLiteral(2);
804  const bool has_length_literal = string_op_info.intLiteralArgAtIdxExists(3);
805  if (has_length_literal) {
806  const auto length_literal = string_op_info.getIntLiteral(3);
807  return std::make_unique<const Overlay>(var_string_optional_literal,
808  replace_string_literal,
809  start_pos_literal,
810  length_literal);
811  } else {
812  return std::make_unique<const Overlay>(
813  var_string_optional_literal, replace_string_literal, start_pos_literal);
814  }
815  }
817  CHECK_GE(num_non_variable_literals, 2UL);
818  CHECK_LE(num_non_variable_literals, 2UL);
819  const auto pattern_string_literal = string_op_info.getStringLiteral(1);
820  const auto replacement_string_literal = string_op_info.getStringLiteral(2);
821  return std::make_unique<const Replace>(var_string_optional_literal,
822  pattern_string_literal,
823  replacement_string_literal);
824  }
826  CHECK_GE(num_non_variable_literals, 2UL);
827  CHECK_LE(num_non_variable_literals, 2UL);
828  const auto delimiter_literal = string_op_info.getStringLiteral(1);
829  const auto split_part_literal = string_op_info.getIntLiteral(2);
830  return std::make_unique<const SplitPart>(
831  var_string_optional_literal, delimiter_literal, split_part_literal);
832  }
834  CHECK_GE(num_non_variable_literals, 5UL);
835  CHECK_LE(num_non_variable_literals, 5UL);
836  const auto pattern_literal = string_op_info.getStringLiteral(1);
837  const auto replacement_literal = string_op_info.getStringLiteral(2);
838  const auto start_pos_literal = string_op_info.getIntLiteral(3);
839  const auto occurrence_literal = string_op_info.getIntLiteral(4);
840  const auto regex_params_literal = string_op_info.getStringLiteral(5);
841  return std::make_unique<const RegexpReplace>(var_string_optional_literal,
842  pattern_literal,
843  replacement_literal,
844  start_pos_literal,
845  occurrence_literal,
846  regex_params_literal);
847  }
849  CHECK_GE(num_non_variable_literals, 5UL);
850  CHECK_LE(num_non_variable_literals, 5UL);
851  const auto pattern_literal = string_op_info.getStringLiteral(1);
852  const auto start_pos_literal = string_op_info.getIntLiteral(2);
853  const auto occurrence_literal = string_op_info.getIntLiteral(3);
854  const auto regex_params_literal = string_op_info.getStringLiteral(4);
855  const auto sub_match_idx_literal = string_op_info.getIntLiteral(5);
856  return std::make_unique<const RegexpSubstr>(var_string_optional_literal,
857  pattern_literal,
858  start_pos_literal,
859  occurrence_literal,
860  regex_params_literal,
861  sub_match_idx_literal);
862  }
864  CHECK_EQ(num_non_variable_literals, 1UL);
865  const auto json_path_literal = string_op_info.getStringLiteral(1);
866  return std::make_unique<const JsonValue>(var_string_optional_literal,
867  json_path_literal);
868  }
870  CHECK_EQ(num_non_variable_literals, 0UL);
871  return std::make_unique<const Base64Encode>(var_string_optional_literal);
872  }
874  CHECK_EQ(num_non_variable_literals, 0UL);
875  return std::make_unique<const Base64Decode>(var_string_optional_literal);
876  }
878  CHECK_EQ(num_non_variable_literals, 0UL);
879  return std::make_unique<const TryStringCast>(return_ti,
880  var_string_optional_literal);
881  }
883  CHECK_GE(num_non_variable_literals, 1UL);
884  CHECK_LE(num_non_variable_literals, 2UL);
885  const auto search_literal = string_op_info.getStringLiteral(1);
886  const bool has_start_pos_literal = string_op_info.intLiteralArgAtIdxExists(2);
887  if (has_start_pos_literal) {
888  const auto start_pos_literal = string_op_info.getIntLiteral(2);
889  return std::make_unique<const Position>(
890  var_string_optional_literal, search_literal, start_pos_literal);
891  } else {
892  return std::make_unique<const Position>(var_string_optional_literal,
893  search_literal);
894  }
895  }
896  default: {
897  UNREACHABLE();
898  return std::make_unique<NullOp>(var_string_optional_literal, op_kind);
899  }
900  }
901  // Make compiler happy
902  return std::make_unique<NullOp>(var_string_optional_literal, op_kind);
903 }
#define CHECK_EQ(x, y)
Definition: Logger.h:297
#define UNREACHABLE()
Definition: Logger.h:333
#define CHECK_GE(x, y)
Definition: Logger.h:302
#define CHECK_LE(x, y)
Definition: Logger.h:300

+ 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(), SQLTypeInfo::get_dimension(), SQLTypeInfo::get_scale(), SQLTypeInfo::get_type(), StringOps_Namespace::StringOpInfo::getOpKind(), StringOps_Namespace::StringOpInfo::getReturnType(), IS_INTEGER, IS_STRING, StringOps_Namespace::StringOpInfo::isLiteralArgNull(), StringOps_Namespace::StringOpInfo::literal_arg_map_, and toString().

24  {
25  stream << "StringOp("
26  << "operator: " << string_op_info.getOpKind()
27  << "return_ti: " << toString(string_op_info.getReturnType().get_type())
28  << " dim: " << string_op_info.getReturnType().get_dimension()
29  << " scale: " << string_op_info.getReturnType().get_scale() << ", literals: [";
30  bool first_elem = true;
31  for (const auto& literal_arg : string_op_info.literal_arg_map_) {
32  if (!first_elem) {
33  stream << ", ";
34  }
35  first_elem = false;
36  const auto datum_type = literal_arg.second.first;
37  const auto& datum = literal_arg.second.second;
38  stream << "{slot: " << literal_arg.first /* slot/idx */ << ", type: "
39  << ::toString(datum_type) << ", value: ";
40  if (string_op_info.isLiteralArgNull(datum_type, literal_arg.second.second)) {
41  stream << "NULL";
42  } else if (IS_STRING(datum_type)) {
43  stream << *datum.stringval;
44  } else {
45  CHECK(IS_INTEGER(datum_type));
46  const SQLTypeInfo ti(datum_type, false);
47  stream << extract_int_type_from_datum(datum, ti);
48  }
49  stream << "}";
50  }
51  stream << "]";
52  return stream;
53 }
int64_t extract_int_type_from_datum(const Datum datum, const SQLTypeInfo &ti)
Definition: Datum.cpp:521
std::string toString(const ExecutorDeviceType &device_type)
#define IS_INTEGER(T)
Definition: sqltypes.h:292
#define IS_STRING(T)
Definition: sqltypes.h:297
#define CHECK(condition)
Definition: Logger.h:289

+ 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 55 of file StringOpInfo.cpp.

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

Definition at line 70 of file StringOpInfo.cpp.

Referenced by operator<<().

70  {
71  std::ostringstream oss;
72  oss << string_op_infos;
73  return oss.str();
74 }

+ Here is the caller graph for this function: