Create Partitioned Table
fields = [
HippoField("column_pk", True, HippoType.STRING),
HippoField("column_partition", False, HippoType.STRING),
HippoField("column_vector_1", False, HippoType.FLOAT_VECTOR, type_params = {"dimension": 128})
]
partition_schema = {
"type":"single_value",
"columns":['column_partition'],
"partitions":[
{
"name":"p1",
"table_name":"p_p1",
"bound":[
{
"field": "column_partition",
"value":"a"
}
]
}
]
}
result = self._hc.create_table(name = self._table_name, fields = fields, database_name = self._database_name, partition_schema = partition_schema)
Result:
This method will return a Hippo object. If failed, “ValueError” exception will be raised.
Parameter description:
Parameters | Description | Required |
---|---|---|
name (str) | Table to be created | Yes |
fields (list[HippoField]) | Field list, every field is a Hippo project containing field name and type | Yes |
database_name (str) | Database where the table is created | No, defaults to "default" database |
number_of_shards (int) | Number of shards | No, defaults to 1 |
number_of_replicas (int) | Number of replicas | No, defaults to 1 |
Add Partition
partitions =
{
"partitions" : [
{
"name": "p3",
"table_name": "p_p3",
"bound": [
{
"field": "book_type",
"value": "a3"
}
]
},
{
"name": "p4",
"table_name": "p_p4",
"bound": [
{
"field": "book_type",
"value": "a4"
}
]
}
]
}
table = self._hc.get_table(tbl_name = self._table_name, database_name = self._database_name)
result = table.add_partitions(partitions = partitions)
Result:
This method will a Boolean value to represent whether this operation is successful. If the error pops up when adding partitions, “ValueError” exception will be raised.
Parameter description:
Parameters | Description | Required |
---|---|---|
partitions (dict) | Partitions to be added; data type is dictionary and each of them should follow the format: {"partitions": [{"name": "partition_name", ...}, ...]} | Yes |
Table 92 Add Partition (Python API)
Delete Partition
partition_names = ["p1", "p2"]
table = self._hc.get_table(tbl_name = self._table_name, database_name = self._database_name)
result = table.delete_partitions(partition_names = partition_names)
Result:
This method will a Boolean value to represent whether this operation is successful. If the error pops up when deleting partitions, “ValueError” exception will be raised.
Parameter description:
Parameters | Description | Required |
---|---|---|
partition_names (list) | Partitions to be deleted | Yes |
Table 93 Delete Partition (Python API)