Skip to content

Commit

Permalink
Linter complainings
Browse files Browse the repository at this point in the history
  • Loading branch information
vitalyisaev2 committed Oct 12, 2024
1 parent 08bdb59 commit 42b3ebc
Show file tree
Hide file tree
Showing 8 changed files with 62 additions and 27 deletions.
1 change: 1 addition & 0 deletions app/server/datasource/rdbms/mysql/table_metadata_query.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ func TableMetadataQuery(request *api_service_protos.TDescribeTableRequest) (stri
WHERE table_name = ? AND table_schema = ?`

var args rdbms_utils.QueryArgs

args.AddUntyped(request.Table)
args.AddUntyped(request.GetDataSourceInstance().Database)

Expand Down
1 change: 1 addition & 0 deletions app/server/datasource/rdbms/oracle/table_metadata_query.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ func TableMetadataQuery(request *api_service_protos.TDescribeTableRequest) (stri
query := "SELECT column_name, data_type FROM user_tab_columns WHERE table_name = :1"

var args rdbms_utils.QueryArgs

args.AddUntyped(request.Table)

return query, &args
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ func TableMetadataQuery(
query := "SELECT column_name, data_type FROM information_schema.columns WHERE table_name = $1 AND table_schema = $2"

var args rdbms_utils.QueryArgs

args.AddUntyped(request.Table)
args.AddUntyped(schema)

Expand Down
36 changes: 30 additions & 6 deletions app/server/datasource/rdbms/utils/predicate_builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,11 @@ func formatValue(formatter SQLFormatter, args *QueryArgs, value *Ydb.TypedValue)
}
}

func addTypedNull[ACCEPTOR_TYPE any](formatter SQLFormatter, args *QueryArgs, typeId Ydb.Type_PrimitiveTypeId) (string, *QueryArgs, error) {
func addTypedNull[ACCEPTOR_TYPE any](
formatter SQLFormatter,
args *QueryArgs,
typeId Ydb.Type_PrimitiveTypeId,
) (string, *QueryArgs, error) {
return formatter.GetPlaceholder(args.Count()),
args.AddTyped(&Ydb.Type{Type: &Ydb.Type_TypeId{TypeId: typeId}}, (*ACCEPTOR_TYPE)(nil)),
nil
Expand Down Expand Up @@ -153,7 +157,11 @@ func formatExpression(formatter SQLFormatter, args *QueryArgs, expression *api_s
}
}

func formatComparison(formatter SQLFormatter, args *QueryArgs, comparison *api_service_protos.TPredicate_TComparison) (string, *QueryArgs, error) {
func formatComparison(
formatter SQLFormatter,
args *QueryArgs,
comparison *api_service_protos.TPredicate_TComparison,
) (string, *QueryArgs, error) {
var operation string

switch op := comparison.Operation; op {
Expand Down Expand Up @@ -186,7 +194,10 @@ func formatComparison(formatter SQLFormatter, args *QueryArgs, comparison *api_s
return fmt.Sprintf("(%s%s%s)", left, operation, right), args, nil
}

func formatNegation(formatter SQLFormatter, args *QueryArgs, negation *api_service_protos.TPredicate_TNegation) (string, *QueryArgs, error) {
func formatNegation(
formatter SQLFormatter,
args *QueryArgs,
negation *api_service_protos.TPredicate_TNegation) (string, *QueryArgs, error) {
pred, args, err := formatPredicate(formatter, args, negation.Operand, false)
if err != nil {
return "", args, fmt.Errorf("failed to format NOT statement: %w", err)
Expand Down Expand Up @@ -296,7 +307,11 @@ func formatDisjunction(
return sb.String(), args, nil
}

func formatIsNull(formatter SQLFormatter, args *QueryArgs, isNull *api_service_protos.TPredicate_TIsNull) (string, *QueryArgs, error) {
func formatIsNull(
formatter SQLFormatter,
args *QueryArgs,
isNull *api_service_protos.TPredicate_TIsNull,
) (string, *QueryArgs, error) {
statement, args, err := formatExpression(formatter, args, isNull.Value)
if err != nil {
return "", args, fmt.Errorf("failed to format IS NULL statement: %w", err)
Expand All @@ -305,7 +320,11 @@ func formatIsNull(formatter SQLFormatter, args *QueryArgs, isNull *api_service_p
return fmt.Sprintf("(%s IS NULL)", statement), args, nil
}

func formatIsNotNull(formatter SQLFormatter, args *QueryArgs, isNotNull *api_service_protos.TPredicate_TIsNotNull) (string, *QueryArgs, error) {
func formatIsNotNull(
formatter SQLFormatter,
args *QueryArgs,
isNotNull *api_service_protos.TPredicate_TIsNotNull,
) (string, *QueryArgs, error) {
statement, args, err := formatExpression(formatter, args, isNotNull.Value)
if err != nil {
return "", args, fmt.Errorf("failed to format IS NOT NULL statement: %w", err)
Expand All @@ -314,7 +333,12 @@ func formatIsNotNull(formatter SQLFormatter, args *QueryArgs, isNotNull *api_ser
return fmt.Sprintf("(%s IS NOT NULL)", statement), args, nil
}

func formatPredicate(formatter SQLFormatter, args *QueryArgs, predicate *api_service_protos.TPredicate, topLevel bool) (string, *QueryArgs, error) {
func formatPredicate(
formatter SQLFormatter,
args *QueryArgs,
predicate *api_service_protos.TPredicate,
topLevel bool,
) (string, *QueryArgs, error) {
switch p := predicate.Payload.(type) {
case *api_service_protos.TPredicate_Negation:
return formatNegation(formatter, args, p.Negation)
Expand Down
9 changes: 8 additions & 1 deletion app/server/datasource/rdbms/utils/query_args_collector.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,13 @@ func (q *QueryArgs) AddTyped(ydbType *Ydb.Type, arg any) *QueryArgs {

func (q *QueryArgs) AddUntyped(arg any) *QueryArgs { return q.AddTyped(nil, arg) }

func (q *QueryArgs) Count() int { return len(q.args) }
func (q *QueryArgs) Count() int {
if q == nil {
return 0
}

return len(q.args)
}

func (q *QueryArgs) Values() []any {
if q == nil {
Expand All @@ -30,6 +36,7 @@ func (q *QueryArgs) Values() []any {
for i, arg := range q.args {
args[i] = arg.Value
}

return args
}

Expand Down
29 changes: 14 additions & 15 deletions tests/infra/datasource/ydb/suite.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (

"github.com/ydb-platform/ydb-go-genproto/protos/Ydb"

api_common "github.com/ydb-platform/fq-connector-go/api/common"
api_service_protos "github.com/ydb-platform/fq-connector-go/api/service/protos"
"github.com/ydb-platform/fq-connector-go/common"
"github.com/ydb-platform/fq-connector-go/tests/infra/datasource"
Expand Down Expand Up @@ -83,19 +84,19 @@ func (s *Suite) TestPushdownComparisonEQ() {
)
}

// func (s *Suite) TestPushdownComparisonEQNull() {
// s.ValidateTable(
// s.dataSource,
// tables["pushdown_comparison_EQ_NULL"],
// suite.WithPredicate(&api_service_protos.TPredicate{
// Payload: tests_utils.MakePredicateComparisonColumn(
// "col_01_int",
// api_service_protos.TPredicate_TComparison_EQ,
// common.MakeTypedValue(common.MakeOptionalType(common.MakePrimitiveType(Ydb.Type_INT32)), nil),
// ),
// }),
// )
// }
func (s *Suite) TestPushdownComparisonEQNull() {
s.ValidateTable(
s.dataSource,
tables["pushdown_comparison_EQ_NULL"],
suite.WithPredicate(&api_service_protos.TPredicate{
Payload: tests_utils.MakePredicateComparisonColumn(
"col_01_int",
api_service_protos.TPredicate_TComparison_EQ,
common.MakeTypedValue(common.MakeOptionalType(common.MakePrimitiveType(Ydb.Type_INT32)), nil),
),
}),
)
}

func (s *Suite) TestPushdownComparisonGE() {
s.ValidateTable(
Expand Down Expand Up @@ -298,7 +299,6 @@ func (s *Suite) TestPositiveStats() {
suite.TestPositiveStats(s.Base, s.dataSource, tables["simple"])
}

/*
func (s *Suite) TestMissingDataSource() {
dsi := &api_common.TDataSourceInstance{
Kind: api_common.EDataSourceKind_YDB,
Expand Down Expand Up @@ -330,7 +330,6 @@ func (s *Suite) TestInvalidPassword() {
suite.TestInvalidPassword(s.Base, dsi, tables["simple"])
}
}
*/

func NewSuite(
baseSuite *suite.Base[int32, *array.Int32Builder],
Expand Down
10 changes: 6 additions & 4 deletions tests/main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,12 @@ import (
"github.com/apache/arrow/go/v13/arrow/array"
testify_suite "github.com/stretchr/testify/suite"

"github.com/ydb-platform/fq-connector-go/tests/infra/datasource/clickhouse"
"github.com/ydb-platform/fq-connector-go/tests/infra/datasource/greenplum"
"github.com/ydb-platform/fq-connector-go/tests/infra/datasource/ms_sql_server"
"github.com/ydb-platform/fq-connector-go/tests/infra/datasource/mysql"
"github.com/ydb-platform/fq-connector-go/tests/infra/datasource/oracle"
"github.com/ydb-platform/fq-connector-go/tests/infra/datasource/postgresql"
"github.com/ydb-platform/fq-connector-go/tests/infra/datasource/ydb"
"github.com/ydb-platform/fq-connector-go/tests/suite"
)
Expand All @@ -25,21 +31,18 @@ func TestMain(m *testing.M) {
m.Run()
}

/*
func TestClickHouse(t *testing.T) {
testify_suite.Run(t, clickhouse.NewSuite(suite.NewBase[int32, *array.Int32Builder](t, state, "ClickHouse")))
}

func TestPostgreSQL(t *testing.T) {
testify_suite.Run(t, postgresql.NewSuite(suite.NewBase[int32, *array.Int32Builder](t, state, "PostgreSQL")))
}
*/

func TestYDB(t *testing.T) {
testify_suite.Run(t, ydb.NewSuite(suite.NewBase[int32, *array.Int32Builder](t, state, "YDB")))
}

/*
func TestGreenplum(t *testing.T) {
testify_suite.Run(t, greenplum.NewSuite(suite.NewBase[int32, *array.Int32Builder](t, state, "Greenplum")))
}
Expand All @@ -55,4 +58,3 @@ func TestOracle(t *testing.T) {
func TestMsSqlServer(t *testing.T) {
testify_suite.Run(t, ms_sql_server.NewSuite(suite.NewBase[int32, *array.Int32Builder](t, state, "MS SQL Server")))
}
*/
2 changes: 1 addition & 1 deletion tests/suite/suite.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ func (b *Base[_, _]) SetupSuite() {
},
),
server.WithConnectionTimeouts("2s", "1s"),
server.WithYdbConnectorMode(config.TYdbConfig_MODE_QUERY_SERVICE_NATIVE),
server.WithYdbConnectorMode(config.TYdbConfig_MODE_TABLE_SERVICE_STDLIB_SCAN_QUERIES),
)
b.Require().NoError(err)
b.Connector.Start()
Expand Down

0 comments on commit 42b3ebc

Please sign in to comment.