Documentation
¶
Index ¶
Examples ¶
Constants ¶
View Source
const (
// DefaultProjectID is the default project ID for the BigQuery container.
DefaultProjectID = "test-project"
)
Variables ¶
View Source
var WithProjectID = shared.WithProjectID
WithProjectID re-exports the common GCloud WithProjectID option
Functions ¶
func WithDataYAML ¶
func WithDataYAML(r io.Reader) testcontainers.CustomizeRequestOption
WithDataYAML seeds the BigQuery project for the GCloud container with an io.Reader representing the data yaml file, which is used to copy the file to the container, and then processed to seed the BigQuery project.
Other GCloud containers will ignore this option.
Types ¶
type Container ¶
type Container struct {
testcontainers.Container
// contains filtered or unexported fields
}
Container represents the BigQuery container type used in the module
func Run ¶
func Run(ctx context.Context, img string, opts ...testcontainers.ContainerCustomizer) (*Container, error)
Run creates an instance of the BigQuery GCloud container type. The URI uses http:// as the protocol.
Example ¶
// runBigQueryContainer {
ctx := context.Background()
bigQueryContainer, err := tcbigquery.Run(
ctx,
"ghcr.io/goccy/bigquery-emulator:0.6.1",
tcbigquery.WithProjectID("bigquery-project"),
)
defer func() {
if err := testcontainers.TerminateContainer(bigQueryContainer); err != nil {
log.Printf("failed to terminate container: %s", err)
}
}()
if err != nil {
log.Printf("failed to run container: %v", err)
return
}
// }
// bigQueryClient {
projectID := bigQueryContainer.ProjectID()
opts := []option.ClientOption{
option.WithEndpoint(bigQueryContainer.URI()),
option.WithGRPCDialOption(grpc.WithTransportCredentials(insecure.NewCredentials())),
option.WithoutAuthentication(),
internaloption.SkipDialSettingsValidation(),
}
client, err := bigquery.NewClient(ctx, projectID, opts...)
if err != nil {
log.Printf("failed to create bigquery client: %v", err)
return
}
defer client.Close()
// }
createFnQuery := client.Query("CREATE FUNCTION testr(arr ARRAY<STRUCT<name STRING, val INT64>>) AS ((SELECT SUM(IF(elem.name = \"foo\",elem.val,null)) FROM UNNEST(arr) AS elem))")
_, err = createFnQuery.Read(ctx)
if err != nil {
log.Printf("failed to create function: %v", err)
return
}
selectQuery := client.Query("SELECT testr([STRUCT<name STRING, val INT64>(\"foo\", 10), STRUCT<name STRING, val INT64>(\"bar\", 40), STRUCT<name STRING, val INT64>(\"foo\", 20)])")
it, err := selectQuery.Read(ctx)
if err != nil {
log.Printf("failed to read query: %v", err)
return
}
var val []bigquery.Value
for {
err := it.Next(&val)
if errors.Is(err, iterator.Done) {
break
}
if err != nil {
log.Printf("failed to iterate: %v", err)
return
}
}
fmt.Println(val)
Output: [30]
Click to show internal directories.
Click to hide internal directories.