-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
21 changed files
with
247 additions
and
41 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
package bigquery_test | ||
|
||
import ( | ||
"os" | ||
"strings" | ||
"testing" | ||
|
||
"github.com/rudderlabs/sqlconnect-go/sqlconnect/internal/bigquery" | ||
integrationtest "github.com/rudderlabs/sqlconnect-go/sqlconnect/internal/integration_test" | ||
) | ||
|
||
func TestBigqueryDB(t *testing.T) { | ||
configJSON, ok := os.LookupEnv("BIGQUERY_TEST_ENVIRONMENT_CREDENTIALS") | ||
if !ok { | ||
t.Skip("skipping bigquery integration test due to lack of a test environment") | ||
} | ||
integrationtest.TestDatabaseScenarios(t, bigquery.DatabaseType, []byte(configJSON), strings.ToLower) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
package bigquery | ||
|
||
import ( | ||
"context" | ||
"errors" | ||
|
||
"cloud.google.com/go/bigquery" | ||
"google.golang.org/api/googleapi" | ||
"google.golang.org/api/iterator" | ||
|
||
"github.com/rudderlabs/sqlconnect-go/sqlconnect" | ||
) | ||
|
||
// SchemaExists uses the bigquery client instead of [INFORMATION_SCHEMA.SCHEMATA] due to absence of a region qualifier | ||
// https://cloud.google.com/bigquery/docs/information-schema-datasets-schemata#scope_and_syntax | ||
func (db *DB) SchemaExists(ctx context.Context, schemaRef sqlconnect.SchemaRef) (bool, error) { | ||
var exists bool | ||
if err := db.WithBigqueryClient(ctx, func(c *bigquery.Client) error { | ||
if _, err := c.Dataset(schemaRef.Name).Metadata(ctx); err != nil { | ||
var e *googleapi.Error | ||
if ok := errors.As(err, &e); ok { | ||
if e.Code == 404 { // not found | ||
return nil | ||
} | ||
} | ||
return err | ||
} | ||
exists = true | ||
return nil | ||
}); err != nil { | ||
return false, err | ||
} | ||
return exists, nil | ||
} | ||
|
||
// ListSchemas uses the bigquery client instead of [INFORMATION_SCHEMA.SCHEMATA] due to absence of a region qualifier | ||
// https://cloud.google.com/bigquery/docs/information-schema-datasets-schemata#scope_and_syntax | ||
func (db *DB) ListSchemas(ctx context.Context) ([]sqlconnect.SchemaRef, error) { | ||
var schemas []sqlconnect.SchemaRef | ||
if err := db.WithBigqueryClient(ctx, func(c *bigquery.Client) error { | ||
datasets := c.Datasets(ctx) | ||
for { | ||
var dataset *bigquery.Dataset | ||
dataset, err := datasets.Next() | ||
if err != nil { | ||
if err == iterator.Done { | ||
return nil | ||
} | ||
return err | ||
} | ||
schemas = append(schemas, sqlconnect.SchemaRef{Name: dataset.DatasetID}) | ||
} | ||
}); err != nil { | ||
return nil, err | ||
} | ||
return schemas, nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
package databricks_test | ||
|
||
import ( | ||
"os" | ||
"strings" | ||
"testing" | ||
"time" | ||
|
||
"github.com/stretchr/testify/require" | ||
"github.com/tidwall/sjson" | ||
|
||
"github.com/rudderlabs/sqlconnect-go/sqlconnect/internal/databricks" | ||
integrationtest "github.com/rudderlabs/sqlconnect-go/sqlconnect/internal/integration_test" | ||
) | ||
|
||
func TestDatabricksDB(t *testing.T) { | ||
configJSON, ok := os.LookupEnv("DATABRICKS_TEST_ENVIRONMENT_CREDENTIALS") | ||
if !ok { | ||
t.Skip("skipping databricks integration test due to lack of a test environment") | ||
} | ||
|
||
configJSON, err := sjson.Set(configJSON, "retryAttempts", 1) | ||
require.NoError(t, err, "failed to set retryAttempts") | ||
configJSON, err = sjson.Set(configJSON, "minRetryWaitTime", time.Second) | ||
require.NoError(t, err, "failed to set minRetryWaitTime") | ||
configJSON, err = sjson.Set(configJSON, "maxRetryWaitTime", time.Minute) | ||
require.NoError(t, err, "failed to set maxRetryWaitTime") | ||
|
||
integrationtest.TestDatabaseScenarios(t, databricks.DatabaseType, []byte(configJSON), strings.ToLower) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
package redshift_test | ||
|
||
import ( | ||
"os" | ||
"strings" | ||
"testing" | ||
|
||
integrationtest "github.com/rudderlabs/sqlconnect-go/sqlconnect/internal/integration_test" | ||
"github.com/rudderlabs/sqlconnect-go/sqlconnect/internal/redshift" | ||
) | ||
|
||
func TestRedshiftDB(t *testing.T) { | ||
configJSON, ok := os.LookupEnv("REDSHIFT_TEST_ENVIRONMENT_CREDENTIALS") | ||
if !ok { | ||
t.Skip("skipping redshift integration test due to lack of a test environment") | ||
} | ||
|
||
integrationtest.TestDatabaseScenarios(t, redshift.DatabaseType, []byte(configJSON), strings.ToLower) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.