Split points are text

pull/6029/head
Nitish Upreti 2022-06-17 11:53:16 -07:00
parent 3e7b3e8f2f
commit b502526ef1
5 changed files with 40 additions and 4 deletions

View File

@ -10,6 +10,7 @@
*/
#include "postgres.h"
#include "catalog/pg_type.h"
#include "nodes/pg_list.h"
#include "distributed/utils/array_type.h"
#include "lib/stringinfo.h"
@ -45,10 +46,10 @@ citus_split_shard_by_split_points(PG_FUNCTION_ARGS)
uint64 shardIdToSplit = DatumGetUInt64(PG_GETARG_DATUM(0));
ArrayType *splitPointsArrayObject = PG_GETARG_ARRAYTYPE_P(1);
List *shardSplitPointsList = IntegerArrayTypeToList(splitPointsArrayObject);
List *shardSplitPointsList = TextArrayTypeToIntegerList(splitPointsArrayObject, INT4OID);
ArrayType *nodeIdsArrayObject = PG_GETARG_ARRAYTYPE_P(2);
List *nodeIdsForPlacementList = IntegerArrayTypeToList(nodeIdsArrayObject);
List *nodeIdsForPlacementList = TextArrayTypeToIntegerList(nodeIdsArrayObject, INT4OID);
Oid shardSplitModeOid = PG_GETARG_OID(3);
SplitMode shardSplitMode = LookupSplitMode(shardSplitModeOid);

View File

@ -6,7 +6,7 @@ CREATE TYPE citus.split_mode AS ENUM (
CREATE OR REPLACE FUNCTION pg_catalog.citus_split_shard_by_split_points(
shard_id bigint,
split_points integer[],
split_points text[],
-- A 'nodeId' is a uint32 in CITUS [1, 4294967296] but postgres does not have unsigned type support.
-- Use integer (consistent with other previously defined UDFs that take nodeId as integer) as for all practical purposes it is big enough.
node_ids integer[],

View File

@ -6,7 +6,7 @@ CREATE TYPE citus.split_mode AS ENUM (
CREATE OR REPLACE FUNCTION pg_catalog.citus_split_shard_by_split_points(
shard_id bigint,
split_points integer[],
split_points text[],
-- A 'nodeId' is a uint32 in CITUS [1, 4294967296] but postgres does not have unsigned type support.
-- Use integer (consistent with other previously defined UDFs that take nodeId as integer) as for all practical purposes it is big enough.
node_ids integer[],

View File

@ -12,6 +12,7 @@
#include "postgres.h"
#include "miscadmin.h"
#include "catalog/pg_type.h"
#include "nodes/pg_list.h"
#include "distributed/utils/array_type.h"
#include "utils/array.h"
@ -115,3 +116,36 @@ IntegerArrayTypeToList(ArrayType *arrayObject)
return list;
}
/*
* Converts Text ArrayType to Integer List.
*/
extern List * TextArrayTypeToIntegerList(ArrayType *arrayObject, Oid datumTypeId)
{
List *list = NULL;
Datum *datumObjectArray = DeconstructArrayObject(arrayObject);
int arrayObjectCount = ArrayObjectCount(arrayObject);
for (int index = 0; index < arrayObjectCount; index++)
{
char *intAsStr = text_to_cstring(DatumGetTextP(datumObjectArray[index]));
switch (datumTypeId)
{
case INT2OID:
list = lappend(list, pg_strtoint16(intAsStr));
break;
case INT4OID:
list = lappend(list, pg_strtoint32(intAsStr));
break;
case INT8OID:
list = lappend(list, pg_strtoint64(intAsStr));
break;
default:
ereport(ERROR, (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
errmsg("Unsupported datum type for array.")));
}
}
return list;
}

View File

@ -21,5 +21,6 @@ extern int32 ArrayObjectCount(ArrayType *arrayObject);
extern ArrayType * DatumArrayToArrayType(Datum *datumArray, int datumCount,
Oid datumTypeId);
extern List * IntegerArrayTypeToList(ArrayType *arrayObject);
extern List * TextArrayTypeToIntegerList(ArrayType *arrayObject, Oid datumTypeId);
#endif /* CITUS_ARRAY_TYPE_H */