Skip to content

Commit

Permalink
Merge pull request #15 from azaurus1/get-schema
Browse files Browse the repository at this point in the history
Get schema
  • Loading branch information
hendoxc authored Mar 3, 2024
2 parents 4e48f59 + 24073a4 commit 7a78170
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 8 deletions.
18 changes: 17 additions & 1 deletion example/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -107,11 +107,27 @@ func main() {
log.Panic(err)
}

currentSchemas, err := client.GetSchemas()
if err != nil {
log.Panic(err)
}

currentSchemas.ForEachSchema(func(schemaName string) {

schemaResp, err := client.GetSchema(schemaName)
if err != nil {
log.Panic(err)
}

fmt.Println("Reading Schema:")
fmt.Println(schemaResp)

})
}

func getSchema() pinotModel.Schema {

schemaFilePath := "./data-gen/block_header_schema.json"
schemaFilePath := "./example/data-gen/block_header_schema.json"

f, err := os.Open(schemaFilePath)
if err != nil {
Expand Down
14 changes: 10 additions & 4 deletions go-pinot-api.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,6 @@ type ValidateSchemaResponse struct {
Error string
}

type GetSchemaResponse []string

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

fullURL := fullUrl(c.pinotControllerUrl, endpoint)
Expand Down Expand Up @@ -314,12 +312,20 @@ func (c *PinotAPIClient) GetTenants() (*GetTenantsResponse, error) {
}

// GetSchemas returns a list of schemas
func (c *PinotAPIClient) GetSchemas() (*GetSchemaResponse, error) {
var result GetSchemaResponse
func (c *PinotAPIClient) GetSchemas() (*model.GetSchemaResponse, error) {
var result model.GetSchemaResponse
err := c.FetchData("/schemas", &result)
return &result, err
}

// GetSchema returns a schema
func (c *PinotAPIClient) GetSchema(schemaName string) (*model.Schema, error) {
var result model.Schema
err := c.FetchData(fmt.Sprintf("/schemas/%s", schemaName), &result)
return &result, err

}

// CreateSchema creates a new schema.
// if it already exists, it will nothing will happen
func (c *PinotAPIClient) CreateSchema(schema model.Schema) (*model.UserActionResponse, error) {
Expand Down
9 changes: 9 additions & 0 deletions model/GetSchemaResponse.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package model

type GetSchemaResponse []string

func (g *GetSchemaResponse) ForEachSchema(apply func(schemaName string)) {
for _, v := range *g {
apply(v)
}
}
14 changes: 11 additions & 3 deletions model/Schema.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@ type FieldSpec struct {
type Schema struct {
SchemaName string `json:"schemaName"`
DimensionFieldSpecs []FieldSpec `json:"dimensionFieldSpecs"`
MetricFieldSpecs []FieldSpec `json:"metricFieldSpecs"`
DateTimeFieldSpecs []FieldSpec `json:"dateTimeFieldSpecs"`
PrimaryKeyColumns []string `json:"primaryKeyColumns"`
MetricFieldSpecs []FieldSpec `json:"metricFieldSpecs,omitempty"`
DateTimeFieldSpecs []FieldSpec `json:"dateTimeFieldSpecs,omitempty"`
PrimaryKeyColumns []string `json:"primaryKeyColumns,omitempty"`
}

func (schema *Schema) AsBytes() ([]byte, error) {
Expand All @@ -27,3 +27,11 @@ func (schema *Schema) AsBytes() ([]byte, error) {
return schemaBytes, nil

}

func (schema *Schema) String() string {
jsonString, err := json.MarshalIndent(schema, "", " ")
if err != nil {
return err.Error()
}
return string(jsonString)
}

0 comments on commit 7a78170

Please sign in to comment.