OmniSciDB  ca0c39ec8f
 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 845 of file StringOps.cpp.

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

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

845  {
846  CHECK(string_op_info.hasVarStringLiteral());
847  const auto string_op = gen_string_op(string_op_info);
848  return string_op->numericEval();
849 }
#define CHECK(condition)
Definition: Logger.h:222
std::unique_ptr< const StringOp > gen_string_op(const StringOpInfo &string_op_info)
Definition: StringOps.cpp:664

+ 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 834 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().

835  {
836  CHECK(string_op_info.hasVarStringLiteral());
837  if (string_op_info.hasNullLiteralArg()) {
838  const std::string null_str{""};
839  return std::make_pair(null_str, true);
840  }
841  const auto string_op = gen_string_op(string_op_info);
842  return string_op->operator()().toPair();
843 }
#define CHECK(condition)
Definition: Logger.h:222
std::unique_ptr< const StringOp > gen_string_op(const StringOpInfo &string_op_info)
Definition: StringOps.cpp:664

+ 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 664 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, 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().

664  {
665  std::optional<std::string> var_string_optional_literal;
666  const auto op_kind = string_op_info.getOpKind();
667  const auto& return_ti = string_op_info.getReturnType();
668 
669  if (string_op_info.hasNullLiteralArg()) {
670  return std::make_unique<const NullOp>(var_string_optional_literal, op_kind);
671  }
672 
673  const auto num_non_variable_literals = string_op_info.numNonVariableLiterals();
674  if (string_op_info.hasVarStringLiteral()) {
675  CHECK_EQ(num_non_variable_literals + 1UL, string_op_info.numLiterals());
676  var_string_optional_literal = string_op_info.getStringLiteral(0);
677  }
678 
679  switch (op_kind) {
680  case SqlStringOpKind::LOWER: {
681  CHECK_EQ(num_non_variable_literals, 0UL);
682  return std::make_unique<const Lower>(var_string_optional_literal);
683  }
684  case SqlStringOpKind::UPPER: {
685  CHECK_EQ(num_non_variable_literals, 0UL);
686  return std::make_unique<const Upper>(var_string_optional_literal);
687  }
689  CHECK_EQ(num_non_variable_literals, 0UL);
690  return std::make_unique<const InitCap>(var_string_optional_literal);
691  }
693  CHECK_EQ(num_non_variable_literals, 0UL);
694  return std::make_unique<const Reverse>(var_string_optional_literal);
695  }
697  CHECK_EQ(num_non_variable_literals, 1UL);
698  const auto num_repeats_literal = string_op_info.getIntLiteral(1);
699  return std::make_unique<const Repeat>(var_string_optional_literal,
700  num_repeats_literal);
701  }
704  CHECK_EQ(num_non_variable_literals, 1UL);
705  const auto str_literal = string_op_info.getStringLiteral(1);
706  // Handle lhs literals by having RCONCAT operator set a flag
707  return std::make_unique<const Concat>(
708  var_string_optional_literal, str_literal, op_kind == SqlStringOpKind::RCONCAT);
709  }
711  case SqlStringOpKind::RPAD: {
712  CHECK_EQ(num_non_variable_literals, 2UL);
713  const auto padded_length_literal = string_op_info.getIntLiteral(1);
714  const auto padding_string_literal = string_op_info.getStringLiteral(2);
715  return std::make_unique<Pad>(var_string_optional_literal,
716  op_kind,
717  padded_length_literal,
718  padding_string_literal);
719  }
722  case SqlStringOpKind::RTRIM: {
723  CHECK_EQ(num_non_variable_literals, 1UL);
724  const auto trim_chars_literal = string_op_info.getStringLiteral(1);
725  return std::make_unique<Trim>(
726  var_string_optional_literal, op_kind, trim_chars_literal);
727  }
729  CHECK_GE(num_non_variable_literals, 1UL);
730  CHECK_LE(num_non_variable_literals, 2UL);
731  const auto start_pos_literal = string_op_info.getIntLiteral(1);
732  const bool has_length_literal = string_op_info.intLiteralArgAtIdxExists(2);
733  if (has_length_literal) {
734  const auto length_literal = string_op_info.getIntLiteral(2);
735  return std::make_unique<const Substring>(
736  var_string_optional_literal, start_pos_literal, length_literal);
737  } else {
738  return std::make_unique<const Substring>(var_string_optional_literal,
739  start_pos_literal);
740  }
741  }
743  CHECK_GE(num_non_variable_literals, 2UL);
744  CHECK_LE(num_non_variable_literals, 3UL);
745  const auto replace_string_literal = string_op_info.getStringLiteral(1);
746  const auto start_pos_literal = string_op_info.getIntLiteral(2);
747  const bool has_length_literal = string_op_info.intLiteralArgAtIdxExists(3);
748  if (has_length_literal) {
749  const auto length_literal = string_op_info.getIntLiteral(3);
750  return std::make_unique<const Overlay>(var_string_optional_literal,
751  replace_string_literal,
752  start_pos_literal,
753  length_literal);
754  } else {
755  return std::make_unique<const Overlay>(
756  var_string_optional_literal, replace_string_literal, start_pos_literal);
757  }
758  }
760  CHECK_GE(num_non_variable_literals, 2UL);
761  CHECK_LE(num_non_variable_literals, 2UL);
762  const auto pattern_string_literal = string_op_info.getStringLiteral(1);
763  const auto replacement_string_literal = string_op_info.getStringLiteral(2);
764  return std::make_unique<const Replace>(var_string_optional_literal,
765  pattern_string_literal,
766  replacement_string_literal);
767  }
769  CHECK_GE(num_non_variable_literals, 2UL);
770  CHECK_LE(num_non_variable_literals, 2UL);
771  const auto delimiter_literal = string_op_info.getStringLiteral(1);
772  const auto split_part_literal = string_op_info.getIntLiteral(2);
773  return std::make_unique<const SplitPart>(
774  var_string_optional_literal, delimiter_literal, split_part_literal);
775  }
777  CHECK_GE(num_non_variable_literals, 5UL);
778  CHECK_LE(num_non_variable_literals, 5UL);
779  const auto pattern_literal = string_op_info.getStringLiteral(1);
780  const auto replacement_literal = string_op_info.getStringLiteral(2);
781  const auto start_pos_literal = string_op_info.getIntLiteral(3);
782  const auto occurrence_literal = string_op_info.getIntLiteral(4);
783  const auto regex_params_literal = string_op_info.getStringLiteral(5);
784  return std::make_unique<const RegexpReplace>(var_string_optional_literal,
785  pattern_literal,
786  replacement_literal,
787  start_pos_literal,
788  occurrence_literal,
789  regex_params_literal);
790  }
792  CHECK_GE(num_non_variable_literals, 5UL);
793  CHECK_LE(num_non_variable_literals, 5UL);
794  const auto pattern_literal = string_op_info.getStringLiteral(1);
795  const auto start_pos_literal = string_op_info.getIntLiteral(2);
796  const auto occurrence_literal = string_op_info.getIntLiteral(3);
797  const auto regex_params_literal = string_op_info.getStringLiteral(4);
798  const auto sub_match_idx_literal = string_op_info.getIntLiteral(5);
799  return std::make_unique<const RegexpSubstr>(var_string_optional_literal,
800  pattern_literal,
801  start_pos_literal,
802  occurrence_literal,
803  regex_params_literal,
804  sub_match_idx_literal);
805  }
807  CHECK_EQ(num_non_variable_literals, 1UL);
808  const auto json_path_literal = string_op_info.getStringLiteral(1);
809  return std::make_unique<const JsonValue>(var_string_optional_literal,
810  json_path_literal);
811  }
813  CHECK_EQ(num_non_variable_literals, 0UL);
814  return std::make_unique<const Base64Encode>(var_string_optional_literal);
815  }
817  CHECK_EQ(num_non_variable_literals, 0UL);
818  return std::make_unique<const Base64Decode>(var_string_optional_literal);
819  }
821  CHECK_EQ(num_non_variable_literals, 0UL);
822  return std::make_unique<const TryStringCast>(return_ti,
823  var_string_optional_literal);
824  }
825  default: {
826  UNREACHABLE();
827  return std::make_unique<NullOp>(var_string_optional_literal, op_kind);
828  }
829  }
830  // Make compiler happy
831  return std::make_unique<NullOp>(var_string_optional_literal, op_kind);
832 }
#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(), 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 }
std::string toString(const QueryDescriptionType &type)
Definition: Types.h:64
int64_t extract_int_type_from_datum(const Datum datum, const SQLTypeInfo &ti)
Definition: Datum.cpp:521
#define IS_INTEGER(T)
Definition: sqltypes.h:292
#define IS_STRING(T)
Definition: sqltypes.h:297
#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 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: