Skip to content

Commit 59c3715

Browse files
authored
fix: Relax plugin tables and columns validation (#1203)
Follow up to #1108. This PR relaxes the validation to check only for duplicates. Some databases allow uppercase table tables and the validation in the SDK seemed to be PostgreSQL oriented. At some point we might want to have destination specific validation/normalization. Related to https://discord.com/channels/872925471417962546/873606591335759872/1148643989348679770 ---
1 parent 3dbf2e9 commit 59c3715

File tree

4 files changed

+0
-146
lines changed

4 files changed

+0
-146
lines changed

plugin/validate.go

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -13,18 +13,10 @@ func validateTables(tables schema.Tables) error {
1313
return fmt.Errorf("found duplicate tables in plugin: %w", err)
1414
}
1515

16-
if err := tables.ValidateTableNames(); err != nil {
17-
return fmt.Errorf("found table with invalid name in plugin: %w", err)
18-
}
19-
2016
if err := tables.ValidateDuplicateColumns(); err != nil {
2117
return fmt.Errorf("found duplicate columns in plugin: %w", err)
2218
}
2319

24-
if err := tables.ValidateColumnNames(); err != nil {
25-
return fmt.Errorf("found column with invalid name in plugin: %w", err)
26-
}
27-
2820
return nil
2921
}
3022

schema/table.go

Lines changed: 0 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,6 @@ type Table struct {
9090
}
9191

9292
var (
93-
reValidTableName = regexp.MustCompile(`^[a-z_][a-z\d_]*$`)
9493
reValidColumnName = regexp.MustCompile(`^[a-z_][a-z\d_]*$`)
9594
)
9695

@@ -359,30 +358,6 @@ func (tt Tables) ValidateDuplicateTables() error {
359358
return nil
360359
}
361360

362-
func (tt Tables) ValidateTableNames() error {
363-
for _, t := range tt {
364-
if err := t.ValidateName(); err != nil {
365-
return err
366-
}
367-
if err := t.Relations.ValidateTableNames(); err != nil {
368-
return err
369-
}
370-
}
371-
return nil
372-
}
373-
374-
func (tt Tables) ValidateColumnNames() error {
375-
for _, t := range tt {
376-
if err := t.ValidateColumnNames(); err != nil {
377-
return err
378-
}
379-
if err := t.Relations.ValidateColumnNames(); err != nil {
380-
return err
381-
}
382-
}
383-
return nil
384-
}
385-
386361
// this will filter the tree in-place
387362
func (t *Table) filterDfs(parentMatched bool, include, exclude func(*Table) bool, skipDependentTables bool) *Table {
388363
if exclude(t) {
@@ -407,14 +382,6 @@ func (t *Table) filterDfs(parentMatched bool, include, exclude func(*Table) bool
407382
return nil
408383
}
409384

410-
func (t *Table) ValidateName() error {
411-
ok := reValidTableName.MatchString(t.Name)
412-
if !ok {
413-
return fmt.Errorf("table name %q is not valid: table names must contain only lower-case letters, numbers and underscores, and must start with a lower-case letter or underscore", t.Name)
414-
}
415-
return ValidateTable(t)
416-
}
417-
418385
func (t *Table) PrimaryKeysIndexes() []int {
419386
var primaryKeys []int
420387
for i, c := range t.Columns {
@@ -500,15 +467,6 @@ func (t *Table) ValidateDuplicateColumns() error {
500467
return nil
501468
}
502469

503-
func (t *Table) ValidateColumnNames() error {
504-
for _, c := range t.Columns {
505-
if !ValidColumnName(c.Name) {
506-
return fmt.Errorf("column name %q on table %q is not valid: column names must contain only lower-case letters, numbers and underscores, and must start with a lower-case letter or underscore", c.Name, t.Name)
507-
}
508-
}
509-
return nil
510-
}
511-
512470
func (t *Table) Column(name string) *Column {
513471
for _, c := range t.Columns {
514472
if c.Name == name {

schema/validators.go

Lines changed: 0 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -1,61 +1,9 @@
11
package schema
22

33
import (
4-
"errors"
5-
"fmt"
6-
74
"github.com/apache/arrow/go/v14/arrow"
85
)
96

10-
type TableValidator interface {
11-
Validate(t *Table) error
12-
}
13-
14-
type LengthTableValidator struct{}
15-
16-
const (
17-
maxTableName = 63 // maximum allowed identifier length is 63 bytes https://www.postgresql.org/docs/13/limits.html
18-
maxColumnName = 63
19-
)
20-
21-
var defaultValidators = []TableValidator{
22-
LengthTableValidator{},
23-
}
24-
25-
func ValidateTable(t *Table) error {
26-
for _, validator := range defaultValidators {
27-
return validator.Validate(t)
28-
}
29-
return nil
30-
}
31-
32-
func validateTableAttributesNameLength(t *Table) error {
33-
// validate table name
34-
if len(t.Name) > maxTableName {
35-
return errors.New("table name has exceeded max length")
36-
}
37-
38-
// validate table columns
39-
for _, col := range t.Columns.Names() {
40-
if len(col) > maxColumnName {
41-
return fmt.Errorf("column name %s has exceeded max length", col)
42-
}
43-
}
44-
45-
// validate table relations
46-
for _, rel := range t.Relations {
47-
err := validateTableAttributesNameLength(rel)
48-
if err != nil {
49-
return err
50-
}
51-
}
52-
return nil
53-
}
54-
55-
func (LengthTableValidator) Validate(t *Table) error {
56-
return validateTableAttributesNameLength(t)
57-
}
58-
597
func FindEmptyColumns(table *Table, records []arrow.Record) []string {
608
columnsWithValues := make([]bool, len(table.Columns))
619
emptyColumns := make([]string, 0)

schema/validators_test.go

Lines changed: 0 additions & 44 deletions
This file was deleted.

0 commit comments

Comments
 (0)