-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
16 changed files
with
380 additions
and
382 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains 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 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 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 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 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 |
---|---|---|
@@ -1,14 +1,14 @@ | ||
package org.virtuslab.iskra | ||
|
||
import org.apache.spark.sql.{functions => f, Column => UntypedColumn} | ||
import org.virtuslab.iskra.types.{Coerce, DataType, BooleanOptType} | ||
import org.virtuslab.iskra.types.{Coerce, DataType, BooleanOptLike} | ||
|
||
object When: | ||
class WhenColumn[T <: DataType](untyped: UntypedColumn) extends Col[DataType.Nullable[T]](untyped): | ||
def when[U <: DataType](condition: Col[BooleanOptType], value: Col[U])(using coerce: Coerce[T, U]): WhenColumn[coerce.Coerced] = | ||
class WhenColumn[T <: DataType](untyped: UntypedColumn) extends Col[DataType.AsNullable[T]](untyped): | ||
def when[U <: DataType](condition: Col[BooleanOptLike], value: Col[U])(using coerce: Coerce[T, U]): WhenColumn[coerce.Coerced] = | ||
WhenColumn(this.untyped.when(condition.untyped, value.untyped)) | ||
def otherwise[U <: DataType](value: Col[U])(using coerce: Coerce[T, U]): Col[coerce.Coerced] = | ||
Col(this.untyped.otherwise(value.untyped)) | ||
|
||
def when[T <: DataType](condition: Col[BooleanOptType], value: Col[T]): WhenColumn[T] = | ||
def when[T <: DataType](condition: Col[BooleanOptLike], value: Col[T]): WhenColumn[T] = | ||
WhenColumn(f.when(condition.untyped, value.untyped)) |
This file contains 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 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 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 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 |
---|---|---|
@@ -1,17 +1,20 @@ | ||
package org.virtuslab.iskra | ||
package types | ||
|
||
import DataType.{CommonNumericNonNullableType, CommonNumericNullableType, NumericOptType, NumericType} | ||
|
||
trait Coerce[-A <: DataType, -B <: DataType]: | ||
trait Coerce[A <: DataType, B <: DataType]: | ||
type Coerced <: DataType | ||
|
||
object Coerce: | ||
given sameType[A <: DataType]: Coerce[A, A] with | ||
object Coerce extends CoerceLowPrio: | ||
given sameType[A <: FinalDataType]: Coerce[A, A] with | ||
override type Coerced = A | ||
|
||
given nullableFirst[A <: FinalDataType & Nullable, B <: FinalDataType & NonNullable](using A <:< NullableOf[B]): Coerce[A, B] with | ||
override type Coerced = A | ||
|
||
given nullable[A <: NumericOptType, B <: NumericOptType]: Coerce[A, B] with | ||
override type Coerced = CommonNumericNullableType[A, B] | ||
given nullableSecond[A <: FinalDataType & NonNullable, B <: FinalDataType & Nullable](using A <:< NonNullableOf[B]): Coerce[A, B] with | ||
override type Coerced = B | ||
|
||
given nonNullable[A <: NumericType, B <: NumericType]: Coerce[A, B] with | ||
override type Coerced = CommonNumericNonNullableType[A, B] | ||
trait CoerceLowPrio: | ||
given numeric[A <: FinalDataType & DoubleOptLike, B <: FinalDataType & DoubleOptLike]: (Coerce[A, B] { type Coerced = CommonNumericType[A, B] }) = | ||
new Coerce[A, B]: | ||
override type Coerced = CommonNumericType[A, B] |
Oops, something went wrong.