-
Notifications
You must be signed in to change notification settings - Fork 7
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
1 parent
154e2e9
commit 8605fe3
Showing
9 changed files
with
204 additions
and
43 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,26 +1,9 @@ | ||
package datasource | ||
|
||
import ( | ||
"fmt" | ||
|
||
api_common "github.com/ydb-platform/fq-connector-go/api/common" | ||
) | ||
|
||
type DataSource struct { | ||
dsi map[api_common.EProtocol]*api_common.TDataSourceInstance | ||
} | ||
|
||
func (ds *DataSource) GetDataSourceInstance(protocol api_common.EProtocol) (*api_common.TDataSourceInstance, error) { | ||
result, exists := ds.dsi[protocol] | ||
if !exists { | ||
return nil, fmt.Errorf("unexpected protocol %v", protocol) | ||
} | ||
|
||
return result, nil | ||
} | ||
|
||
func NewDataSource( | ||
dsi map[api_common.EProtocol]*api_common.TDataSourceInstance, | ||
) *DataSource { | ||
return &DataSource{dsi: dsi} | ||
Instances []*api_common.TDataSourceInstance | ||
} |
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,51 @@ | ||
package postgresql | ||
|
||
import ( | ||
"fmt" | ||
|
||
api_common "github.com/ydb-platform/fq-connector-go/api/common" | ||
"github.com/ydb-platform/fq-connector-go/tests/infra/datasource" | ||
"github.com/ydb-platform/fq-connector-go/tests/infra/docker_compose" | ||
) | ||
|
||
const ( | ||
serviceName = "postgresql" | ||
internalPort = 5432 | ||
database = "connector" | ||
username = "admin" | ||
password = "password" | ||
schema = "public" | ||
) | ||
|
||
func DeriveDataSourceFromDockerCompose(ed *docker_compose.EndpointDeterminer) (*datasource.DataSource, error) { | ||
dsi := &api_common.TDataSourceInstance{ | ||
Kind: api_common.EDataSourceKind_POSTGRESQL, | ||
Database: database, | ||
Credentials: &api_common.TCredentials{ | ||
Payload: &api_common.TCredentials_Basic{ | ||
Basic: &api_common.TCredentials_TBasic{ | ||
Username: username, | ||
Password: password, | ||
}, | ||
}, | ||
}, | ||
Protocol: api_common.EProtocol_NATIVE, | ||
UseTls: false, | ||
Options: &api_common.TDataSourceInstance_PgOptions{ | ||
PgOptions: &api_common.TPostgreSQLDataSourceOptions{ | ||
Schema: schema, | ||
}, | ||
}, | ||
} | ||
|
||
var err error | ||
dsi.Endpoint, err = ed.GetEndpoint(serviceName, internalPort) | ||
|
||
if err != nil { | ||
return nil, fmt.Errorf("derive endpoint: %w", err) | ||
} | ||
|
||
return &datasource.DataSource{ | ||
Instances: []*api_common.TDataSourceInstance{dsi}, | ||
}, 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
#!/bin/bash | ||
set -e | ||
|
||
psql -v ON_ERROR_STOP=1 --username "$POSTGRES_USER" --dbname "$POSTGRES_DB" <<-EOSQL | ||
DROP TABLE IF EXISTS simple; | ||
CREATE TABLE simple (id integer, col1 text, col2 integer); | ||
INSERT INTO simple VALUES (1, 'pg_a', 10); | ||
INSERT INTO simple VALUES (2, 'pg_b', 20); | ||
INSERT INTO simple VALUES (3, 'pg_c', 30); | ||
INSERT INTO simple VALUES (4, 'pg_d', 40); | ||
INSERT INTO simple VALUES (5, 'pg_e', 50); | ||
EOSQL | ||
|
||
psql -v ON_ERROR_STOP=1 --username "$POSTGRES_USER" --dbname "$POSTGRES_DB" <<-EOSQL | ||
DROP TABLE IF EXISTS primitives; | ||
CREATE TABLE primitives ( | ||
col_01_bool bool, | ||
col_02_smallint smallint, | ||
col_03_int2 int2, | ||
col_04_smallserial smallserial, | ||
col_05_serial2 serial2, | ||
col_06_integer integer, | ||
col_07_int int, | ||
col_08_int4 int4, | ||
col_09_serial serial, | ||
col_10_serial4 serial4, | ||
col_11_bigint bigint, | ||
col_12_int8 int8, | ||
col_13_bigserial bigserial, | ||
col_14_serial8 serial8, | ||
col_15_real real, | ||
col_16_float4 float4, | ||
col_17_double_precision double precision, | ||
col_18_float8 float8, | ||
col_19_bytea bytea, | ||
col_20_character_n character(20), | ||
col_21_character_varying_n character varying(21), | ||
col_22_text text, | ||
col_23_timestamp timestamp, | ||
col_24_date date | ||
); | ||
INSERT INTO primitives VALUES ( | ||
false, 2, 3, DEFAULT, DEFAULT, 6, 7, 8, DEFAULT, DEFAULT, 11, 12, DEFAULT, DEFAULT, | ||
15.15, 16.16, 17.17, 18.18, 'az', 'az', 'az', 'az', | ||
current_timestamp, current_timestamp); | ||
INSERT INTO primitives VALUES ( | ||
true, -2, -3, DEFAULT, DEFAULT, -6, -7, -8, DEFAULT, DEFAULT, -11, -12, DEFAULT, DEFAULT, | ||
-15.15, -16.16, -17.17, -18.18, 'буки', 'буки', 'буки', 'буки', | ||
current_timestamp, current_timestamp); | ||
INSERT INTO primitives VALUES ( | ||
NULL, NULL, NULL, DEFAULT, DEFAULT, NULL, | ||
NULL, NULL, DEFAULT, DEFAULT, NULL, NULL, | ||
DEFAULT, DEFAULT, NULL, NULL, NULL, NULL, | ||
NULL, NULL, NULL, NULL, NULL, NULL | ||
); | ||
EOSQL |
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,46 @@ | ||
package postgresql | ||
|
||
import ( | ||
"github.com/ydb-platform/ydb-go-genproto/protos/Ydb" | ||
|
||
api_service_protos "github.com/ydb-platform/fq-connector-go/api/service/protos" | ||
"github.com/ydb-platform/fq-connector-go/app/common" | ||
"github.com/ydb-platform/fq-connector-go/library/go/ptr" | ||
"github.com/ydb-platform/fq-connector-go/tests/infra/datasource" | ||
) | ||
|
||
var Tables = map[string]*datasource.Table{ | ||
"simple": { | ||
SchemaYdb: &api_service_protos.TSchema{ | ||
Columns: []*Ydb.Column{ | ||
{ | ||
Name: "id", | ||
Type: common.MakeOptionalType(common.MakePrimitiveType(Ydb.Type_INT32)), | ||
}, | ||
{ | ||
Name: "col1", | ||
Type: common.MakeOptionalType(common.MakePrimitiveType(Ydb.Type_UTF8)), | ||
}, | ||
{ | ||
Name: "col2", | ||
Type: common.MakeOptionalType(common.MakePrimitiveType(Ydb.Type_INT32)), | ||
}, | ||
}, | ||
}, | ||
Records: []*datasource.Record{ | ||
{ | ||
Columns: []any{ | ||
[]*int32{ptr.Int32(1), ptr.Int32(2), ptr.Int32(3), ptr.Int32(4), ptr.Int32(5)}, | ||
[]*string{ | ||
ptr.String("pg_a"), | ||
ptr.String("pg_b"), | ||
ptr.String("pg_c"), | ||
ptr.String("pg_d"), | ||
ptr.String("pg_e"), | ||
}, | ||
[]*int32{ptr.Int32(10), ptr.Int32(20), ptr.Int32(30), ptr.Int32(40), ptr.Int32(50)}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
} |
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