@@ -5,12 +5,15 @@ import org.jetbrains.kotlinx.dataframe.AnyRow
5
5
import org.jetbrains.kotlinx.dataframe.DataFrame
6
6
import org.jetbrains.kotlinx.dataframe.DataRow
7
7
import org.jetbrains.kotlinx.dataframe.columns.ColumnKind
8
+ import org.jetbrains.kotlinx.dataframe.schema.ComparisonMode.LENIENT
9
+ import org.jetbrains.kotlinx.dataframe.schema.ComparisonMode.STRICT
10
+ import org.jetbrains.kotlinx.dataframe.schema.ComparisonMode.STRICT_FOR_NESTED_SCHEMAS
8
11
import kotlin.reflect.KType
9
12
import kotlin.reflect.full.isSubtypeOf
10
13
import kotlin.reflect.full.isSupertypeOf
11
14
import kotlin.reflect.typeOf
12
15
13
- public abstract class ColumnSchema {
16
+ public sealed class ColumnSchema {
14
17
15
18
/* * Either [Value] or [Group] or [Frame]. */
16
19
public abstract val kind: ColumnKind
@@ -55,10 +58,11 @@ public abstract class ColumnSchema {
55
58
override val nullable: Boolean = false
56
59
override val type: KType get() = typeOf<AnyRow >()
57
60
58
- public fun compare (other : Group ): CompareResult = schema.compare(other.schema)
59
-
60
- internal fun compareStrictlyEqualNestedSchemas (other : Group ): CompareResult =
61
- schema.compare(other.schema, strictlyEqualNestedSchemas = true )
61
+ public fun compare (other : Group , comparisonMode : ComparisonMode = LENIENT ): CompareResult =
62
+ schema.compare(
63
+ other = other.schema,
64
+ comparisonMode = comparisonMode,
65
+ )
62
66
}
63
67
64
68
public class Frame (
@@ -69,14 +73,11 @@ public abstract class ColumnSchema {
69
73
public override val kind: ColumnKind = ColumnKind .Frame
70
74
override val type: KType get() = typeOf<AnyFrame >()
71
75
72
- public fun compare (other : Frame ): CompareResult =
73
- schema.compare(other.schema).combine(CompareResult .compareNullability(nullable, other.nullable))
74
-
75
- internal fun compareStrictlyEqualNestedSchemas (other : Frame ): CompareResult =
76
+ public fun compare (other : Frame , comparisonMode : ComparisonMode = LENIENT ): CompareResult =
76
77
schema.compare(
77
- other.schema,
78
- strictlyEqualNestedSchemas = true ,
79
- ).combine( CompareResult .compareNullability(nullable, other.nullable) )
78
+ other = other .schema,
79
+ comparisonMode = comparisonMode ,
80
+ ) + CompareResult .compareNullability(thisIsNullable = nullable, otherIsNullable = other.nullable)
80
81
}
81
82
82
83
/* * Checks equality just on kind, type, or schema. */
@@ -88,37 +89,27 @@ public abstract class ColumnSchema {
88
89
is Value -> type == (otherType as Value ).type
89
90
is Group -> schema == (otherType as Group ).schema
90
91
is Frame -> schema == (otherType as Frame ).schema
91
- else -> throw NotImplementedError ()
92
92
}
93
93
}
94
94
95
- public fun compare (other : ColumnSchema ): CompareResult = compare(other, false )
96
-
97
- internal fun compareStrictlyEqualNestedSchemas (other : ColumnSchema ): CompareResult = compare(other, true )
98
-
99
- private fun compare (other : ColumnSchema , strictlyEqualNestedSchemas : Boolean ): CompareResult {
95
+ public fun compare (other : ColumnSchema , comparisonMode : ComparisonMode = LENIENT ): CompareResult {
100
96
if (kind != other.kind) return CompareResult .None
101
97
if (this == = other) return CompareResult .Equals
102
98
return when (this ) {
103
99
is Value -> compare(other as Value )
100
+ is Group -> compare(other as Group , comparisonMode)
101
+ is Frame -> compare(other as Frame , comparisonMode)
102
+ }
103
+ }
104
104
105
- is Group -> if (strictlyEqualNestedSchemas) {
106
- compareStrictlyEqualNestedSchemas(
107
- other as Group ,
108
- )
109
- } else {
110
- compare(other as Group )
111
- }
112
-
113
- is Frame -> if (strictlyEqualNestedSchemas) {
114
- compareStrictlyEqualNestedSchemas(
115
- other as Frame ,
116
- )
117
- } else {
118
- compare(other as Frame )
119
- }
120
-
121
- else -> throw NotImplementedError ()
105
+ override fun hashCode (): Int {
106
+ var result = nullable.hashCode()
107
+ result = 31 * result + kind.hashCode()
108
+ result = 31 * result + when (this ) {
109
+ is Value -> type.hashCode()
110
+ is Group -> schema.hashCode()
111
+ is Frame -> schema.hashCode()
122
112
}
113
+ return result
123
114
}
124
115
}
0 commit comments