-
Notifications
You must be signed in to change notification settings - Fork 25
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* WIP * tokenize Nullable Functions * clean up tests * Don't make Column sealed (allow extension) --------- Co-authored-by: Sjoerd Mulder <[email protected]> Co-authored-by: Tayfun Oztemel <[email protected]>
- Loading branch information
1 parent
61f347d
commit 2531f25
Showing
11 changed files
with
187 additions
and
149 deletions.
There are no files selected for viewing
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
44 changes: 44 additions & 0 deletions
44
dsl/src/main/scala/com/crobox/clickhouse/dsl/column/NullableFunctions.scala
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 |
---|---|---|
@@ -0,0 +1,44 @@ | ||
package com.crobox.clickhouse.dsl.column | ||
|
||
import com.crobox.clickhouse.dsl.{Column, ExpressionColumn} | ||
|
||
trait NullableFunctions { self: Magnets => | ||
|
||
sealed trait NullableFunction | ||
|
||
sealed abstract class AbsNullableFunction[+V](val innerCol: Column) | ||
extends ExpressionColumn[V](innerCol) | ||
with NullableFunction | ||
|
||
case class IsNull(col: ConstOrColMagnet[_]) extends AbsNullableFunction[Boolean](col.column) | ||
case class IsNullable(col: ConstOrColMagnet[_]) extends AbsNullableFunction[Boolean](col.column) | ||
case class IsNotNull(col: ConstOrColMagnet[_]) extends AbsNullableFunction[Boolean](col.column) | ||
case class IsZeroOrNull(col: ConstOrColMagnet[_]) extends AbsNullableFunction[Boolean](col.column) | ||
case class AssumeNotNull(col: ConstOrColMagnet[_]) extends AbsNullableFunction(col.column) | ||
case class ToNullable(col: ConstOrColMagnet[_]) extends AbsNullableFunction(col.column) | ||
case class IfNull(col: ConstOrColMagnet[_], alt: ConstOrColMagnet[_]) extends AbsNullableFunction(col.column) | ||
case class NullIf(col: ConstOrColMagnet[_], other: ConstOrColMagnet[_]) extends AbsNullableFunction(col.column) | ||
|
||
trait NullableOps { | ||
self: ConstOrColMagnet[_] => | ||
|
||
def isNull(): IsNull = IsNull(self) | ||
def isNullable(): IsNullable = IsNullable(self) | ||
def isNotNull(): IsNotNull = IsNotNull(self) | ||
def isZeroOrNull(): IsZeroOrNull = IsZeroOrNull(self) | ||
def ifNull(alternative: ConstOrColMagnet[_]): IfNull = IfNull(self, alternative) | ||
def nullIf(other: ConstOrColMagnet[_]): NullIf = NullIf(self, other) | ||
def assumeNotNull(): AssumeNotNull = AssumeNotNull(self) | ||
def toNullable(): ToNullable = ToNullable(self) | ||
|
||
} | ||
|
||
def isNull(col: ConstOrColMagnet[_]): IsNull = IsNull(col) | ||
def isNullable(col: ConstOrColMagnet[_]): IsNullable = IsNullable(col) | ||
def isNotNull(col: ConstOrColMagnet[_]): IsNotNull = IsNotNull(col) | ||
def isZeroOrNull(col: ConstOrColMagnet[_]): IsZeroOrNull = IsZeroOrNull(col) | ||
def ifNull(col: ConstOrColMagnet[_], alternative: ConstOrColMagnet[_]): IfNull = IfNull(col, alternative) | ||
def nullIf(col: ConstOrColMagnet[_], other: ConstOrColMagnet[_]): NullIf = NullIf(col, other) | ||
def assumeNotNull(col: ConstOrColMagnet[_]): AssumeNotNull = AssumeNotNull(col) | ||
def toNullable(col: ConstOrColMagnet[_]): ToNullable = ToNullable(col) | ||
} |
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
19 changes: 19 additions & 0 deletions
19
dsl/src/main/scala/com/crobox/clickhouse/dsl/language/NullableFunctionTokenizer.scala
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 |
---|---|---|
@@ -0,0 +1,19 @@ | ||
package com.crobox.clickhouse.dsl.language | ||
|
||
import com.crobox.clickhouse.dsl._ | ||
|
||
trait NullableFunctionTokenizer { | ||
self: ClickhouseTokenizerModule => | ||
|
||
protected def tokenizeNullableFunction(col: NullableFunction)(implicit ctx: TokenizeContext): String = | ||
col match { | ||
case IsNull(c) => s"isNull(${tokenizeColumn(c.column)})" | ||
case IsNullable(c) => s"isNullable(${tokenizeColumn(c.column)})" | ||
case IsNotNull(c) => s"isNotNull(${tokenizeColumn(c.column)})" | ||
case IsZeroOrNull(c) => s"isZeroOrNull(${tokenizeColumn(c.column)})" | ||
case AssumeNotNull(c) => s"assumeNotNull(${tokenizeColumn(c.column)})" | ||
case ToNullable(c) => s"toNullable(${tokenizeColumn(c.column)})" | ||
case IfNull(c, alt) => s"ifNull(${tokenizeColumn(c.column)}, ${tokenizeColumn(alt.column)})" | ||
case NullIf(c, o) => s"nullIf(${tokenizeColumn(c.column)}, ${tokenizeColumn(o.column)})" | ||
} | ||
} |
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
Oops, something went wrong.