mirror of https://github.com/citusdata/citus.git
Split points are text
parent
3e7b3e8f2f
commit
b502526ef1
|
@ -10,6 +10,7 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "postgres.h"
|
#include "postgres.h"
|
||||||
|
#include "catalog/pg_type.h"
|
||||||
#include "nodes/pg_list.h"
|
#include "nodes/pg_list.h"
|
||||||
#include "distributed/utils/array_type.h"
|
#include "distributed/utils/array_type.h"
|
||||||
#include "lib/stringinfo.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));
|
uint64 shardIdToSplit = DatumGetUInt64(PG_GETARG_DATUM(0));
|
||||||
|
|
||||||
ArrayType *splitPointsArrayObject = PG_GETARG_ARRAYTYPE_P(1);
|
ArrayType *splitPointsArrayObject = PG_GETARG_ARRAYTYPE_P(1);
|
||||||
List *shardSplitPointsList = IntegerArrayTypeToList(splitPointsArrayObject);
|
List *shardSplitPointsList = TextArrayTypeToIntegerList(splitPointsArrayObject, INT4OID);
|
||||||
|
|
||||||
ArrayType *nodeIdsArrayObject = PG_GETARG_ARRAYTYPE_P(2);
|
ArrayType *nodeIdsArrayObject = PG_GETARG_ARRAYTYPE_P(2);
|
||||||
List *nodeIdsForPlacementList = IntegerArrayTypeToList(nodeIdsArrayObject);
|
List *nodeIdsForPlacementList = TextArrayTypeToIntegerList(nodeIdsArrayObject, INT4OID);
|
||||||
|
|
||||||
Oid shardSplitModeOid = PG_GETARG_OID(3);
|
Oid shardSplitModeOid = PG_GETARG_OID(3);
|
||||||
SplitMode shardSplitMode = LookupSplitMode(shardSplitModeOid);
|
SplitMode shardSplitMode = LookupSplitMode(shardSplitModeOid);
|
||||||
|
|
|
@ -6,7 +6,7 @@ CREATE TYPE citus.split_mode AS ENUM (
|
||||||
|
|
||||||
CREATE OR REPLACE FUNCTION pg_catalog.citus_split_shard_by_split_points(
|
CREATE OR REPLACE FUNCTION pg_catalog.citus_split_shard_by_split_points(
|
||||||
shard_id bigint,
|
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.
|
-- 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.
|
-- 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[],
|
node_ids integer[],
|
||||||
|
|
|
@ -6,7 +6,7 @@ CREATE TYPE citus.split_mode AS ENUM (
|
||||||
|
|
||||||
CREATE OR REPLACE FUNCTION pg_catalog.citus_split_shard_by_split_points(
|
CREATE OR REPLACE FUNCTION pg_catalog.citus_split_shard_by_split_points(
|
||||||
shard_id bigint,
|
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.
|
-- 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.
|
-- 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[],
|
node_ids integer[],
|
||||||
|
|
|
@ -12,6 +12,7 @@
|
||||||
#include "postgres.h"
|
#include "postgres.h"
|
||||||
#include "miscadmin.h"
|
#include "miscadmin.h"
|
||||||
|
|
||||||
|
#include "catalog/pg_type.h"
|
||||||
#include "nodes/pg_list.h"
|
#include "nodes/pg_list.h"
|
||||||
#include "distributed/utils/array_type.h"
|
#include "distributed/utils/array_type.h"
|
||||||
#include "utils/array.h"
|
#include "utils/array.h"
|
||||||
|
@ -115,3 +116,36 @@ IntegerArrayTypeToList(ArrayType *arrayObject)
|
||||||
|
|
||||||
return list;
|
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;
|
||||||
|
}
|
||||||
|
|
|
@ -21,5 +21,6 @@ extern int32 ArrayObjectCount(ArrayType *arrayObject);
|
||||||
extern ArrayType * DatumArrayToArrayType(Datum *datumArray, int datumCount,
|
extern ArrayType * DatumArrayToArrayType(Datum *datumArray, int datumCount,
|
||||||
Oid datumTypeId);
|
Oid datumTypeId);
|
||||||
extern List * IntegerArrayTypeToList(ArrayType *arrayObject);
|
extern List * IntegerArrayTypeToList(ArrayType *arrayObject);
|
||||||
|
extern List * TextArrayTypeToIntegerList(ArrayType *arrayObject, Oid datumTypeId);
|
||||||
|
|
||||||
#endif /* CITUS_ARRAY_TYPE_H */
|
#endif /* CITUS_ARRAY_TYPE_H */
|
||||||
|
|
Loading…
Reference in New Issue