CUBRID Engine  latest
func_type.cpp
Go to the documentation of this file.
1 /*
2  * Copyright 2008 Search Solution Corporation
3  * Copyright 2016 CUBRID Corporation
4  *
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at
8  *
9  * http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  *
17  */
18 
19 /*
20  * func_type.cpp
21  */
22 
23 #include "func_type.hpp"
24 #include "message_catalog.h"
25 #include "object_primitive.h"
26 #include "parse_tree.h"
27 #include "parser.h"
28 #include "parser_message.h"
29 
30 #include <algorithm>
31 
32 //PT_TYPE_MAYBE
33 // - for the moment I don't see how to eliminate PT_TYPE_MAYBE from functions with multiple signature
34 // - with PT_TYPE_MAYBE in signature, the final type will not be decided during type checking but later
35 // - without PT_TYPE_MAYBE in signature you must either:
36 // 1. choose one signature and apply cast
37 // ... but what about "prepare median(?)... execute with date'2018-06-13'... execute with 123"?
38 // 2. handle from code
39 // ... but there are cases when the cast should be made
40 // but neither one of them is OK
41 
43 {
44  {PT_TYPE_INTEGER, {}, {}},
45 };
46 
48 {
50 };
51 
53 {
55 };
56 
58 {
60 };
61 
63 {
64  {PT_TYPE_BIGINT, {}, {}},
65 };
66 
68 {
69 #if 1
71  {0, {PT_GENERIC_TYPE_DATETIME}, {}},
73  {0, {PT_TYPE_MAYBE}, {}},
74 #else //use double as return type (as documentation says)... but tests are failing (adjust doc or tests)
76  {0, {PT_GENERIC_TYPE_STRING}, {}},
78  {0, {PT_TYPE_MAYBE}, {}},
79  {0, {PT_TYPE_NA}, {}},
80 #endif
81 };
82 
84 {
86  {0, {PT_GENERIC_TYPE_DATETIME}, {}},
88  {0, {PT_TYPE_MAYBE}, {}},
89 };
90 
92 {
94  {PT_TYPE_BIGINT, {PT_TYPE_NA}, {}}, //not needed???
95 };
96 
98 {
100 };
101 
103 {
105 };
106 
108 {
109  {PT_TYPE_INTEGER, {}, {}},
110 };
111 
113 {
115 };
116 
118 {
119  {0, {PT_GENERIC_TYPE_NUMBER}, {}},
120  {0, {PT_TYPE_MAYBE}, {}},
121  {0, {PT_TYPE_SET}, {}},
122  {0, {PT_TYPE_MULTISET}, {}},
123  {0, {PT_TYPE_SEQUENCE}, {}},
124 };
125 
127 {
128  {PT_TYPE_DOUBLE, {}, {}},
130 };
131 
133 {
134  {PT_TYPE_INTEGER, {PT_GENERIC_TYPE_NUMBER}, {}}, //argument value will be truncated at execution
135 };
136 
137 /*cannot define a clear signature because casting depends on actual value
138  MEDIAN('123456') <=> MEDIAN(double) -> double
139  MEDIAN('2018-03-14') <=> MEDIAN(date) -> date */
141 {
142  {PT_TYPE_MAYBE, {PT_GENERIC_TYPE_NUMBER}, {}}, //if ret type is double => tests with median(int) will fail
143  {0, {PT_GENERIC_TYPE_DATETIME}, {}},
145  {0, {PT_TYPE_MAYBE}, {}}, //DISCUSSION: can we get rid of MAYBE here??? prepare median(?)...execute with date'2018-06-13'
146 };
147 
149 {
150  {0, {PT_GENERIC_TYPE_SCALAR}, {}},
151 };
152 
154 {
160 };
161 
163 {
164  {PT_TYPE_VARCHAR, {PT_TYPE_ENUMERATION, PT_GENERIC_TYPE_CHAR}, {}}, //needed because pt_are_equivalent_types(PT_GENERIC_TYPE_CHAR, PT_TYPE_ENUMERATION) and casting to VCHR will affect order
166 
167 //normal cases
171 
172 #if 0 //anything else should be casted to separator's type (if possible! makes sense to detect incompatible types when detecting/applying signatures?); NOTE: casting affects the order!!!
173  {PT_TYPE_VARCHAR, {1, PT_GENERIC_TYPE_CHAR }, {}}, //test
174  {PT_TYPE_VARNCHAR, {1, PT_GENERIC_TYPE_NCHAR }, {}}, //test
175 #else //anything else should be left untouched (like in the original code), maybe it will be casted later?
176 #if 0 //it allows group_concat(SET) but it should not!
177 //{PT_TYPE_VARCHAR , {PT_GENERIC_TYPE_ANY , PT_GENERIC_TYPE_CHAR }, {}},
178 //{PT_TYPE_VARNCHAR , {PT_GENERIC_TYPE_ANY , PT_GENERIC_TYPE_NCHAR }, {}},
179 #else //OK to keep the order but it allows cast (n)char -> number and it should not because group_concat(n'123', ', ') should be rejected?!
180 //like that it allows group_concat(n'123', ', ') or group_concat(<nchar field>, ', ') when <nchar field> can be casted to double (acceptable for me)
181 //but solved in preprocess for compatibility to original behaviour
186 #endif
187 #endif
188 };
189 
191 {
192  {0, {PT_GENERIC_TYPE_NUMBER}, {}},
193  {0, {PT_GENERIC_TYPE_STRING}, {}},
194  {0, {PT_GENERIC_TYPE_DATETIME}, {}},
195  {0, {PT_GENERIC_TYPE_BIT}, {}},
196  {0, {PT_GENERIC_TYPE_SEQUENCE}, {}},
197 };
198 
200 {
201  {PT_TYPE_VARCHAR, {PT_GENERIC_TYPE_DISCRETE_NUMBER}, {PT_TYPE_VARCHAR}}, //get_current_result() expects args to be VCHAR, not just equivalent
202  {PT_TYPE_VARNCHAR, {PT_GENERIC_TYPE_DISCRETE_NUMBER}, {PT_TYPE_VARNCHAR}}, //get_current_result() expects args to be VNCHAR, not just equivalent
204 };
205 
207 {
210 
211  //{0, {3, PT_TYPE_INTEGER, PT_TYPE_INTEGER, PT_GENERIC_TYPE_NCHAR}, {}}, //for insert(?, i, i, n'nchar')
212  //{0, {3, PT_TYPE_INTEGER, PT_TYPE_INTEGER, PT_GENERIC_TYPE_STRING}, {}}, //for insert(?, i, i, 'char or anything else')
213 };
214 
216 {
218  {PT_TYPE_JSON, {}, {}}
219 };
220 
222 {
224  {PT_TYPE_JSON, {}, {}}
225 };
226 
228 {
230 };
231 
233 {
235 };
236 
238 {
240 };
241 
243 {
245 };
246 
248 {
249  {PT_TYPE_JSON, {PT_GENERIC_TYPE_JSON_DOC, PT_GENERIC_TYPE_STRING}, {PT_GENERIC_TYPE_STRING}},
250 };
251 
253 {
255 };
256 
258 {
261 };
262 
264 {
265  {PT_TYPE_INTEGER, {PT_GENERIC_TYPE_JSON_DOC, PT_GENERIC_TYPE_STRING}, {PT_GENERIC_TYPE_STRING}},
266 };
267 
269 {
272 };
273 
275 {
278 };
279 
281 {
282 // all signatures: json_doc, one_or_all_str, search_str[, escape_char[, path] ... -> JSON_DOC
283 // first overload: json_doc, one_or_all_str, search_str:
284  {PT_TYPE_JSON, {PT_GENERIC_TYPE_JSON_DOC, PT_GENERIC_TYPE_STRING, PT_GENERIC_TYPE_STRING}, {}},
285 // second overload: json_doc, one_or_all_str, search_str, escape_char
287 // third overload: json_doc, one_or_all_str, search_str, escape_char, path...
288  {
289  PT_TYPE_JSON,
291  {PT_GENERIC_TYPE_STRING}
292  },
293 };
294 
296 {
298 };
299 
301 {
303 };
304 
306 {
308 };
309 
311 {
313 };
314 
316 {
318 };
319 
321 {
322  {0, {PT_GENERIC_TYPE_ANY}, {}},
323 };
324 
326 {
328 };
329 
331 {
332  {0, {PT_GENERIC_TYPE_STRING}, {}},
333 };
334 
336 {
338 };
339 
341 {
342 // all signatures: src, pattern [,position, [,match_type ]] -> INTEGER
346 };
347 
349 {
350 // all signatures: src, pattern [,position [,occurrence [,return_option [,match_type ]]]] -> INTEGER
356 };
357 
359 {
360 // all signatures: src, pattern [,match_type ] -> INTEGER
363 };
364 
366 {
367 // all signatures: src, pattern, replacement [,position [,occurrence [, match_type]]] -> STRING
368  {PT_TYPE_VARCHAR, {PT_GENERIC_TYPE_STRING, PT_GENERIC_TYPE_STRING, PT_GENERIC_TYPE_STRING}, {}},
372  {PT_TYPE_VARNCHAR, {PT_GENERIC_TYPE_STRING, PT_GENERIC_TYPE_STRING, PT_GENERIC_TYPE_STRING}, {}},
376 };
377 
379 {
380 // all signatures: src, pattern [,position [,occurrence [, match_type]]] -> STRING
389 };
390 
393 {
394  switch (ft)
395  {
396  case PT_MIN:
397  case PT_MAX:
398  return &sig_ret_type0_arg_scalar;
399  case PT_SUM:
400  return &sig_of_sum;
401  case PT_AVG:
402  return &sig_of_avg;
403  case PT_STDDEV:
404  case PT_VARIANCE:
405  case PT_STDDEV_POP:
406  case PT_VAR_POP:
407  case PT_STDDEV_SAMP:
408  case PT_VAR_SAMP:
410  case PT_COUNT:
411  return &sig_of_count;
412  case PT_COUNT_STAR:
413  return &sig_of_count_star;
414  case PT_GROUPBY_NUM:
415  return &sig_ret_bigint;
416  case PT_AGG_BIT_AND:
417  case PT_AGG_BIT_OR:
418  case PT_AGG_BIT_XOR:
420  case PT_GROUP_CONCAT:
421  return &sig_of_group_concat;
422  case PT_ROW_NUMBER:
423  case PT_RANK:
424  case PT_DENSE_RANK:
425  return &sig_ret_int_no_arg;
426  case PT_NTILE:
427  return &sig_of_ntile;
428  case PT_TOP_AGG_FUNC:
429  return nullptr;
430  case PT_LEAD:
431  case PT_LAG:
432  return &sig_of_lead_lag;
433  case PT_GENERIC:
434  return &sig_of_generic;
435  case F_SET:
436  case F_TABLE_SET:
437  return &sig_ret_set_arg_r_any;
438  case F_MULTISET:
439  case F_TABLE_MULTISET:
441  case F_SEQUENCE:
442  case F_TABLE_SEQUENCE:
444  case F_TOP_TABLE_FUNC:
445  return nullptr;
446  case F_MIDXKEY:
447  return nullptr;
448  case F_VID:
449  case F_GENERIC:
450  case F_CLASS_OF:
451  return nullptr;
452  case F_INSERT_SUBSTRING:
453  return &sig_of_insert_substring;
454  case F_ELT:
455  return &sig_of_elt;
456  case F_BENCHMARK:
457  return &sig_of_benchmark;
458  case F_JSON_ARRAY:
460  case F_JSON_ARRAY_APPEND:
461  case F_JSON_ARRAY_INSERT:
463  case F_JSON_CONTAINS:
464  return &sig_of_json_contains;
467  case F_JSON_DEPTH:
468  return &sig_ret_int_arg_doc;
469  case F_JSON_EXTRACT:
472  return &sig_ret_json_arg_jdoc;
473  case F_JSON_INSERT:
475  case F_JSON_KEYS:
476  return &sig_of_json_keys;
477  case F_JSON_LENGTH:
478  return &sig_of_json_length;
479  case F_JSON_MERGE:
480  case F_JSON_MERGE_PATCH:
482  case F_JSON_OBJECT:
484  case F_JSON_PRETTY:
485  return &sig_ret_string_arg_jdoc;
486  case F_JSON_QUOTE:
487  return &sig_ret_type0_arg_str;
488  case F_JSON_REMOVE:
490  case F_JSON_REPLACE:
492  case F_JSON_SEARCH:
493  return &sig_of_json_search;
494  case F_JSON_SET:
496  case F_JSON_TYPE:
497  return &sig_ret_string_arg_jdoc;
498  case F_JSON_UNQUOTE:
499  return &sig_ret_string_arg_jdoc;
500  case F_JSON_VALID:
501  return &sig_ret_int_arg_any;
502  case PT_FIRST_VALUE:
503  case PT_LAST_VALUE:
504  return &sig_ret_type0_arg_scalar;
505  case PT_NTH_VALUE:
507  case PT_MEDIAN:
508  return &sig_of_median;
509  case PT_CUME_DIST:
510  case PT_PERCENT_RANK:
511  return &sig_ret_double_arg_r_any;
512  case PT_PERCENTILE_CONT:
513  return &sig_of_percentile_cont;
514  case PT_PERCENTILE_DISC:
515  return &sig_of_percentile_disc;
516  case PT_JSON_ARRAYAGG:
517  return &sig_of_json_arrayagg;
518  case PT_JSON_OBJECTAGG:
519  return &sig_of_json_objectagg;
520  case F_REGEXP_COUNT:
521  return &sig_of_regexp_count;
522  case F_REGEXP_INSTR:
523  return &sig_of_regexp_instr;
524  case F_REGEXP_LIKE:
525  return &sig_of_regexp_like;
526  case F_REGEXP_REPLACE:
527  return &sig_of_regexp_replace;
528  case F_REGEXP_SUBSTR:
529  return &sig_of_regexp_substr;
530  default:
531  assert (false);
532  return nullptr;
533  }
534 }
535 
536 void
538 {
539  bool first = true;
540  for (auto fix_arg : fix)
541  {
542  if (first)
543  {
544  first = false;
545  }
546  else
547  {
548  sb (", ");
549  }
550  pt_arg_type_to_string_buffer (fix_arg, sb);
551  }
552  if (!rep.empty ())
553  {
554  if (!first)
555  {
556  sb (", ");
557  }
558  sb ("repeat[");
559  first = true;
560  for (auto rep_arg : rep)
561  {
562  if (first)
563  {
564  first = false;
565  }
566  else
567  {
568  sb (", ");
569  }
570  pt_arg_type_to_string_buffer (rep_arg, sb);
571  }
572  sb ("]");
573  }
574  sb (" -> ");
576 }
577 
578 namespace func_type
579 {
580  argument_resolve::argument_resolve ()
581  : m_type (PT_TYPE_NONE)
582  , m_check_coll_infer (false)
583  , m_coll_infer ()
584  {
585  //
586  }
587 
589  : m_compat (type_compatibility::INCOMPATIBLE)
590  , m_args_resolve {}
591  , m_common_collation {}
593  , m_signature (NULL)
594  {
595  //
596  }
597 
598  bool
600  {
601  auto find_pred = [] (const pt_arg_type & arg)
602  {
603  return arg.type == arg.GENERIC && (arg.val.generic_type == PT_GENERIC_TYPE_JSON_DOC
604  || arg.val.generic_type == PT_GENERIC_TYPE_JSON_VAL);
605  };
606 
607  auto it_found = std::find_if (sig.fix.begin (), sig.fix.end (), find_pred);
608  if (it_found != sig.fix.end ())
609  {
610  return true;
611  }
612 
613  // also search in repeateable args
614  it_found = std::find_if (sig.rep.begin (), sig.rep.end (), find_pred);
615  return it_found != sig.rep.end ();
616  }
617 
618  bool
620  {
621  return PT_HAS_COLLATION (type) || type == PT_TYPE_MAYBE;
622  }
623 
624  bool
626  {
627  switch (arg_sig.type)
628  {
629  case pt_arg_type::NORMAL:
630  // types that can have collations
631  return is_type_with_collation (arg_sig.val.type);
632 
634  // all generic that can accept string (and result is still string)
635  return arg_sig.val.generic_type == PT_GENERIC_TYPE_STRING
640  || arg_sig.val.generic_type == PT_GENERIC_TYPE_ANY
642 
643  case pt_arg_type::INDEX:
644  default:
645  assert (false);
646  return false;
647  }
648  }
649 
650  bool
652  {
653  assert (type.type != pt_arg_type::INDEX);
654  return type_enum == PT_TYPE_NULL || pt_are_equivalent_types (type, type_enum);
655  }
656 
657  bool
658  cmp_types_castable (const pt_arg_type &type, pt_type_enum type_enum) //is possible to cast type_enum -> type?
659  {
660  assert (type.type != pt_arg_type::INDEX);
661  if (type_enum == PT_TYPE_NULL)
662  {
663  return true; // PT_TYPE_NULL is castable to any type
664  }
665  if (type_enum == PT_TYPE_MAYBE)
666  {
667  return true; // consider this castable, and truth will be told after late binding
668  }
669  if (type.type == pt_arg_type::NORMAL)
670  {
671  switch (type.val.type)
672  {
673  case PT_TYPE_INTEGER:
674  return (PT_IS_NUMERIC_TYPE (type_enum) || PT_IS_STRING_TYPE (type_enum));
675  case PT_TYPE_BIGINT:
676  return (PT_IS_DISCRETE_NUMBER_TYPE (type_enum));
677  case PT_TYPE_VARCHAR:
678  return (PT_IS_SIMPLE_CHAR_STRING_TYPE (type_enum) || PT_IS_NUMERIC_TYPE (type_enum)
679  || PT_IS_DATE_TIME_TYPE (type_enum) || PT_IS_BIT_STRING_TYPE (type_enum)
680  || type_enum == PT_TYPE_ENUMERATION); //monetary should be here???
681  case PT_TYPE_VARNCHAR:
682  return (PT_IS_NATIONAL_CHAR_STRING_TYPE (type_enum) || PT_IS_NUMERIC_TYPE (type_enum)
683  || PT_IS_DATE_TIME_TYPE (type_enum) || PT_IS_BIT_STRING_TYPE (type_enum)
684  || type_enum == PT_TYPE_ENUMERATION); //monetary should be here???
685  default:
686  return type.val.type == type_enum;
687  }
688  }
689 
690  //type.type == pt_arg_type::GENERIC
691  switch (type.val.generic_type)
692  {
694  return (PT_IS_NUMERIC_TYPE (type_enum) || PT_IS_STRING_TYPE (type_enum) || type_enum == PT_TYPE_JSON);
695 
697  return (PT_IS_NUMERIC_TYPE (type_enum) || PT_IS_STRING_TYPE (type_enum));
698 
699  case PT_GENERIC_TYPE_ANY:
703  case PT_GENERIC_TYPE_BIT:
704  // any non-set?
705  return !PT_IS_COLLECTION_TYPE (type_enum);
706 
708  return (PT_IS_NUMERIC_TYPE (type_enum) || PT_IS_SIMPLE_CHAR_STRING_TYPE (type_enum)
709  || PT_IS_DATE_TIME_TYPE (type_enum) || type_enum == PT_TYPE_JSON);
710 
712  return (PT_IS_NUMERIC_TYPE (type_enum) || PT_IS_NATIONAL_CHAR_STRING_TYPE (type_enum)
713  || PT_IS_DATE_TIME_TYPE (type_enum) || type_enum == PT_TYPE_JSON);
714 
717  return PT_IS_STRING_TYPE (type_enum) || PT_IS_DATE_TIME_TYPE (type_enum);
718 
720  return !PT_IS_COLLECTION_TYPE (type_enum);
721 
723  // it will be resolved at runtime
724  return PT_IS_NUMERIC_TYPE (type_enum); // numerics can be converted to a json value
725 
727  return false; // only equivalent types
728 
730  // todo -
731  return false;
732 
733  case PT_GENERIC_TYPE_LOB:
734  // todo -
735  return false;
736 
738  // ??
739  assert (false);
740  return false;
741 
742  default:
743  assert (false);
744  return false;
745  }
746  }
747 
748  parser_node *
750  {
751  for (auto arg = m_node->info.function.arg_list; arg; arg = arg->next, --index)
752  {
753  if (index == 0)
754  {
755  return arg;
756  }
757  }
758  return NULL;
759  }
760 
761  parser_node *
763  {
764  parser_node *save_next = arg->next;
765 
766  if (arg_res.m_type != arg->type_enum)
767  {
768  arg = pt_wrap_with_cast_op (m_parser, arg, arg_res.m_type, TP_FLOATING_PRECISION_VALUE, 0, NULL);
769  if (arg == NULL)
770  {
771  assert (false);
772  return NULL;
773  }
774  }
775  if (m_best_signature.m_common_collation.coll_id != -1 && arg_res.m_check_coll_infer)
776  {
777  if (m_best_signature.m_common_collation.coll_id != arg_res.m_coll_infer.coll_id)
778  {
779  PT_NODE *new_node = pt_coerce_node_collation (m_parser, arg, m_best_signature.m_common_collation.coll_id,
780  m_best_signature.m_common_collation.codeset,
781  arg_res.m_coll_infer.can_force_cs, false, arg_res.m_type,
782  PT_TYPE_NONE);
783  if (new_node != NULL)
784  {
785  arg = new_node;
786  }
787  else
788  {
789  // what if it is null?
790  }
791  }
792  }
793 
794  // restore links
795  if (prev != NULL)
796  {
797  prev->next = arg;
798  }
799  else
800  {
801  m_node->info.function.arg_list = arg;
802  }
803  arg->next = save_next;
804 
805  return arg;
806  }
807 
808  PT_NODE *
810  {
811  if (m_node->info.function.is_type_checked)
812  {
813  // already checked
814  return m_node;
815  }
816 
817  if (preprocess ())
818  {
819  auto func_sigs = get_signatures (m_node->info.function.function_type);
820  assert ("ERR no function signature" && func_sigs != NULL);
821  if (!func_sigs)
822  {
824  fcode_get_uppercase_name (m_node->info.function.function_type));
825  return m_node;
826  }
827  const func_signature *func_sig = get_signature (*func_sigs);
828  if (func_sig == NULL || !apply_signature (*func_sig))
829  {
830  m_node->type_enum = PT_TYPE_NA;
832  fcode_get_uppercase_name (m_node->info.function.function_type));
833  }
834  else
835  {
836  set_return_type (*func_sig);
837  }
838  }
839  else
840  {
841  // do nothing??
842  }
843  m_node->info.function.is_type_checked = true;
844  return m_node;
845  }
846 
847  bool
849  {
850  auto arg_list = m_node->info.function.arg_list;
851  switch (m_node->info.function.function_type)
852  {
853  case F_GENERIC:
854  case F_CLASS_OF: //move it to the beginning of pt_eval_function_type() ... not without complicating the code
855  m_node->type_enum = (arg_list) ? arg_list->type_enum : PT_TYPE_NONE;
856  return false; //no need to continue with generic code
857  case PT_GROUP_CONCAT: //ToDo: try without this!
858  {
859  auto arg1 = m_node->info.function.arg_list;
860  if (arg1 != NULL)
861  {
862  auto arg2 = arg1->next;
863  if (arg2 != NULL)
864  {
865  if ((PT_IS_SIMPLE_CHAR_STRING_TYPE (arg1->type_enum) && PT_IS_NATIONAL_CHAR_STRING_TYPE (arg2->type_enum))
866  || (PT_IS_SIMPLE_CHAR_STRING_TYPE (arg2->type_enum)
867  && PT_IS_NATIONAL_CHAR_STRING_TYPE (arg1->type_enum)))
868  {
871  pt_show_type_enum (arg2->type_enum));
872  m_node->type_enum = PT_TYPE_VARCHAR;
873  return false;
874  }
875  }
876  }
877  break;
878  }
879  default:
880  ;
881  }
882  return true;
883  }
884 
885  const char *
886  Node::get_types (const func_all_signatures &signatures, size_t index, string_buffer &sb)
887  {
888  for (auto &signature: signatures)
889  {
890  auto i = index;
891  if (index < signature.fix.size ())
892  {
893  pt_arg_type_to_string_buffer (signature.fix[i], sb);
894  sb (", ");
895  }
896  else
897  {
898  i -= signature.fix.size ();
899  if (signature.rep.size () > 0)
900  {
901  i %= signature.rep.size ();
902  pt_arg_type_to_string_buffer (signature.rep[i], sb);
903  sb (", ");
904  }
905  }
906  }
907  return sb.get_buffer ();
908  }
909 
910  const func_signature *
912  {
913  if (pt_has_error (m_parser))
914  {
915  return nullptr;
916  }
917  pt_reset_error (m_parser);
918 
919  size_t arg_count = static_cast<size_t> (pt_length_of_list (m_node->info.function.arg_list));
920  signature_compatibility sgn_compat;
921 
922  int sigIndex = 0;
923  for (auto &sig: signatures)
924  {
925  ++sigIndex;
926  parser_node *arg = m_node->info.function.arg_list;
927  size_t arg_idx = 0;
928 
929  sgn_compat.m_args_resolve.resize (arg_count);
931  sgn_compat.m_signature = &sig;
932  // collation action is initialized as leave. if string-signature arguments are all maybes, then it will remain
933  // leave, and is decided at runtime. if any argument is string, it will be set to TP_DOMAIN_COLL_NORMAL.
935 
936  bool coerce_args_utf8 = sig_has_json_args (sig);
937 
938  //check fix part of the signature
939  for (auto &fix: sig.fix)
940  {
941  if (arg == NULL)
942  {
943  invalid_arg_count_error (arg_count, sig);
945  break;
946  }
947 
948  // todo - index type signature should copy argument type, not argument signature
949  auto t = ((fix.type == pt_arg_type::INDEX) ? sig.fix[fix.val.index] : fix);
950 
951  if (!check_arg_compat (t, arg, sgn_compat, sgn_compat.m_args_resolve[arg_idx], coerce_args_utf8))
952  {
953  break;
954  }
955 
956  ++arg_idx;
957  arg = arg->next;
958  }
959  if (sgn_compat.m_compat == type_compatibility::INCOMPATIBLE)
960  {
961  continue;
962  }
963  if ((arg != NULL && sig.rep.size () == 0) || (arg == NULL && sig.rep.size () != 0))
964  {
965  // number of arguments don't match
966  invalid_arg_count_error (arg_count, sig);
967  continue;
968  }
969 
970  //check repetitive args
971  int index = 0;
972  for (; arg; arg = arg->next, index = (index + 1) % sig.rep.size ())
973  {
974  auto &rep = sig.rep[index];
975  // todo - index type signature should copy argument type, not argument signature
976  auto t = ((rep.type == pt_arg_type::INDEX) ? sig.rep[rep.val.index] : rep);
977 
978  if (!check_arg_compat (t, arg, sgn_compat, sgn_compat.m_args_resolve[arg_idx], coerce_args_utf8))
979  {
980  break;
981  }
982  ++arg_idx;
983  }
984  if (index != 0 && sgn_compat.m_compat != type_compatibility::INCOMPATIBLE)
985  {
986  invalid_arg_count_error (arg_count, sig);
988  continue;
989  }
990 
991  if (sgn_compat.m_compat == type_compatibility::EQUIVALENT)
992  {
993  m_best_signature = std::move (sgn_compat);
994  break; //stop at 1st equivalent signature
995  }
996  if (sgn_compat.m_compat == type_compatibility::COERCIBLE && m_best_signature.m_signature == NULL)
997  {
998  //don't stop, continue because it is possible to find an equivalent signature later
999  m_best_signature = sgn_compat;
1000  }
1001  }
1002  if (m_best_signature.m_signature != NULL)
1003  {
1004  // signature found => clear error messages accumulated during signature checking
1005  pt_reset_error (m_parser);
1006  }
1007  return m_best_signature.m_signature;
1008  }
1009 
1010  void
1012  {
1013  parser_node *arg_list = m_node->info.function.arg_list;
1014  if (m_node->type_enum == PT_TYPE_NONE || m_node->data_type == NULL) //return type
1015  {
1016  // todo - make this really generic
1017 
1018  //set node->type_enum
1019  switch (signature.ret.type)
1020  {
1021  case pt_arg_type::NORMAL:
1022  m_node->type_enum = signature.ret.val.type;
1023  break;
1024  case pt_arg_type::GENERIC:
1025  assert (false);
1026  break;
1027  case pt_arg_type::INDEX:
1028  {
1029  parser_node *arg_node = get_arg (signature.ret.val.index);
1030  if (arg_node != NULL)
1031  {
1032  m_node->type_enum = arg_node->type_enum;
1033  if (m_node->type_enum == PT_TYPE_MAYBE && arg_node->expected_domain != NULL)
1034  {
1035  m_node->type_enum = pt_db_to_type_enum (arg_node->expected_domain->type->id);
1036  }
1037  if (arg_node->data_type != NULL)
1038  {
1039  m_node->data_type = parser_copy_tree_list (m_parser, arg_node->data_type);
1040  }
1041  }
1042  else
1043  {
1044  // ??
1045  assert (false);
1046  }
1047  break;
1048  }
1049  }
1050  // set node->data_type
1051  // todo - remove this switch
1052  switch (m_node->info.function.function_type)
1053  {
1054  case PT_MAX:
1055  case PT_MIN:
1056  case PT_LEAD:
1057  case PT_LAG:
1058  case PT_FIRST_VALUE:
1059  case PT_LAST_VALUE:
1060  case PT_NTH_VALUE:
1061  m_node->data_type = (arg_list ? parser_copy_tree_list (m_parser, arg_list->data_type) : NULL);
1062  break;
1063  case PT_SUM:
1064  m_node->data_type = (arg_list ? parser_copy_tree_list (m_parser, arg_list->data_type) : NULL);
1065  if (arg_list && arg_list->type_enum == PT_TYPE_NUMERIC && m_node->data_type)
1066  {
1067  m_node->data_type->info.data_type.precision = DB_MAX_NUMERIC_PRECISION;
1068  }
1069  break;
1070  case F_ELT:
1071  m_node->data_type = pt_make_prim_data_type (m_parser, m_node->type_enum);
1072  if (m_node->data_type)
1073  {
1074  m_node->data_type->info.data_type.precision =
1076  m_node->data_type->info.data_type.dec_precision = 0;
1077  }
1078  break;
1079  case PT_GROUP_CONCAT:
1080  case F_INSERT_SUBSTRING:
1081  m_node->data_type = pt_make_prim_data_type (m_parser, m_node->type_enum);
1082  if (m_node->data_type)
1083  {
1084  m_node->data_type->info.data_type.precision = TP_FLOATING_PRECISION_VALUE;
1085  }
1086  break;
1087  case F_SET:
1088  case F_MULTISET:
1089  case F_SEQUENCE:
1090  pt_add_type_to_set (m_parser, arg_list, &m_node->data_type);
1091  break;
1092  case F_TABLE_SET:
1093  case F_TABLE_MULTISET:
1094  case F_TABLE_SEQUENCE:
1095  pt_add_type_to_set (m_parser, pt_get_select_list (m_parser, arg_list), &m_node->data_type);
1096  break;
1097  default:
1098  // m_node->data_type = NULL;
1099  break;
1100  }
1101 
1102  if (m_node->data_type == NULL)
1103  {
1104  m_node->data_type = pt_make_prim_data_type (m_parser, m_node->type_enum);
1105  }
1106  if (m_node->data_type != NULL && PT_IS_STRING_TYPE (m_node->type_enum))
1107  {
1108  // always return string without precision
1109  m_node->type_enum = pt_to_variable_size_type (m_node->type_enum);
1110  m_node->data_type->info.data_type.precision = TP_FLOATING_PRECISION_VALUE;
1111  m_node->data_type->type_enum = pt_to_variable_size_type (m_node->type_enum);
1112  assert (m_node->type_enum == m_node->data_type->type_enum);
1113  }
1114  }
1115  else
1116  {
1117  // when is this already set??
1118  }
1119 
1120  // set collation on result node... I am not sure this is correct
1121  if (PT_HAS_COLLATION (m_node->type_enum) && m_best_signature.m_common_collation.coll_id != -1)
1122  {
1123  pt_coll_infer result_coll_infer;
1124  if (is_type_with_collation (m_node->type_enum) && m_best_signature.m_collation_action == TP_DOMAIN_COLL_LEAVE
1125  && m_node->data_type != NULL)
1126  {
1127  // all maybes case. leave collation coming from arguments
1128  m_node->data_type->info.data_type.collation_flag = TP_DOMAIN_COLL_LEAVE;
1129  }
1130  else if (pt_get_collation_info (m_node, &result_coll_infer)
1131  && m_best_signature.m_common_collation.coll_id != result_coll_infer.coll_id)
1132  {
1133  parser_node *new_node = pt_coerce_node_collation (m_parser, m_node,
1134  m_best_signature.m_common_collation.coll_id,
1135  m_best_signature.m_common_collation.codeset,
1136  true, false, PT_TYPE_VARCHAR, PT_TYPE_NONE);
1137  if (new_node != NULL)
1138  {
1139  m_node = new_node;
1140  }
1141  }
1142  }
1143  }
1144 
1145  bool
1147  {
1148  FUNC_TYPE func_type = m_node->info.function.function_type;
1149  parser_node *arg = m_node->info.function.arg_list;
1150  parser_node *prev = NULL;
1151  size_t arg_pos = 0;
1152 
1153  // check fixed part of the function signature
1154  for (auto type: signature.fix)
1155  {
1156  if (arg == NULL)
1157  {
1158  assert (false);
1159  return false;
1160  }
1161 
1162  arg = apply_argument (prev, arg, m_best_signature.m_args_resolve[arg_pos]);
1163  if (arg == NULL)
1164  {
1165  assert (false);
1166  return false;
1167  }
1168 
1169  ++arg_pos;
1170  prev = arg;
1171  arg = arg->next;
1172  }
1173 
1174  if (arg != NULL && signature.rep.size () == 0)
1175  {
1176  assert (false);
1177  return false;
1178  }
1179 
1180  //check repetitive part of the function signature
1181  int index = 0;
1182  for (; arg != NULL; prev = arg, arg = arg->next, index = (index + 1) % signature.rep.size (), ++arg_pos)
1183  {
1184  arg = apply_argument (prev, arg, m_best_signature.m_args_resolve[arg_pos]);
1185  if (arg == NULL)
1186  {
1187  assert (false);
1188  return false;
1189  }
1190  }
1191  if (index != 0)
1192  {
1193  assert (false);
1194  return false;
1195  }
1196 
1197  return true;
1198  }
1199 
1200  bool
1201  Node::check_arg_compat (const pt_arg_type &arg_signature, const PT_NODE *arg_node,
1202  signature_compatibility &compat, argument_resolve &arg_res, bool string_args_to_utf8)
1203  {
1204  arg_res.m_type = PT_TYPE_NONE;
1205 
1206  // todo - equivalent type & coercible type checks should all be in a the same place to have a better view of how
1207  // each type can convert to another
1208 
1209  if (cmp_types_equivalent (arg_signature, arg_node->type_enum))
1210  {
1211  arg_res.m_type = pt_get_equivalent_type (arg_signature, arg_node->type_enum);
1212  }
1213  else if (cmp_types_castable (arg_signature, arg_node->type_enum))
1214  {
1216  arg_res.m_type = pt_get_equivalent_type (arg_signature, arg_node->type_enum);
1217  }
1218  else
1219  {
1221  invalid_arg_error (arg_signature, arg_node, *compat.m_signature);
1222  return false;
1223  }
1224 
1225  // if compatible, pt_get_equivalent_type should return a valid type. but we need to double-check
1226  if (arg_res.m_type == PT_TYPE_NONE)
1227  {
1228  assert (false);
1230  invalid_arg_error (arg_signature, arg_node, *compat.m_signature);
1231  return false;
1232  }
1233 
1234  // three conditions should be met to require collation inference:
1235  //
1236  // 1. argument signature should allow collation. e.g. all generic strings allow collations, but json docs and values
1237  // don't allow
1238  //
1239  // 2. equivalent type should have collation.
1240  //
1241  // 3. original argument type should have collation. if it doesn't have, it doesn't affect common collation.
1242  // NOTE - if first two conditions are true and this is false, we don't do collation inference, but argument will
1243  // be coerced to common collation.
1244  //
1245  // todo - what happens when all arguments are maybe??
1246  //
1247  // NOTE:
1248  // Most of the time, first and second conditions are similar. There are cases when first condition is false and
1249  // second is true. I don't know at this moment if second argument can be false while first is true. To be on the
1250  // safe side, we check them both.
1251  //
1252  if (!can_signature_have_collation (arg_signature) || !is_type_with_collation (arg_res.m_type))
1253  {
1254  // collation does not matter for this argument
1255  arg_res.m_coll_infer.coll_id = -1;
1256  arg_res.m_check_coll_infer = false;
1257  }
1258  else
1259  {
1260  // collation matters for this argument
1261  if (string_args_to_utf8)
1262  {
1265  compat.m_common_collation.can_force_cs = true;
1267  return true;
1268  }
1269 
1270  arg_res.m_coll_infer.coll_id = -1;
1271  arg_res.m_check_coll_infer = true;
1272  if (is_type_with_collation (arg_node->type_enum) && pt_get_collation_info (arg_node, &arg_res.m_coll_infer))
1273  {
1274  // do collation inference
1275  int common_coll;
1276  INTL_CODESET common_cs;
1277  if (compat.m_common_collation.coll_id == -1)
1278  {
1283  }
1284  else if (pt_common_collation (&compat.m_common_collation, &arg_res.m_coll_infer, NULL, 2, false,
1285  &common_coll, &common_cs) == NO_ERROR)
1286  {
1287  compat.m_common_collation.coll_id = common_coll;
1288  compat.m_common_collation.codeset = common_cs;
1289  }
1290  else
1291  {
1292  // todo: we'll need a clear error here
1294  invalid_coll_error (*compat.m_signature);
1295  return false;
1296  }
1297 
1298  if (arg_node->type_enum != PT_TYPE_MAYBE)
1299  {
1301  }
1302  }
1303  else
1304  {
1305  // third condition is not met; this argument does not contribute to common collation.
1306  }
1307  }
1308  return true;
1309  }
1310 
1311  void
1312  Node::invalid_arg_error (const pt_arg_type &arg_sgn, const PT_NODE *arg_node, const func_signature &func_sgn)
1313  {
1314  string_buffer expected_sb;
1315  string_buffer sgn_sb;
1316 
1317  pt_arg_type_to_string_buffer (arg_sgn, expected_sb);
1318  func_sgn.to_string_buffer (sgn_sb);
1319 
1321  pt_show_type_enum (arg_node->type_enum), expected_sb.get_buffer ());
1323  sgn_sb.get_buffer ());
1324  }
1325 
1326  void
1328  {
1329  string_buffer sgn_sb;
1330  func_sgn.to_string_buffer (sgn_sb);
1331 
1333  fcode_get_lowercase_name (m_node->info.function.function_type));
1335  sgn_sb.get_buffer ());
1336  }
1337 
1338  void
1339  Node::invalid_arg_count_error (std::size_t arg_count, const func_signature &func_sgn)
1340  {
1341  string_buffer sgn_sb;
1342  func_sgn.to_string_buffer (sgn_sb);
1343 
1345  (int) arg_count);
1347  sgn_sb.get_buffer ());
1348  }
1349 } // namespace func_type
1350 
1351 /*
1352  * pt_are_equivalent_types () - check if a node type is equivalent with a
1353  * definition type
1354  * return : true if the types are equivalent, false otherwise
1355  * def_type(in) : the definition type
1356  * op_type(in) : argument type
1357  */
1358 bool
1359 pt_are_equivalent_types (const PT_ARG_TYPE def_type, const PT_TYPE_ENUM op_type)
1360 {
1361  if (def_type.type == pt_arg_type::NORMAL)
1362  {
1363  if (def_type.val.type == op_type && op_type == PT_TYPE_NONE)
1364  {
1365  /* return false if both arguments are of type none */
1366  return false;
1367  }
1368  if (def_type.val.type == op_type)
1369  {
1370  /* return true if both have the same type */
1371  return true;
1372  }
1373  /* if def_type is a PT_TYPE_ENUM and the conditions above did not hold then the two types are not equivalent. */
1374  return false;
1375  }
1376 
1377  switch (def_type.val.generic_type)
1378  {
1379  case PT_GENERIC_TYPE_ANY:
1380  /* PT_GENERIC_TYPE_ANY is equivalent to any type */
1381  return true;
1383  if (PT_IS_PRIMITIVE_TYPE (op_type))
1384  {
1385  return true;
1386  }
1387  break;
1389  if (PT_IS_DISCRETE_NUMBER_TYPE (op_type) || op_type == PT_TYPE_ENUMERATION)
1390  {
1391  /* PT_GENERIC_TYPE_DISCRETE_NUMBER is equivalent with SHORT, INTEGER and BIGINT */
1392  return true;
1393  }
1394  break;
1395 
1397  if (PT_IS_NUMERIC_TYPE (op_type) || op_type == PT_TYPE_ENUMERATION)
1398  {
1399  /* any NUMBER type is equivalent with PT_GENERIC_TYPE_NUMBER */
1400  return true;
1401  }
1402  break;
1403 
1405  if (PT_IS_CHAR_STRING_TYPE (op_type) || op_type == PT_TYPE_ENUMERATION)
1406  {
1407  /* any STRING type is equivalent with PT_GENERIC_TYPE_STRING */
1408  return true;
1409  }
1410  break;
1411 
1412  case PT_GENERIC_TYPE_CHAR:
1413  if (op_type == PT_TYPE_CHAR || op_type == PT_TYPE_VARCHAR || op_type == PT_TYPE_ENUMERATION)
1414  {
1415  /* CHAR and VARCHAR are equivalent to PT_GENERIC_TYPE_CHAR */
1416  return true;
1417  }
1418  break;
1419 
1420  case PT_GENERIC_TYPE_NCHAR:
1421  if (op_type == PT_TYPE_NCHAR || op_type == PT_TYPE_VARNCHAR)
1422  {
1423  /* NCHAR and VARNCHAR are equivalent to PT_GENERIC_TYPE_NCHAR */
1424  return true;
1425  }
1426  break;
1427 
1428  case PT_GENERIC_TYPE_BIT:
1429  if (PT_IS_BIT_STRING_TYPE (op_type))
1430  {
1431  /* BIT and BIT VARYING are equivalent to PT_GENERIC_TYPE_BIT */
1432  return true;
1433  }
1434  break;
1435 
1437  if (PT_IS_DATE_TIME_TYPE (op_type))
1438  {
1439  return true;
1440  }
1441  break;
1442  case PT_GENERIC_TYPE_DATE:
1443  if (PT_HAS_DATE_PART (op_type))
1444  {
1445  return true;
1446  }
1447  break;
1449  if (PT_IS_COLLECTION_TYPE (op_type))
1450  {
1451  /* any COLLECTION is equivalent with PT_GENERIC_TYPE_SEQUENCE */
1452  return true;
1453  }
1454  break;
1455 
1457  return pt_is_json_value_type (op_type);
1458 
1460  return pt_is_json_doc_type (op_type);
1461 
1463  return ((op_type == PT_TYPE_ENUMERATION) || PT_IS_NUMERIC_TYPE (op_type) || PT_IS_STRING_TYPE (op_type)
1464  || PT_IS_DATE_TIME_TYPE (op_type));
1465 
1466  default:
1467  return false;
1468  }
1469 
1470  return false;
1471 }
1472 
1473 /*
1474  * pt_get_equivalent_type () - get the type to which a node should be
1475  * converted to in order to match an expression
1476  * definition
1477  * return : the new type
1478  * def_type(in) : the type defined in the expression signature
1479  * arg_type(in) : the type of the received expression argument
1480  */
1482 pt_get_equivalent_type (const PT_ARG_TYPE def_type, const PT_TYPE_ENUM arg_type)
1483 {
1484  if (arg_type == PT_TYPE_NULL || arg_type == PT_TYPE_NONE)
1485  {
1486  /* either the argument is null or not defined */
1487  return arg_type;
1488  }
1489 
1490  if (def_type.type != pt_arg_type::GENERIC)
1491  {
1492  /* if the definition does not have a generic type, return the definition type */
1493  return def_type.val.type;
1494  }
1495 
1496  /* In some cases that involve ENUM (e.g. bit_length function) we need to convert ENUM to the other type even if the
1497  * types are equivalent */
1498  if (pt_are_equivalent_types (def_type, arg_type) && arg_type != PT_TYPE_ENUMERATION)
1499  {
1500  /* def_type includes type */
1501  if (arg_type == PT_TYPE_LOGICAL)
1502  {
1503  /* def_type is a generic type and even though logical type might be equivalent with the generic definition,
1504  * we are sure that we don't want it to be logical here */
1505  return PT_TYPE_INTEGER;
1506  }
1507  return arg_type;
1508  }
1509 
1510  /* At this point we do not have a clear match. We will return the "largest" type for the generic type defined in the
1511  * expression signature */
1512  switch (def_type.val.generic_type)
1513  {
1514  case PT_GENERIC_TYPE_ANY:
1515  if (arg_type == PT_TYPE_LOGICAL)
1516  {
1517  /* if PT_TYPE_LOGICAL appears for a PT_GENERIC_TYPE_ANY, it should be converted to PT_TYPE_INTEGER. */
1518  return PT_TYPE_INTEGER;
1519  }
1520  return arg_type;
1521 
1523  if (PT_IS_PRIMITIVE_TYPE (arg_type))
1524  {
1525  return arg_type;
1526  }
1527  break;
1528 
1529  case PT_GENERIC_TYPE_LOB:
1530  if (PT_IS_LOB_TYPE (arg_type))
1531  {
1532  return arg_type;
1533  }
1534  break;
1535 
1537  return PT_TYPE_BIGINT;
1538 
1540  if (arg_type == PT_TYPE_ENUMERATION)
1541  {
1542  return PT_TYPE_SMALLINT;
1543  }
1544  return PT_TYPE_DOUBLE;
1545 
1546  case PT_GENERIC_TYPE_CHAR:
1549  return PT_TYPE_VARCHAR;
1550 
1551  case PT_GENERIC_TYPE_NCHAR:
1552  return PT_TYPE_VARNCHAR;
1553 
1554  case PT_GENERIC_TYPE_BIT:
1555  return PT_TYPE_VARBIT;
1556 
1557  case PT_GENERIC_TYPE_DATE:
1558  return PT_TYPE_DATETIME;
1559 
1561  if (arg_type == PT_TYPE_ENUMERATION || arg_type == PT_TYPE_MAYBE || PT_IS_NUMERIC_TYPE (arg_type)
1562  || PT_IS_STRING_TYPE (arg_type) || PT_IS_DATE_TIME_TYPE (arg_type))
1563  {
1564  return arg_type;
1565  }
1566  else
1567  {
1568  return PT_TYPE_NONE;
1569  }
1570 
1572  if (pt_is_json_value_type (arg_type))
1573  {
1574  return arg_type;
1575  }
1576  else if (PT_IS_NUMERIC_TYPE (arg_type))
1577  {
1578  return PT_TYPE_JSON;
1579  }
1580  else
1581  {
1582  return PT_TYPE_NONE;
1583  }
1584 
1586  if (pt_is_json_doc_type (arg_type))
1587  {
1588  return arg_type;
1589  }
1590  else
1591  {
1592  return PT_TYPE_NONE;
1593  }
1594 
1595  default:
1596  return PT_TYPE_NONE;
1597  }
1598 
1599  return PT_TYPE_NONE;
1600 }
func_all_signatures * get_signatures(FUNC_TYPE ft)
Definition: func_type.cpp:392
PT_NODE * pt_coerce_node_collation(PARSER_CONTEXT *parser, PT_NODE *node, const int coll_id, const INTL_CODESET codeset, bool force_mode, bool use_collate_modifier, PT_TYPE_ENUM wrap_type_for_maybe, PT_TYPE_ENUM wrap_type_collection)
func_all_signatures sig_ret_double_arg_r_any
Definition: func_type.cpp:126
func_all_signatures sig_of_elt
Definition: func_type.cpp:199
PT_NODE * next
Definition: parse_tree.h:3447
func_all_signatures sig_ret_int_arg_doc
Definition: func_type.cpp:52
func_all_signatures sig_ret_type0_arg_str
Definition: func_type.cpp:330
func_all_signatures sig_of_lead_lag
Definition: func_type.cpp:190
PT_NODE * arg_list
Definition: parse_tree.h:2258
#define NO_ERROR
Definition: error_code.h:46
func_all_signatures sig_of_regexp_like
Definition: func_type.cpp:358
bool can_signature_have_collation(const pt_arg_type &arg_sig)
Definition: func_type.cpp:625
func_all_signatures sig_of_json_length
Definition: func_type.cpp:274
pt_generic_type_enum generic_type
Definition: parse_type.hpp:71
#define PT_IS_CHAR_STRING_TYPE(t)
Definition: parse_tree.h:164
PT_STATEMENT_INFO info
Definition: parse_tree.h:3487
TP_DOMAIN * expected_domain
Definition: parse_tree.h:3452
func_all_signatures sig_ret_type0_arg_nr_or_str_discrete
Definition: func_type.cpp:153
#define MSGCAT_SEMANTIC_NO_VALID_FUNCTION_SIGNATURE
void invalid_arg_error(const pt_arg_type &arg_sgn, const PT_NODE *arg_node, const func_signature &func_sgn)
Definition: func_type.cpp:1312
#define MSGCAT_SEMANTIC_INCOMPATIBLE_SIGNATURE
parser_node * apply_argument(parser_node *prev, parser_node *arg, const argument_resolve &arg_res)
Definition: func_type.cpp:762
#define MSGCAT_SEMANTIC_COLLATION_OP_ERROR
PT_NODE * pt_get_select_list(PARSER_CONTEXT *parser, PT_NODE *query)
Definition: query_result.c:404
bool cmp_types_equivalent(const pt_arg_type &type, pt_type_enum type_enum)
Definition: func_type.cpp:651
func_all_signatures sig_of_regexp_substr
Definition: func_type.cpp:378
std::vector< func_signature > func_all_signatures
Definition: func_type.hpp:42
PT_NODE * type_checking()
Definition: func_type.cpp:809
void pt_reset_error(PARSER_CONTEXT *parser)
func_all_signatures sig_of_json_keys
Definition: func_type.cpp:268
enum pt_type_enum PT_TYPE_ENUM
Definition: parse_tree.h:962
bool cmp_types_castable(const pt_arg_type &type, pt_type_enum type_enum)
Definition: func_type.cpp:658
func_all_signatures sig_ret_bigint
Definition: func_type.cpp:62
func_all_signatures sig_ret_int_arg_str
Definition: func_type.cpp:57
FUNC_TYPE
PT_TYPE_ENUM pt_db_to_type_enum(const DB_TYPE t)
Definition: parse_dbi.c:2595
const char * pt_arg_type_to_string_buffer(const pt_arg_type &type, string_buffer &sb)
Definition: parse_type.cpp:56
PT_TYPE_ENUM pt_get_equivalent_type(const PT_ARG_TYPE def_type, const PT_TYPE_ENUM arg_type)
Definition: func_type.cpp:1482
#define PT_IS_LOB_TYPE(t)
Definition: parse_tree.h:239
bool pt_is_json_doc_type(PT_TYPE_ENUM type)
Definition: parse_tree.c:1442
#define MSGCAT_SEMANTIC_INCOMPATIBLE_ARGUMENT_TYPE
#define PT_IS_DATE_TIME_TYPE(t)
Definition: parse_tree.h:195
bool pt_is_json_value_type(PT_TYPE_ENUM type)
Definition: parse_tree.c:1429
func_all_signatures sig_ret_string_arg_jdoc
Definition: func_type.cpp:325
func_all_signatures sig_of_json_objectagg
Definition: func_type.cpp:300
#define PT_IS_STRING_TYPE(t)
Definition: parse_tree.h:148
const char * get_types(const func_all_signatures &signatures, size_t index, string_buffer &sb)
Definition: func_type.cpp:886
func_all_signatures sig_ret_json_arg_jdoc_str_r_jpath
Definition: func_type.cpp:247
void pt_add_type_to_set(PARSER_CONTEXT *parser, const PT_NODE *typs, PT_NODE **set)
Definition: parse_dbi.c:198
func_all_signatures sig_of_regexp_replace
Definition: func_type.cpp:365
func_all_signatures sig_ret_json_arg_r_jkey_jval_or_empty
Definition: func_type.cpp:215
func_all_signatures sig_of_benchmark
Definition: func_type.cpp:335
func_all_signatures sig_of_json_contains
Definition: func_type.cpp:257
PT_NODE * data_type
Definition: parse_tree.h:3453
INTL_CODESET codeset
Definition: parse_tree.h:3673
PT_NODE * pt_wrap_with_cast_op(PARSER_CONTEXT *parser, PT_NODE *arg, PT_TYPE_ENUM new_type, int p, int s, PT_NODE *desired_dt)
pt_coll_infer m_coll_infer
Definition: func_type.hpp:58
func_all_signatures sig_of_ntile
Definition: func_type.cpp:132
func_all_signatures sig_ret_json_arg_jdoc
Definition: func_type.cpp:227
PT_TYPE_ENUM type_enum
Definition: parse_tree.h:3457
func_all_signatures sig_of_regexp_count
Definition: func_type.cpp:340
func_all_signatures sig_of_sum
Definition: func_type.cpp:117
func_all_signatures sig_ret_sequence_arg_r_any
Definition: func_type.cpp:315
PT_FUNCTION_INFO function
Definition: parse_tree.h:3301
enum pt_arg_type::@135 type
#define DB_MAX_VARCHAR_PRECISION
Definition: dbtype_def.h:536
#define DB_MAX_NUMERIC_PRECISION
Definition: dbtype_def.h:522
#define assert(x)
bool check_arg_compat(const pt_arg_type &arg_signature, const PT_NODE *arg_node, signature_compatibility &compat, argument_resolve &resolved_type, bool args_to_utf8)
Definition: func_type.cpp:1201
std::vector< argument_resolve > m_args_resolve
Definition: func_type.hpp:66
void invalid_coll_error(const func_signature &func_sgn)
Definition: func_type.cpp:1327
func_all_signatures sig_of_percentile_cont
Definition: func_type.cpp:67
#define MSGCAT_SEMANTIC_WRONG_ARGS_COUNT
#define MSGCAT_SEMANTIC_NO_SIGNATURES
const char * pt_show_type_enum(PT_TYPE_ENUM t)
#define PT_IS_BIT_STRING_TYPE(t)
Definition: parse_tree.h:170
pt_group_arg_type rep
Definition: func_type.hpp:38
#define PT_IS_NATIONAL_CHAR_STRING_TYPE(t)
Definition: parse_tree.h:156
func_all_signatures sig_json_arg_r_jval_or_empty
Definition: func_type.cpp:221
#define pt_cat_error(parser, node, setNo, msgNo,...)
Definition: parse_tree.h:50
func_all_signatures sig_ret_int_no_arg
Definition: func_type.cpp:42
void to_string_buffer(string_buffer &sb) const
Definition: func_type.cpp:537
#define PT_IS_DISCRETE_NUMBER_TYPE(t)
Definition: parse_tree.h:135
#define NULL
Definition: freelistheap.h:34
func_all_signatures sig_ret_bigint_arg_discrete
Definition: func_type.cpp:91
struct pr_type * type
Definition: object_domain.h:76
TP_DOMAIN_COLL_ACTION m_collation_action
Definition: func_type.hpp:68
pt_arg_type ret
Definition: func_type.hpp:36
func_all_signatures sig_of_generic
Definition: func_type.cpp:320
if(extra_options)
Definition: dynamic_load.c:958
func_all_signatures sig_of_json_search
Definition: func_type.cpp:280
pt_group_arg_type fix
Definition: func_type.hpp:37
func_all_signatures sig_ret_set_arg_r_any
Definition: func_type.cpp:305
func_all_signatures sig_ret_double_arg_number
Definition: func_type.cpp:102
bool pt_are_equivalent_types(const PT_ARG_TYPE def_type, const PT_TYPE_ENUM op_type)
Definition: func_type.cpp:1359
func_all_signatures sig_of_regexp_instr
Definition: func_type.cpp:348
const char * get_buffer() const
#define PT_IS_COLLECTION_TYPE(t)
Definition: parse_tree.h:143
func_all_signatures sig_ret_json_arg_jdoc_r_jdoc
Definition: func_type.cpp:232
func_all_signatures sig_of_json_contains_path
Definition: func_type.cpp:263
bool pt_get_collation_info(const PT_NODE *node, PT_COLL_INFER *coll_infer)
func_all_signatures sig_ret_json_arg_jdoc_r_jpath_jval
Definition: func_type.cpp:252
func_all_signatures sig_ret_type0_arg_scalar
Definition: func_type.cpp:148
func_all_signatures sig_ret_json_arg_jdoc_jpath
Definition: func_type.cpp:237
#define PT_IS_SIMPLE_CHAR_STRING_TYPE(t)
Definition: parse_tree.h:160
func_all_signatures sig_ret_multiset_arg_r_any
Definition: func_type.cpp:310
const func_signature * m_signature
Definition: func_type.hpp:70
func_all_signatures sig_of_count_star
Definition: func_type.cpp:107
const char * fcode_get_lowercase_name(FUNC_TYPE ftype)
PT_COLL_COERC_LEV coerc_level
Definition: parse_tree.h:3674
#define PT_IS_PRIMITIVE_TYPE(t)
Definition: parse_tree.h:226
#define MSGCAT_SET_PARSER_SEMANTIC
func_all_signatures sig_ret_json_arg_jdoc_r_jpath
Definition: func_type.cpp:242
PT_NODE * pt_make_prim_data_type(PARSER_CONTEXT *parser, PT_TYPE_ENUM e)
#define PT_HAS_DATE_PART(t)
Definition: parse_tree.h:205
func_all_signatures sig_of_count
Definition: func_type.cpp:112
func_all_signatures sig_of_percentile_disc
Definition: func_type.cpp:83
enum intl_codeset INTL_CODESET
Definition: intl_support.h:190
func_all_signatures sig_of_insert_substring
Definition: func_type.cpp:206
int pt_common_collation(PT_COLL_INFER *arg1_coll_infer, PT_COLL_INFER *arg2_coll_infer, PT_COLL_INFER *arg3_coll_infer, const int args_w_coll, bool op_has_3_args, int *common_coll, INTL_CODESET *common_cs)
#define TP_FLOATING_PRECISION_VALUE
union pt_arg_type::pt_arg_type_val val
int i
Definition: dynamic_load.c:954
DB_TYPE id
pt_type_enum
Definition: parse_tree.h:907
bool is_type_with_collation(PT_TYPE_ENUM type)
Definition: func_type.cpp:619
func_all_signatures sig_ret_int_arg_any
Definition: func_type.cpp:47
void invalid_arg_count_error(std::size_t arg_count, const func_signature &func_sgn)
Definition: func_type.cpp:1339
#define DB_MAX_VARNCHAR_PRECISION
Definition: dbtype_def.h:546
#define MSGCAT_SEMANTIC_OP_NOT_DEFINED_ON
#define PT_IS_NUMERIC_TYPE(t)
Definition: parse_tree.h:125
#define pt_has_error(parser)
Definition: parser.h:507
const func_signature * get_signature(const func_all_signatures &signatures)
Definition: func_type.cpp:911
#define PT_HAS_COLLATION(t)
Definition: parse_tree.h:243
parser_node * get_arg(size_t index)
Definition: func_type.cpp:749
type_compatibility
Definition: func_type.hpp:47
func_all_signatures sig_of_group_concat
Definition: func_type.cpp:162
int pt_length_of_list(const PT_NODE *list)
func_all_signatures sig_of_median
Definition: func_type.cpp:140
void set_return_type(const func_signature &signature)
Definition: func_type.cpp:1011
bool sig_has_json_args(const func_signature &sig)
Definition: func_type.cpp:599
PT_TYPE_ENUM pt_to_variable_size_type(PT_TYPE_ENUM type_enum)
bool apply_signature(const func_signature &signature)
Definition: func_type.cpp:1146
PT_NODE * parser_copy_tree_list(PARSER_CONTEXT *parser, PT_NODE *tree)
const char * fcode_get_uppercase_name(FUNC_TYPE ftype)
func_all_signatures sig_of_json_arrayagg
Definition: func_type.cpp:295
func_all_signatures sig_of_avg
Definition: func_type.cpp:97