Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 0 additions & 20 deletions bigquery/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,26 +30,6 @@ type BigQueryAdapter struct {
cancel context.CancelFunc
}

func (bq *BigQueryConfig) Validate() error {
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Validation methods were moved from client.go (build tags) to conf.go (no build tags) so it's consistent with some newer adapters (WEL, Mac Unified Logging) to work around build tag issue (so validation methods are always available regardless of the target platform) and so those validation functions can be used by the new validation command / tool.

The change should be fully backward compatible.

if bq.ProjectId == "" {
return errors.New("missing project_id")
}
// this will usually be th same as projectID but could be different if using outside project dataset such as a public data set
if bq.BigQueryProject == "" {
return errors.New("missing bigquery project name")
}
if bq.DatasetName == "" {
return errors.New("missing dataset_name")
}
if bq.TableName == "" {
return errors.New("missing table_name")
}
if bq.SqlQuery == "" {
return errors.New("missing sql query")
}
return nil
}

func NewBigQueryAdapter(ctx context.Context, conf BigQueryConfig) (*BigQueryAdapter, chan struct{}, error) {
// Create bq cancellable context
ctx, cancel := context.WithCancel(context.Background())
Expand Down
32 changes: 32 additions & 0 deletions bigquery/conf.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package usp_bigquery

import (
"errors"

"github.com/refractionPOINT/go-uspclient"
)

Expand All @@ -15,3 +17,33 @@ type BigQueryConfig struct {
QueryInterval string `json:"query_interval" yaml:"query_interval"`
IsOneTimeLoad bool `json:"is_one_time_load" yaml:"is_one_time_load"`
}

// Validate validates the BigQuery adapter configuration.
//
// Parameters:
//
// None
//
// Returns:
//
// error - Returns nil if validation passes, or an error describing the validation failure.
func (c *BigQueryConfig) Validate() error {
if c.ProjectId == "" {
return errors.New("missing project_id")
}
// BigQueryProject will usually be the same as ProjectId but could be different
// if using outside project dataset such as a public data set.
if c.BigQueryProject == "" {
return errors.New("missing bigquery_project")
}
if c.DatasetName == "" {
return errors.New("missing dataset_name")
}
if c.TableName == "" {
return errors.New("missing table_name")
}
if c.SqlQuery == "" {
return errors.New("missing sql_query")
}
return nil
}
Loading