diff --git a/functions/dialect.go b/functions/dialect.go index 8ff5c65..a238f6c 100644 --- a/functions/dialect.go +++ b/functions/dialect.go @@ -7,6 +7,7 @@ import ( "io" "strings" + "github.com/creasty/defaults" "github.com/goccy/go-yaml" substraitgo "github.com/substrait-io/substrait-go" "github.com/substrait-io/substrait-go/extensions" @@ -187,7 +188,20 @@ type dialectFile struct { type dialectTypeInfo struct { SqlTypeName string `yaml:"sql_type_name"` - SupportedAsColumn bool `yaml:"supported_as_column"` + SupportedAsColumn bool `yaml:"supported_as_column" default:"true"` +} + +func (ti *dialectTypeInfo) UnmarshalYAML(unmarshal func(interface{}) error) error { + type alias dialectTypeInfo + aux := &alias{} + if err := defaults.Set(aux); err != nil { + return err + } + if err := unmarshal(aux); err != nil { + return err + } + *ti = dialectTypeInfo(*aux) + return nil } func (d *dialectFile) getUriAndFunctionName(df *dialectFunction) (string, string) { diff --git a/functions/types_test.go b/functions/types_test.go index b9d33fb..c858e99 100644 --- a/functions/types_test.go +++ b/functions/types_test.go @@ -99,8 +99,6 @@ supported_types: supported_as_column: true i64: sql_type_name: int64 - supported_as_column: true - supported_as_column: true date: sql_type_name: DATE supported_as_column: true @@ -112,16 +110,12 @@ supported_types: supported_as_column: true dec: sql_type_name: NUMERIC - supported_as_column: true vchar: sql_type_name: VARCHAR - supported_as_column: true fchar: sql_type_name: CHAR - supported_as_column: true fbin: sql_type_name: BINARY - supported_as_column: true scalar_functions: - name: arithmetic.add local_name: + @@ -182,7 +176,8 @@ scalar_functions: assert.NoError(t, err) assert.Equal(t, tt.localName, localType) - assert.Equal(t, tt.asColumn, localTypeRegistry.IsTypeSupportedInTables(tt.want)) + assert.Equal(t, tt.asColumn, localTypeRegistry.IsTypeSupportedInTables(tt.want), + "IsTypeSupportedInTables(%s) failed", tt.name) }) }