robozmey commented on code in PR #901:
URL: https://github.com/apache/cloudberry/pull/901#discussion_r2139748116


##########
contrib/try_convert/try_convert.c:
##########
@@ -0,0 +1,446 @@
+#include "postgres.h"
+
+#include "catalog/pg_cast.h"
+#include "utils/syscache.h"
+#include "utils/lsyscache.h"
+#include "nodes/nodeFuncs.h"
+// #include "nodes/miscnodes.h"
+
+#include "executor/spi.h"
+
+#include "funcapi.h"
+
+#define USE_PG_TRY_CATCH
+
+PG_MODULE_MAGIC;
+
+PG_FUNCTION_INFO_V1(try_convert);
+
+
+typedef enum ConversionType
+{
+       CONVERSION_TYPE_FUNC,
+       CONVERSION_TYPE_RELABEL,
+       CONVERSION_TYPE_VIA_IO,
+       CONVERSION_TYPE_ARRAY,  
+    CONVERSION_TYPE_NONE       
+} ConversionType;
+
+
+ConversionType find_conversion_way(Oid targetTypeId, Oid sourceTypeId, Oid 
*funcId);
+ConversionType find_typmod_conversion_function(Oid typeId, Oid *funcId);
+Datum convert_from_function(Datum value, int32 typmod, Oid funcId, bool 
*is_failed);
+Datum convert_via_io(Datum value, Oid sourceTypeId, Oid targetTypeId, int32 
targetTypMod, bool *is_failed);
+int32 get_call_expr_argtypmod(Node *expr, int argnum);
+Oid get_fn_expr_argtypmod(FmgrInfo *flinfo, int argnum);
+Datum convert(Datum value, ConversionType conversion_type, Oid funcId, Oid 
sourceTypeId, Oid targetTypeId, int32 targetTypMod, bool *is_failed);
+Datum convert_type_typmod(Datum value, int32 sourceTypMod, Oid targetTypeId, 
int32 targetTypMod, bool *is_failed);
+
+
+ConversionType
+find_conversion_way(Oid targetTypeId, Oid sourceTypeId, Oid *funcId)
+{
+       ConversionType result = CONVERSION_TYPE_NONE;
+       HeapTuple       tuple;
+
+       *funcId = InvalidOid;
+
+       /* Perhaps the types are domains; if so, look at their base types */
+       if (OidIsValid(sourceTypeId))
+               sourceTypeId = getBaseType(sourceTypeId);
+       if (OidIsValid(targetTypeId))
+               targetTypeId = getBaseType(targetTypeId);

Review Comment:
   All will happend like in 
https://github.com/apache/cloudberry/blob/e601fb6a1d3fdf28bad259a851f778f161f02a5e/src/backend/parser/parse_coerce.c#L3151
 (My conversion algorithm duplicates internal one)
   
   We will look in pg_cast table - will find nothing, will try to get 
TypeCategory and will get assert in [TypeCategory(targetTypeId) 
](https://github.com/apache/cloudberry/blob/3e6dc7511b533bbca4d711249997a71448bb359d/contrib/try_convert/try_convert.c#L152)



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to