Skip to content

Commit

Permalink
StructuredDataset without column should be castable to StructuredData…
Browse files Browse the repository at this point in the history
…set with column (flyteorg#395)

Signed-off-by: Kevin Su <[email protected]>
  • Loading branch information
pingsutw authored Feb 16, 2022
1 parent 031375b commit 2876f0c
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 6 deletions.
8 changes: 4 additions & 4 deletions pkg/compiler/validators/typing.go
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ func (t structuredDatasetChecker) CastsFrom(upstreamType *flyte.LiteralType) boo

// Upstream (schema) -> downstream (schema)
func schemaCastFromSchema(upstream *flyte.SchemaType, downstream *flyte.SchemaType) bool {
if len(downstream.Columns) == 0 {
if len(upstream.Columns) == 0 || len(downstream.Columns) == 0 {
return true
}

Expand All @@ -189,7 +189,7 @@ func schemaCastFromSchema(upstream *flyte.SchemaType, downstream *flyte.SchemaTy

// Upstream (structuredDatasetType) -> downstream (structuredDatasetType)
func structuredDatasetCastFromStructuredDataset(upstream *flyte.StructuredDatasetType, downstream *flyte.StructuredDatasetType) bool {
if len(downstream.Columns) == 0 {
if len(upstream.Columns) == 0 || len(downstream.Columns) == 0 {
return true
}

Expand All @@ -213,7 +213,7 @@ func structuredDatasetCastFromStructuredDataset(upstream *flyte.StructuredDatase

// Upstream (schemaType) -> downstream (structuredDatasetType)
func structuredDatasetCastFromSchema(upstream *flyte.SchemaType, downstream *flyte.StructuredDatasetType) bool {
if len(downstream.Columns) == 0 {
if len(upstream.Columns) == 0 || len(downstream.Columns) == 0 {
return true
}
nameToTypeMap := make(map[string]flyte.SchemaType_SchemaColumn_SchemaColumnType)
Expand All @@ -236,7 +236,7 @@ func structuredDatasetCastFromSchema(upstream *flyte.SchemaType, downstream *fly

// Upstream (structuredDatasetType) -> downstream (schemaType)
func schemaCastFromStructuredDataset(upstream *flyte.StructuredDatasetType, downstream *flyte.SchemaType) bool {
if len(downstream.Columns) == 0 {
if len(upstream.Columns) == 0 || len(downstream.Columns) == 0 {
return true
}
nameToTypeMap := make(map[string]flyte.SimpleType)
Expand Down
4 changes: 2 additions & 2 deletions pkg/compiler/validators/typing_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -411,7 +411,7 @@ func TestSchemaCasting(t *testing.T) {

t.Run("GenericSchemaToNonGeneric", func(t *testing.T) {
castable := AreTypesCastable(genericSchema, subsetIntegerSchema)
assert.False(t, castable, "Schema() should not be castable to Schema(a=Integer)")
assert.True(t, castable, "Schema() should be castable to Schema(a=Integer)")
})

t.Run("NonGenericSchemaToGeneric", func(t *testing.T) {
Expand Down Expand Up @@ -548,7 +548,7 @@ func TestStructuredDatasetCasting(t *testing.T) {

t.Run("GenericStructuredDatasetToNonGeneric", func(t *testing.T) {
castable := AreTypesCastable(genericStructuredDataset, subsetStructuredDataset)
assert.False(t, castable, "StructuredDataset() should not be castable to StructuredDataset(a=Integer, b=Collection)")
assert.True(t, castable, "StructuredDataset() should be castable to StructuredDataset(a=Integer, b=Collection)")
})

t.Run("NonGenericStructuredDatasetToGeneric", func(t *testing.T) {
Expand Down

0 comments on commit 2876f0c

Please sign in to comment.