Skip to content

Commit

Permalink
Explicitly handle all partition types
Browse files Browse the repository at this point in the history
Error out if we see a partition type we don't understand.
  • Loading branch information
jasonmp85 committed May 23, 2015
1 parent 2814e90 commit 42749a6
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 28 deletions.
36 changes: 25 additions & 11 deletions distribution_metadata.c
Expand Up @@ -512,19 +512,33 @@ TupleToShardInterval(HeapTuple heapTuple, TupleDesc tupleDescriptor)
Oid relationId = DatumGetObjectId(relationIdDatum);

char partitionType = DatumGetChar(partitionTypeDatum);
if (partitionType == HASH_PARTITION_TYPE)
switch (partitionType)
{
intervalTypeId = INT4OID;
}
else
{
Datum keyDatum = SPI_getbinval(heapTuple, tupleDescriptor,
TLIST_NUM_SHARD_KEY, &isNull);
char *partitionColumnName = TextDatumGetCString(keyDatum);
case APPEND_PARTITION_TYPE:
case RANGE_PARTITION_TYPE:
{
Datum keyDatum = SPI_getbinval(heapTuple, tupleDescriptor,
TLIST_NUM_SHARD_KEY, &isNull);
char *partitionColumnName = TextDatumGetCString(keyDatum);

Var *partitionColumn = ColumnNameToColumn(relationId, partitionColumnName);
intervalTypeId = partitionColumn->vartype;
intervalTypeMod = partitionColumn->vartypmod;
break;
}

Var *partitionColumn = ColumnNameToColumn(relationId, partitionColumnName);
intervalTypeId = partitionColumn->vartype;
intervalTypeMod = partitionColumn->vartypmod;
case HASH_PARTITION_TYPE:
{
intervalTypeId = INT4OID;
break;
}

default:
{
ereport(ERROR, (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
errmsg("unsupported table partition type: %c",
partitionType)));
}
}

getTypeInputInfo(intervalTypeId, &inputFunctionId, &typeIoParam);
Expand Down
1 change: 1 addition & 0 deletions distribution_metadata.h
Expand Up @@ -52,6 +52,7 @@
#define TLIST_NUM_SHARD_PLACEMENT_NODE_PORT 5

/* denotes partition type of the distributed table */
#define APPEND_PARTITION_TYPE 'a'
#define HASH_PARTITION_TYPE 'h'
#define RANGE_PARTITION_TYPE 'r'

Expand Down
39 changes: 25 additions & 14 deletions prune_shard_list.c
Expand Up @@ -82,23 +82,34 @@ PruneShardList(Oid relationId, List *whereClauseList, List *shardIntervalList)
char partitionMethod = PartitionType(relationId);

/* build the filter clause list for the partition method */
if (partitionMethod == DISTRIBUTE_BY_HASH)
switch (partitionMethod)
{
Node *hashedNode = HashableClauseMutator((Node *) whereClauseList,
partitionColumn);
case APPEND_PARTITION_TYPE:
case RANGE_PARTITION_TYPE:
{
restrictInfoList = BuildRestrictInfoList(whereClauseList);
break;
}

List *hashedClauseList = (List *) hashedNode;
restrictInfoList = BuildRestrictInfoList(hashedClauseList);
}
else
{
restrictInfoList = BuildRestrictInfoList(whereClauseList);
}
case HASH_PARTITION_TYPE:
{
Node *hashedNode = HashableClauseMutator((Node *) whereClauseList,
partitionColumn);

/* override the partition column for hash partitioning */
if (partitionMethod == DISTRIBUTE_BY_HASH)
{
partitionColumn = MakeInt4Column();
List *hashedClauseList = (List *) hashedNode;
restrictInfoList = BuildRestrictInfoList(hashedClauseList);

/* override the partition column for hash partitioning */
partitionColumn = MakeInt4Column();
break;
}

default:
{
ereport(ERROR, (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
errmsg("unsupported table partition type: %c",
partitionMethod)));
}
}

/* build the base expression for constraint */
Expand Down
3 changes: 0 additions & 3 deletions prune_shard_list.h
Expand Up @@ -21,9 +21,6 @@
#include "nodes/primnodes.h"


/* character used to indicate a hash-partitioned table */
#define DISTRIBUTE_BY_HASH 'h'

/*
* Column ID used to signify that a partition column value has been replaced by
* its hashed value.
Expand Down

0 comments on commit 42749a6

Please sign in to comment.