-
Notifications
You must be signed in to change notification settings - Fork 11
Handle nullable columns #233
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
hariso
wants to merge
63
commits into
main
Choose a base branch
from
haris/handle-nullable-columns
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
63 commits
Select commit
Hold shift + click to select a range
5b5a0e4
[WIP] Handle nullable columns
hariso 44db32b
improve integration test
hariso df71d71
improve tests
hariso 74e3d99
get table info
hariso 5924975
fixing tests
hariso cc1ecf8
rename
hariso 0d1533b
updated integration test
hariso e961a17
first validate, then refresh tables
hariso afbe851
linter
hariso 5a8913a
Merge branch 'main' into haris/handle-nullable-columns
hariso 53b79f6
support timestamps
hariso ec5d5f0
Merge branch 'main' into haris/handle-nullable-columns
hariso 321f149
Merge changes for big.Rat
hariso 752982f
uncomment numeric, fix stuff
hariso d79dc99
table_info: support capital case in table name
hariso 830eb6f
better way to take a pointer
hariso b7b60c9
fix types_test
hariso 98a0a3c
minor change
hariso cf60d50
add more types to source integration test
hariso 74275b4
update avro_integration_test
hariso 2f9de01
fix tests
hariso 84d8a20
more tests fixed
hariso 28ed11b
fix fetch worker int test
hariso dcf70c4
updates
hariso 4297c35
fix usage of pointers in tests
hariso 0027279
fix usage of pointers in tests
hariso d396f70
Merge branch 'main' into haris/handle-nullable-columns
hariso 6b79643
fixes
hariso b40a8ef
fix cdc_test
hariso 5aa9fd2
fix source_integration_test
hariso aef7582
fix source_integration_test
hariso 7bc7d76
sync with main
hariso 7d70122
add comment
hariso b2c5210
better source_integration_test
hariso 40c7476
more checks in source_integration_test
hariso 06f4114
more checks in source_integration_test
hariso d372fe7
fix source_integration_test
hariso 6647017
format, fixes
hariso 9c0cc47
move method
hariso 1ce91bf
move method
hariso 5ea78ab
move method
hariso f1f44b6
destination from main
hariso 0bbc863
fix date
hariso 2447721
lint
hariso 8327705
finally done with source_integration_test
hariso aa732dd
simplify method
hariso e00e218
col_bytea
hariso edbfe3c
simplify method
hariso ee8f150
simplify col_date
hariso 49c99ed
no normalization needed
hariso 19cabba
less type casting
hariso 66b66d3
simplify test
hariso 99f0030
add comment
hariso 42ecfd5
add time zone offsets
hariso fa095eb
comments
hariso 0eb72c5
move table_info
hariso 0fb14ac
fix uuid test
hariso 0db44e4
remove comment
hariso 4406396
add test for delete
hariso 59a0f5d
refactor integration test, add note about delete test
hariso dc9f97d
refactor integration test, add note about delete test
hariso 09ac652
refactor tests
hariso 2826c91
rename file
hariso File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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,114 @@ | ||
// Copyright © 2024 Meroxa, Inc. | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
package internal | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
|
||
sdk "github.com/conduitio/conduit-connector-sdk" | ||
"github.com/jackc/pgx/v5/pgxpool" | ||
) | ||
|
||
type TableInfo struct { | ||
Name string | ||
Columns map[string]*ColumnInfo | ||
} | ||
|
||
func NewTableInfo(tableName string) *TableInfo { | ||
return &TableInfo{ | ||
Name: tableName, | ||
Columns: make(map[string]*ColumnInfo), | ||
} | ||
} | ||
|
||
type ColumnInfo struct { | ||
IsNotNull bool | ||
} | ||
|
||
type TableInfoFetcher struct { | ||
connPool *pgxpool.Pool | ||
tableInfo map[string]*TableInfo | ||
} | ||
|
||
func NewTableInfoFetcher(connPool *pgxpool.Pool) *TableInfoFetcher { | ||
return &TableInfoFetcher{ | ||
connPool: connPool, | ||
tableInfo: make(map[string]*TableInfo), | ||
} | ||
} | ||
|
||
func (i TableInfoFetcher) Refresh(ctx context.Context, tableName string) error { | ||
tx, err := i.connPool.Begin(ctx) | ||
if err != nil { | ||
return fmt.Errorf("failed to start tx for getting table info: %w", err) | ||
} | ||
defer func() { | ||
if err := tx.Rollback(ctx); err != nil { | ||
sdk.Logger(ctx).Warn(). | ||
Err(err). | ||
Msgf("error on tx rollback for getting table info") | ||
} | ||
}() | ||
|
||
query := ` | ||
SELECT a.attname as column_name, a.attnotnull as is_not_null | ||
FROM pg_catalog.pg_attribute a | ||
WHERE a.attrelid = $1::regclass | ||
AND a.attnum > 0 | ||
AND NOT a.attisdropped | ||
ORDER BY a.attnum; | ||
` | ||
|
||
rows, err := tx.Query(ctx, query, WrapSQLIdent(tableName)) | ||
if err != nil { | ||
sdk.Logger(ctx). | ||
Err(err). | ||
Str("query", query). | ||
Msgf("failed to execute table info query") | ||
|
||
return fmt.Errorf("failed to get table info: %w", err) | ||
} | ||
defer rows.Close() | ||
|
||
ti := NewTableInfo(tableName) | ||
for rows.Next() { | ||
var columnName string | ||
var isNotNull bool | ||
|
||
err := rows.Scan(&columnName, &isNotNull) | ||
if err != nil { | ||
return fmt.Errorf("failed to scan table info row: %w", err) | ||
} | ||
|
||
ci := ti.Columns[columnName] | ||
if ci == nil { | ||
ci = &ColumnInfo{} | ||
ti.Columns[columnName] = ci | ||
} | ||
ci.IsNotNull = isNotNull | ||
} | ||
|
||
if err := rows.Err(); err != nil { | ||
return fmt.Errorf("failed to get table info rows: %w", err) | ||
} | ||
|
||
i.tableInfo[tableName] = ti | ||
return nil | ||
} | ||
|
||
func (i TableInfoFetcher) GetTable(name string) *TableInfo { | ||
return i.tableInfo[name] | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.