Partitioned Table

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:

ParametersDescriptionRequired
name (str)Table to be createdYes
fields (list[HippoField])Field list, every field is a Hippo project containing field name and typeYes
database_name (str)Database where the table is createdNo, defaults to "default" database
number_of_shards (int)Number of shardsNo, defaults to 1
number_of_replicas (int)Number of replicasNo, defaults to 1
Table 91 Create Partitioned Table (Python API)

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:

ParametersDescriptionRequired
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:

ParametersDescriptionRequired
partition_names (list)Partitions to be deletedYes

Table 93 Delete Partition (Python API)