Skip to content

Commit

Permalink
Merge pull request #13 from azaurus1/hhe-table-config
Browse files Browse the repository at this point in the history
Hhe table config
  • Loading branch information
hendoxc authored Mar 3, 2024
2 parents 03c0740 + 77d39b4 commit 734f9cd
Show file tree
Hide file tree
Showing 2 changed files with 118 additions and 4 deletions.
27 changes: 23 additions & 4 deletions go-pinot-api.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,6 @@ type ValidateSchemaResponse struct {

type GetSchemaResponse []string

// generic function
func (c *PinotAPIClient) FetchData(endpoint string, result any) error {

fullURL := fullUrl(c.pinotControllerUrl, endpoint)
Expand Down Expand Up @@ -225,7 +224,6 @@ func (c *PinotAPIClient) UpdateObject(endpoint string, queryParams map[string]st

}

// users
func (c *PinotAPIClient) GetUsers() (*model.GetUsersResponse, error) {
var result model.GetUsersResponse
err := c.FetchData("/users", &result)
Expand Down Expand Up @@ -274,7 +272,6 @@ func (c *PinotAPIClient) UpdateUser(username string, component string, passwordC
return &result, err
}

// tables
func (c *PinotAPIClient) GetTables() (*GetTablesResponse, error) {
var result GetTablesResponse
err := c.FetchData("/tables", &result)
Expand All @@ -287,7 +284,29 @@ func (c *PinotAPIClient) CreateTable(body []byte) (*model.UserActionResponse, er
return &result, err
}

// tenants
func (c *PinotAPIClient) CreateTableFromFile(tableConfigFile string) (*model.UserActionResponse, error) {

f, err := os.Open(tableConfigFile)
if err != nil {
return nil, fmt.Errorf("unable to open table config file: %w", err)
}

defer f.Close()

var tableConfig model.TableConfig
err = json.NewDecoder(f).Decode(&tableConfig)
if err != nil {
return nil, fmt.Errorf("unable to unmarshal table config: %w", err)
}

tableConfigBytes, err := tableConfig.AsBytes()
if err != nil {
return nil, fmt.Errorf("unable to marshal table config: %w", err)
}

return c.CreateTable(tableConfigBytes)
}

func (c *PinotAPIClient) GetTenants() (*GetTenantsResponse, error) {
var result GetTenantsResponse
err := c.FetchData("/tenants", &result)
Expand Down
95 changes: 95 additions & 0 deletions model/TableConfig.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
package model

import (
"encoding/json"
)

type Tenants struct {
Broker string `json:"broker"`
Server string `json:"server"`
TagOverrideConfig map[string]any `json:"tagOverrideConfig"`
}

type SegmentsConfig struct {
SchemaName string `json:"schemaName"`
TimeColumnName any `json:"timeColumnName"`
Replication string `json:"replication"`
ReplicasPerPartition string `json:"replicasPerPartition"`
RetentionTimeUnit any `json:"retentionTimeUnit"`
RetentionTimeValue any `json:"retentionTimeValue"`
CompletionConfig any `json:"completionConfig"`
CrypterClassName any `json:"crypterClassName"`
PeerSegmentDownloadScheme any `json:"peerSegmentDownloadScheme"`
}

type TableIndexConfig struct {
LoadMode string `json:"loadMode"`
InvertedIndexColumns []any `json:"invertedIndexColumns"`
CreateInvertedIndexDuringSegmentGeneration bool `json:"createInvertedIndexDuringSegmentGeneration"`
RangeIndexColumns []any `json:"rangeIndexColumns"`
SortedColumn []any `json:"sortedColumn"`
BloomFilterColumns []any `json:"bloomFilterColumns"`
BloomFilterConfigs any `json:"bloomFilterConfigs"`
NoDictionaryColumns []any `json:"noDictionaryColumns"`
OnHeapDictionaryColumns []any `json:"onHeapDictionaryColumns"`
VarLengthDictionaryColumns []any `json:"varLengthDictionaryColumns"`
EnableDefaultStarTree bool `json:"enableDefaultStarTree"`
StarTreeIndexConfigs any `json:"starTreeIndexConfigs"`
EnableDynamicStarTreeCreation bool `json:"enableDynamicStarTreeCreation"`
SegmentPartitionConfig any `json:"segmentPartitionConfig"`
ColumnMinMaxValueGeneratorMode any `json:"columnMinMaxValueGeneratorMode"`
AggregateMetrics bool `json:"aggregateMetrics"`
NullHandlingEnabled bool `json:"nullHandlingEnabled"`
StreamConfigs map[string]string `json:"streamConfigs"`
}

type IngestionConfig struct {
FilterConfig any `json:"filterConfig"`
TransformConfigs any `json:"transformConfigs"`
}

type Quota struct {
Storage any `json:"storage"`
MaxQueriesPerSecond any `json:"maxQueriesPerSecond"`
}

type Routing struct {
SegmentPrunerTypes any `json:"segmentPrunerTypes"`
InstanceSelectorType any `json:"instanceSelectorType"`
}

type Query struct {
TimeoutMs any `json:"timeoutMs"`
}

type Metadata map[string]any

type UpsertConfig any

type TierConfigs any

type TableConfig struct {
TableName string `json:"tableName"`
TableType string `json:"tableType"`
Tenants Tenants `json:"tenants"`
SegmentsConfig SegmentsConfig `json:"segmentsConfig"`
TableIndexConfig TableIndexConfig `json:"tableIndexConfig"`
Metadata Metadata `json:"metadata"`
IngestionConfig IngestionConfig `json:"ingestionConfig"`
Quota Quota `json:"quota"`
Task any `json:"task"`
Routing Routing `json:"routing"`
Query Query `json:"query"`
FieldConfigList any `json:"fieldConfigList"`
UpsertConfig UpsertConfig `json:"upsertConfig"`
TierConfigs TierConfigs `json:"tierConfigs"`
}

func (tableConfig *TableConfig) AsBytes() ([]byte, error) {
tableBytes, err := json.Marshal(tableConfig)
if err != nil {
return nil, err
}

return tableBytes, nil
}

0 comments on commit 734f9cd

Please sign in to comment.